1/**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements.  See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership.  The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License.  You may obtain a copy of the License at
10 *
11 *   http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied.  See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23#ifndef __com_sun_star_sdb_XSingleSelectQueryAnalyzer_idl__
24#define __com_sun_star_sdb_XSingleSelectQueryAnalyzer_idl__
25
26#ifndef __com_sun_star_beans_XPropertySet_idl__
27#include <com/sun/star/beans/XPropertySet.idl>
28#endif
29
30#ifndef __com_sun_star_beans_PropertyValue_idl__
31#include <com/sun/star/beans/PropertyValue.idl>
32#endif
33
34#ifndef __com_sun_star_sdbc_SQLException_idl__
35#include <com/sun/star/sdbc/SQLException.idl>
36#endif
37
38module com {  module sun {  module star {  module container {
39published interface XIndexAccess;
40};};};};
41//=============================================================================
42
43 module com {  module sun {  module star {  module sdb {
44
45//=============================================================================
46
47/** simplifies the analyzing of single select statements.
48
49    <p>
50    The interface can be used for analyzing single SELECT statements without knowing the
51    structure of the used query.
52    </p>
53 */
54published interface XSingleSelectQueryAnalyzer : com::sun::star::uno::XInterface
55{
56
57    /** returns the query.
58        @returns
59            the query
60     */
61    string getQuery();
62    //-------------------------------------------------------------------------
63
64    /** sets a new query for the composer, which may be expanded by filters, group by, having
65        and sort criteria.
66        @param command
67            the single select statement to set
68        @throws com::sun::star::sdbc::SQLException
69            if a database access error occurs
70            or the statement isn't a single select statement
71            or the statement isn't valid
72            or the statement can not be parsed.
73     */
74    void setQuery([in] string command )
75            raises (com::sun::star::sdbc::SQLException);
76    //-------------------------------------------------------------------------
77    // FILTER
78    //-------------------------------------------------------------------------
79
80    /** returns the used filter.
81        <p>
82        The filter criteria returned is part of the where condition of the
83        select command, but it does not contain the where token.
84        </p>
85        @returns
86            the filter
87     */
88    string getFilter();
89    //-------------------------------------------------------------------------
90
91    /** returns the currently used filter.
92             <p>
93             The filter criteria is split into levels. Each level represents the
94             OR criteria. Within each level, the filters are provided as an AND criteria
95             with the name of the column and the filter condition. The filter condition
96             is of type string. The operator used, is defined by <type scope="com::sun::star::sdb">SQLFilterOperator</type>.
97             </p>
98        @returns
99            the structured filter
100     */
101    sequence< sequence<com::sun::star::beans::PropertyValue> >
102        getStructuredFilter();
103
104    //-------------------------------------------------------------------------
105    // GROUP BY
106    //-------------------------------------------------------------------------
107
108    /** returns the currently used GROUP BY.
109        <p>
110        The group criteria returned is part of the GROUP BY clause of the
111        select command, but it does not contain the GROUP BY keyword .
112        </p>
113        @returns
114            the group
115     */
116    string getGroup();
117
118    //-------------------------------------------------------------------------
119    /** returns the currently used group.
120        <p>
121        The columns returned form the GROUP BY clause.
122        </p>
123        @returns
124            a collection of <type scope="com::sun::star::sdb">GroupColumn</type> which form the GROUP BY.
125     */
126    com::sun::star::container::XIndexAccess getGroupColumns();
127
128    //-------------------------------------------------------------------------
129    // HAVING
130    //-------------------------------------------------------------------------
131
132    /** returns the used HAVING filter.
133        <p>
134        The HAVING filter criteria returned is part of the HAVING condition of the
135        select command, but it does not contain the HAVING token.
136        </p>
137        @returns
138            the filter
139     */
140    string getHavingClause();
141    //-------------------------------------------------------------------------
142
143    /** returns the currently used HAVING filter.
144             <p>
145             The HAVING filter criteria is split into levels. Each level represents the
146             OR criteria. Within each level, the filters are provided as an AND criteria
147             with the name of the column and the filter condition. The filter condition
148             is of type string. The operator used, is defined by <type scope="com::sun::star::sdb">SQLFilterOperator</type>.
149             </p>
150        @returns
151            the structured HAVING filter
152     */
153    sequence< sequence<com::sun::star::beans::PropertyValue> >
154        getStructuredHavingClause();
155
156    //-------------------------------------------------------------------------
157    // ORDER BY
158    //-------------------------------------------------------------------------
159    /** returns the currently used sort order.
160        <p>
161        The order criteria returned is part of the ORDER BY clause of the
162        select command, but it does not contain the ORDER BY keyword .
163        </p>
164        @returns
165            the order
166     */
167    string getOrder();
168
169    //-------------------------------------------------------------------------
170    /** returns the currently used sort order.
171        <p>
172        The order criteria returned is part of the ORDER BY clause of the
173        select command, but it does not contain the ORDER BY keyword .
174        </p>
175        @returns
176            a collection of <type scope="com::sun::star::sdb">OrderColumn</type> which form the ORDER BY.
177     */
178    com::sun::star::container::XIndexAccess getOrderColumns();
179
180    //-------------------------------------------------------------------------
181    /** returns the query previously set at the analyzer, with all application-level
182        features being substituted by their database-level counterparts.
183
184        <p>The <type>XSingleSelectQueryAnalyzer</type> is an application-level component,
185        which in some respect understands SQL features usually not present at the database
186        level. As a prominent example, you might pass a <code>SELECT</code> statement to the analyzer
187        which is based on another query.</p>
188
189        <p>While all other methods will handle those additional features transparently - e.g.
190        the query in the <code>FROM</code> part of a <code>SELECT</code> statement will be handled
191        as if it really is a table -, <code>getQueryWithSubstitution</code> gives you the SQL statement
192        where all those features have been stripped, and replaced with appropriate standard SQL.</p>
193
194        <p>For example, consider a database document which contains a client-side query named <code>All Orders</code>.
195        This query is not known to the underlying database, so an SQL statement like
196        <code>SELECT * from "All Orders"</code> would be rejected by the database. However, instantiating
197        a <type>SingleSelectQueryAnalyzer</type> at the <type>Connection</type> object, and passing it the above query,
198        you can then use <code>getQueryWithSubstitution</code> to retrieve a statement where <code>"All Orders"</code>
199        has been replaced with the <code>SELECT</code> statement which actually constitutes the <code>"All Orders"</code>
200        query.</p>
201
202        @throws com::sun::star::sdbc::SQLException
203            if the query represented cannot be completely substituted. A usual case for this is a recursion in
204            the sub queries: Consider a query named <code>foo</code>, which is defined as <code>SELECT * FROM "bar"</code>.
205            Now assume that <code>bar</code> is a query defined as <code>SELECT * FROM "foo"</code>. Passing either
206            of those statements to an analyzer, and calling <member>getQueryWithSubstitution</member>, would result
207            in an exception being thrown, since it's impossible to substitute the sub queries with their
208            constituting statements.
209
210        @see Connection
211        @see XQueriesSupplier
212        @see DatabaseDocument
213
214        @since OpenOffice 2.0.4
215    */
216    string getQueryWithSubstitution()
217        raises (com::sun::star::sdbc::SQLException);
218
219    /** sets a new query for the composer, which may be expanded by filters, group by, having
220        and sort criteria.
221        @param Command
222            is the command which should be executed, the type of command depends
223            on the CommandType.
224
225            <p>In case of a <member>CommandType</member> of <member>CommandType::COMMAND</member>,
226            means in case the <member>Command</member> specifies an SQL statement, the inherited
227            <member scope="com::sun::star::sdbc">RowSet::EscapeProcessing</member>
228            becomes relevant:<br/>
229            It then can be to used to specify whether the SQL statement should be analyzed on the
230            client side before sending it to the database server.<br/>
231            The default value for <member scope="com::sun::star::sdbc">RowSet::EscapeProcessing</member>
232            is <TRUE/>. By switching it to <FALSE/>, you can pass backend-specific SQL statements,
233            which are not standard SQL, to your database.</p>
234
235            @see com::sun::star::sdb::CommandType
236            @see com::sun::star::sdbc::RowSet::EscapeProcessing
237        @param  CommandType
238            is the type of the command.
239            @see com::sun::star::sdb::CommandType
240        @throws com::sun::star::sdbc::SQLException
241            if a database access error occurs
242            or the statement isn't a single select statement
243            or the statement isn't valid
244            or the statement can not be parsed.
245     */
246    void setCommand([in] string Command ,[in] long CommandType)
247            raises (com::sun::star::sdbc::SQLException);
248};
249
250//=============================================================================
251
252}; }; }; };
253
254/*=============================================================================
255
256=============================================================================*/
257#endif
258
259