merge the formfield patch from ooo-build
[ooovba.git] / dbaccess / source / core / inc / SingleSelectQueryComposer.hxx
blob0943b6a85cf1990c7b87d6a1fb1e11a25949c403
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: SingleSelectQueryComposer.hxx,v $
10 * $Revision: 1.9 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
30 #ifndef DBACCESS_CORE_API_SINGLESELECTQUERYCOMPOSER_HXX
31 #define DBACCESS_CORE_API_SINGLESELECTQUERYCOMPOSER_HXX
33 #ifndef _COM_SUN_STAR_SDB_XPARAMETERSSUPPLIER_HPP_
34 #include <com/sun/star/sdb/XParametersSupplier.hpp>
35 #endif
36 #ifndef _COM_SUN_STAR_SDBCX_XTABLESSUPPLIER_HPP_
37 #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
38 #endif
39 #ifndef _COM_SUN_STAR_SDBCX_XCOLUMNSSUPPLIER_HPP_
40 #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
41 #endif
42 #ifndef _COM_SUN_STAR_SDB_XSINGLESELECTQUERYCOMPOSER_HPP_
43 #include <com/sun/star/sdb/XSingleSelectQueryComposer.hpp>
44 #endif
45 #ifndef _COM_SUN_STAR_LANG_XSERVICEINFO_HPP_
46 #include <com/sun/star/lang/XServiceInfo.hpp>
47 #endif
48 #ifndef _COM_SUN_STAR_SCRIPT_XTYPECONVERTER_HPP_
49 #include <com/sun/star/script/XTypeConverter.hpp>
50 #endif
51 #ifndef _CPPUHELPER_IMPLBASE5_HXX_
52 #include <cppuhelper/implbase5.hxx>
53 #endif
54 #ifndef _CONNECTIVITY_PARSE_SQLITERATOR_HXX_
55 #include <connectivity/sqliterator.hxx>
56 #endif
57 #ifndef _CONNECTIVITY_SQLPARSE_HXX
58 #include <connectivity/sqlparse.hxx>
59 #endif
60 #ifndef _DBASHARED_APITOOLS_HXX_
61 #include "apitools.hxx"
62 #endif
63 #ifndef _COMPHELPER_BROADCASTHELPER_HXX_
64 #include <comphelper/broadcasthelper.hxx>
65 #endif
66 #ifndef _COMPHELPER_UNO3_HXX_
67 #include <comphelper/uno3.hxx>
68 #endif
69 #ifndef _COMPHELPER_PROPERTY_ARRAY_HELPER_HXX_
70 #include <comphelper/proparrhlp.hxx>
71 #endif
72 #ifndef _COMPHELPER_PROPERTYCONTAINER_HXX_
73 #include <comphelper/propertycontainer.hxx>
74 #endif
75 #ifndef COMPHELPER_COMPONENTCONTEXT_HXX
76 #include <comphelper/componentcontext.hxx>
77 #endif
79 #include <memory>
81 namespace com { namespace sun { namespace star { namespace util {
82 class XNumberFormatsSupplier;
83 class XNumberFormatter;
84 }}}}
86 namespace dbaccess
88 typedef ::cppu::ImplHelper5< ::com::sun::star::sdb::XSingleSelectQueryComposer,
89 ::com::sun::star::sdb::XParametersSupplier,
90 ::com::sun::star::sdbcx::XColumnsSupplier,
91 ::com::sun::star::sdbcx::XTablesSupplier,
92 ::com::sun::star::lang::XServiceInfo > OSingleSelectQueryComposer_BASE;
94 class OPrivateColumns;
95 class OPrivateTables;
97 class OSingleSelectQueryComposer : public ::comphelper::OMutexAndBroadcastHelper
98 ,public OSubComponent
99 ,public ::comphelper::OPropertyContainer
100 ,public ::comphelper::OPropertyArrayUsageHelper < OSingleSelectQueryComposer >
101 ,public OSingleSelectQueryComposer_BASE
103 enum SQLPart
105 Where = 0, // the 0 is important, as it will be used as index into arrays
106 Group,
107 Having,
108 Order,
110 SQLPartCount
112 inline void incSQLPart( SQLPart& e ) { e = (SQLPart)(1 + (size_t)e); }
113 enum EColumnType
115 SelectColumns = 0,
116 GroupByColumns = 1,
117 OrderColumns = 2,
118 ParameterColumns = 3
120 typedef ::std::const_mem_fun_t< const ::connectivity::OSQLParseNode*, ::connectivity::OSQLParseTreeIterator >
121 TGetParseNode;
122 ::connectivity::OSQLParser m_aSqlParser;
123 ::connectivity::OSQLParseTreeIterator m_aSqlIterator; // the iterator for the complete statement
124 ::connectivity::OSQLParseTreeIterator m_aAdditiveIterator; // the iterator for the "additive statement" (means without the clauses of the elementary statement)
125 ::std::vector<OPrivateColumns*> m_aColumnsCollection; // used for columns and parameters of old queries
126 ::std::vector<OPrivateTables*> m_aTablesCollection;
128 ::std::vector< ::rtl::OUString > m_aElementaryParts; // the filter/groupby/having/order of the elementary statement
130 ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection> m_xConnection;
131 ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDatabaseMetaData> m_xMetaData;
132 ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess> m_xConnectionTables;
133 ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatsSupplier > m_xNumberFormatsSupplier;
134 ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess> m_xColumns;
135 ::comphelper::ComponentContext m_aContext;
136 ::com::sun::star::uno::Reference< ::com::sun::star::script::XTypeConverter > m_xTypeConverter;
138 ::std::vector<OPrivateColumns*> m_aCurrentColumns;
139 OPrivateTables* m_pTables; // currently used tables
141 ::rtl::OUString m_aPureSelectSQL; // the pure select statement, without filter/order/groupby/having
142 ::rtl::OUString m_sDecimalSep;
143 ::com::sun::star::lang::Locale m_aLocale;
144 sal_Int32 m_nBoolCompareMode; // how to compare bool values
146 // <properties>
147 ::rtl::OUString m_sOrignal;
148 // </properties>
151 sal_Bool setORCriteria(::connectivity::OSQLParseNode* pCondition, ::connectivity::OSQLParseTreeIterator& _rIterator,
152 ::std::vector< ::std::vector < ::com::sun::star::beans::PropertyValue > >& rFilters, const ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatter > & xFormatter) const;
153 sal_Bool setANDCriteria(::connectivity::OSQLParseNode* pCondition, ::connectivity::OSQLParseTreeIterator& _rIterator,
154 ::std::vector < ::com::sun::star::beans::PropertyValue > & rFilters, const ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatter > & xFormatter) const;
155 sal_Bool setComparsionPredicate(::connectivity::OSQLParseNode* pCondition, ::connectivity::OSQLParseTreeIterator& _rIterator,
156 ::std::vector < ::com::sun::star::beans::PropertyValue > & rFilters, const ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatter > & xFormatter) const;
158 ::rtl::OUString getColumnName(::connectivity::OSQLParseNode* pColumnRef,::connectivity::OSQLParseTreeIterator& _rIterator) const;
159 ::rtl::OUString getTableAlias(const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& column ) const;
160 sal_Int32 getPredicateType(::connectivity::OSQLParseNode * _pPredicate) const;
161 // clears all Columns,Parameters and tables and insert it to their vectors
162 void clearCurrentCollections();
163 // clears the columns collection given by EColumnType
164 void clearColumns( const EColumnType _eType );
166 /** retrieves a particular part of a statement
167 @param _rIterator
168 the iterator to use.
170 ::rtl::OUString getStatementPart( TGetParseNode& _aGetFunctor, ::connectivity::OSQLParseTreeIterator& _rIterator );
171 void setQuery_Impl( const ::rtl::OUString& command );
173 void setConditionByColumn( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& column
174 , sal_Bool andCriteria
175 ,::std::mem_fun1_t<bool,OSingleSelectQueryComposer,::rtl::OUString>& _aSetFunctor);
178 /** getStructuredCondition returns the structured condition for the where or having clause
179 @param _aGetFunctor
180 A member function to get the correct parse node.
182 @return
183 The structured filter
185 ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > >
186 getStructuredCondition( TGetParseNode& _aGetFunctor );
188 ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexAccess >
189 setCurrentColumns( EColumnType _eType, const ::vos::ORef< ::connectivity::OSQLColumns >& _rCols );
191 //helper methods for mem_fun_t
192 inline bool implSetFilter(::rtl::OUString _sFilter) { setFilter(_sFilter); return true;}
193 inline bool implSetHavingClause(::rtl::OUString _sFilter) { setHavingClause(_sFilter); return true;}
195 /** returns the part of the seelect statement
196 @param _ePart
197 Which part should be returned.
198 @param _bWithKeyword
199 If <TRUE/> the keyword will be added too. Otherwise not.
200 @param _rIterator
201 The iterator to use.
203 @return
204 The part of the select statement.
206 ::rtl::OUString getSQLPart( SQLPart _ePart, ::connectivity::OSQLParseTreeIterator& _rIterator, sal_Bool _bWithKeyword );
208 /** retrieves the keyword for the given SQLPart
210 ::rtl::OUString getKeyword( SQLPart _ePart ) const;
212 /** sets a single "additive" clause, means a filter/groupby/having/order clause
214 void setSingleAdditiveClause( SQLPart _ePart, const ::rtl::OUString& _rClause );
216 /** composes a statement from m_aPureSelectSQL and the 4 usual clauses
218 ::rtl::OUString composeStatementFromParts( const ::std::vector< ::rtl::OUString >& _rParts );
220 /** return the name of the column.
222 ::rtl::OUString impl_getColumnName_throw(const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& column);
224 protected:
225 virtual ~OSingleSelectQueryComposer();
226 public:
228 OSingleSelectQueryComposer( const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess>& _xTableSupplier,
229 const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection>& _xConnection,
230 const ::comphelper::ComponentContext& _rContext);
233 void SAL_CALL disposing(void);
234 // ::com::sun::star::lang::XTypeProvider
235 DECLARE_TYPEPROVIDER( );
237 // com::sun::star::lang::XUnoTunnel
238 virtual sal_Int64 SAL_CALL getSomething( const ::com::sun::star::uno::Sequence< sal_Int8 >& aIdentifier ) throw(::com::sun::star::uno::RuntimeException);
239 // ::com::sun::star::uno::XInterface
240 DECLARE_XINTERFACE( )
242 // XServiceInfo
243 DECLARE_SERVICE_INFO();
245 DECLARE_PROPERTYCONTAINER_DEFAULTS();
247 // ::com::sun::star::sdb::XSingleSelectQueryComposer
248 virtual ::rtl::OUString SAL_CALL getElementaryQuery() throw (::com::sun::star::uno::RuntimeException);
249 virtual void SAL_CALL setElementaryQuery( const ::rtl::OUString& _rElementary ) throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
250 virtual void SAL_CALL setFilter( const ::rtl::OUString& filter ) throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
251 virtual void SAL_CALL setStructuredFilter( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > >& filter ) throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException);
252 virtual void SAL_CALL appendFilterByColumn( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& column, sal_Bool andCriteria ) throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
253 virtual void SAL_CALL appendGroupByColumn( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& column ) throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
254 virtual void SAL_CALL setGroup( const ::rtl::OUString& group ) throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
255 virtual void SAL_CALL setHavingClause( const ::rtl::OUString& filter ) throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
256 virtual void SAL_CALL setStructuredHavingClause( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > >& filter ) throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
257 virtual void SAL_CALL appendHavingClauseByColumn( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& column, sal_Bool andCriteria ) throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
258 virtual void SAL_CALL appendOrderByColumn( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& column, sal_Bool ascending ) throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
259 virtual void SAL_CALL setOrder( const ::rtl::OUString& order ) throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
261 // XSingleSelectQueryAnalyzer
262 virtual ::rtl::OUString SAL_CALL getQuery( ) throw (::com::sun::star::uno::RuntimeException);
263 virtual void SAL_CALL setQuery( const ::rtl::OUString& command ) throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
264 virtual ::rtl::OUString SAL_CALL getFilter( ) throw (::com::sun::star::uno::RuntimeException);
265 virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > > SAL_CALL getStructuredFilter( ) throw (::com::sun::star::uno::RuntimeException);
266 virtual ::rtl::OUString SAL_CALL getGroup( ) throw (::com::sun::star::uno::RuntimeException);
267 virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexAccess > SAL_CALL getGroupColumns( ) throw (::com::sun::star::uno::RuntimeException);
268 virtual ::rtl::OUString SAL_CALL getHavingClause( ) throw (::com::sun::star::uno::RuntimeException);
269 virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > > SAL_CALL getStructuredHavingClause( ) throw (::com::sun::star::uno::RuntimeException);
270 virtual ::rtl::OUString SAL_CALL getOrder( ) throw (::com::sun::star::uno::RuntimeException);
271 virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexAccess > SAL_CALL getOrderColumns( ) throw (::com::sun::star::uno::RuntimeException);
272 virtual ::rtl::OUString SAL_CALL getQueryWithSubstitution( ) throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
274 // XColumnsSupplier
275 virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > SAL_CALL getColumns( ) throw(::com::sun::star::uno::RuntimeException);
276 // XTablesSupplier
277 virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > SAL_CALL getTables( ) throw(::com::sun::star::uno::RuntimeException);
278 // XParametersSupplier
279 virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexAccess > SAL_CALL getParameters( ) throw(::com::sun::star::uno::RuntimeException);
282 #endif // DBACCESS_CORE_API_SINGLESELECTQUERYCOMPOSER_HXX