2010-10-27 12:33:13 +01:00
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2012-06-14 17:39:53 +01:00
/*
* This file is part of the LibreOffice project .
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License , v . 2.0 . If a copy of the MPL was not distributed with this
* file , You can obtain one at http : //mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice :
*
* Licensed to the Apache Software Foundation ( ASF ) under one or more
* contributor license agreements . See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership . The ASF licenses this file to you under the Apache
* License , Version 2.0 ( the " License " ) ; you may not use this file
* except in compliance with the License . You may obtain a copy of
* the License at http : //www.apache.org/licenses/LICENSE-2.0 .
*/
2003-12-16 11:41:56 +00:00
# ifndef DBACCESS_CORE_API_SINGLESELECTQUERYCOMPOSER_HXX
# define DBACCESS_CORE_API_SINGLESELECTQUERYCOMPOSER_HXX
# include <com/sun/star/sdb/XParametersSupplier.hpp>
# include <com/sun/star/sdbcx/XTablesSupplier.hpp>
# include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
# include <com/sun/star/sdb/XSingleSelectQueryComposer.hpp>
# include <com/sun/star/lang/XServiceInfo.hpp>
# include <com/sun/star/script/XTypeConverter.hpp>
2005-01-05 11:29:15 +00:00
# include <cppuhelper/implbase5.hxx>
2003-12-16 11:41:56 +00:00
# include <connectivity/sqliterator.hxx>
# include <connectivity/sqlparse.hxx>
# include "apitools.hxx"
# include <comphelper/broadcasthelper.hxx>
# include <comphelper/uno3.hxx>
# include <comphelper/proparrhlp.hxx>
# include <comphelper/propertycontainer.hxx>
2013-05-18 08:53:54 +02:00
# include <svx/ParseContext.hxx>
2003-12-16 11:41:56 +00:00
2005-01-05 11:29:15 +00:00
# include <memory>
2003-12-16 11:41:56 +00:00
namespace com { namespace sun { namespace star { namespace util {
class XNumberFormatsSupplier ;
class XNumberFormatter ;
} } } }
namespace dbaccess
{
2005-01-05 11:29:15 +00:00
typedef : : cppu : : ImplHelper5 < : : com : : sun : : star : : sdb : : XSingleSelectQueryComposer ,
2003-12-16 11:41:56 +00:00
: : com : : sun : : star : : sdb : : XParametersSupplier ,
: : com : : sun : : star : : sdbcx : : XColumnsSupplier ,
: : com : : sun : : star : : sdbcx : : XTablesSupplier ,
: : com : : sun : : star : : lang : : XServiceInfo > OSingleSelectQueryComposer_BASE ;
class OPrivateColumns ;
class OPrivateTables ;
class OSingleSelectQueryComposer : public : : comphelper : : OMutexAndBroadcastHelper
, public OSubComponent
, public : : comphelper : : OPropertyContainer
, public : : comphelper : : OPropertyArrayUsageHelper < OSingleSelectQueryComposer >
, public OSingleSelectQueryComposer_BASE
{
enum SQLPart
{
2005-01-05 11:29:15 +00:00
Where = 0 , // the 0 is important, as it will be used as index into arrays
2003-12-16 11:41:56 +00:00
Group ,
Having ,
2005-01-05 11:29:15 +00:00
Order ,
SQLPartCount
2003-12-16 11:41:56 +00:00
} ;
2005-01-05 11:29:15 +00:00
inline void incSQLPart ( SQLPart & e ) { e = ( SQLPart ) ( 1 + ( size_t ) e ) ; }
2003-12-16 11:41:56 +00:00
enum EColumnType
{
SelectColumns = 0 ,
GroupByColumns = 1 ,
OrderColumns = 2 ,
ParameterColumns = 3
} ;
2005-01-05 11:29:15 +00:00
typedef : : std : : const_mem_fun_t < const : : connectivity : : OSQLParseNode * , : : connectivity : : OSQLParseTreeIterator >
TGetParseNode ;
2013-05-18 08:53:54 +02:00
: : svxform : : OSystemParseContext m_aParseContext ;
2003-12-16 11:41:56 +00:00
: : connectivity : : OSQLParser m_aSqlParser ;
2005-01-05 11:29:15 +00:00
: : connectivity : : OSQLParseTreeIterator m_aSqlIterator ; // the iterator for the complete statement
: : connectivity : : OSQLParseTreeIterator m_aAdditiveIterator ; // the iterator for the "additive statement" (means without the clauses of the elementary statement)
: : std : : vector < OPrivateColumns * > m_aColumnsCollection ; // used for columns and parameters of old queries
2003-12-16 11:41:56 +00:00
: : std : : vector < OPrivateTables * > m_aTablesCollection ;
2013-04-07 12:06:47 +02:00
: : std : : vector < OUString > m_aElementaryParts ; // the filter/groupby/having/order of the elementary statement
2005-01-05 11:29:15 +00:00
2003-12-16 11:41:56 +00:00
: : com : : sun : : star : : uno : : Reference < : : com : : sun : : star : : sdbc : : XConnection > m_xConnection ;
: : com : : sun : : star : : uno : : Reference < : : com : : sun : : star : : sdbc : : XDatabaseMetaData > m_xMetaData ;
2006-07-10 14:12:10 +00:00
: : com : : sun : : star : : uno : : Reference < : : com : : sun : : star : : container : : XNameAccess > m_xConnectionTables ;
2010-01-22 08:14:22 +01:00
: : com : : sun : : star : : uno : : Reference < : : com : : sun : : star : : container : : XNameAccess > m_xConnectionQueries ;
2003-12-16 11:41:56 +00:00
: : com : : sun : : star : : uno : : Reference < : : com : : sun : : star : : util : : XNumberFormatsSupplier > m_xNumberFormatsSupplier ;
: : com : : sun : : star : : uno : : Reference < : : com : : sun : : star : : container : : XNameAccess > m_xColumns ;
2013-03-19 13:08:47 +02:00
: : com : : sun : : star : : uno : : Reference < : : com : : sun : : star : : uno : : XComponentContext > m_aContext ;
2003-12-16 11:41:56 +00:00
: : com : : sun : : star : : uno : : Reference < : : com : : sun : : star : : script : : XTypeConverter > m_xTypeConverter ;
: : std : : vector < OPrivateColumns * > m_aCurrentColumns ;
OPrivateTables * m_pTables ; // currently used tables
2013-04-07 12:06:47 +02:00
OUString m_aPureSelectSQL ; // the pure select statement, without filter/order/groupby/having
OUString m_sDecimalSep ;
OUString m_sCommand ;
2003-12-16 11:41:56 +00:00
: : com : : sun : : star : : lang : : Locale m_aLocale ;
sal_Int32 m_nBoolCompareMode ; // how to compare bool values
2010-01-22 08:14:22 +01:00
sal_Int32 m_nCommandType ;
2003-12-16 11:41:56 +00:00
// <properties>
2013-04-07 12:06:47 +02:00
OUString m_sOrignal ;
2003-12-16 11:41:56 +00:00
// </properties>
2005-01-05 11:29:15 +00:00
sal_Bool setORCriteria ( : : connectivity : : OSQLParseNode * pCondition , : : connectivity : : OSQLParseTreeIterator & _rIterator ,
2003-12-16 11:41:56 +00:00
: : std : : vector < : : std : : vector < : : com : : sun : : star : : beans : : PropertyValue > > & rFilters , const : : com : : sun : : star : : uno : : Reference < : : com : : sun : : star : : util : : XNumberFormatter > & xFormatter ) const ;
2005-01-05 11:29:15 +00:00
sal_Bool setANDCriteria ( : : connectivity : : OSQLParseNode * pCondition , : : connectivity : : OSQLParseTreeIterator & _rIterator ,
2003-12-16 11:41:56 +00:00
: : std : : vector < : : com : : sun : : star : : beans : : PropertyValue > & rFilters , const : : com : : sun : : star : : uno : : Reference < : : com : : sun : : star : : util : : XNumberFormatter > & xFormatter ) const ;
2005-01-05 11:29:15 +00:00
sal_Bool setComparsionPredicate ( : : connectivity : : OSQLParseNode * pCondition , : : connectivity : : OSQLParseTreeIterator & _rIterator ,
2003-12-16 11:41:56 +00:00
: : std : : vector < : : com : : sun : : star : : beans : : PropertyValue > & rFilters , const : : com : : sun : : star : : uno : : Reference < : : com : : sun : : star : : util : : XNumberFormatter > & xFormatter ) const ;
2013-04-07 12:06:47 +02:00
OUString getColumnName ( : : connectivity : : OSQLParseNode * pColumnRef , : : connectivity : : OSQLParseTreeIterator & _rIterator ) const ;
OUString getTableAlias ( const : : com : : sun : : star : : uno : : Reference < : : com : : sun : : star : : beans : : XPropertySet > & column ) const ;
2003-12-16 11:41:56 +00:00
sal_Int32 getPredicateType ( : : connectivity : : OSQLParseNode * _pPredicate ) const ;
// clears all Columns,Parameters and tables and insert it to their vectors
void clearCurrentCollections ( ) ;
2009-07-06 09:00:26 +00:00
// clears the columns collection given by EColumnType
void clearColumns ( const EColumnType _eType ) ;
2003-12-16 11:41:56 +00:00
2005-01-05 11:29:15 +00:00
/** retrieves a particular part of a statement
@ param _rIterator
the iterator to use .
*/
2013-04-07 12:06:47 +02:00
OUString getStatementPart ( TGetParseNode & _aGetFunctor , : : connectivity : : OSQLParseTreeIterator & _rIterator ) ;
void setQuery_Impl ( const OUString & command ) ;
2003-12-16 11:41:56 +00:00
void setConditionByColumn ( const : : com : : sun : : star : : uno : : Reference < : : com : : sun : : star : : beans : : XPropertySet > & column
, sal_Bool andCriteria
2013-04-07 12:06:47 +02:00
, : : std : : mem_fun1_t < bool , OSingleSelectQueryComposer , OUString > & _aSetFunctor
2010-01-22 08:14:22 +01:00
, sal_Int32 filterOperator ) ;
2003-12-16 11:41:56 +00:00
/** getStructuredCondition returns the structured condition for the where or having clause
@ param _aGetFunctor
A member function to get the correct parse node .
@ return
The structured filter
*/
: : com : : sun : : star : : uno : : Sequence < : : com : : sun : : star : : uno : : Sequence < : : com : : sun : : star : : beans : : PropertyValue > >
2005-01-05 11:29:15 +00:00
getStructuredCondition ( TGetParseNode & _aGetFunctor ) ;
2003-12-16 11:41:56 +00:00
: : com : : sun : : star : : uno : : Reference < : : com : : sun : : star : : container : : XIndexAccess >
2010-10-15 12:22:54 -05:00
setCurrentColumns ( EColumnType _eType , const : : rtl : : Reference < : : connectivity : : OSQLColumns > & _rCols ) ;
2003-12-16 11:41:56 +00:00
//helper methods for mem_fun_t
2013-04-07 12:06:47 +02:00
inline bool implSetFilter ( OUString _sFilter ) { setFilter ( _sFilter ) ; return true ; }
inline bool implSetHavingClause ( OUString _sFilter ) { setHavingClause ( _sFilter ) ; return true ; }
2003-12-16 11:41:56 +00:00
/** returns the part of the seelect statement
@ param _ePart
Which part should be returned .
@ param _bWithKeyword
If < TRUE / > the keyword will be added too . Otherwise not .
2005-01-05 11:29:15 +00:00
@ param _rIterator
The iterator to use .
2003-12-16 11:41:56 +00:00
@ return
The part of the select statement .
*/
2013-04-07 12:06:47 +02:00
OUString getSQLPart ( SQLPart _ePart , : : connectivity : : OSQLParseTreeIterator & _rIterator , sal_Bool _bWithKeyword ) ;
2005-01-05 11:29:15 +00:00
/** retrieves the keyword for the given SQLPart
*/
2013-04-07 12:06:47 +02:00
OUString getKeyword ( SQLPart _ePart ) const ;
2005-01-05 11:29:15 +00:00
/** sets a single "additive" clause, means a filter/groupby/having/order clause
*/
2013-04-07 12:06:47 +02:00
void setSingleAdditiveClause ( SQLPart _ePart , const OUString & _rClause ) ;
2005-01-05 11:29:15 +00:00
/** composes a statement from m_aPureSelectSQL and the 4 usual clauses
*/
2013-04-07 12:06:47 +02:00
OUString composeStatementFromParts ( const : : std : : vector < OUString > & _rParts ) ;
2003-12-16 11:41:56 +00:00
2013-07-11 16:53:23 +02:00
/** return the name of the column in the *source* *table*.
That is , for ( SELECT a AS b FROM t ) , it returns A or " t " . " A " , as appropriate .
Use e . g . for WHERE , GROUP BY and HAVING clauses .
@ param bGroupBy : for GROUP BY clause ? In that case , throw exception if trying to use an unrelated column and the database does not support that .
*/
OUString impl_getColumnRealName_throw ( const : : com : : sun : : star : : uno : : Reference < : : com : : sun : : star : : beans : : XPropertySet > & column , bool bGroupBy ) ;
/** return the name of the column in the *query*
That is , for ( SELECT a AS b FROM t ) , it returns " b "
Use e . g . for ORDER BY clause .
@ param bOrderBy : for ORDER BY clause ? In that case , throw exception if trying to use an unrelated column and the database does not support that .
2009-04-23 10:42:05 +00:00
*/
2013-07-11 16:53:23 +02:00
OUString impl_getColumnName_throw ( const : : com : : sun : : star : : uno : : Reference < : : com : : sun : : star : : beans : : XPropertySet > & column , bool bOrderBy ) ;
2009-04-23 10:42:05 +00:00
2003-12-16 11:41:56 +00:00
protected :
virtual ~ OSingleSelectQueryComposer ( ) ;
public :
OSingleSelectQueryComposer ( const : : com : : sun : : star : : uno : : Reference < : : com : : sun : : star : : container : : XNameAccess > & _xTableSupplier ,
const : : com : : sun : : star : : uno : : Reference < : : com : : sun : : star : : sdbc : : XConnection > & _xConnection ,
2013-03-19 13:08:47 +02:00
const : : com : : sun : : star : : uno : : Reference < : : com : : sun : : star : : uno : : XComponentContext > & _rContext ) ;
2003-12-16 11:41:56 +00:00
void SAL_CALL disposing ( void ) ;
// ::com::sun::star::lang::XTypeProvider
DECLARE_TYPEPROVIDER ( ) ;
// com::sun::star::lang::XUnoTunnel
virtual sal_Int64 SAL_CALL getSomething ( const : : com : : sun : : star : : uno : : Sequence < sal_Int8 > & aIdentifier ) throw ( : : com : : sun : : star : : uno : : RuntimeException ) ;
// ::com::sun::star::uno::XInterface
DECLARE_XINTERFACE ( )
// XServiceInfo
DECLARE_SERVICE_INFO ( ) ;
DECLARE_PROPERTYCONTAINER_DEFAULTS ( ) ;
// ::com::sun::star::sdb::XSingleSelectQueryComposer
2013-04-07 12:06:47 +02:00
virtual OUString SAL_CALL getElementaryQuery ( ) throw ( : : com : : sun : : star : : uno : : RuntimeException ) ;
virtual void SAL_CALL setElementaryQuery ( const OUString & _rElementary ) throw ( : : com : : sun : : star : : sdbc : : SQLException , : : com : : sun : : star : : uno : : RuntimeException ) ;
virtual void SAL_CALL setFilter ( const OUString & filter ) throw ( : : com : : sun : : star : : sdbc : : SQLException , : : com : : sun : : star : : uno : : RuntimeException ) ;
2003-12-16 11:41:56 +00:00
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 ) ;
2010-01-22 08:14:22 +01:00
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 ) ;
2003-12-16 11:41:56 +00:00
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 ) ;
2013-04-07 12:06:47 +02:00
virtual void SAL_CALL setGroup ( const OUString & group ) throw ( : : com : : sun : : star : : sdbc : : SQLException , : : com : : sun : : star : : uno : : RuntimeException ) ;
virtual void SAL_CALL setHavingClause ( const OUString & filter ) throw ( : : com : : sun : : star : : sdbc : : SQLException , : : com : : sun : : star : : uno : : RuntimeException ) ;
2005-01-05 11:29:15 +00:00
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 ) ;
2010-01-22 08:14:22 +01:00
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 ) ;
2003-12-16 11:41:56 +00:00
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 ) ;
2013-04-07 12:06:47 +02:00
virtual void SAL_CALL setOrder ( const OUString & order ) throw ( : : com : : sun : : star : : sdbc : : SQLException , : : com : : sun : : star : : uno : : RuntimeException ) ;
2003-12-16 11:41:56 +00:00
// XSingleSelectQueryAnalyzer
2013-04-07 12:06:47 +02:00
virtual OUString SAL_CALL getQuery ( ) throw ( : : com : : sun : : star : : uno : : RuntimeException ) ;
virtual void SAL_CALL setQuery ( const OUString & command ) throw ( : : com : : sun : : star : : sdbc : : SQLException , : : com : : sun : : star : : uno : : RuntimeException ) ;
virtual void SAL_CALL setCommand ( const OUString & command , sal_Int32 CommandType ) throw ( : : com : : sun : : star : : sdbc : : SQLException , : : com : : sun : : star : : uno : : RuntimeException ) ;
virtual OUString SAL_CALL getFilter ( ) throw ( : : com : : sun : : star : : uno : : RuntimeException ) ;
2003-12-16 11:41:56 +00:00
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 ) ;
2013-04-07 12:06:47 +02:00
virtual OUString SAL_CALL getGroup ( ) throw ( : : com : : sun : : star : : uno : : RuntimeException ) ;
2003-12-16 11:41:56 +00:00
virtual : : com : : sun : : star : : uno : : Reference < : : com : : sun : : star : : container : : XIndexAccess > SAL_CALL getGroupColumns ( ) throw ( : : com : : sun : : star : : uno : : RuntimeException ) ;
2013-04-07 12:06:47 +02:00
virtual OUString SAL_CALL getHavingClause ( ) throw ( : : com : : sun : : star : : uno : : RuntimeException ) ;
2005-01-05 11:29:15 +00:00
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 ) ;
2013-04-07 12:06:47 +02:00
virtual OUString SAL_CALL getOrder ( ) throw ( : : com : : sun : : star : : uno : : RuntimeException ) ;
2003-12-16 11:41:56 +00:00
virtual : : com : : sun : : star : : uno : : Reference < : : com : : sun : : star : : container : : XIndexAccess > SAL_CALL getOrderColumns ( ) throw ( : : com : : sun : : star : : uno : : RuntimeException ) ;
2013-04-07 12:06:47 +02:00
virtual OUString SAL_CALL getQueryWithSubstitution ( ) throw ( : : com : : sun : : star : : sdbc : : SQLException , : : com : : sun : : star : : uno : : RuntimeException ) ;
2003-12-16 11:41:56 +00:00
// XColumnsSupplier
virtual : : com : : sun : : star : : uno : : Reference < : : com : : sun : : star : : container : : XNameAccess > SAL_CALL getColumns ( ) throw ( : : com : : sun : : star : : uno : : RuntimeException ) ;
// XTablesSupplier
virtual : : com : : sun : : star : : uno : : Reference < : : com : : sun : : star : : container : : XNameAccess > SAL_CALL getTables ( ) throw ( : : com : : sun : : star : : uno : : RuntimeException ) ;
// XParametersSupplier
virtual : : com : : sun : : star : : uno : : Reference < : : com : : sun : : star : : container : : XIndexAccess > SAL_CALL getParameters ( ) throw ( : : com : : sun : : star : : uno : : RuntimeException ) ;
} ;
}
# endif // DBACCESS_CORE_API_SINGLESELECTQUERYCOMPOSER_HXX
2010-10-27 12:33:13 +01:00
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */