Version 4.0.0.1, tag libreoffice-4.0.0.1
[LibreOffice.git] / dbaccess / source / core / inc / SingleSelectQueryComposer.hxx
blob34166c26b6b4ce3dbecfccc88b82f5c148ace277
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 #ifndef DBACCESS_CORE_API_SINGLESELECTQUERYCOMPOSER_HXX
20 #define DBACCESS_CORE_API_SINGLESELECTQUERYCOMPOSER_HXX
22 #include <com/sun/star/sdb/XParametersSupplier.hpp>
23 #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
24 #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
25 #include <com/sun/star/sdb/XSingleSelectQueryComposer.hpp>
26 #include <com/sun/star/lang/XServiceInfo.hpp>
27 #include <com/sun/star/script/XTypeConverter.hpp>
28 #include <cppuhelper/implbase5.hxx>
29 #include <connectivity/sqliterator.hxx>
30 #include <connectivity/sqlparse.hxx>
31 #include "apitools.hxx"
32 #include <comphelper/broadcasthelper.hxx>
33 #include <comphelper/uno3.hxx>
34 #include <comphelper/proparrhlp.hxx>
35 #include <comphelper/propertycontainer.hxx>
36 #include <comphelper/componentcontext.hxx>
38 #include <memory>
40 namespace com { namespace sun { namespace star { namespace util {
41 class XNumberFormatsSupplier;
42 class XNumberFormatter;
43 }}}}
45 namespace dbaccess
47 typedef ::cppu::ImplHelper5< ::com::sun::star::sdb::XSingleSelectQueryComposer,
48 ::com::sun::star::sdb::XParametersSupplier,
49 ::com::sun::star::sdbcx::XColumnsSupplier,
50 ::com::sun::star::sdbcx::XTablesSupplier,
51 ::com::sun::star::lang::XServiceInfo > OSingleSelectQueryComposer_BASE;
53 class OPrivateColumns;
54 class OPrivateTables;
56 class OSingleSelectQueryComposer : public ::comphelper::OMutexAndBroadcastHelper
57 ,public OSubComponent
58 ,public ::comphelper::OPropertyContainer
59 ,public ::comphelper::OPropertyArrayUsageHelper < OSingleSelectQueryComposer >
60 ,public OSingleSelectQueryComposer_BASE
62 enum SQLPart
64 Where = 0, // the 0 is important, as it will be used as index into arrays
65 Group,
66 Having,
67 Order,
69 SQLPartCount
71 inline void incSQLPart( SQLPart& e ) { e = (SQLPart)(1 + (size_t)e); }
72 enum EColumnType
74 SelectColumns = 0,
75 GroupByColumns = 1,
76 OrderColumns = 2,
77 ParameterColumns = 3
79 typedef ::std::const_mem_fun_t< const ::connectivity::OSQLParseNode*, ::connectivity::OSQLParseTreeIterator >
80 TGetParseNode;
81 ::connectivity::OSQLParser m_aSqlParser;
82 ::connectivity::OSQLParseTreeIterator m_aSqlIterator; // the iterator for the complete statement
83 ::connectivity::OSQLParseTreeIterator m_aAdditiveIterator; // the iterator for the "additive statement" (means without the clauses of the elementary statement)
84 ::std::vector<OPrivateColumns*> m_aColumnsCollection; // used for columns and parameters of old queries
85 ::std::vector<OPrivateTables*> m_aTablesCollection;
87 ::std::vector< ::rtl::OUString > m_aElementaryParts; // the filter/groupby/having/order of the elementary statement
89 ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection> m_xConnection;
90 ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDatabaseMetaData> m_xMetaData;
91 ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess> m_xConnectionTables;
92 ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess> m_xConnectionQueries;
93 ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatsSupplier > m_xNumberFormatsSupplier;
94 ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess> m_xColumns;
95 ::comphelper::ComponentContext m_aContext;
96 ::com::sun::star::uno::Reference< ::com::sun::star::script::XTypeConverter > m_xTypeConverter;
98 ::std::vector<OPrivateColumns*> m_aCurrentColumns;
99 OPrivateTables* m_pTables; // currently used tables
101 ::rtl::OUString m_aPureSelectSQL; // the pure select statement, without filter/order/groupby/having
102 ::rtl::OUString m_sDecimalSep;
103 ::rtl::OUString m_sCommand;
104 ::com::sun::star::lang::Locale m_aLocale;
105 sal_Int32 m_nBoolCompareMode; // how to compare bool values
106 sal_Int32 m_nCommandType;
108 // <properties>
109 ::rtl::OUString m_sOrignal;
110 // </properties>
113 sal_Bool setORCriteria(::connectivity::OSQLParseNode* pCondition, ::connectivity::OSQLParseTreeIterator& _rIterator,
114 ::std::vector< ::std::vector < ::com::sun::star::beans::PropertyValue > >& rFilters, const ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatter > & xFormatter) const;
115 sal_Bool setANDCriteria(::connectivity::OSQLParseNode* pCondition, ::connectivity::OSQLParseTreeIterator& _rIterator,
116 ::std::vector < ::com::sun::star::beans::PropertyValue > & rFilters, const ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatter > & xFormatter) const;
117 sal_Bool setComparsionPredicate(::connectivity::OSQLParseNode* pCondition, ::connectivity::OSQLParseTreeIterator& _rIterator,
118 ::std::vector < ::com::sun::star::beans::PropertyValue > & rFilters, const ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatter > & xFormatter) const;
120 ::rtl::OUString getColumnName(::connectivity::OSQLParseNode* pColumnRef,::connectivity::OSQLParseTreeIterator& _rIterator) const;
121 ::rtl::OUString getTableAlias(const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& column ) const;
122 sal_Int32 getPredicateType(::connectivity::OSQLParseNode * _pPredicate) const;
123 // clears all Columns,Parameters and tables and insert it to their vectors
124 void clearCurrentCollections();
125 // clears the columns collection given by EColumnType
126 void clearColumns( const EColumnType _eType );
128 /** retrieves a particular part of a statement
129 @param _rIterator
130 the iterator to use.
132 ::rtl::OUString getStatementPart( TGetParseNode& _aGetFunctor, ::connectivity::OSQLParseTreeIterator& _rIterator );
133 void setQuery_Impl( const ::rtl::OUString& command );
135 void setConditionByColumn( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& column
136 , sal_Bool andCriteria
137 ,::std::mem_fun1_t<bool,OSingleSelectQueryComposer,::rtl::OUString>& _aSetFunctor
138 ,sal_Int32 filterOperator);
140 /** getStructuredCondition returns the structured condition for the where or having clause
141 @param _aGetFunctor
142 A member function to get the correct parse node.
144 @return
145 The structured filter
147 ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > >
148 getStructuredCondition( TGetParseNode& _aGetFunctor );
150 ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexAccess >
151 setCurrentColumns( EColumnType _eType, const ::rtl::Reference< ::connectivity::OSQLColumns >& _rCols );
153 //helper methods for mem_fun_t
154 inline bool implSetFilter(::rtl::OUString _sFilter) { setFilter(_sFilter); return true;}
155 inline bool implSetHavingClause(::rtl::OUString _sFilter) { setHavingClause(_sFilter); return true;}
157 /** returns the part of the seelect statement
158 @param _ePart
159 Which part should be returned.
160 @param _bWithKeyword
161 If <TRUE/> the keyword will be added too. Otherwise not.
162 @param _rIterator
163 The iterator to use.
165 @return
166 The part of the select statement.
168 ::rtl::OUString getSQLPart( SQLPart _ePart, ::connectivity::OSQLParseTreeIterator& _rIterator, sal_Bool _bWithKeyword );
170 /** retrieves the keyword for the given SQLPart
172 ::rtl::OUString getKeyword( SQLPart _ePart ) const;
174 /** sets a single "additive" clause, means a filter/groupby/having/order clause
176 void setSingleAdditiveClause( SQLPart _ePart, const ::rtl::OUString& _rClause );
178 /** composes a statement from m_aPureSelectSQL and the 4 usual clauses
180 ::rtl::OUString composeStatementFromParts( const ::std::vector< ::rtl::OUString >& _rParts );
182 /** return the name of the column.
184 ::rtl::OUString impl_getColumnName_throw(const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& column);
186 protected:
187 virtual ~OSingleSelectQueryComposer();
188 public:
190 OSingleSelectQueryComposer( const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess>& _xTableSupplier,
191 const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection>& _xConnection,
192 const ::comphelper::ComponentContext& _rContext);
195 void SAL_CALL disposing(void);
196 // ::com::sun::star::lang::XTypeProvider
197 DECLARE_TYPEPROVIDER( );
199 // com::sun::star::lang::XUnoTunnel
200 virtual sal_Int64 SAL_CALL getSomething( const ::com::sun::star::uno::Sequence< sal_Int8 >& aIdentifier ) throw(::com::sun::star::uno::RuntimeException);
201 // ::com::sun::star::uno::XInterface
202 DECLARE_XINTERFACE( )
204 // XServiceInfo
205 DECLARE_SERVICE_INFO();
207 DECLARE_PROPERTYCONTAINER_DEFAULTS();
209 // ::com::sun::star::sdb::XSingleSelectQueryComposer
210 virtual ::rtl::OUString SAL_CALL getElementaryQuery() throw (::com::sun::star::uno::RuntimeException);
211 virtual void SAL_CALL setElementaryQuery( const ::rtl::OUString& _rElementary ) throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
212 virtual void SAL_CALL setFilter( const ::rtl::OUString& filter ) throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
213 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);
214 virtual void SAL_CALL appendFilterByColumn( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& column, sal_Bool andCriteria,sal_Int32 filterOperator ) throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
215 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);
216 virtual void SAL_CALL setGroup( const ::rtl::OUString& group ) throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
217 virtual void SAL_CALL setHavingClause( const ::rtl::OUString& filter ) throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
218 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);
219 virtual void SAL_CALL appendHavingClauseByColumn( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& column, sal_Bool andCriteria,sal_Int32 filterOperator ) throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
220 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);
221 virtual void SAL_CALL setOrder( const ::rtl::OUString& order ) throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
223 // XSingleSelectQueryAnalyzer
224 virtual ::rtl::OUString SAL_CALL getQuery( ) throw (::com::sun::star::uno::RuntimeException);
225 virtual void SAL_CALL setQuery( const ::rtl::OUString& command ) throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
226 virtual void SAL_CALL setCommand( const ::rtl::OUString& command,sal_Int32 CommandType ) throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
227 virtual ::rtl::OUString SAL_CALL getFilter( ) throw (::com::sun::star::uno::RuntimeException);
228 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);
229 virtual ::rtl::OUString SAL_CALL getGroup( ) throw (::com::sun::star::uno::RuntimeException);
230 virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexAccess > SAL_CALL getGroupColumns( ) throw (::com::sun::star::uno::RuntimeException);
231 virtual ::rtl::OUString SAL_CALL getHavingClause( ) throw (::com::sun::star::uno::RuntimeException);
232 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);
233 virtual ::rtl::OUString SAL_CALL getOrder( ) throw (::com::sun::star::uno::RuntimeException);
234 virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexAccess > SAL_CALL getOrderColumns( ) throw (::com::sun::star::uno::RuntimeException);
235 virtual ::rtl::OUString SAL_CALL getQueryWithSubstitution( ) throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
237 // XColumnsSupplier
238 virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > SAL_CALL getColumns( ) throw(::com::sun::star::uno::RuntimeException);
239 // XTablesSupplier
240 virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > SAL_CALL getTables( ) throw(::com::sun::star::uno::RuntimeException);
241 // XParametersSupplier
242 virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexAccess > SAL_CALL getParameters( ) throw(::com::sun::star::uno::RuntimeException);
245 #endif // DBACCESS_CORE_API_SINGLESELECTQUERYCOMPOSER_HXX
247 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */