2010-10-12 15:59:03 +02: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:40:06 +00:00
2012-10-01 16:11:22 -05:00
# include <string.h>
2007-11-21 14:33:37 +00:00
# include "composertools.hxx"
# include "core_resource.hrc"
# include "core_resource.hxx"
# include "dbastrings.hrc"
# include "HelperCollections.hxx"
2003-12-16 11:40:06 +00:00
# include "SingleSelectQueryComposer.hxx"
2009-12-16 12:46:33 +01:00
# include "sdbcoretools.hxx"
2003-12-16 11:40:06 +00:00
2007-11-21 14:33:37 +00:00
# include <com/sun/star/beans/PropertyAttribute.hpp>
# include <com/sun/star/container/XChild.hpp>
2012-09-13 12:47:11 +02:00
# include <com/sun/star/i18n/LocaleData.hpp>
2003-12-16 11:40:06 +00:00
# include <com/sun/star/lang/DisposedException.hpp>
2012-08-21 08:07:58 +02:00
# include <com/sun/star/script/Converter.hpp>
2007-11-21 14:33:37 +00:00
# include <com/sun/star/sdb/BooleanComparisonMode.hpp>
# include <com/sun/star/sdb/SQLFilterOperator.hpp>
2010-01-22 08:14:22 +01:00
# include <com/sun/star/sdb/XQueriesSupplier.hpp>
# include <com/sun/star/sdb/CommandType.hpp>
2003-12-16 11:40:06 +00:00
# include <com/sun/star/sdbc/ColumnSearch.hpp>
# include <com/sun/star/sdbc/DataType.hpp>
# include <com/sun/star/sdbc/XResultSetMetaData.hpp>
2007-11-21 14:33:37 +00:00
# include <com/sun/star/sdbc/XResultSetMetaDataSupplier.hpp>
2010-03-17 09:11:06 +00:00
# include <com/sun/star/sdbc/XParameters.hpp>
2003-12-16 11:40:06 +00:00
# include <com/sun/star/uno/XAggregation.hpp>
2012-08-29 09:32:55 +02:00
# include <com/sun/star/util/NumberFormatter.hpp>
2007-11-21 14:33:37 +00:00
2003-12-16 11:40:06 +00:00
# include <comphelper/processfactory.hxx>
2007-11-21 14:33:37 +00:00
# include <comphelper/sequence.hxx>
2003-12-16 11:40:06 +00:00
# include <comphelper/types.hxx>
2014-08-07 09:55:54 +02:00
# include <cppuhelper/exc_hlp.hxx>
2007-11-21 14:33:37 +00:00
# include <cppuhelper/typeprovider.hxx>
2011-01-10 13:41:20 +01:00
# include <connectivity/predicateinput.hxx>
2009-10-16 00:05:16 +02:00
# include <unotools/syslocale.hxx>
2003-12-16 11:40:06 +00:00
# include <tools/debug.hxx>
2006-07-10 14:04:12 +00:00
# include <tools/diagnose_ex.h>
2011-02-03 00:33:36 +01:00
# include <osl/diagnose.h>
2007-11-21 14:33:37 +00:00
# include <unotools/configmgr.hxx>
# include <unotools/sharedunocomponent.hxx>
2014-02-20 11:02:54 +09:00
# include <boost/scoped_ptr.hpp>
2003-12-16 11:40:06 +00:00
2007-11-21 14:33:37 +00:00
using namespace : : dbaccess ;
using namespace : : dbtools ;
using namespace : : comphelper ;
using namespace : : connectivity ;
2003-12-16 11:40:06 +00:00
using namespace : : com : : sun : : star : : uno ;
using namespace : : com : : sun : : star : : beans ;
using namespace : : com : : sun : : star : : sdbc ;
using namespace : : com : : sun : : star : : sdb ;
using namespace : : com : : sun : : star : : sdbcx ;
using namespace : : com : : sun : : star : : container ;
using namespace : : com : : sun : : star : : i18n ;
using namespace : : com : : sun : : star : : lang ;
using namespace : : com : : sun : : star : : script ;
2005-01-05 11:27:39 +00:00
using namespace : : com : : sun : : star : : util ;
2003-12-16 11:40:06 +00:00
using namespace : : cppu ;
using namespace : : osl ;
using namespace : : utl ;
2007-11-21 14:33:37 +00:00
namespace dbaccess {
namespace BooleanComparisonMode = : : com : : sun : : star : : sdb : : BooleanComparisonMode ;
}
2013-01-07 08:44:24 -02:00
# define STR_SELECT "SELECT "
# define STR_FROM " FROM "
# define STR_WHERE " WHERE "
# define STR_GROUP_BY " GROUP BY "
# define STR_HAVING " HAVING "
# define STR_ORDER_BY " ORDER BY "
# define STR_AND " AND "
# define STR_OR " OR "
# define STR_LIKE OUString(" LIKE ")
# define L_BRACKET "("
# define R_BRACKET ")"
# define COMMA ","
2003-12-16 11:40:06 +00:00
2005-01-05 11:27:39 +00:00
namespace
{
/** parses the given statement, using the given parser, returns a parse node representing
the statement
If the statement cannot be parsed , an error is thrown .
*/
2013-01-07 08:44:24 -02:00
const OSQLParseNode * parseStatement_throwError ( OSQLParser & _rParser , const OUString & _rStatement , const Reference < XInterface > & _rxContext )
2005-01-05 11:27:39 +00:00
{
2013-01-07 08:44:24 -02:00
OUString aErrorMsg ;
2005-01-05 11:27:39 +00:00
const OSQLParseNode * pNewSqlParseNode = _rParser . parseTree ( aErrorMsg , _rStatement ) ;
if ( ! pNewSqlParseNode )
{
2013-01-07 08:44:24 -02:00
OUString sSQLStateGeneralError ( getStandardSQLState ( SQL_GENERAL_ERROR ) ) ;
2006-07-10 14:04:12 +00:00
SQLException aError2 ( aErrorMsg , _rxContext , sSQLStateGeneralError , 1000 , Any ( ) ) ;
SQLException aError1 ( _rStatement , _rxContext , sSQLStateGeneralError , 1000 , makeAny ( aError2 ) ) ;
throw SQLException ( _rParser . getContext ( ) . getErrorMessage ( OParseContext : : ERROR_GENERAL ) , _rxContext , sSQLStateGeneralError , 1000 , makeAny ( aError1 ) ) ;
2005-01-05 11:27:39 +00:00
}
return pNewSqlParseNode ;
}
/** checks whether the given parse node describes a valid single select statement, throws
an error if not
*/
void checkForSingleSelect_throwError ( const OSQLParseNode * pStatementNode , OSQLParseTreeIterator & _rIterator ,
2013-01-07 08:44:24 -02:00
const Reference < XInterface > & _rxContext , const OUString & _rOriginatingCommand )
2005-01-05 11:27:39 +00:00
{
const OSQLParseNode * pOldNode = _rIterator . getParseTree ( ) ;
// determine the statement type
_rIterator . setParseTree ( pStatementNode ) ;
_rIterator . traverseAll ( ) ;
2006-07-10 14:04:12 +00:00
bool bIsSingleSelect = ( _rIterator . getStatementType ( ) = = SQL_STATEMENT_SELECT ) ;
2005-01-05 11:27:39 +00:00
// throw the error, if necessary
if ( ! bIsSingleSelect | | SQL_ISRULE ( pStatementNode , union_statement ) ) // #i4229# OJ
{
// restore the old node before throwing the exception
_rIterator . setParseTree ( pOldNode ) ;
// and now really ...
2006-07-10 14:04:12 +00:00
SQLException aError1 ( _rOriginatingCommand , _rxContext , getStandardSQLState ( SQL_GENERAL_ERROR ) , 1000 , Any ( ) ) ;
2005-01-05 11:27:39 +00:00
throw SQLException ( DBACORE_RESSTRING ( RID_STR_ONLY_QUERY ) , _rxContext ,
2006-07-10 14:04:12 +00:00
getStandardSQLState ( SQL_GENERAL_ERROR ) , 1000 , makeAny ( aError1 ) ) ;
2005-01-05 11:27:39 +00:00
}
delete pOldNode ;
}
/** combines parseStatement_throwError and checkForSingleSelect_throwError
*/
2013-01-07 08:44:24 -02:00
void parseAndCheck_throwError ( OSQLParser & _rParser , const OUString & _rStatement ,
2005-01-05 11:27:39 +00:00
OSQLParseTreeIterator & _rIterator , const Reference < XInterface > & _rxContext )
{
const OSQLParseNode * pNode = parseStatement_throwError ( _rParser , _rStatement , _rxContext ) ;
checkForSingleSelect_throwError ( pNode , _rIterator , _rxContext , _rStatement ) ;
}
/** transforms a parse node describing a complete statement into a pure select
statement , without any filter / order / groupby / having clauses
*/
2013-01-07 08:44:24 -02:00
OUString getPureSelectStatement ( const OSQLParseNode * _pRootNode , Reference < XConnection > _rxConnection )
2005-01-05 11:27:39 +00:00
{
2013-01-07 08:44:24 -02:00
OUString sSQL = STR_SELECT ;
2006-12-13 15:44:42 +00:00
_pRootNode - > getChild ( 1 ) - > parseNodeToStr ( sSQL , _rxConnection ) ;
_pRootNode - > getChild ( 2 ) - > parseNodeToStr ( sSQL , _rxConnection ) ;
2005-01-05 11:27:39 +00:00
sSQL + = STR_FROM ;
2006-12-13 15:44:42 +00:00
_pRootNode - > getChild ( 3 ) - > getChild ( 0 ) - > getChild ( 1 ) - > parseNodeToStr ( sSQL , _rxConnection ) ;
2005-01-05 11:27:39 +00:00
return sSQL ;
}
/** resets an SQL iterator, including deletion of the parse tree, and disposal if desired
*/
void resetIterator ( OSQLParseTreeIterator & _rIterator , bool _bDispose )
{
const OSQLParseNode * pSqlParseNode = _rIterator . getParseTree ( ) ;
_rIterator . setParseTree ( NULL ) ;
delete pSqlParseNode ;
if ( _bDispose )
_rIterator . dispose ( ) ;
}
2013-01-07 08:44:24 -02:00
void lcl_addFilterCriteria_throw ( sal_Int32 i_nFilterOperator , const OUString & i_sValue , OUStringBuffer & o_sRet )
2010-01-22 08:14:22 +01:00
{
switch ( i_nFilterOperator )
{
case SQLFilterOperator : : EQUAL :
2013-01-07 08:44:24 -02:00
o_sRet . append ( " = " + i_sValue ) ;
2010-01-22 08:14:22 +01:00
break ;
case SQLFilterOperator : : NOT_EQUAL :
2013-01-07 08:44:24 -02:00
o_sRet . append ( " <> " + i_sValue ) ;
2010-01-22 08:14:22 +01:00
break ;
case SQLFilterOperator : : LESS :
2013-01-07 08:44:24 -02:00
o_sRet . append ( " < " + i_sValue ) ;
2010-01-22 08:14:22 +01:00
break ;
case SQLFilterOperator : : GREATER :
2013-01-07 08:44:24 -02:00
o_sRet . append ( " > " + i_sValue ) ;
2010-01-22 08:14:22 +01:00
break ;
case SQLFilterOperator : : LESS_EQUAL :
2013-01-07 08:44:24 -02:00
o_sRet . append ( " <= " + i_sValue ) ;
2010-01-22 08:14:22 +01:00
break ;
case SQLFilterOperator : : GREATER_EQUAL :
2013-01-07 08:44:24 -02:00
o_sRet . append ( " >= " + i_sValue ) ;
2010-01-22 08:14:22 +01:00
break ;
case SQLFilterOperator : : LIKE :
2013-01-07 08:44:24 -02:00
o_sRet . append ( " LIKE " + i_sValue ) ;
2010-01-22 08:14:22 +01:00
break ;
case SQLFilterOperator : : NOT_LIKE :
2013-01-07 08:44:24 -02:00
o_sRet . append ( " NOT LIKE " + i_sValue ) ;
2010-01-22 08:14:22 +01:00
break ;
case SQLFilterOperator : : SQLNULL :
2013-01-07 08:44:24 -02:00
o_sRet . append ( " IS NULL " ) ;
2010-01-22 08:14:22 +01:00
break ;
case SQLFilterOperator : : NOT_SQLNULL :
2013-01-07 08:44:24 -02:00
o_sRet . append ( " IS NOT NULL " ) ;
2010-01-22 08:14:22 +01:00
break ;
default :
throw SQLException ( ) ;
}
}
2005-01-05 11:27:39 +00:00
}
2010-10-12 22:40:56 +02:00
2006-07-10 14:04:12 +00:00
OSingleSelectQueryComposer : : OSingleSelectQueryComposer ( const Reference < XNameAccess > & _rxTables ,
2003-12-16 11:40:06 +00:00
const Reference < XConnection > & _xConnection ,
2013-03-19 13:08:47 +02:00
const Reference < XComponentContext > & _rContext )
2006-06-20 01:37:34 +00:00
: OSubComponent ( m_aMutex , _xConnection )
, OPropertyContainer ( m_aBHelper )
2013-05-18 08:53:54 +02:00
, m_aSqlParser ( _rContext , & m_aParseContext )
2006-07-10 14:04:12 +00:00
, m_aSqlIterator ( _xConnection , _rxTables , m_aSqlParser , NULL )
, m_aAdditiveIterator ( _xConnection , _rxTables , m_aSqlParser , NULL )
2006-06-20 01:37:34 +00:00
, m_aElementaryParts ( ( size_t ) SQLPartCount )
, m_xConnection ( _xConnection )
, m_xMetaData ( _xConnection - > getMetaData ( ) )
2006-07-10 14:04:12 +00:00
, m_xConnectionTables ( _rxTables )
2007-11-21 14:33:37 +00:00
, m_aContext ( _rContext )
2006-06-20 01:37:34 +00:00
, m_pTables ( NULL )
2007-11-21 14:33:37 +00:00
, m_nBoolCompareMode ( BooleanComparisonMode : : EQUAL_INTEGER )
2010-01-22 08:14:22 +01:00
, m_nCommandType ( CommandType : : COMMAND )
2003-12-16 11:40:06 +00:00
{
2007-11-21 14:33:37 +00:00
if ( ! m_aContext . is ( ) | | ! m_xConnection . is ( ) | | ! m_xConnectionTables . is ( ) )
2006-07-10 14:04:12 +00:00
throw IllegalArgumentException ( ) ;
2003-12-16 11:40:06 +00:00
registerProperty ( PROPERTY_ORIGINAL , PROPERTY_ID_ORIGINAL , PropertyAttribute : : BOUND | PropertyAttribute : : READONLY , & m_sOrignal , : : getCppuType ( & m_sOrignal ) ) ;
m_aCurrentColumns . resize ( 4 ) ;
2013-05-18 08:53:54 +02:00
m_aLocale = m_aParseContext . getPreferredLocale ( ) ;
2014-03-31 16:46:08 +02:00
m_xNumberFormatsSupplier = dbtools : : getNumberFormats ( m_xConnection , true , m_aContext ) ;
2013-03-19 13:08:47 +02:00
Reference < XLocaleData4 > xLocaleData ( LocaleData : : create ( m_aContext ) ) ;
2003-12-16 11:40:06 +00:00
LocaleDataItem aData = xLocaleData - > getLocaleItem ( m_aLocale ) ;
m_sDecimalSep = aData . decimalSeparator ;
OSL_ENSURE ( m_sDecimalSep . getLength ( ) = = 1 , " OSingleSelectQueryComposer::OSingleSelectQueryComposer decimal separator is not 1 length " ) ;
try
{
2009-12-16 12:46:33 +01:00
Any aValue ;
Reference < XInterface > xDs = dbaccess : : getDataSource ( _xConnection ) ;
2013-02-20 04:33:49 +01:00
if ( dbtools : : getDataSourceSetting ( xDs , static_cast < OUString > ( PROPERTY_BOOLEANCOMPARISONMODE ) , aValue ) )
2003-12-16 11:40:06 +00:00
{
2009-12-16 12:46:33 +01:00
OSL_VERIFY ( aValue > > = m_nBoolCompareMode ) ;
2003-12-16 11:40:06 +00:00
}
2010-01-22 08:14:22 +01:00
Reference < XQueriesSupplier > xQueriesAccess ( m_xConnection , UNO_QUERY ) ;
if ( xQueriesAccess . is ( ) )
m_xConnectionQueries = xQueriesAccess - > getQueries ( ) ;
2003-12-16 11:40:06 +00:00
}
catch ( Exception & )
{
}
}
2010-10-12 22:40:56 +02:00
2003-12-16 11:40:06 +00:00
OSingleSelectQueryComposer : : ~ OSingleSelectQueryComposer ( )
{
: : std : : vector < OPrivateColumns * > : : iterator aColIter = m_aColumnsCollection . begin ( ) ;
: : std : : vector < OPrivateColumns * > : : iterator aEnd = m_aColumnsCollection . end ( ) ;
for ( ; aColIter ! = aEnd ; + + aColIter )
delete * aColIter ;
: : std : : vector < OPrivateTables * > : : iterator aTabIter = m_aTablesCollection . begin ( ) ;
2009-07-03 12:24:35 +00:00
: : std : : vector < OPrivateTables * > : : iterator aTabEnd = m_aTablesCollection . end ( ) ;
for ( ; aTabIter ! = aTabEnd ; + + aTabIter )
2003-12-16 11:40:06 +00:00
delete * aTabIter ;
}
2010-10-12 22:40:56 +02:00
2003-12-16 11:40:06 +00:00
// OComponentHelper
void SAL_CALL OSingleSelectQueryComposer : : disposing ( void )
{
OSubComponent : : disposing ( ) ;
MutexGuard aGuard ( m_aMutex ) ;
2005-01-05 11:27:39 +00:00
resetIterator ( m_aSqlIterator , true ) ;
resetIterator ( m_aAdditiveIterator , true ) ;
2003-12-16 11:40:06 +00:00
2006-07-10 14:04:12 +00:00
m_xConnectionTables = NULL ;
2003-12-16 11:40:06 +00:00
m_xConnection = NULL ;
clearCurrentCollections ( ) ;
}
2013-08-17 23:43:14 +02:00
2003-12-16 11:40:06 +00:00
IMPLEMENT_FORWARD_XINTERFACE3 ( OSingleSelectQueryComposer , OSubComponent , OSingleSelectQueryComposer_BASE , OPropertyContainer )
2013-04-25 10:56:02 +02:00
IMPLEMENT_SERVICE_INFO1 ( OSingleSelectQueryComposer , " org.openoffice.comp.dba.OSingleSelectQueryComposer " , SERVICE_NAME_SINGLESELECTQUERYCOMPOSER )
2014-03-11 13:02:59 +01:00
css : : uno : : Sequence < sal_Int8 > OSingleSelectQueryComposer : : getImplementationId ( )
throw ( css : : uno : : RuntimeException , std : : exception )
{
return css : : uno : : Sequence < sal_Int8 > ( ) ;
}
IMPLEMENT_GETTYPES3 ( OSingleSelectQueryComposer , OSubComponent , OSingleSelectQueryComposer_BASE , OPropertyContainer )
2003-12-16 11:40:06 +00:00
IMPLEMENT_PROPERTYCONTAINER_DEFAULTS ( OSingleSelectQueryComposer )
// XSingleSelectQueryAnalyzer
2014-02-25 21:31:58 +01:00
OUString SAL_CALL OSingleSelectQueryComposer : : getQuery ( ) throw ( RuntimeException , std : : exception )
2003-12-16 11:40:06 +00:00
{
2005-01-05 11:27:39 +00:00
: : connectivity : : checkDisposed ( OSubComponent : : rBHelper . bDisposed ) ;
: : osl : : MutexGuard aGuard ( m_aMutex ) ;
2003-12-16 11:40:06 +00:00
2005-01-05 11:27:39 +00:00
TGetParseNode F_tmp ( & OSQLParseTreeIterator : : getParseTree ) ;
return getStatementPart ( F_tmp , m_aSqlIterator ) ;
2003-12-16 11:40:06 +00:00
}
2005-01-05 11:27:39 +00:00
2014-02-25 21:31:58 +01:00
void SAL_CALL OSingleSelectQueryComposer : : setQuery ( const OUString & command ) throw ( SQLException , RuntimeException , std : : exception )
2003-12-16 11:40:06 +00:00
{
: : connectivity : : checkDisposed ( OSubComponent : : rBHelper . bDisposed ) ;
: : osl : : MutexGuard aGuard ( m_aMutex ) ;
2010-01-22 08:14:22 +01:00
m_nCommandType = CommandType : : COMMAND ;
2003-12-16 11:40:06 +00:00
// first clear the tables and columns
clearCurrentCollections ( ) ;
// now set the new one
2005-03-10 15:31:39 +00:00
setQuery_Impl ( command ) ;
2003-12-16 11:40:06 +00:00
m_sOrignal = command ;
2005-01-05 11:27:39 +00:00
// reset the additive iterator to the same statement
parseAndCheck_throwError ( m_aSqlParser , m_sOrignal , m_aAdditiveIterator , * this ) ;
// we have no "elementary" parts anymore (means filter/groupby/having/order clauses)
for ( SQLPart eLoopParts = Where ; eLoopParts ! = SQLPartCount ; incSQLPart ( eLoopParts ) )
2013-01-07 08:44:24 -02:00
m_aElementaryParts [ eLoopParts ] = OUString ( ) ;
2003-12-16 11:40:06 +00:00
}
2010-10-12 22:40:56 +02:00
2014-02-25 21:31:58 +01:00
void SAL_CALL OSingleSelectQueryComposer : : setCommand ( const OUString & Command , sal_Int32 _nCommandType ) throw ( SQLException , RuntimeException , std : : exception )
2010-01-22 08:14:22 +01:00
{
2013-01-07 08:44:24 -02:00
OUStringBuffer sSQL ;
2010-01-22 08:14:22 +01:00
switch ( _nCommandType )
{
case CommandType : : COMMAND :
setElementaryQuery ( Command ) ;
return ;
case CommandType : : TABLE :
if ( m_xConnectionTables - > hasByName ( Command ) )
{
sSQL . appendAscii ( " SELECT * FROM " ) ;
Reference < XPropertySet > xTable ;
try
{
m_xConnectionTables - > getByName ( Command ) > > = xTable ;
}
catch ( const WrappedTargetException & e )
{
SQLException e2 ;
if ( e . TargetException > > = e2 )
throw e2 ;
}
catch ( Exception & )
{
DBG_UNHANDLED_EXCEPTION ( ) ;
}
sSQL . append ( dbtools : : composeTableNameForSelect ( m_xConnection , xTable ) ) ;
}
else
{
2013-02-20 04:33:49 +01:00
OUString sMessage ( DBACORE_RESSTRING ( RID_STR_TABLE_DOES_NOT_EXIST ) ) ;
throwGenericSQLException ( sMessage . replaceAll ( " $table$ " , Command ) , * this ) ;
2010-01-22 08:14:22 +01:00
}
break ;
case CommandType : : QUERY :
if ( m_xConnectionQueries - > hasByName ( Command ) )
{
Reference < XPropertySet > xQuery ( m_xConnectionQueries - > getByName ( Command ) , UNO_QUERY ) ;
2013-01-07 08:44:24 -02:00
OUString sCommand ;
2010-01-22 08:14:22 +01:00
xQuery - > getPropertyValue ( PROPERTY_COMMAND ) > > = sCommand ;
sSQL . append ( sCommand ) ;
}
else
{
2013-02-18 14:29:48 +01:00
OUString sMessage ( DBACORE_RESSTRING ( RID_STR_QUERY_DOES_NOT_EXIST ) ) ;
throwGenericSQLException ( sMessage . replaceAll ( " $table$ " , Command ) , * this ) ;
2010-01-22 08:14:22 +01:00
}
break ;
default :
break ;
}
: : connectivity : : checkDisposed ( OSubComponent : : rBHelper . bDisposed ) ;
: : osl : : MutexGuard aGuard ( m_aMutex ) ;
m_nCommandType = _nCommandType ;
m_sCommand = Command ;
// first clear the tables and columns
clearCurrentCollections ( ) ;
// now set the new one
2013-01-07 08:44:24 -02:00
OUString sCommand = sSQL . makeStringAndClear ( ) ;
2010-01-22 08:14:22 +01:00
setElementaryQuery ( sCommand ) ;
m_sOrignal = sCommand ;
}
2010-10-12 22:40:56 +02:00
2013-01-07 08:44:24 -02:00
void OSingleSelectQueryComposer : : setQuery_Impl ( const OUString & command )
2003-12-16 11:40:06 +00:00
{
2005-01-05 11:27:39 +00:00
// parse this
parseAndCheck_throwError ( m_aSqlParser , command , m_aSqlIterator , * this ) ;
2004-10-22 07:55:36 +00:00
2005-01-05 11:27:39 +00:00
// strip it from all clauses, to have the pure SELECT statement
2006-12-13 15:44:42 +00:00
m_aPureSelectSQL = getPureSelectStatement ( m_aSqlIterator . getParseTree ( ) , m_xConnection ) ;
2003-12-16 11:40:06 +00:00
2010-10-12 22:40:56 +02:00
// update tables
2003-12-16 11:40:06 +00:00
getTables ( ) ;
}
2010-10-12 22:40:56 +02:00
2014-02-25 21:31:58 +01:00
Sequence < Sequence < PropertyValue > > SAL_CALL OSingleSelectQueryComposer : : getStructuredHavingClause ( ) throw ( RuntimeException , std : : exception )
2003-12-16 11:40:06 +00:00
{
2005-01-05 11:27:39 +00:00
TGetParseNode F_tmp ( & OSQLParseTreeIterator : : getSimpleHavingTree ) ;
2003-12-16 11:40:06 +00:00
return getStructuredCondition ( F_tmp ) ;
}
2010-10-12 22:40:56 +02:00
2014-02-25 21:31:58 +01:00
Sequence < Sequence < PropertyValue > > SAL_CALL OSingleSelectQueryComposer : : getStructuredFilter ( ) throw ( RuntimeException , std : : exception )
2003-12-16 11:40:06 +00:00
{
2005-01-05 11:27:39 +00:00
TGetParseNode F_tmp ( & OSQLParseTreeIterator : : getSimpleWhereTree ) ;
2003-12-16 11:40:06 +00:00
return getStructuredCondition ( F_tmp ) ;
}
2010-10-12 22:40:56 +02:00
2014-08-17 11:54:26 +01:00
void SAL_CALL OSingleSelectQueryComposer : : appendHavingClauseByColumn ( const Reference < XPropertySet > & column , sal_Bool andCriteria , sal_Int32 filterOperator ) throw ( SQLException , WrappedTargetException , RuntimeException , std : : exception )
2003-12-16 11:40:06 +00:00
{
2014-03-17 09:18:05 +02:00
: : std : : mem_fun1_t < bool , OSingleSelectQueryComposer , const OUString & > F_tmp ( & OSingleSelectQueryComposer : : implSetHavingClause ) ;
2010-01-22 08:14:22 +01:00
setConditionByColumn ( column , andCriteria , F_tmp , filterOperator ) ;
2003-12-16 11:40:06 +00:00
}
2010-10-12 22:40:56 +02:00
2014-08-17 11:54:26 +01:00
void SAL_CALL OSingleSelectQueryComposer : : appendFilterByColumn ( const Reference < XPropertySet > & column , sal_Bool andCriteria , sal_Int32 filterOperator ) throw ( SQLException , WrappedTargetException , RuntimeException , std : : exception )
2003-12-16 11:40:06 +00:00
{
2014-03-17 09:18:05 +02:00
: : std : : mem_fun1_t < bool , OSingleSelectQueryComposer , const OUString & > F_tmp ( & OSingleSelectQueryComposer : : implSetFilter ) ;
2010-01-22 08:14:22 +01:00
setConditionByColumn ( column , andCriteria , F_tmp , filterOperator ) ;
2003-12-16 11:40:06 +00:00
}
2010-10-12 22:40:56 +02:00
2013-07-11 16:53:23 +02:00
OUString OSingleSelectQueryComposer : : impl_getColumnRealName_throw ( const Reference < XPropertySet > & column , bool bGroupBy )
2003-12-16 11:40:06 +00:00
{
: : connectivity : : checkDisposed ( OSubComponent : : rBHelper . bDisposed ) ;
2009-09-08 09:50:48 +00:00
getColumns ( ) ;
2003-12-16 11:40:06 +00:00
if ( ! column . is ( )
| | ! m_aCurrentColumns [ SelectColumns ]
| | ! column - > getPropertySetInfo ( ) - > hasPropertyByName ( PROPERTY_NAME )
)
2004-06-01 09:09:41 +00:00
{
2013-02-20 04:33:49 +01:00
OUString sError ( DBACORE_RESSTRING ( RID_STR_COLUMN_UNKNOWN_PROP ) ) ;
SQLException aErr ( sError . replaceAll ( " %value " , OUString ( PROPERTY_NAME ) ) , * this , SQLSTATE_GENERAL , 1000 , Any ( ) ) ;
2004-06-01 09:09:41 +00:00
throw SQLException ( DBACORE_RESSTRING ( RID_STR_COLUMN_NOT_VALID ) , * this , SQLSTATE_GENERAL , 1000 , makeAny ( aErr ) ) ;
}
2003-12-16 11:40:06 +00:00
2013-07-11 16:53:23 +02:00
OUString aName , aNewName ;
2003-12-16 11:40:06 +00:00
column - > getPropertyValue ( PROPERTY_NAME ) > > = aName ;
2013-07-11 16:53:23 +02:00
if ( bGroupBy & &
! m_xMetaData - > supportsGroupByUnrelated ( ) & &
m_aCurrentColumns [ SelectColumns ] & &
! m_aCurrentColumns [ SelectColumns ] - > hasByName ( aName ) )
2004-06-01 09:09:41 +00:00
{
2013-02-18 14:29:48 +01:00
OUString sError ( DBACORE_RESSTRING ( RID_STR_COLUMN_MUST_VISIBLE ) ) ;
throw SQLException ( sError . replaceAll ( " %name " , aName ) , * this , SQLSTATE_GENERAL , 1000 , Any ( ) ) ;
2004-06-01 09:09:41 +00:00
}
2003-12-16 11:40:06 +00:00
2013-01-07 08:44:24 -02:00
OUString aQuote = m_xMetaData - > getIdentifierQuoteString ( ) ;
2003-12-16 11:40:06 +00:00
if ( m_aCurrentColumns [ SelectColumns ] - > hasByName ( aName ) )
{
Reference < XPropertySet > xColumn ;
m_aCurrentColumns [ SelectColumns ] - > getByName ( aName ) > > = xColumn ;
OSL_ENSURE ( xColumn - > getPropertySetInfo ( ) - > hasPropertyByName ( PROPERTY_REALNAME ) , " Property REALNAME not available! " ) ;
OSL_ENSURE ( xColumn - > getPropertySetInfo ( ) - > hasPropertyByName ( PROPERTY_TABLENAME ) , " Property TABLENAME not available! " ) ;
2013-01-07 08:44:24 -02:00
OSL_ENSURE ( xColumn - > getPropertySetInfo ( ) - > hasPropertyByName ( " Function " ) , " Property FUNCTION not available! " ) ;
2003-12-16 11:40:06 +00:00
2013-07-11 16:53:23 +02:00
OUString sRealName , sTableName ;
2003-12-16 11:40:06 +00:00
xColumn - > getPropertyValue ( PROPERTY_REALNAME ) > > = sRealName ;
xColumn - > getPropertyValue ( PROPERTY_TABLENAME ) > > = sTableName ;
2014-04-17 11:16:55 +02:00
bool bFunction = false ;
2013-01-07 08:44:24 -02:00
xColumn - > getPropertyValue ( " Function " ) > > = bFunction ;
2004-08-02 14:01:24 +00:00
if ( sRealName = = aName )
2003-12-16 11:40:06 +00:00
{
2004-08-02 14:01:24 +00:00
if ( bFunction )
2009-04-23 10:42:05 +00:00
aNewName = aName ;
2004-08-02 14:01:24 +00:00
else
{
if ( sTableName . indexOf ( ' . ' , 0 ) ! = - 1 )
{
2013-01-07 08:44:24 -02:00
OUString aCatlog , aSchema , aTable ;
2004-08-02 14:01:24 +00:00
: : dbtools : : qualifiedNameComponents ( m_xMetaData , sTableName , aCatlog , aSchema , aTable , : : dbtools : : eInDataManipulation ) ;
2014-03-31 16:46:08 +02:00
sTableName = : : dbtools : : composeTableName ( m_xMetaData , aCatlog , aSchema , aTable , true , : : dbtools : : eInDataManipulation ) ;
2004-08-02 14:01:24 +00:00
}
2013-07-10 02:58:32 +02:00
else if ( ! sTableName . isEmpty ( ) )
2004-08-02 14:01:24 +00:00
sTableName = : : dbtools : : quoteName ( aQuote , sTableName ) ;
2013-07-10 02:58:32 +02:00
if ( sTableName . isEmpty ( ) )
aNewName = : : dbtools : : quoteName ( aQuote , sRealName ) ;
else
aNewName = sTableName + " . " + : : dbtools : : quoteName ( aQuote , sRealName ) ;
2004-08-02 14:01:24 +00:00
}
2003-12-16 11:40:06 +00:00
}
else
2009-04-23 10:42:05 +00:00
aNewName = : : dbtools : : quoteName ( aQuote , aName ) ;
2003-12-16 11:40:06 +00:00
}
else
2009-04-23 10:42:05 +00:00
aNewName = getTableAlias ( column ) + : : dbtools : : quoteName ( aQuote , aName ) ;
return aNewName ;
}
2010-10-12 22:40:56 +02:00
2013-07-11 16:53:23 +02:00
OUString OSingleSelectQueryComposer : : impl_getColumnName_throw ( const Reference < XPropertySet > & column , bool bOrderBy )
{
: : connectivity : : checkDisposed ( OSubComponent : : rBHelper . bDisposed ) ;
getColumns ( ) ;
if ( ! column . is ( )
| | ! m_aCurrentColumns [ SelectColumns ]
| | ! column - > getPropertySetInfo ( ) - > hasPropertyByName ( PROPERTY_NAME )
)
{
OUString sError ( DBACORE_RESSTRING ( RID_STR_COLUMN_UNKNOWN_PROP ) ) ;
SQLException aErr ( sError . replaceAll ( " %value " , OUString ( PROPERTY_NAME ) ) , * this , SQLSTATE_GENERAL , 1000 , Any ( ) ) ;
throw SQLException ( DBACORE_RESSTRING ( RID_STR_COLUMN_NOT_VALID ) , * this , SQLSTATE_GENERAL , 1000 , makeAny ( aErr ) ) ;
}
2013-08-02 12:08:16 +02:00
OUString aName ;
2013-07-11 16:53:23 +02:00
column - > getPropertyValue ( PROPERTY_NAME ) > > = aName ;
2013-08-02 12:08:16 +02:00
const OUString aQuote = m_xMetaData - > getIdentifierQuoteString ( ) ;
if ( m_aCurrentColumns [ SelectColumns ] & &
m_aCurrentColumns [ SelectColumns ] - > hasByName ( aName ) )
{
// It is a column from the SELECT list, use it as such.
return : : dbtools : : quoteName ( aQuote , aName ) ;
}
// Nope, it is an unrelated column.
// Is that supported?
2013-07-11 16:53:23 +02:00
if ( bOrderBy & &
2013-08-02 12:08:16 +02:00
! m_xMetaData - > supportsOrderByUnrelated ( ) )
2013-07-11 16:53:23 +02:00
{
OUString sError ( DBACORE_RESSTRING ( RID_STR_COLUMN_MUST_VISIBLE ) ) ;
throw SQLException ( sError . replaceAll ( " %name " , aName ) , * this , SQLSTATE_GENERAL , 1000 , Any ( ) ) ;
}
2013-08-02 12:08:16 +02:00
// We need to refer to it by its "real" name, that is by schemaName.tableName.columnNameInTable
return impl_getColumnRealName_throw ( column , false ) ;
2013-07-11 16:53:23 +02:00
}
2014-02-25 21:31:58 +01:00
void SAL_CALL OSingleSelectQueryComposer : : appendOrderByColumn ( const Reference < XPropertySet > & column , sal_Bool ascending ) throw ( SQLException , RuntimeException , std : : exception )
2009-04-23 10:42:05 +00:00
{
: : osl : : MutexGuard aGuard ( m_aMutex ) ;
2013-07-11 16:53:23 +02:00
OUString sColumnName ( impl_getColumnName_throw ( column , true ) ) ;
2013-01-07 08:44:24 -02:00
OUString sOrder = getOrder ( ) ;
2011-12-19 18:10:37 -02:00
if ( ! ( sOrder . isEmpty ( ) | | sColumnName . isEmpty ( ) ) )
2003-12-16 11:40:06 +00:00
sOrder + = COMMA ;
2009-04-23 10:42:05 +00:00
sOrder + = sColumnName ;
2011-12-19 18:10:37 -02:00
if ( ! ( ascending | | sColumnName . isEmpty ( ) ) )
2013-01-07 08:44:24 -02:00
sOrder + = " DESC " ;
2003-12-16 11:40:06 +00:00
setOrder ( sOrder ) ;
}
2005-01-05 11:27:39 +00:00
2014-02-25 21:31:58 +01:00
void SAL_CALL OSingleSelectQueryComposer : : appendGroupByColumn ( const Reference < XPropertySet > & column ) throw ( SQLException , RuntimeException , std : : exception )
2003-12-16 11:40:06 +00:00
{
: : osl : : MutexGuard aGuard ( m_aMutex ) ;
2013-07-11 16:53:23 +02:00
OUString sColumnName ( impl_getColumnRealName_throw ( column , true ) ) ;
2005-01-05 11:27:39 +00:00
OrderCreator aComposer ;
aComposer . append ( getGroup ( ) ) ;
2009-04-23 10:42:05 +00:00
aComposer . append ( sColumnName ) ;
2005-01-05 11:27:39 +00:00
setGroup ( aComposer . getComposedAndClear ( ) ) ;
2003-12-16 11:40:06 +00:00
}
2010-10-12 22:40:56 +02:00
2013-01-07 08:44:24 -02:00
OUString OSingleSelectQueryComposer : : composeStatementFromParts ( const : : std : : vector < OUString > & _rParts )
2003-12-16 11:40:06 +00:00
{
2011-02-03 00:33:36 +01:00
OSL_ENSURE ( _rParts . size ( ) = = ( size_t ) SQLPartCount , " OSingleSelectQueryComposer::composeStatementFromParts: invalid parts array! " ) ;
2003-12-16 11:40:06 +00:00
2013-01-07 08:44:24 -02:00
OUStringBuffer aSql ( m_aPureSelectSQL ) ;
2005-01-05 11:27:39 +00:00
for ( SQLPart eLoopParts = Where ; eLoopParts ! = SQLPartCount ; incSQLPart ( eLoopParts ) )
2011-12-19 18:10:37 -02:00
if ( ! _rParts [ eLoopParts ] . isEmpty ( ) )
2005-01-05 11:27:39 +00:00
{
aSql . append ( getKeyword ( eLoopParts ) ) ;
aSql . append ( _rParts [ eLoopParts ] ) ;
}
2003-12-16 11:40:06 +00:00
2005-01-05 11:27:39 +00:00
return aSql . makeStringAndClear ( ) ;
2003-12-16 11:40:06 +00:00
}
2005-01-05 11:27:39 +00:00
2014-02-25 21:31:58 +01:00
OUString SAL_CALL OSingleSelectQueryComposer : : getElementaryQuery ( ) throw ( : : com : : sun : : star : : uno : : RuntimeException , std : : exception )
2005-01-05 11:27:39 +00:00
{
return composeStatementFromParts ( m_aElementaryParts ) ;
}
2014-02-25 21:31:58 +01:00
void SAL_CALL OSingleSelectQueryComposer : : setElementaryQuery ( const OUString & _rElementary ) throw ( : : com : : sun : : star : : sdbc : : SQLException , : : com : : sun : : star : : uno : : RuntimeException , std : : exception )
2003-12-16 11:40:06 +00:00
{
: : connectivity : : checkDisposed ( OSubComponent : : rBHelper . bDisposed ) ;
: : osl : : MutexGuard aGuard ( m_aMutex ) ;
2005-01-05 11:27:39 +00:00
// remember the 4 current "additive" clauses
2013-01-07 08:44:24 -02:00
: : std : : vector < OUString > aAdditiveClauses ( SQLPartCount ) ;
2005-01-05 11:27:39 +00:00
for ( SQLPart eLoopParts = Where ; eLoopParts ! = SQLPartCount ; incSQLPart ( eLoopParts ) )
2014-04-17 11:16:55 +02:00
aAdditiveClauses [ eLoopParts ] = getSQLPart ( eLoopParts , m_aAdditiveIterator , false ) ;
2005-01-05 11:27:39 +00:00
2006-08-15 09:42:50 +00:00
// clear the tables and columns
clearCurrentCollections ( ) ;
// set and parse the new query
setQuery_Impl ( _rElementary ) ;
// get the 4 elementary parts of the statement
for ( SQLPart eLoopParts = Where ; eLoopParts ! = SQLPartCount ; incSQLPart ( eLoopParts ) )
2014-04-17 11:16:55 +02:00
m_aElementaryParts [ eLoopParts ] = getSQLPart ( eLoopParts , m_aSqlIterator , false ) ;
2005-01-05 11:27:39 +00:00
2013-02-22 09:48:17 +02:00
// reset the AdditiveIterator: m_aPureSelectSQL may have changed
2005-01-05 11:27:39 +00:00
try
{
parseAndCheck_throwError ( m_aSqlParser , composeStatementFromParts ( aAdditiveClauses ) , m_aAdditiveIterator , * this ) ;
}
catch ( const Exception & e )
2003-12-16 11:40:06 +00:00
{
2006-06-20 01:37:34 +00:00
( void ) e ;
2013-06-29 17:38:04 +03:00
SAL_WARN ( " dbaccess " , " OSingleSelectQueryComposer::setElementaryQuery: there should be no error anymore for the additive statement! " ) ;
2012-07-12 18:10:14 +02:00
DBG_UNHANDLED_EXCEPTION ( ) ;
2005-01-05 11:27:39 +00:00
// every part of the additive statement should have passed other tests already, and should not
// be able to cause any errors ... me thinks
2003-12-16 11:40:06 +00:00
}
}
2005-01-05 11:27:39 +00:00
namespace
{
2014-03-17 09:18:05 +02:00
OUString getComposedClause ( const OUString & _rElementaryClause , const OUString & _rAdditionalClause ,
TokenComposer & _rComposer , const OUString & _rKeyword )
2003-12-16 11:40:06 +00:00
{
2005-01-05 11:27:39 +00:00
_rComposer . clear ( ) ;
_rComposer . append ( _rElementaryClause ) ;
_rComposer . append ( _rAdditionalClause ) ;
2013-01-07 08:44:24 -02:00
OUString sComposed = _rComposer . getComposedAndClear ( ) ;
2011-12-19 18:10:37 -02:00
if ( ! sComposed . isEmpty ( ) )
2005-01-05 11:27:39 +00:00
sComposed = _rKeyword + sComposed ;
return sComposed ;
2003-12-16 11:40:06 +00:00
}
}
2005-01-05 11:27:39 +00:00
2013-01-07 08:44:24 -02:00
void OSingleSelectQueryComposer : : setSingleAdditiveClause ( SQLPart _ePart , const OUString & _rClause )
2003-12-16 11:40:06 +00:00
{
: : connectivity : : checkDisposed ( OSubComponent : : rBHelper . bDisposed ) ;
: : osl : : MutexGuard aGuard ( m_aMutex ) ;
2007-09-26 13:38:38 +00:00
// if nothing is changed, do nothing
2014-04-17 11:16:55 +02:00
if ( getSQLPart ( _ePart , m_aAdditiveIterator , false ) = = _rClause )
2007-09-26 13:38:38 +00:00
return ;
2005-01-05 11:27:39 +00:00
// collect the 4 single parts as they're currently set
2013-01-07 08:44:24 -02:00
: : std : : vector < OUString > aClauses ;
2005-01-05 11:27:39 +00:00
aClauses . reserve ( ( size_t ) SQLPartCount ) ;
for ( SQLPart eLoopParts = Where ; eLoopParts ! = SQLPartCount ; incSQLPart ( eLoopParts ) )
2014-04-17 11:16:55 +02:00
aClauses . push_back ( getSQLPart ( eLoopParts , m_aSqlIterator , true ) ) ;
2005-01-05 11:27:39 +00:00
// overwrite the one part in question here
2014-02-20 11:02:54 +09:00
boost : : scoped_ptr < TokenComposer > pComposer ;
2005-01-05 11:27:39 +00:00
if ( ( _ePart = = Where ) | | ( _ePart = = Having ) )
pComposer . reset ( new FilterCreator ) ;
else
pComposer . reset ( new OrderCreator ) ;
aClauses [ _ePart ] = getComposedClause ( m_aElementaryParts [ _ePart ] , _rClause ,
* pComposer , getKeyword ( _ePart ) ) ;
// construct the complete statement
2013-01-07 08:44:24 -02:00
OUStringBuffer aSql ( m_aPureSelectSQL ) ;
2005-01-05 11:27:39 +00:00
for ( SQLPart eLoopParts = Where ; eLoopParts ! = SQLPartCount ; incSQLPart ( eLoopParts ) )
2009-07-03 12:24:35 +00:00
aSql . append ( aClauses [ eLoopParts ] ) ;
2005-01-05 11:27:39 +00:00
// set the query
2009-07-03 12:24:35 +00:00
setQuery_Impl ( aSql . makeStringAndClear ( ) ) ;
2009-07-06 09:00:26 +00:00
// clear column collections which (might) have changed
clearColumns ( ParameterColumns ) ;
if ( _ePart = = Order )
clearColumns ( OrderColumns ) ;
2013-07-11 17:04:42 +02:00
else if ( _ePart = = Group )
2009-07-06 09:00:26 +00:00
clearColumns ( GroupByColumns ) ;
2005-01-05 11:27:39 +00:00
// also, since the "additive filter" change, we need to rebuild our "additive" statement
aSql = m_aPureSelectSQL ;
// again, first get all the old additive parts
for ( SQLPart eLoopParts = Where ; eLoopParts ! = SQLPartCount ; incSQLPart ( eLoopParts ) )
2014-04-17 11:16:55 +02:00
aClauses [ eLoopParts ] = getSQLPart ( eLoopParts , m_aAdditiveIterator , true ) ;
2005-01-05 11:27:39 +00:00
// then overwrite the one in question
2013-01-07 08:44:24 -02:00
aClauses [ _ePart ] = getComposedClause ( OUString ( ) , _rClause , * pComposer , getKeyword ( _ePart ) ) ;
2005-01-05 11:27:39 +00:00
// and parse it, so that m_aAdditiveIterator is up to date
for ( SQLPart eLoopParts = Where ; eLoopParts ! = SQLPartCount ; incSQLPart ( eLoopParts ) )
2009-07-03 12:24:35 +00:00
aSql . append ( aClauses [ eLoopParts ] ) ;
2005-01-05 11:27:39 +00:00
try
2003-12-16 11:40:06 +00:00
{
2009-07-03 12:24:35 +00:00
parseAndCheck_throwError ( m_aSqlParser , aSql . makeStringAndClear ( ) , m_aAdditiveIterator , * this ) ;
2003-12-16 11:40:06 +00:00
}
2005-01-05 11:27:39 +00:00
catch ( const Exception & e )
{
2006-06-20 01:37:34 +00:00
( void ) e ;
2013-06-29 17:38:04 +03:00
SAL_WARN ( " dbaccess " , " OSingleSelectQueryComposer::setSingleAdditiveClause: there should be no error anymore for the additive statement! " ) ;
2005-01-05 11:27:39 +00:00
// every part of the additive statement should have passed other tests already, and should not
// be able to cause any errors ... me thinks
}
}
2003-12-16 11:40:06 +00:00
2014-02-25 21:31:58 +01:00
void SAL_CALL OSingleSelectQueryComposer : : setFilter ( const OUString & filter ) throw ( SQLException , RuntimeException , std : : exception )
2005-01-05 11:27:39 +00:00
{
setSingleAdditiveClause ( Where , filter ) ;
}
2014-02-25 21:31:58 +01:00
void SAL_CALL OSingleSelectQueryComposer : : setOrder ( const OUString & order ) throw ( SQLException , RuntimeException , std : : exception )
2005-01-05 11:27:39 +00:00
{
setSingleAdditiveClause ( Order , order ) ;
}
2010-10-12 22:40:56 +02:00
2014-02-25 21:31:58 +01:00
void SAL_CALL OSingleSelectQueryComposer : : setGroup ( const OUString & group ) throw ( SQLException , RuntimeException , std : : exception )
2005-01-05 11:27:39 +00:00
{
setSingleAdditiveClause ( Group , group ) ;
}
2010-10-12 22:40:56 +02:00
2014-02-25 21:31:58 +01:00
void SAL_CALL OSingleSelectQueryComposer : : setHavingClause ( const OUString & filter ) throw ( SQLException , RuntimeException , std : : exception )
2005-01-05 11:27:39 +00:00
{
setSingleAdditiveClause ( Having , filter ) ;
2003-12-16 11:40:06 +00:00
}
2005-01-05 11:27:39 +00:00
2003-12-16 11:40:06 +00:00
// XTablesSupplier
2014-02-25 21:31:58 +01:00
Reference < XNameAccess > SAL_CALL OSingleSelectQueryComposer : : getTables ( ) throw ( RuntimeException , std : : exception )
2003-12-16 11:40:06 +00:00
{
: : connectivity : : checkDisposed ( OSubComponent : : rBHelper . bDisposed ) ;
: : osl : : MutexGuard aGuard ( m_aMutex ) ;
if ( ! m_pTables )
{
const OSQLTables & aTables = m_aSqlIterator . getTables ( ) ;
2013-01-07 08:44:24 -02:00
: : std : : vector < OUString > aNames ;
2009-07-03 12:24:35 +00:00
OSQLTables : : const_iterator aEnd = aTables . end ( ) ;
for ( OSQLTables : : const_iterator aIter = aTables . begin ( ) ; aIter ! = aEnd ; + + aIter )
2003-12-16 11:40:06 +00:00
aNames . push_back ( aIter - > first ) ;
2006-08-15 09:42:50 +00:00
m_pTables = new OPrivateTables ( aTables , m_xMetaData - > supportsMixedCaseQuotedIdentifiers ( ) , * this , m_aMutex , aNames ) ;
2003-12-16 11:40:06 +00:00
}
return m_pTables ;
}
2010-10-12 22:40:56 +02:00
2003-12-16 11:40:06 +00:00
// XColumnsSupplier
2014-02-25 21:31:58 +01:00
Reference < XNameAccess > SAL_CALL OSingleSelectQueryComposer : : getColumns ( ) throw ( RuntimeException , std : : exception )
2003-12-16 11:40:06 +00:00
{
: : connectivity : : checkDisposed ( OSubComponent : : rBHelper . bDisposed ) ;
: : osl : : MutexGuard aGuard ( m_aMutex ) ;
2006-07-10 14:04:12 +00:00
if ( ! ! m_aCurrentColumns [ SelectColumns ] )
return m_aCurrentColumns [ SelectColumns ] ;
2013-01-07 08:44:24 -02:00
: : std : : vector < OUString > aNames ;
2010-10-15 12:22:54 -05:00
: : rtl : : Reference < OSQLColumns > aSelectColumns ;
2014-04-17 11:16:55 +02:00
bool bCase = true ;
2010-01-22 08:14:22 +01:00
Reference < XNameAccess > xQueryColumns ;
if ( m_nCommandType = = CommandType : : QUERY )
{
Reference < XColumnsSupplier > xSup ( m_xConnectionQueries - > getByName ( m_sCommand ) , UNO_QUERY ) ;
if ( xSup . is ( ) )
xQueryColumns = xSup - > getColumns ( ) ;
}
2006-07-10 14:04:12 +00:00
do {
try
2005-12-21 12:34:19 +00:00
{
2006-07-10 14:04:12 +00:00
SharedUNOComponent < XStatement , DisposableComponent > xStatement ;
SharedUNOComponent < XPreparedStatement , DisposableComponent > xPreparedStatement ;
2006-08-15 09:42:50 +00:00
bCase = m_xMetaData - > supportsMixedCaseQuotedIdentifiers ( ) ;
2006-07-10 14:04:12 +00:00
aSelectColumns = m_aSqlIterator . getSelectColumns ( ) ;
2014-07-01 15:45:52 +02:00
OUStringBuffer aSQL ( m_aPureSelectSQL + STR_WHERE " ( 0 = 1 ) " ) ;
2009-07-06 09:00:26 +00:00
// preserve the original WHERE clause
2011-02-27 22:55:22 +01:00
// #i102234#
2014-04-17 11:16:55 +02:00
OUString sOriginalWhereClause = getSQLPart ( Where , m_aSqlIterator , false ) ;
2011-12-19 18:10:37 -02:00
if ( ! sOriginalWhereClause . isEmpty ( ) )
2009-07-06 09:00:26 +00:00
{
2013-01-07 07:45:44 -02:00
aSQL . append ( " AND ( " + sOriginalWhereClause + " ) " ) ;
2009-07-06 09:00:26 +00:00
}
2014-04-17 11:16:55 +02:00
OUString sGroupBy = getSQLPart ( Group , m_aSqlIterator , true ) ;
2011-12-19 18:10:37 -02:00
if ( ! sGroupBy . isEmpty ( ) )
2009-07-06 09:00:26 +00:00
aSQL . append ( sGroupBy ) ;
2006-07-10 14:04:12 +00:00
2013-01-07 08:44:24 -02:00
OUString sSQL ( aSQL . makeStringAndClear ( ) ) ;
2006-07-10 14:04:12 +00:00
// normalize the statement so that it doesn't contain any application-level features anymore
2013-01-07 08:44:24 -02:00
OUString sError ;
2014-02-20 11:02:54 +09:00
const boost : : scoped_ptr < OSQLParseNode > pStatementTree ( m_aSqlParser . parseTree ( sError , sSQL , false ) ) ;
2011-02-03 00:33:36 +01:00
OSL_ENSURE ( pStatementTree . get ( ) , " OSingleSelectQueryComposer::getColumns: could not parse the column retrieval statement! " ) ;
2006-07-10 14:04:12 +00:00
if ( pStatementTree . get ( ) )
2009-07-06 09:00:26 +00:00
if ( ! pStatementTree - > parseNodeToExecutableStatement ( sSQL , m_xConnection , m_aSqlParser , NULL ) )
2006-07-10 14:04:12 +00:00
break ;
Reference < XResultSetMetaData > xResultSetMeta ;
2008-06-30 14:09:50 +00:00
Reference < XResultSetMetaDataSupplier > xResMetaDataSup ;
2003-12-16 11:40:06 +00:00
try
{
2009-07-06 09:00:26 +00:00
xPreparedStatement . set ( m_xConnection - > prepareStatement ( sSQL ) , UNO_QUERY_THROW ) ;
2008-10-01 12:28:29 +00:00
xResMetaDataSup . set ( xPreparedStatement , UNO_QUERY_THROW ) ;
2006-07-10 14:04:12 +00:00
xResultSetMeta . set ( xResMetaDataSup - > getMetaData ( ) , UNO_QUERY_THROW ) ;
}
catch ( const Exception & ) { }
2010-03-17 09:11:06 +00:00
try
{
if ( ! xResultSetMeta . is ( ) )
{
xStatement . reset ( Reference < XStatement > ( m_xConnection - > createStatement ( ) , UNO_QUERY_THROW ) ) ;
Reference < XPropertySet > xStatementProps ( xStatement , UNO_QUERY_THROW ) ;
try { xStatementProps - > setPropertyValue ( PROPERTY_ESCAPE_PROCESSING , makeAny ( sal_False ) ) ; }
catch ( const Exception & ) { DBG_UNHANDLED_EXCEPTION ( ) ; }
xResMetaDataSup . set ( xStatement - > executeQuery ( sSQL ) , UNO_QUERY_THROW ) ;
xResultSetMeta . set ( xResMetaDataSup - > getMetaData ( ) , UNO_QUERY_THROW ) ;
}
}
catch ( const Exception & )
2006-07-10 14:04:12 +00:00
{
2010-03-17 09:11:06 +00:00
//@see issue http://qa.openoffice.org/issues/show_bug.cgi?id=110111
// access returns a different order of column names when executing select * from
// and asking the columns from the metadata.
Reference < XParameters > xParameters ( xPreparedStatement , UNO_QUERY_THROW ) ;
Reference < XIndexAccess > xPara = getParameters ( ) ;
for ( sal_Int32 i = 1 ; i < = xPara - > getCount ( ) ; + + i )
xParameters - > setNull ( i , DataType : : VARCHAR ) ;
xResMetaDataSup . set ( xPreparedStatement - > executeQuery ( ) , UNO_QUERY_THROW ) ;
2006-07-10 14:04:12 +00:00
xResultSetMeta . set ( xResMetaDataSup - > getMetaData ( ) , UNO_QUERY_THROW ) ;
}
2008-12-30 13:32:01 +00:00
if ( aSelectColumns - > get ( ) . empty ( ) )
2006-07-10 14:04:12 +00:00
{
2009-09-08 09:50:48 +00:00
// This is a valid case. If we can syntactically parse the query, but not semantically
2006-07-10 14:04:12 +00:00
// (e.g. because it is based on a table we do not know), then there will be no SelectColumns
2010-01-22 10:31:43 +01:00
aSelectColumns = : : connectivity : : parse : : OParseColumn : : createColumnsForResultSet ( xResultSetMeta , m_xMetaData , xQueryColumns ) ;
2006-07-10 14:04:12 +00:00
break ;
}
const : : comphelper : : UStringMixEqual aCaseCompare ( bCase ) ;
typedef : : std : : set < size_t > SizeTSet ;
SizeTSet aUsedSelectColumns ;
2010-01-13 12:37:12 +01:00
: : connectivity : : parse : : OParseColumn : : StringMap aColumnNames ;
2006-07-10 14:04:12 +00:00
2006-08-22 11:52:10 +00:00
sal_Int32 nCount = xResultSetMeta - > getColumnCount ( ) ;
2008-12-30 13:32:01 +00:00
OSL_ENSURE ( ( size_t ) nCount = = aSelectColumns - > get ( ) . size ( ) , " OSingleSelectQueryComposer::getColumns: inconsistent column counts, this might result in wrong columns! " ) ;
2006-07-10 14:04:12 +00:00
for ( sal_Int32 i = 1 ; i < = nCount ; + + i )
{
2013-01-07 08:44:24 -02:00
OUString sColumnName = xResultSetMeta - > getColumnName ( i ) ;
OUString sColumnLabel ;
2010-01-22 08:14:22 +01:00
if ( xQueryColumns . is ( ) & & xQueryColumns - > hasByName ( sColumnName ) )
{
Reference < XPropertySet > xQueryColumn ( xQueryColumns - > getByName ( sColumnName ) , UNO_QUERY_THROW ) ;
xQueryColumn - > getPropertyValue ( PROPERTY_LABEL ) > > = sColumnLabel ;
}
else
sColumnLabel = xResultSetMeta - > getColumnLabel ( i ) ;
2014-04-17 11:16:55 +02:00
bool bFound = false ;
2009-11-18 13:06:25 +01:00
OSQLColumns : : Vector : : const_iterator aFind = : : connectivity : : find ( aSelectColumns - > get ( ) . begin ( ) , aSelectColumns - > get ( ) . end ( ) , sColumnLabel , aCaseCompare ) ;
2008-12-30 13:32:01 +00:00
size_t nFoundSelectColumnPos = aFind - aSelectColumns - > get ( ) . begin ( ) ;
if ( aFind ! = aSelectColumns - > get ( ) . end ( ) )
2003-12-16 11:40:06 +00:00
{
2006-07-10 14:04:12 +00:00
if ( aUsedSelectColumns . find ( nFoundSelectColumnPos ) ! = aUsedSelectColumns . end ( ) )
{ // we found a column name which exists twice
// so we start after the first found
do
2003-12-16 11:40:06 +00:00
{
2009-11-18 13:06:25 +01:00
aFind = : : connectivity : : findRealName ( + + aFind , aSelectColumns - > get ( ) . end ( ) , sColumnName , aCaseCompare ) ;
2008-12-30 13:32:01 +00:00
nFoundSelectColumnPos = aFind - aSelectColumns - > get ( ) . begin ( ) ;
2003-12-16 11:40:06 +00:00
}
2006-07-10 14:04:12 +00:00
while ( ( aUsedSelectColumns . find ( nFoundSelectColumnPos ) ! = aUsedSelectColumns . end ( ) )
2008-12-30 13:32:01 +00:00
& & ( aFind ! = aSelectColumns - > get ( ) . end ( ) )
2006-07-10 14:04:12 +00:00
) ;
}
2008-12-30 13:32:01 +00:00
if ( aFind ! = aSelectColumns - > get ( ) . end ( ) )
2006-07-10 14:04:12 +00:00
{
2009-11-18 13:06:25 +01:00
( * aFind ) - > getPropertyValue ( PROPERTY_NAME ) > > = sColumnName ;
2006-07-10 14:04:12 +00:00
aUsedSelectColumns . insert ( nFoundSelectColumnPos ) ;
2009-11-18 13:06:25 +01:00
aNames . push_back ( sColumnName ) ;
2014-04-17 11:16:55 +02:00
bFound = true ;
2003-12-16 11:40:06 +00:00
}
}
2006-07-10 14:04:12 +00:00
if ( bFound )
continue ;
2008-12-30 13:32:01 +00:00
OSQLColumns : : Vector : : const_iterator aRealFind = : : connectivity : : findRealName (
2009-11-18 13:06:25 +01:00
aSelectColumns - > get ( ) . begin ( ) , aSelectColumns - > get ( ) . end ( ) , sColumnName , aCaseCompare ) ;
2006-07-10 14:04:12 +00:00
2008-12-30 13:32:01 +00:00
if ( i > static_cast < sal_Int32 > ( aSelectColumns - > get ( ) . size ( ) ) )
2003-12-16 11:40:06 +00:00
{
2008-12-30 13:32:01 +00:00
aSelectColumns - > get ( ) . push_back (
2010-01-13 12:37:12 +01:00
: : connectivity : : parse : : OParseColumn : : createColumnForResultSet ( xResultSetMeta , m_xMetaData , i , aColumnNames )
2006-07-10 14:04:12 +00:00
) ;
2008-12-30 13:32:01 +00:00
OSL_ENSURE ( aSelectColumns - > get ( ) . size ( ) = = ( size_t ) i , " OSingleSelectQueryComposer::getColumns: inconsistency! " ) ;
2003-12-16 11:40:06 +00:00
}
2008-12-30 13:32:01 +00:00
else if ( aRealFind = = aSelectColumns - > get ( ) . end ( ) )
2006-07-10 14:04:12 +00:00
{
// we can now only look if we found it under the realname propertery
// here we have to make the assumption that the position is correct
2008-12-30 13:32:01 +00:00
OSQLColumns : : Vector : : iterator aFind2 = aSelectColumns - > get ( ) . begin ( ) + i - 1 ;
2006-07-10 14:04:12 +00:00
Reference < XPropertySet > xProp ( * aFind2 , UNO_QUERY ) ;
if ( ! xProp . is ( ) | | ! xProp - > getPropertySetInfo ( ) - > hasPropertyByName ( PROPERTY_REALNAME ) )
continue ;
: : connectivity : : parse : : OParseColumn * pColumn = new : : connectivity : : parse : : OParseColumn ( xProp , bCase ) ;
2013-01-07 08:44:24 -02:00
pColumn - > setFunction ( : : comphelper : : getBOOL ( xProp - > getPropertyValue ( " Function " ) ) ) ;
pColumn - > setAggregateFunction ( : : comphelper : : getBOOL ( xProp - > getPropertyValue ( " AggregateFunction " ) ) ) ;
2006-07-10 14:04:12 +00:00
2013-01-07 08:44:24 -02:00
OUString sRealName ;
2006-07-10 14:04:12 +00:00
xProp - > getPropertyValue ( PROPERTY_REALNAME ) > > = sRealName ;
2013-01-07 08:44:24 -02:00
: : std : : vector < OUString > : : iterator aFindName ;
2011-12-19 18:10:37 -02:00
if ( sColumnName . isEmpty ( ) )
2009-11-18 13:06:25 +01:00
xProp - > getPropertyValue ( PROPERTY_NAME ) > > = sColumnName ;
2006-07-10 14:04:12 +00:00
2013-12-06 14:27:53 +01:00
aFindName = : : std : : find_if ( aNames . begin ( ) , aNames . end ( ) , : : std : : bind2nd ( aCaseCompare , sColumnName ) ) ;
2006-07-10 14:04:12 +00:00
sal_Int32 j = 0 ;
while ( aFindName ! = aNames . end ( ) )
{
2013-08-21 15:07:31 +02:00
sColumnName + = OUString : : number ( + + j ) ;
2013-12-06 14:27:53 +01:00
aFindName = : : std : : find_if ( aNames . begin ( ) , aNames . end ( ) , : : std : : bind2nd ( aCaseCompare , sColumnName ) ) ;
2006-07-10 14:04:12 +00:00
}
2009-11-18 13:06:25 +01:00
pColumn - > setName ( sColumnName ) ;
2006-07-10 14:04:12 +00:00
pColumn - > setRealName ( sRealName ) ;
pColumn - > setTableName ( : : comphelper : : getString ( xProp - > getPropertyValue ( PROPERTY_TABLENAME ) ) ) ;
2008-12-30 13:32:01 +00:00
( aSelectColumns - > get ( ) ) [ i - 1 ] = pColumn ;
2006-07-10 14:04:12 +00:00
}
else
continue ;
aUsedSelectColumns . insert ( ( size_t ) ( i - 1 ) ) ;
2009-11-18 13:06:25 +01:00
aNames . push_back ( sColumnName ) ;
2003-12-16 11:40:06 +00:00
}
2005-12-21 12:34:19 +00:00
}
2006-07-10 14:04:12 +00:00
catch ( const Exception & )
{
}
} while ( false ) ;
2013-02-07 17:01:57 +00:00
bool bMissingSomeColumnLabels = ! aNames . empty ( ) & & aNames . size ( ) ! = aSelectColumns - > get ( ) . size ( ) ;
SAL_WARN_IF ( bMissingSomeColumnLabels , " dbaccess " , " We have column labels for *some* columns but not all " ) ;
//^^this happens in the evolution address book where we have real column names of e.g.
//first_name, second_name and city. On parsing via
//OSQLParseTreeIterator::appendColumns it creates some labels using those real names
//but the evo address book gives them proper labels of First Name, Second Name and City
//the munge means that here we have e.g. just "City" as a label because it matches
2013-08-17 23:43:14 +02:00
2013-02-07 17:01:57 +00:00
//This is all a horrible mess
if ( bMissingSomeColumnLabels )
aNames . clear ( ) ;
2006-07-10 14:04:12 +00:00
if ( aNames . empty ( ) )
m_aCurrentColumns [ SelectColumns ] = OPrivateColumns : : createWithIntrinsicNames ( aSelectColumns , bCase , * this , m_aMutex ) ;
else
m_aCurrentColumns [ SelectColumns ] = new OPrivateColumns ( aSelectColumns , bCase , * this , m_aMutex , aNames ) ;
2003-12-16 11:40:06 +00:00
return m_aCurrentColumns [ SelectColumns ] ;
}
2010-10-12 22:40:56 +02:00
2014-04-17 11:16:55 +02:00
bool OSingleSelectQueryComposer : : setORCriteria ( OSQLParseNode * pCondition , OSQLParseTreeIterator & _rIterator ,
2003-12-16 11:40:06 +00:00
: : std : : vector < : : std : : vector < PropertyValue > > & rFilters , const Reference < : : com : : sun : : star : : util : : XNumberFormatter > & xFormatter ) const
{
2012-03-28 17:24:08 +02:00
// Round brackets around the expression
2003-12-16 11:40:06 +00:00
if ( pCondition - > count ( ) = = 3 & &
SQL_ISPUNCTUATION ( pCondition - > getChild ( 0 ) , " ( " ) & &
SQL_ISPUNCTUATION ( pCondition - > getChild ( 2 ) , " ) " ) )
{
2005-01-05 11:27:39 +00:00
return setORCriteria ( pCondition - > getChild ( 1 ) , _rIterator , rFilters , xFormatter ) ;
2003-12-16 11:40:06 +00:00
}
2012-03-28 17:24:08 +02:00
// OR logic expression
2003-12-16 11:40:06 +00:00
// a searchcondition can only look like this: search_condition SQL_TOKEN_OR boolean_term
else if ( SQL_ISRULE ( pCondition , search_condition ) )
{
2014-04-17 11:16:55 +02:00
bool bResult = true ;
2003-12-16 11:40:06 +00:00
for ( int i = 0 ; bResult & & i < 3 ; i + = 2 )
{
2012-03-28 17:24:08 +02:00
// Is the first element a OR logic expression again?
// Then descend recursively ...
2003-12-16 11:40:06 +00:00
if ( SQL_ISRULE ( pCondition - > getChild ( i ) , search_condition ) )
2005-01-05 11:27:39 +00:00
bResult = setORCriteria ( pCondition - > getChild ( i ) , _rIterator , rFilters , xFormatter ) ;
2003-12-16 11:40:06 +00:00
else
{
rFilters . push_back ( : : std : : vector < PropertyValue > ( ) ) ;
2005-01-05 11:27:39 +00:00
bResult = setANDCriteria ( pCondition - > getChild ( i ) , _rIterator , rFilters [ rFilters . size ( ) - 1 ] , xFormatter ) ;
2003-12-16 11:40:06 +00:00
}
}
return bResult ;
}
else
{
rFilters . push_back ( : : std : : vector < PropertyValue > ( ) ) ;
2005-01-05 11:27:39 +00:00
return setANDCriteria ( pCondition , _rIterator , rFilters [ rFilters . size ( ) - 1 ] , xFormatter ) ;
2003-12-16 11:40:06 +00:00
}
}
2014-04-17 11:16:55 +02:00
bool OSingleSelectQueryComposer : : setANDCriteria ( OSQLParseNode * pCondition ,
2005-01-05 11:27:39 +00:00
OSQLParseTreeIterator & _rIterator , : : std : : vector < PropertyValue > & rFilter , const Reference < XNumberFormatter > & xFormatter ) const
2003-12-16 11:40:06 +00:00
{
2012-03-28 17:24:08 +02:00
// Round brackets
2003-12-16 11:40:06 +00:00
if ( SQL_ISRULE ( pCondition , boolean_primary ) )
{
// this should not occur
2013-06-29 17:38:04 +03:00
SAL_WARN ( " dbaccess " , " boolean_primary in And-Criteria " ) ;
2014-04-17 11:16:55 +02:00
return false ;
2003-12-16 11:40:06 +00:00
}
2012-03-28 17:24:08 +02:00
// The first element is an AND logical expression again
2003-12-16 11:40:06 +00:00
else if ( SQL_ISRULE ( pCondition , boolean_term ) & & pCondition - > count ( ) = = 3 )
{
2005-01-05 11:27:39 +00:00
return setANDCriteria ( pCondition - > getChild ( 0 ) , _rIterator , rFilter , xFormatter ) & &
setANDCriteria ( pCondition - > getChild ( 2 ) , _rIterator , rFilter , xFormatter ) ;
2003-12-16 11:40:06 +00:00
}
else if ( SQL_ISRULE ( pCondition , comparison_predicate ) )
{
2005-01-05 11:27:39 +00:00
return setComparsionPredicate ( pCondition , _rIterator , rFilter , xFormatter ) ;
2003-12-16 11:40:06 +00:00
}
else if ( SQL_ISRULE ( pCondition , like_predicate ) | |
SQL_ISRULE ( pCondition , test_for_null ) | |
SQL_ISRULE ( pCondition , in_predicate ) | |
SQL_ISRULE ( pCondition , all_or_any_predicate ) | |
SQL_ISRULE ( pCondition , between_predicate ) )
{
if ( SQL_ISRULE ( pCondition - > getChild ( 0 ) , column_ref ) )
{
PropertyValue aItem ;
2013-01-07 08:44:24 -02:00
OUString aValue ;
OUString aColumnName ;
2003-12-16 11:40:06 +00:00
2006-12-13 15:44:42 +00:00
pCondition - > parseNodeToStr ( aValue , m_xConnection , NULL ) ;
pCondition - > getChild ( 0 ) - > parseNodeToStr ( aColumnName , m_xConnection , NULL ) ;
2003-12-16 11:40:06 +00:00
// don't display the column name
aValue = aValue . copy ( aColumnName . getLength ( ) ) ;
aValue = aValue . trim ( ) ;
2005-01-05 11:27:39 +00:00
aItem . Name = getColumnName ( pCondition - > getChild ( 0 ) , _rIterator ) ;
2003-12-16 11:40:06 +00:00
aItem . Value < < = aValue ;
aItem . Handle = 0 ; // just to know that this is not one the known ones
2010-02-08 14:11:22 +01:00
if ( SQL_ISRULE ( pCondition , like_predicate ) )
2003-12-16 11:40:06 +00:00
{
2010-02-08 14:11:22 +01:00
if ( SQL_ISTOKEN ( pCondition - > getChild ( 1 ) - > getChild ( 0 ) , NOT ) )
2003-12-16 11:40:06 +00:00
aItem . Handle = SQLFilterOperator : : NOT_LIKE ;
else
aItem . Handle = SQLFilterOperator : : LIKE ;
}
else if ( SQL_ISRULE ( pCondition , test_for_null ) )
{
2010-11-24 15:02:39 +01:00
if ( SQL_ISTOKEN ( pCondition - > getChild ( 1 ) - > getChild ( 1 ) , NOT ) )
2003-12-16 11:40:06 +00:00
aItem . Handle = SQLFilterOperator : : NOT_SQLNULL ;
else
aItem . Handle = SQLFilterOperator : : SQLNULL ;
}
else if ( SQL_ISRULE ( pCondition , in_predicate ) )
{
2013-06-29 17:38:04 +03:00
SAL_WARN ( " dbaccess " , " OSingleSelectQueryComposer::setANDCriteria: in_predicate not implemented! " ) ;
2003-12-16 11:40:06 +00:00
}
else if ( SQL_ISRULE ( pCondition , all_or_any_predicate ) )
{
2013-06-29 17:38:04 +03:00
SAL_WARN ( " dbaccess " , " OSingleSelectQueryComposer::setANDCriteria: all_or_any_predicate not implemented! " ) ;
2003-12-16 11:40:06 +00:00
}
else if ( SQL_ISRULE ( pCondition , between_predicate ) )
{
2013-06-29 17:38:04 +03:00
SAL_WARN ( " dbaccess " , " OSingleSelectQueryComposer::setANDCriteria: between_predicate not implemented! " ) ;
2003-12-16 11:40:06 +00:00
}
rFilter . push_back ( aItem ) ;
}
else
2014-04-17 11:16:55 +02:00
return false ;
2003-12-16 11:40:06 +00:00
}
else if ( SQL_ISRULE ( pCondition , existence_test ) | |
SQL_ISRULE ( pCondition , unique_test ) )
{
// this couldn't be handled here, too complex
// as we need a field name
2014-04-17 11:16:55 +02:00
return false ;
2003-12-16 11:40:06 +00:00
}
else
2014-04-17 11:16:55 +02:00
return false ;
2003-12-16 11:40:06 +00:00
2014-04-17 11:16:55 +02:00
return true ;
2003-12-16 11:40:06 +00:00
}
2010-10-12 22:40:56 +02:00
2003-12-16 11:40:06 +00:00
sal_Int32 OSingleSelectQueryComposer : : getPredicateType ( OSQLParseNode * _pPredicate ) const
{
sal_Int32 nPredicate = SQLFilterOperator : : EQUAL ;
switch ( _pPredicate - > getNodeType ( ) )
{
case SQL_NODE_EQUAL :
nPredicate = SQLFilterOperator : : EQUAL ;
break ;
2004-10-22 07:55:36 +00:00
case SQL_NODE_NOTEQUAL :
nPredicate = SQLFilterOperator : : NOT_EQUAL ;
break ;
2003-12-16 11:40:06 +00:00
case SQL_NODE_LESS :
nPredicate = SQLFilterOperator : : LESS ;
break ;
case SQL_NODE_LESSEQ :
nPredicate = SQLFilterOperator : : LESS_EQUAL ;
break ;
case SQL_NODE_GREAT :
nPredicate = SQLFilterOperator : : GREATER ;
break ;
case SQL_NODE_GREATEQ :
nPredicate = SQLFilterOperator : : GREATER_EQUAL ;
break ;
default :
2013-06-29 17:38:04 +03:00
SAL_WARN ( " dbaccess " , " Wrong NodeType! " ) ;
2003-12-16 11:40:06 +00:00
}
return nPredicate ;
}
2010-10-12 22:40:56 +02:00
2014-04-17 11:16:55 +02:00
bool OSingleSelectQueryComposer : : setComparsionPredicate ( OSQLParseNode * pCondition , OSQLParseTreeIterator & _rIterator ,
2003-12-16 11:40:06 +00:00
: : std : : vector < PropertyValue > & rFilter , const Reference < : : com : : sun : : star : : util : : XNumberFormatter > & xFormatter ) const
{
2011-02-03 00:33:36 +01:00
OSL_ENSURE ( SQL_ISRULE ( pCondition , comparison_predicate ) , " setComparsionPredicate: pCondition ist kein ComparsionPredicate " ) ;
2003-12-16 11:40:06 +00:00
if ( SQL_ISRULE ( pCondition - > getChild ( 0 ) , column_ref ) | |
SQL_ISRULE ( pCondition - > getChild ( pCondition - > count ( ) - 1 ) , column_ref ) )
{
PropertyValue aItem ;
2013-01-07 08:44:24 -02:00
OUString aValue ;
2003-12-16 11:40:06 +00:00
sal_uInt32 nPos ;
if ( SQL_ISRULE ( pCondition - > getChild ( 0 ) , column_ref ) )
{
nPos = 0 ;
sal_uInt32 i = 1 ;
aItem . Handle = getPredicateType ( pCondition - > getChild ( i ) ) ;
// don't display the equal
if ( pCondition - > getChild ( i ) - > getNodeType ( ) = = SQL_NODE_EQUAL )
i + + ;
// go forward
for ( ; i < pCondition - > count ( ) ; i + + )
2006-12-13 15:44:42 +00:00
pCondition - > getChild ( i ) - > parseNodeToPredicateStr (
aValue , m_xConnection , xFormatter , m_aLocale , static_cast < sal_Char > ( m_sDecimalSep . toChar ( ) ) ) ;
2003-12-16 11:40:06 +00:00
}
else if ( SQL_ISRULE ( pCondition - > getChild ( pCondition - > count ( ) - 1 ) , column_ref ) )
{
nPos = pCondition - > count ( ) - 1 ;
2006-06-20 01:37:34 +00:00
sal_Int32 i = pCondition - > count ( ) - 2 ;
2003-12-16 11:40:06 +00:00
switch ( pCondition - > getChild ( i ) - > getNodeType ( ) )
{
case SQL_NODE_EQUAL :
// don't display the equal
i - - ;
aItem . Handle = SQLFilterOperator : : EQUAL ;
break ;
2004-10-22 07:55:36 +00:00
case SQL_NODE_NOTEQUAL :
i - - ;
aItem . Handle = SQLFilterOperator : : NOT_EQUAL ;
break ;
2003-12-16 11:40:06 +00:00
case SQL_NODE_LESS :
// take the opposite as we change the order
i - - ;
2013-01-07 08:44:24 -02:00
aValue = " >= " ;
2003-12-16 11:40:06 +00:00
aItem . Handle = SQLFilterOperator : : GREATER_EQUAL ;
break ;
case SQL_NODE_LESSEQ :
// take the opposite as we change the order
i - - ;
2013-01-07 08:44:24 -02:00
aValue = " > " ;
2003-12-16 11:40:06 +00:00
aItem . Handle = SQLFilterOperator : : GREATER ;
break ;
case SQL_NODE_GREAT :
// take the opposite as we change the order
i - - ;
2013-01-07 08:44:24 -02:00
aValue = " <= " ;
2003-12-16 11:40:06 +00:00
aItem . Handle = SQLFilterOperator : : LESS_EQUAL ;
break ;
case SQL_NODE_GREATEQ :
// take the opposite as we change the order
i - - ;
2013-01-07 08:44:24 -02:00
aValue = " < " ;
2003-12-16 11:40:06 +00:00
aItem . Handle = SQLFilterOperator : : LESS ;
break ;
2006-06-20 01:37:34 +00:00
default :
break ;
2003-12-16 11:40:06 +00:00
}
// go backward
for ( ; i > = 0 ; i - - )
2006-12-13 15:44:42 +00:00
pCondition - > getChild ( i ) - > parseNodeToPredicateStr (
aValue , m_xConnection , xFormatter , m_aLocale , static_cast < sal_Char > ( m_sDecimalSep . toChar ( ) ) ) ;
2003-12-16 11:40:06 +00:00
}
else
2014-04-17 11:16:55 +02:00
return false ;
2003-12-16 11:40:06 +00:00
2005-01-05 11:27:39 +00:00
aItem . Name = getColumnName ( pCondition - > getChild ( nPos ) , _rIterator ) ;
2003-12-16 11:40:06 +00:00
aItem . Value < < = aValue ;
rFilter . push_back ( aItem ) ;
}
else if ( SQL_ISRULE ( pCondition - > getChild ( 0 ) , set_fct_spec ) | |
SQL_ISRULE ( pCondition - > getChild ( 0 ) , general_set_fct ) )
{
PropertyValue aItem ;
2013-01-07 08:44:24 -02:00
OUString aValue ;
OUString aColumnName ;
2003-12-16 11:40:06 +00:00
2011-01-10 13:41:20 +01:00
pCondition - > getChild ( 2 ) - > parseNodeToPredicateStr ( aValue , m_xConnection , xFormatter , m_aLocale , static_cast < sal_Char > ( m_sDecimalSep . toChar ( ) ) ) ;
2006-12-13 15:44:42 +00:00
pCondition - > getChild ( 0 ) - > parseNodeToPredicateStr ( aColumnName , m_xConnection , xFormatter , m_aLocale , static_cast < sal_Char > ( m_sDecimalSep . toChar ( ) ) ) ;
2003-12-16 11:40:06 +00:00
2010-02-08 14:11:22 +01:00
aItem . Name = getColumnName ( pCondition - > getChild ( 0 ) , _rIterator ) ;
2003-12-16 11:40:06 +00:00
aItem . Value < < = aValue ;
2011-01-10 13:41:20 +01:00
aItem . Handle = getPredicateType ( pCondition - > getChild ( 1 ) ) ;
2003-12-16 11:40:06 +00:00
rFilter . push_back ( aItem ) ;
}
2012-03-28 17:24:08 +02:00
else // Can only be an expression
2003-12-16 11:40:06 +00:00
{
PropertyValue aItem ;
2013-01-07 08:44:24 -02:00
OUString aName , aValue ;
2003-12-16 11:40:06 +00:00
OSQLParseNode * pLhs = pCondition - > getChild ( 0 ) ;
OSQLParseNode * pRhs = pCondition - > getChild ( 2 ) ;
2012-03-28 17:24:08 +02:00
// Field names
2003-12-16 11:40:06 +00:00
sal_uInt16 i ;
for ( i = 0 ; i < pLhs - > count ( ) ; i + + )
2010-09-01 09:29:20 +02:00
pLhs - > getChild ( i ) - > parseNodeToPredicateStr ( aName , m_xConnection , xFormatter , m_aLocale , static_cast < sal_Char > ( m_sDecimalSep . toChar ( ) ) ) ;
2003-12-16 11:40:06 +00:00
2012-03-28 17:24:08 +02:00
// Criterion
2011-01-10 13:41:20 +01:00
aItem . Handle = getPredicateType ( pCondition - > getChild ( 1 ) ) ;
2003-12-16 11:40:06 +00:00
aValue = pCondition - > getChild ( 1 ) - > getTokenValue ( ) ;
for ( i = 0 ; i < pRhs - > count ( ) ; i + + )
2010-09-01 09:29:20 +02:00
pRhs - > getChild ( i ) - > parseNodeToPredicateStr ( aValue , m_xConnection , xFormatter , m_aLocale , static_cast < sal_Char > ( m_sDecimalSep . toChar ( ) ) ) ;
2003-12-16 11:40:06 +00:00
aItem . Name = aName ;
aItem . Value < < = aValue ;
rFilter . push_back ( aItem ) ;
}
2014-04-17 11:16:55 +02:00
return true ;
2003-12-16 11:40:06 +00:00
}
2010-10-12 22:40:56 +02:00
2012-03-28 17:24:08 +02:00
// Functions for analysing SQL
2013-01-07 08:44:24 -02:00
OUString OSingleSelectQueryComposer : : getColumnName ( : : connectivity : : OSQLParseNode * pColumnRef , OSQLParseTreeIterator & _rIterator ) const
2003-12-16 11:40:06 +00:00
{
2013-01-07 08:44:24 -02:00
OUString aTableRange , aColumnName ;
2005-01-05 11:27:39 +00:00
_rIterator . getColumnRange ( pColumnRef , aColumnName , aTableRange ) ;
2003-12-16 11:40:06 +00:00
return aColumnName ;
}
2010-10-12 22:40:56 +02:00
2014-02-25 21:31:58 +01:00
OUString SAL_CALL OSingleSelectQueryComposer : : getFilter ( ) throw ( RuntimeException , std : : exception )
2003-12-16 11:40:06 +00:00
{
2005-01-05 11:27:39 +00:00
: : connectivity : : checkDisposed ( OSubComponent : : rBHelper . bDisposed ) ;
: : osl : : MutexGuard aGuard ( m_aMutex ) ;
2014-04-17 11:16:55 +02:00
return getSQLPart ( Where , m_aAdditiveIterator , false ) ;
2003-12-16 11:40:06 +00:00
}
2010-10-12 22:40:56 +02:00
2014-02-25 21:31:58 +01:00
OUString SAL_CALL OSingleSelectQueryComposer : : getOrder ( ) throw ( RuntimeException , std : : exception )
2003-12-16 11:40:06 +00:00
{
2005-01-05 11:27:39 +00:00
: : connectivity : : checkDisposed ( OSubComponent : : rBHelper . bDisposed ) ;
: : osl : : MutexGuard aGuard ( m_aMutex ) ;
2014-04-17 11:16:55 +02:00
return getSQLPart ( Order , m_aAdditiveIterator , false ) ;
2003-12-16 11:40:06 +00:00
}
2010-10-12 22:40:56 +02:00
2014-02-25 21:31:58 +01:00
OUString SAL_CALL OSingleSelectQueryComposer : : getGroup ( ) throw ( RuntimeException , std : : exception )
2003-12-16 11:40:06 +00:00
{
2005-01-05 11:27:39 +00:00
: : connectivity : : checkDisposed ( OSubComponent : : rBHelper . bDisposed ) ;
: : osl : : MutexGuard aGuard ( m_aMutex ) ;
2014-04-17 11:16:55 +02:00
return getSQLPart ( Group , m_aAdditiveIterator , false ) ;
2003-12-16 11:40:06 +00:00
}
2010-10-12 22:40:56 +02:00
2014-02-25 21:31:58 +01:00
OUString OSingleSelectQueryComposer : : getHavingClause ( ) throw ( RuntimeException , std : : exception )
2003-12-16 11:40:06 +00:00
{
2005-01-05 11:27:39 +00:00
: : connectivity : : checkDisposed ( OSubComponent : : rBHelper . bDisposed ) ;
: : osl : : MutexGuard aGuard ( m_aMutex ) ;
2014-04-17 11:16:55 +02:00
return getSQLPart ( Having , m_aAdditiveIterator , false ) ;
2003-12-16 11:40:06 +00:00
}
2010-10-12 22:40:56 +02:00
2013-01-07 08:44:24 -02:00
OUString OSingleSelectQueryComposer : : getTableAlias ( const Reference < XPropertySet > & column ) const
2003-12-16 11:40:06 +00:00
{
2013-01-07 08:44:24 -02:00
OUString sReturn ;
2003-12-16 11:40:06 +00:00
if ( m_pTables & & m_pTables - > getCount ( ) > 1 )
{
2013-01-07 08:44:24 -02:00
OUString aCatalog , aSchema , aTable , aComposedName , aColumnName ;
2012-11-01 09:56:58 +01:00
if ( column - > getPropertySetInfo ( ) - > hasPropertyByName ( PROPERTY_CATALOGNAME ) )
column - > getPropertyValue ( PROPERTY_CATALOGNAME ) > > = aCatalog ;
if ( column - > getPropertySetInfo ( ) - > hasPropertyByName ( PROPERTY_SCHEMANAME ) )
column - > getPropertyValue ( PROPERTY_SCHEMANAME ) > > = aSchema ;
if ( column - > getPropertySetInfo ( ) - > hasPropertyByName ( PROPERTY_TABLENAME ) )
column - > getPropertyValue ( PROPERTY_TABLENAME ) > > = aTable ;
2003-12-16 11:40:06 +00:00
column - > getPropertyValue ( PROPERTY_NAME ) > > = aColumnName ;
2013-01-07 08:44:24 -02:00
Sequence < OUString > aNames ( m_pTables - > getElementNames ( ) ) ;
2013-08-02 12:09:53 +02:00
const OUString * pBegin = aNames . getConstArray ( ) ;
const OUString * const pEnd = pBegin + aNames . getLength ( ) ;
2003-12-16 11:40:06 +00:00
2011-12-19 18:10:37 -02:00
if ( aTable . isEmpty ( ) )
2010-11-09 22:15:21 +00:00
{ // we haven't found a table name, now we must search every table for this column
2003-12-16 11:40:06 +00:00
for ( ; pBegin ! = pEnd ; + + pBegin )
{
Reference < XColumnsSupplier > xColumnsSupp ;
m_pTables - > getByName ( * pBegin ) > > = xColumnsSupp ;
if ( xColumnsSupp . is ( ) & & xColumnsSupp - > getColumns ( ) - > hasByName ( aColumnName ) )
{
aTable = * pBegin ;
break ;
}
}
}
else
{
2014-03-31 16:46:08 +02:00
aComposedName = : : dbtools : : composeTableName ( m_xMetaData , aCatalog , aSchema , aTable , false , : : dbtools : : eInDataManipulation ) ;
2003-12-16 11:40:06 +00:00
2013-08-02 12:10:25 +02:00
// Is this the right case for the table name?
// Else, look for it with different case, if applicable.
2003-12-16 11:40:06 +00:00
if ( ! m_pTables - > hasByName ( aComposedName ) )
{
2005-01-05 11:27:39 +00:00
: : comphelper : : UStringMixLess aTmp ( m_aAdditiveIterator . getTables ( ) . key_comp ( ) ) ;
2003-12-16 11:40:06 +00:00
: : comphelper : : UStringMixEqual aComp ( static_cast < : : comphelper : : UStringMixLess * > ( & aTmp ) - > isCaseSensitive ( ) ) ;
for ( ; pBegin ! = pEnd ; + + pBegin )
{
Reference < XPropertySet > xTableProp ;
m_pTables - > getByName ( * pBegin ) > > = xTableProp ;
OSL_ENSURE ( xTableProp . is ( ) , " Table isn't a propertyset! " ) ;
if ( xTableProp . is ( ) )
{
2013-01-07 08:44:24 -02:00
OUString aCatalog2 , aSchema2 , aTable2 ;
2003-12-16 11:40:06 +00:00
xTableProp - > getPropertyValue ( PROPERTY_CATALOGNAME ) > > = aCatalog2 ;
xTableProp - > getPropertyValue ( PROPERTY_SCHEMANAME ) > > = aSchema2 ;
xTableProp - > getPropertyValue ( PROPERTY_NAME ) > > = aTable2 ;
if ( aComp ( aCatalog , aCatalog2 ) & & aComp ( aSchema , aSchema2 ) & & aComp ( aTable , aTable2 ) )
{
aCatalog = aCatalog2 ;
aSchema = aSchema2 ;
aTable = aTable2 ;
break ;
}
}
}
}
}
if ( pBegin ! = pEnd )
{
2014-03-31 16:46:08 +02:00
sReturn = : : dbtools : : composeTableName ( m_xMetaData , aCatalog , aSchema , aTable , true , : : dbtools : : eInDataManipulation ) + " . " ;
2003-12-16 11:40:06 +00:00
}
}
return sReturn ;
}
2010-10-12 22:40:56 +02:00
2014-02-25 21:31:58 +01:00
Reference < XIndexAccess > SAL_CALL OSingleSelectQueryComposer : : getParameters ( ) throw ( RuntimeException , std : : exception )
2003-12-16 11:40:06 +00:00
{
// now set the Parameters
if ( ! m_aCurrentColumns [ ParameterColumns ] )
{
2010-10-15 12:22:54 -05:00
: : rtl : : Reference < OSQLColumns > aCols = m_aSqlIterator . getParameters ( ) ;
2013-01-07 08:44:24 -02:00
: : std : : vector < OUString > aNames ;
2009-07-03 12:24:35 +00:00
OSQLColumns : : Vector : : const_iterator aEnd = aCols - > get ( ) . end ( ) ;
for ( OSQLColumns : : Vector : : const_iterator aIter = aCols - > get ( ) . begin ( ) ; aIter ! = aEnd ; + + aIter )
2003-12-16 11:40:06 +00:00
aNames . push_back ( getString ( ( * aIter ) - > getPropertyValue ( PROPERTY_NAME ) ) ) ;
2014-04-17 11:16:55 +02:00
m_aCurrentColumns [ ParameterColumns ] = new OPrivateColumns ( aCols , m_xMetaData - > supportsMixedCaseQuotedIdentifiers ( ) , * this , m_aMutex , aNames , true ) ;
2003-12-16 11:40:06 +00:00
}
return m_aCurrentColumns [ ParameterColumns ] ;
}
2010-10-12 22:40:56 +02:00
2009-07-06 09:00:26 +00:00
void OSingleSelectQueryComposer : : clearColumns ( const EColumnType _eType )
2004-03-15 11:41:53 +00:00
{
2009-07-06 09:00:26 +00:00
OPrivateColumns * pColumns = m_aCurrentColumns [ _eType ] ;
if ( pColumns ! = NULL )
2004-03-15 11:41:53 +00:00
{
2009-07-06 09:00:26 +00:00
pColumns - > disposing ( ) ;
m_aColumnsCollection . push_back ( pColumns ) ;
m_aCurrentColumns [ _eType ] = NULL ;
2004-03-15 11:41:53 +00:00
}
}
2010-10-12 22:40:56 +02:00
2003-12-16 11:40:06 +00:00
void OSingleSelectQueryComposer : : clearCurrentCollections ( )
{
: : std : : vector < OPrivateColumns * > : : iterator aIter = m_aCurrentColumns . begin ( ) ;
: : std : : vector < OPrivateColumns * > : : iterator aEnd = m_aCurrentColumns . end ( ) ;
for ( ; aIter ! = aEnd ; + + aIter )
{
if ( * aIter )
{
( * aIter ) - > disposing ( ) ;
m_aColumnsCollection . push_back ( * aIter ) ;
* aIter = NULL ;
}
}
if ( m_pTables )
{
m_pTables - > disposing ( ) ;
m_aTablesCollection . push_back ( m_pTables ) ;
m_pTables = NULL ;
}
}
2010-10-12 22:40:56 +02:00
2005-01-05 11:27:39 +00:00
Reference < XIndexAccess > OSingleSelectQueryComposer : : setCurrentColumns ( EColumnType _eType ,
2010-10-15 12:22:54 -05:00
const : : rtl : : Reference < OSQLColumns > & _rCols )
2003-12-16 11:40:06 +00:00
{
: : connectivity : : checkDisposed ( OSubComponent : : rBHelper . bDisposed ) ;
: : osl : : MutexGuard aGuard ( m_aMutex ) ;
// now set the group columns
if ( ! m_aCurrentColumns [ _eType ] )
{
2013-01-07 08:44:24 -02:00
: : std : : vector < OUString > aNames ;
2009-07-03 12:24:35 +00:00
OSQLColumns : : Vector : : const_iterator aEnd = _rCols - > get ( ) . end ( ) ;
for ( OSQLColumns : : Vector : : const_iterator aIter = _rCols - > get ( ) . begin ( ) ; aIter ! = aEnd ; + + aIter )
2003-12-16 11:40:06 +00:00
aNames . push_back ( getString ( ( * aIter ) - > getPropertyValue ( PROPERTY_NAME ) ) ) ;
2014-04-17 11:16:55 +02:00
m_aCurrentColumns [ _eType ] = new OPrivateColumns ( _rCols , m_xMetaData - > supportsMixedCaseQuotedIdentifiers ( ) , * this , m_aMutex , aNames , true ) ;
2003-12-16 11:40:06 +00:00
}
return m_aCurrentColumns [ _eType ] ;
}
2010-10-12 22:40:56 +02:00
2014-02-25 21:31:58 +01:00
Reference < XIndexAccess > SAL_CALL OSingleSelectQueryComposer : : getGroupColumns ( ) throw ( RuntimeException , std : : exception )
2003-12-16 11:40:06 +00:00
{
2005-01-05 11:27:39 +00:00
return setCurrentColumns ( GroupByColumns , m_aAdditiveIterator . getGroupColumns ( ) ) ;
2003-12-16 11:40:06 +00:00
}
2010-10-12 22:40:56 +02:00
2014-02-25 21:31:58 +01:00
Reference < XIndexAccess > SAL_CALL OSingleSelectQueryComposer : : getOrderColumns ( ) throw ( RuntimeException , std : : exception )
2003-12-16 11:40:06 +00:00
{
2005-01-05 11:27:39 +00:00
return setCurrentColumns ( OrderColumns , m_aAdditiveIterator . getOrderColumns ( ) ) ;
2003-12-16 11:40:06 +00:00
}
2010-10-12 22:40:56 +02:00
2014-02-25 21:31:58 +01:00
OUString SAL_CALL OSingleSelectQueryComposer : : getQueryWithSubstitution ( ) throw ( SQLException , RuntimeException , std : : exception )
2006-07-10 14:04:12 +00:00
{
: : osl : : MutexGuard aGuard ( m_aMutex ) ;
: : connectivity : : checkDisposed ( OSubComponent : : rBHelper . bDisposed ) ;
2013-01-07 08:44:24 -02:00
OUString sSqlStatement ( getQuery ( ) ) ;
2006-07-10 14:04:12 +00:00
const OSQLParseNode * pStatementNode = m_aSqlIterator . getParseTree ( ) ;
if ( pStatementNode )
{
SQLException aError ;
if ( ! pStatementNode - > parseNodeToExecutableStatement ( sSqlStatement , m_xConnection , m_aSqlParser , & aError ) )
throw SQLException ( aError ) ;
}
return sSqlStatement ;
}
2010-10-12 22:40:56 +02:00
2013-01-07 08:44:24 -02:00
OUString OSingleSelectQueryComposer : : getStatementPart ( TGetParseNode & _aGetFunctor , OSQLParseTreeIterator & _rIterator )
2003-12-16 11:40:06 +00:00
{
2013-01-07 08:44:24 -02:00
OUString sResult ;
2003-12-16 11:40:06 +00:00
2005-01-05 11:27:39 +00:00
const OSQLParseNode * pNode = _aGetFunctor ( & _rIterator ) ;
2003-12-16 11:40:06 +00:00
if ( pNode )
2006-12-13 15:44:42 +00:00
pNode - > parseNodeToStr ( sResult , m_xConnection ) ;
2003-12-16 11:40:06 +00:00
return sResult ;
}
2010-10-12 22:40:56 +02:00
2003-12-16 11:40:06 +00:00
namespace
{
2014-09-18 22:49:12 +00:00
OUString lcl_getDecomposedColumnName ( const OUString & rComposedName , const OUString & rQuoteString )
{
const sal_Int32 nQuoteLength = rQuoteString . getLength ( ) ;
OUString sName = rComposedName . trim ( ) ;
OUString sColumnName ;
sal_Int32 nPos , nRPos = 0 ;
for ( ; ; )
{
nPos = sName . indexOf ( rQuoteString , nRPos ) ;
if ( nPos > = 0 )
{
nRPos = sName . indexOf ( rQuoteString , nPos + nQuoteLength ) ;
if ( nRPos > nPos )
{
if ( nRPos + nQuoteLength < sName . getLength ( ) )
{
nRPos + = nQuoteLength ; // -1 + 1 skip dot
}
else
{
sColumnName = sName . copy ( nPos + nQuoteLength , nRPos - nPos - nQuoteLength ) ;
break ;
}
}
else
break ;
}
else
break ;
}
return sColumnName . isEmpty ( ) ? rComposedName : sColumnName ;
}
OUString lcl_getCondition ( const Sequence < Sequence < PropertyValue > > & filter ,
const OPredicateInputController & i_aPredicateInputController ,
const Reference < XNameAccess > & i_xSelectColumns ,
const OUString & rQuoteString )
2003-12-16 11:40:06 +00:00
{
2013-01-07 08:44:24 -02:00
OUStringBuffer sRet ;
2003-12-16 11:40:06 +00:00
const Sequence < PropertyValue > * pOrIter = filter . getConstArray ( ) ;
const Sequence < PropertyValue > * pOrEnd = pOrIter + filter . getLength ( ) ;
while ( pOrIter ! = pOrEnd )
{
2004-10-22 07:55:36 +00:00
if ( pOrIter - > getLength ( ) )
2003-12-16 11:40:06 +00:00
{
2009-07-03 12:24:35 +00:00
sRet . append ( L_BRACKET ) ;
2004-10-22 07:55:36 +00:00
const PropertyValue * pAndIter = pOrIter - > getConstArray ( ) ;
const PropertyValue * pAndEnd = pAndIter + pOrIter - > getLength ( ) ;
while ( pAndIter ! = pAndEnd )
2003-12-16 11:40:06 +00:00
{
2009-07-03 12:24:35 +00:00
sRet . append ( pAndIter - > Name ) ;
2013-01-07 08:44:24 -02:00
OUString sValue ;
2004-10-22 07:55:36 +00:00
pAndIter - > Value > > = sValue ;
2014-09-18 22:49:12 +00:00
const OUString sColumnName = lcl_getDecomposedColumnName ( pAndIter - > Name , rQuoteString ) ;
if ( i_xSelectColumns . is ( ) & & i_xSelectColumns - > hasByName ( sColumnName ) )
2011-01-10 13:41:20 +01:00
{
2014-09-18 22:49:12 +00:00
Reference < XPropertySet > xColumn ( i_xSelectColumns - > getByName ( sColumnName ) , UNO_QUERY ) ;
2014-03-31 16:58:07 +02:00
sValue = i_aPredicateInputController . getPredicateValue ( sValue , xColumn , true ) ;
2011-01-10 13:41:20 +01:00
}
else
{
2014-03-31 16:58:07 +02:00
sValue = i_aPredicateInputController . getPredicateValue ( pAndIter - > Name , sValue , true ) ;
2011-01-10 13:41:20 +01:00
}
2010-01-22 08:14:22 +01:00
lcl_addFilterCriteria_throw ( pAndIter - > Handle , sValue , sRet ) ;
2004-10-22 07:55:36 +00:00
+ + pAndIter ;
if ( pAndIter ! = pAndEnd )
2009-07-03 12:24:35 +00:00
sRet . append ( STR_AND ) ;
2003-12-16 11:40:06 +00:00
}
2009-07-03 12:24:35 +00:00
sRet . append ( R_BRACKET ) ;
2003-12-16 11:40:06 +00:00
}
+ + pOrIter ;
2013-06-17 20:01:18 +02:00
if ( pOrIter ! = pOrEnd & & ! sRet . isEmpty ( ) )
2009-07-03 12:24:35 +00:00
sRet . append ( STR_OR ) ;
2003-12-16 11:40:06 +00:00
}
2009-07-03 12:24:35 +00:00
return sRet . makeStringAndClear ( ) ;
2003-12-16 11:40:06 +00:00
}
}
2010-10-12 22:40:56 +02:00
2014-02-25 21:31:58 +01:00
void SAL_CALL OSingleSelectQueryComposer : : setStructuredFilter ( const Sequence < Sequence < PropertyValue > > & filter ) throw ( SQLException , : : com : : sun : : star : : lang : : IllegalArgumentException , RuntimeException , std : : exception )
2003-12-16 11:40:06 +00:00
{
2013-05-18 08:53:54 +02:00
OPredicateInputController aPredicateInput ( m_aContext , m_xConnection , & m_aParseContext ) ;
2014-09-18 22:49:12 +00:00
setFilter ( lcl_getCondition ( filter , aPredicateInput , getColumns ( ) , m_xMetaData - > getIdentifierQuoteString ( ) ) ) ;
2003-12-16 11:40:06 +00:00
}
2010-10-12 22:40:56 +02:00
2014-02-25 21:31:58 +01:00
void SAL_CALL OSingleSelectQueryComposer : : setStructuredHavingClause ( const Sequence < Sequence < PropertyValue > > & filter ) throw ( SQLException , RuntimeException , std : : exception )
2003-12-16 11:40:06 +00:00
{
2013-03-19 13:08:47 +02:00
OPredicateInputController aPredicateInput ( m_aContext , m_xConnection ) ;
2014-09-18 22:49:12 +00:00
setHavingClause ( lcl_getCondition ( filter , aPredicateInput , getColumns ( ) , m_xMetaData - > getIdentifierQuoteString ( ) ) ) ;
2003-12-16 11:40:06 +00:00
}
2010-10-12 22:40:56 +02:00
2014-04-17 11:16:55 +02:00
void OSingleSelectQueryComposer : : setConditionByColumn ( const Reference < XPropertySet > & column , bool andCriteria , : : std : : mem_fun1_t < bool , OSingleSelectQueryComposer , const OUString & > & _aSetFunctor , sal_Int32 filterOperator )
2003-12-16 11:40:06 +00:00
{
2014-08-07 09:40:02 +02:00
try
{
: : connectivity : : checkDisposed ( OSubComponent : : rBHelper . bDisposed ) ;
2003-12-16 11:40:06 +00:00
2014-08-07 09:40:02 +02:00
if ( ! column . is ( )
| | ! column - > getPropertySetInfo ( ) - > hasPropertyByName ( PROPERTY_VALUE )
| | ! column - > getPropertySetInfo ( ) - > hasPropertyByName ( PROPERTY_NAME )
| | ! column - > getPropertySetInfo ( ) - > hasPropertyByName ( PROPERTY_TYPE ) )
throw SQLException ( DBACORE_RESSTRING ( RID_STR_COLUMN_NOT_VALID ) , * this , SQLSTATE_GENERAL , 1000 , Any ( ) ) ;
2003-12-16 11:40:06 +00:00
2014-08-07 09:40:02 +02:00
sal_Int32 nType = 0 ;
column - > getPropertyValue ( PROPERTY_TYPE ) > > = nType ;
sal_Int32 nSearchable = dbtools : : getSearchColumnFlag ( m_xConnection , nType ) ;
if ( nSearchable = = ColumnSearch : : NONE )
throw SQLException ( DBACORE_RESSTRING ( RID_STR_COLUMN_NOT_SEARCHABLE ) , * this , SQLSTATE_GENERAL , 1000 , Any ( ) ) ;
2003-12-16 11:40:06 +00:00
2014-08-07 09:40:02 +02:00
: : osl : : MutexGuard aGuard ( m_aMutex ) ;
2003-12-16 11:40:06 +00:00
2014-08-07 09:40:02 +02:00
OUString aName ;
column - > getPropertyValue ( PROPERTY_NAME ) > > = aName ;
2003-12-16 11:40:06 +00:00
2014-08-07 09:40:02 +02:00
Any aValue ;
column - > getPropertyValue ( PROPERTY_VALUE ) > > = aValue ;
2003-12-16 11:40:06 +00:00
2014-08-07 09:40:02 +02:00
OUStringBuffer aSQL ;
const OUString aQuote = m_xMetaData - > getIdentifierQuoteString ( ) ;
getColumns ( ) ;
2013-08-02 12:10:57 +02:00
2014-08-07 09:40:02 +02:00
// TODO: if this is called for HAVING, check that the column is a GROUP BY column
// or that it is an aggregate function
2003-12-16 11:40:06 +00:00
2014-08-07 09:40:02 +02:00
if ( m_aCurrentColumns [ SelectColumns ] & & m_aCurrentColumns [ SelectColumns ] - > hasByName ( aName ) )
2003-12-16 11:40:06 +00:00
{
2014-08-07 09:40:02 +02:00
Reference < XPropertySet > xColumn ;
m_aCurrentColumns [ SelectColumns ] - > getByName ( aName ) > > = xColumn ;
OSL_ENSURE ( xColumn - > getPropertySetInfo ( ) - > hasPropertyByName ( PROPERTY_REALNAME ) , " Property REALNAME not available! " ) ;
OSL_ENSURE ( xColumn - > getPropertySetInfo ( ) - > hasPropertyByName ( PROPERTY_TABLENAME ) , " Property TABLENAME not available! " ) ;
OSL_ENSURE ( xColumn - > getPropertySetInfo ( ) - > hasPropertyByName ( " AggregateFunction " ) , " Property AggregateFunction not available! " ) ;
OUString sRealName , sTableName ;
xColumn - > getPropertyValue ( PROPERTY_REALNAME ) > > = sRealName ;
xColumn - > getPropertyValue ( PROPERTY_TABLENAME ) > > = sTableName ;
if ( sTableName . indexOf ( ' . ' , 0 ) ! = - 1 )
{
OUString aCatlog , aSchema , aTable ;
: : dbtools : : qualifiedNameComponents ( m_xMetaData , sTableName , aCatlog , aSchema , aTable , : : dbtools : : eInDataManipulation ) ;
sTableName = : : dbtools : : composeTableName ( m_xMetaData , aCatlog , aSchema , aTable , true , : : dbtools : : eInDataManipulation ) ;
}
else
sTableName = : : dbtools : : quoteName ( aQuote , sTableName ) ;
2003-12-16 11:40:06 +00:00
2014-08-07 09:40:02 +02:00
if ( ! : : comphelper : : getBOOL ( xColumn - > getPropertyValue ( " Function " ) ) )
{
aSQL = sTableName + " . " + : : dbtools : : quoteName ( aQuote , sRealName ) ;
}
else
aSQL = sRealName ;
2004-10-22 07:55:36 +00:00
}
else
2010-01-22 08:14:22 +01:00
{
2014-08-07 09:40:02 +02:00
aSQL = getTableAlias ( column ) + : : dbtools : : quoteName ( aQuote , aName ) ;
2010-01-22 08:14:22 +01:00
}
2014-08-07 09:40:02 +02:00
if ( aValue . hasValue ( ) )
2003-12-16 11:40:06 +00:00
{
2014-08-07 09:40:02 +02:00
if ( ! m_xTypeConverter . is ( ) )
m_xTypeConverter . set ( Converter : : create ( m_aContext ) ) ;
OSL_ENSURE ( m_xTypeConverter . is ( ) , " NO typeconverter! " ) ;
if ( nType ! = DataType : : BOOLEAN & & DataType : : BIT ! = nType )
{
OUString sEmpty ;
lcl_addFilterCriteria_throw ( filterOperator , sEmpty , aSQL ) ;
}
switch ( nType )
{
2003-12-16 11:40:06 +00:00
case DataType : : VARCHAR :
case DataType : : CHAR :
case DataType : : LONGVARCHAR :
2014-03-31 16:46:08 +02:00
aSQL . append ( DBTypeConversion : : toSQLString ( nType , aValue , true , m_xTypeConverter ) ) ;
2003-12-16 11:40:06 +00:00
break ;
2009-11-11 14:16:42 +01:00
case DataType : : CLOB :
{
Reference < XClob > xClob ( aValue , UNO_QUERY ) ;
if ( xClob . is ( ) )
{
const : : sal_Int64 nLength = xClob - > length ( ) ;
if ( sal_Int64 ( nLength + aSQL . getLength ( ) + STR_LIKE . getLength ( ) ) < sal_Int64 ( SAL_MAX_INT32 ) )
{
2013-01-07 08:44:24 -02:00
aSQL . append ( " ' " + xClob - > getSubString ( 1 , ( sal_Int32 ) nLength ) + " ' " ) ;
2009-11-11 14:16:42 +01:00
}
}
else
{
2014-03-31 16:46:08 +02:00
aSQL . append ( DBTypeConversion : : toSQLString ( nType , aValue , true , m_xTypeConverter ) ) ;
2009-11-11 14:16:42 +01:00
}
}
break ;
2003-12-16 11:40:06 +00:00
case DataType : : VARBINARY :
case DataType : : BINARY :
case DataType : : LONGVARBINARY :
{
Sequence < sal_Int8 > aSeq ;
if ( aValue > > = aSeq )
{
if ( nSearchable = = ColumnSearch : : CHAR )
{
2013-01-07 08:44:24 -02:00
aSQL . append ( " \' " ) ;
2003-12-16 11:40:06 +00:00
}
2007-11-21 14:33:37 +00:00
aSQL . appendAscii ( " 0x " ) ;
2003-12-16 11:40:06 +00:00
const sal_Int8 * pBegin = aSeq . getConstArray ( ) ;
const sal_Int8 * pEnd = pBegin + aSeq . getLength ( ) ;
for ( ; pBegin ! = pEnd ; + + pBegin )
{
2007-11-21 14:33:37 +00:00
aSQL . append ( ( sal_Int32 ) * pBegin , 16 ) . getStr ( ) ;
2003-12-16 11:40:06 +00:00
}
2007-11-21 14:33:37 +00:00
if ( nSearchable = = ColumnSearch : : CHAR )
2013-01-07 08:44:24 -02:00
aSQL . append ( " \' " ) ;
2003-12-16 11:40:06 +00:00
}
else
2004-06-01 09:09:41 +00:00
throw SQLException ( DBACORE_RESSTRING ( RID_STR_NOT_SEQUENCE_INT8 ) , * this , SQLSTATE_GENERAL , 1000 , Any ( ) ) ;
2003-12-16 11:40:06 +00:00
}
break ;
case DataType : : BIT :
2005-02-17 10:01:55 +00:00
case DataType : : BOOLEAN :
2003-12-16 11:40:06 +00:00
{
2014-04-17 11:16:55 +02:00
bool bValue = false ;
2003-12-16 11:40:06 +00:00
m_xTypeConverter - > convertToSimpleType ( aValue , TypeClass_BOOLEAN ) > > = bValue ;
2013-01-07 08:44:24 -02:00
OUString sColumnExp = aSQL . makeStringAndClear ( ) ;
2014-03-31 16:46:08 +02:00
getBooleanComparisonPredicate ( sColumnExp , bValue , m_nBoolCompareMode , aSQL ) ;
2003-12-16 11:40:06 +00:00
}
2008-12-01 12:31:27 +00:00
break ;
2003-12-16 11:40:06 +00:00
default :
2014-03-31 16:46:08 +02:00
aSQL . append ( DBTypeConversion : : toSQLString ( nType , aValue , true , m_xTypeConverter ) ) ;
2007-11-21 14:33:37 +00:00
break ;
2014-08-07 09:40:02 +02:00
}
}
else
{
sal_Int32 nFilterOp = filterOperator ;
if ( filterOperator ! = SQLFilterOperator : : SQLNULL & & filterOperator ! = SQLFilterOperator : : NOT_SQLNULL )
nFilterOp = SQLFilterOperator : : SQLNULL ;
OUString sEmpty ;
lcl_addFilterCriteria_throw ( nFilterOp , sEmpty , aSQL ) ;
2003-12-16 11:40:06 +00:00
}
2014-08-07 09:40:02 +02:00
// Attach filter
// Construct SELECT without WHERE and ORDER BY
OUString sFilter = getFilter ( ) ;
if ( ! sFilter . isEmpty ( ) & & ! aSQL . isEmpty ( ) )
{
OUString sTemp ( L_BRACKET + sFilter + R_BRACKET ) ;
sTemp + = andCriteria ? OUString ( STR_AND ) : OUString ( STR_OR ) ;
sFilter = sTemp ;
}
sFilter + = aSQL . makeStringAndClear ( ) ;
2003-12-16 11:40:06 +00:00
2014-08-07 09:40:02 +02:00
// add the filter and the sort order
_aSetFunctor ( this , sFilter ) ;
}
catch ( css : : lang : : WrappedTargetException & e )
2003-12-16 11:40:06 +00:00
{
2014-08-07 09:40:02 +02:00
if ( e . TargetException . isExtractableTo (
cppu : : UnoType < css : : sdbc : : SQLException > : : get ( ) ) )
{
cppu : : throwException ( e . TargetException ) ;
}
else
{
2014-08-16 13:43:40 +02:00
throw ;
2014-08-07 09:40:02 +02:00
}
2003-12-16 11:40:06 +00:00
}
}
2010-10-12 22:40:56 +02:00
2005-01-05 11:27:39 +00:00
Sequence < Sequence < PropertyValue > > OSingleSelectQueryComposer : : getStructuredCondition ( TGetParseNode & _aGetFunctor )
2003-12-16 11:40:06 +00:00
{
: : connectivity : : checkDisposed ( OSubComponent : : rBHelper . bDisposed ) ;
MutexGuard aGuard ( m_aMutex ) ;
Sequence < Sequence < PropertyValue > > aFilterSeq ;
2013-01-07 08:44:24 -02:00
OUString sFilter = getStatementPart ( _aGetFunctor , m_aAdditiveIterator ) ;
2003-12-16 11:40:06 +00:00
2011-12-19 18:10:37 -02:00
if ( ! sFilter . isEmpty ( ) )
2003-12-16 11:40:06 +00:00
{
2013-01-07 08:44:24 -02:00
OUString aSql ( m_aPureSelectSQL + STR_WHERE + sFilter ) ;
2003-12-16 11:40:06 +00:00
// build a temporary parse node
2005-01-05 11:27:39 +00:00
const OSQLParseNode * pTempNode = m_aAdditiveIterator . getParseTree ( ) ;
2003-12-16 11:40:06 +00:00
2013-01-07 08:44:24 -02:00
OUString aErrorMsg ;
2014-02-20 11:02:54 +09:00
boost : : scoped_ptr < OSQLParseNode > pSqlParseNode ( m_aSqlParser . parseTree ( aErrorMsg , aSql ) ) ;
2003-12-16 11:40:06 +00:00
if ( pSqlParseNode . get ( ) )
{
2005-01-05 11:27:39 +00:00
m_aAdditiveIterator . setParseTree ( pSqlParseNode . get ( ) ) ;
2003-12-16 11:40:06 +00:00
// normalize the filter
2005-01-05 11:27:39 +00:00
OSQLParseNode * pWhereNode = const_cast < OSQLParseNode * > ( m_aAdditiveIterator . getWhereTree ( ) ) ;
2003-12-16 11:40:06 +00:00
OSQLParseNode * pCondition = pWhereNode - > getChild ( 1 ) ;
2008-01-30 07:29:51 +00:00
# if OSL_DEBUG_LEVEL > 0
2013-01-07 08:44:24 -02:00
OUString sCondition ;
2008-01-30 07:29:51 +00:00
pCondition - > parseNodeToStr ( sCondition , m_xConnection ) ;
# endif
2003-12-16 11:40:06 +00:00
OSQLParseNode : : negateSearchCondition ( pCondition ) ;
pCondition = pWhereNode - > getChild ( 1 ) ;
2008-01-30 07:29:51 +00:00
# if OSL_DEBUG_LEVEL > 0
2013-01-07 08:44:24 -02:00
sCondition = OUString ( ) ;
2008-01-30 07:29:51 +00:00
pCondition - > parseNodeToStr ( sCondition , m_xConnection ) ;
# endif
2003-12-16 11:40:06 +00:00
OSQLParseNode : : disjunctiveNormalForm ( pCondition ) ;
pCondition = pWhereNode - > getChild ( 1 ) ;
2008-01-30 07:29:51 +00:00
# if OSL_DEBUG_LEVEL > 0
2013-01-07 08:44:24 -02:00
sCondition = OUString ( ) ;
2008-01-30 07:29:51 +00:00
pCondition - > parseNodeToStr ( sCondition , m_xConnection ) ;
# endif
2003-12-16 11:40:06 +00:00
OSQLParseNode : : absorptions ( pCondition ) ;
pCondition = pWhereNode - > getChild ( 1 ) ;
2008-01-30 07:29:51 +00:00
# if OSL_DEBUG_LEVEL > 0
2013-01-07 08:44:24 -02:00
sCondition = OUString ( ) ;
2008-01-30 07:29:51 +00:00
pCondition - > parseNodeToStr ( sCondition , m_xConnection ) ;
# endif
2003-12-16 11:40:06 +00:00
if ( pCondition )
{
: : std : : vector < : : std : : vector < PropertyValue > > aFilters ;
2013-03-19 13:08:47 +02:00
Reference < XNumberFormatter > xFormatter ( NumberFormatter : : create ( m_aContext ) , UNO_QUERY_THROW ) ;
2007-11-21 14:33:37 +00:00
xFormatter - > attachNumberFormatsSupplier ( m_xNumberFormatsSupplier ) ;
2003-12-16 11:40:06 +00:00
2005-01-05 11:27:39 +00:00
if ( setORCriteria ( pCondition , m_aAdditiveIterator , aFilters , xFormatter ) )
2003-12-16 11:40:06 +00:00
{
aFilterSeq . realloc ( aFilters . size ( ) ) ;
Sequence < PropertyValue > * pFilters = aFilterSeq . getArray ( ) ;
: : std : : vector < : : std : : vector < PropertyValue > > : : const_iterator aEnd = aFilters . end ( ) ;
: : std : : vector < : : std : : vector < PropertyValue > > : : const_iterator i = aFilters . begin ( ) ;
for ( ; i ! = aEnd ; + + i )
{
const : : std : : vector < PropertyValue > & rProperties = * i ;
pFilters - > realloc ( rProperties . size ( ) ) ;
PropertyValue * pFilter = pFilters - > getArray ( ) ;
: : std : : vector < PropertyValue > : : const_iterator j = rProperties . begin ( ) ;
: : std : : vector < PropertyValue > : : const_iterator aEnd2 = rProperties . end ( ) ;
for ( ; j ! = aEnd2 ; + + j )
{
* pFilter = * j ;
+ + pFilter ;
}
+ + pFilters ;
}
}
}
// restore
2005-01-05 11:27:39 +00:00
m_aAdditiveIterator . setParseTree ( pTempNode ) ;
2003-12-16 11:40:06 +00:00
}
}
return aFilterSeq ;
}
2010-10-12 22:40:56 +02:00
2013-01-07 08:44:24 -02:00
OUString OSingleSelectQueryComposer : : getKeyword ( SQLPart _ePart ) const
2003-12-16 11:40:06 +00:00
{
2013-01-07 08:44:24 -02:00
OUString sKeyword ;
2003-12-16 11:40:06 +00:00
switch ( _ePart )
{
2005-01-05 11:27:39 +00:00
default :
2013-06-29 17:38:04 +03:00
SAL_WARN ( " dbaccess " , " OSingleSelectQueryComposer::getKeyWord: Invalid enum value! " ) ;
2005-01-05 11:27:39 +00:00
// no break, fallback to WHERE
2003-12-16 11:40:06 +00:00
case Where :
sKeyword = STR_WHERE ;
break ;
case Group :
sKeyword = STR_GROUP_BY ;
break ;
case Having :
sKeyword = STR_HAVING ;
break ;
case Order :
sKeyword = STR_ORDER_BY ;
2005-01-05 11:27:39 +00:00
break ;
}
return sKeyword ;
}
2014-04-17 11:16:55 +02:00
OUString OSingleSelectQueryComposer : : getSQLPart ( SQLPart _ePart , OSQLParseTreeIterator & _rIterator , bool _bWithKeyword )
2005-01-05 11:27:39 +00:00
{
TGetParseNode F_tmp ( & OSQLParseTreeIterator : : getSimpleWhereTree ) ;
2013-01-07 08:44:24 -02:00
OUString sKeyword ( getKeyword ( _ePart ) ) ;
2005-01-05 11:27:39 +00:00
switch ( _ePart )
{
case Where :
F_tmp = TGetParseNode ( & OSQLParseTreeIterator : : getSimpleWhereTree ) ;
break ;
case Group :
F_tmp = TGetParseNode ( & OSQLParseTreeIterator : : getSimpleGroupByTree ) ;
break ;
case Having :
F_tmp = TGetParseNode ( & OSQLParseTreeIterator : : getSimpleHavingTree ) ;
break ;
case Order :
F_tmp = TGetParseNode ( & OSQLParseTreeIterator : : getSimpleOrderTree ) ;
2003-12-16 11:40:06 +00:00
break ;
default :
2013-06-29 17:38:04 +03:00
SAL_WARN ( " dbaccess " , " Invalid enum value! " ) ;
2003-12-16 11:40:06 +00:00
}
2013-01-07 08:44:24 -02:00
OUString sRet = getStatementPart ( F_tmp , _rIterator ) ;
2011-12-19 18:10:37 -02:00
if ( _bWithKeyword & & ! sRet . isEmpty ( ) )
2003-12-16 11:40:06 +00:00
sRet = sKeyword + sRet ;
return sRet ;
}
2013-08-17 23:43:14 +02:00
2010-10-12 15:59:03 +02:00
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */