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