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>
2007-11-21 14:33:37 +00:00
# include <cppuhelper/typeprovider.hxx>
2011-01-10 13:41:20 +01:00
# include <connectivity/predicateinput.hxx>
2007-11-21 14:33:37 +00:00
# include <rtl/logfile.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>
2003-12-16 11:40:06 +00:00
# include <memory>
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
{
2006-08-15 09:42:50 +00:00
RTL_LOGFILE_CONTEXT_AUTHOR ( aLogger , " dbaccess " , " frank.schoenheit@sun.com " , " SingleSelectQueryComposer.cxx::parseStatement_throwError " ) ;
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 )
{
2006-08-15 09:42:50 +00:00
RTL_LOGFILE_CONTEXT_AUTHOR ( aLogger , " dbaccess " , " frank.schoenheit@sun.com " , " SingleSelectQueryComposer.cxx::parseAndCheck_throwError " ) ;
2005-01-05 11:27:39 +00:00
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
}
2003-12-16 11:40:06 +00:00
DBG_NAME ( OSingleSelectQueryComposer )
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 ,
2007-11-21 14:33:37 +00:00
const : : comphelper : : ComponentContext & _rContext )
2006-06-20 01:37:34 +00:00
: OSubComponent ( m_aMutex , _xConnection )
, OPropertyContainer ( m_aBHelper )
2012-11-02 15:13:28 +02:00
, m_aSqlParser ( _rContext . getUNOContext ( ) )
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
{
2009-04-23 10:42:05 +00:00
RTL_LOGFILE_CONTEXT_AUTHOR ( aLogger , " dbaccess " , " Ocke.Janssen@sun.com " , " OSingleSelectQueryComposer::OSingleSelectQueryComposer " ) ;
2003-12-16 11:40:06 +00:00
DBG_CTOR ( OSingleSelectQueryComposer , NULL ) ;
2006-07-10 14:04:12 +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 ) ;
2012-11-23 23:06:10 +01:00
m_aLocale = SvtSysLocale ( ) . GetLanguageTag ( ) . getLocale ( ) ;
2012-12-04 13:18:35 +02:00
m_xNumberFormatsSupplier = dbtools : : getNumberFormats ( m_xConnection , sal_True , m_aContext . getUNOContext ( ) ) ;
2012-09-13 12:47:11 +02:00
Reference < XLocaleData4 > xLocaleData ( LocaleData : : create ( m_aContext . getUNOContext ( ) ) ) ;
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 ) ;
if ( dbtools : : getDataSourceSetting ( xDs , static_cast < rtl : : 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 ( )
{
DBG_DTOR ( OSingleSelectQueryComposer , NULL ) ;
: : 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 )
{
2009-04-23 10:42:05 +00:00
RTL_LOGFILE_CONTEXT_AUTHOR ( aLogger , " dbaccess " , " Ocke.Janssen@sun.com " , " OSingleSelectQueryComposer::disposing " ) ;
2003-12-16 11:40:06 +00:00
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 ( ) ;
}
IMPLEMENT_FORWARD_XINTERFACE3 ( OSingleSelectQueryComposer , OSubComponent , OSingleSelectQueryComposer_BASE , OPropertyContainer )
2012-05-17 14:00:15 +01:00
IMPLEMENT_SERVICE_INFO1 ( OSingleSelectQueryComposer , " org.openoffice.comp.dba.OSingleSelectQueryComposer " , SERVICE_NAME_SINGLESELECTQUERYCOMPOSER . ascii )
2003-12-16 11:40:06 +00:00
IMPLEMENT_TYPEPROVIDER3 ( OSingleSelectQueryComposer , OSubComponent , OSingleSelectQueryComposer_BASE , OPropertyContainer )
IMPLEMENT_PROPERTYCONTAINER_DEFAULTS ( OSingleSelectQueryComposer )
// com::sun::star::lang::XUnoTunnel
sal_Int64 SAL_CALL OSingleSelectQueryComposer : : getSomething ( const Sequence < sal_Int8 > & rId ) throw ( RuntimeException )
{
2009-04-23 10:42:05 +00:00
RTL_LOGFILE_CONTEXT_AUTHOR ( aLogger , " dbaccess " , " Ocke.Janssen@sun.com " , " OSingleSelectQueryComposer::getSomething " ) ;
2012-09-29 14:47:11 +02:00
if ( rId . getLength ( ) = = 16 & & 0 = = memcmp ( getImplementationId ( ) . getConstArray ( ) , rId . getConstArray ( ) , 16 ) )
2004-03-15 11:41:53 +00:00
return reinterpret_cast < sal_Int64 > ( this ) ;
2003-12-16 11:40:06 +00:00
2004-03-15 11:41:53 +00:00
return sal_Int64 ( 0 ) ;
2003-12-16 11:40:06 +00:00
}
2005-01-05 11:27:39 +00:00
2003-12-16 11:40:06 +00:00
// XSingleSelectQueryAnalyzer
2013-01-07 08:44:24 -02:00
OUString SAL_CALL OSingleSelectQueryComposer : : getQuery ( ) throw ( RuntimeException )
2003-12-16 11:40:06 +00:00
{
2009-04-23 10:42:05 +00:00
RTL_LOGFILE_CONTEXT_AUTHOR ( aLogger , " dbaccess " , " Ocke.Janssen@sun.com " , " OSingleSelectQueryComposer::getQuery " ) ;
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
2013-01-07 08:44:24 -02:00
void SAL_CALL OSingleSelectQueryComposer : : setQuery ( const OUString & command ) throw ( SQLException , RuntimeException )
2003-12-16 11:40:06 +00:00
{
2006-08-15 09:42:50 +00:00
RTL_LOGFILE_CONTEXT_AUTHOR ( aLogger , " dbaccess " , " frank.schoenheit@sun.com " , " OSingleSelectQueryComposer::setQuery " ) ;
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
2013-01-07 08:44:24 -02:00
void SAL_CALL OSingleSelectQueryComposer : : setCommand ( const OUString & Command , sal_Int32 _nCommandType ) throw ( SQLException , RuntimeException )
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
{
String sMessage ( DBACORE_RESSTRING ( RID_STR_TABLE_DOES_NOT_EXIST ) ) ;
sMessage . SearchAndReplaceAscii ( " $table$ " , Command ) ;
throwGenericSQLException ( sMessage , * this ) ;
}
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
{
2006-08-15 09:42:50 +00:00
RTL_LOGFILE_CONTEXT_AUTHOR ( aLogger , " dbaccess " , " frank.schoenheit@sun.com " , " OSingleSelectQueryComposer::setQuery_Impl " ) ;
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
2005-01-05 11:27:39 +00:00
Sequence < Sequence < PropertyValue > > SAL_CALL OSingleSelectQueryComposer : : getStructuredHavingClause ( ) throw ( RuntimeException )
2003-12-16 11:40:06 +00:00
{
2009-04-23 10:42:05 +00:00
RTL_LOGFILE_CONTEXT_AUTHOR ( aLogger , " dbaccess " , " Ocke.Janssen@sun.com " , " OSingleSelectQueryComposer::getStructuredHavingClause " ) ;
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
2003-12-16 11:40:06 +00:00
Sequence < Sequence < PropertyValue > > SAL_CALL OSingleSelectQueryComposer : : getStructuredFilter ( ) throw ( RuntimeException )
{
2009-04-23 10:42:05 +00:00
RTL_LOGFILE_CONTEXT_AUTHOR ( aLogger , " dbaccess " , " Ocke.Janssen@sun.com " , " OSingleSelectQueryComposer::getStructuredFilter " ) ;
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
2010-01-22 08:14:22 +01:00
void SAL_CALL OSingleSelectQueryComposer : : appendHavingClauseByColumn ( const Reference < XPropertySet > & column , sal_Bool andCriteria , sal_Int32 filterOperator ) throw ( SQLException , RuntimeException )
2003-12-16 11:40:06 +00:00
{
2009-04-23 10:42:05 +00:00
RTL_LOGFILE_CONTEXT_AUTHOR ( aLogger , " dbaccess " , " Ocke.Janssen@sun.com " , " OSingleSelectQueryComposer::appendHavingClauseByColumn " ) ;
2013-01-07 08:44:24 -02:00
: : std : : mem_fun1_t < bool , OSingleSelectQueryComposer , 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
2010-01-22 08:14:22 +01:00
void SAL_CALL OSingleSelectQueryComposer : : appendFilterByColumn ( const Reference < XPropertySet > & column , sal_Bool andCriteria , sal_Int32 filterOperator ) throw ( SQLException , RuntimeException )
2003-12-16 11:40:06 +00:00
{
2009-04-23 10:42:05 +00:00
RTL_LOGFILE_CONTEXT_AUTHOR ( aLogger , " dbaccess " , " Ocke.Janssen@sun.com " , " OSingleSelectQueryComposer::appendFilterByColumn " ) ;
2013-01-07 08:44:24 -02:00
: : std : : mem_fun1_t < bool , OSingleSelectQueryComposer , 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-01-07 08:44:24 -02:00
OUString OSingleSelectQueryComposer : : impl_getColumnName_throw ( const Reference < XPropertySet > & column )
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
{
String sError ( DBACORE_RESSTRING ( RID_STR_COLUMN_UNKNOWN_PROP ) ) ;
2013-01-07 08:44:24 -02:00
sError . SearchAndReplaceAscii ( " %value " , OUString ( PROPERTY_NAME ) ) ;
2004-06-01 09:09:41 +00:00
SQLException aErr ( sError , * this , SQLSTATE_GENERAL , 1000 , Any ( ) ) ;
throw SQLException ( DBACORE_RESSTRING ( RID_STR_COLUMN_NOT_VALID ) , * this , SQLSTATE_GENERAL , 1000 , makeAny ( aErr ) ) ;
}
2003-12-16 11:40:06 +00:00
2013-01-07 08:44:24 -02:00
OUString aName , aNewName ;
2003-12-16 11:40:06 +00:00
column - > getPropertyValue ( PROPERTY_NAME ) > > = aName ;
if ( ! m_xMetaData - > supportsOrderByUnrelated ( ) & & 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
2012-03-28 17:24:08 +02:00
// Attach filter
// Construct SELECT without WHERE and ORDER BY
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-01-07 08:44:24 -02:00
OUString sRealName , sTableName ;
2003-12-16 11:40:06 +00:00
xColumn - > getPropertyValue ( PROPERTY_REALNAME ) > > = sRealName ;
xColumn - > getPropertyValue ( PROPERTY_TABLENAME ) > > = sTableName ;
2004-08-02 14:01:24 +00:00
sal_Bool bFunction = sal_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 ) ;
2006-07-10 14:04:12 +00:00
sTableName = : : dbtools : : composeTableName ( m_xMetaData , aCatlog , aSchema , aTable , sal_True , : : dbtools : : eInDataManipulation ) ;
2004-08-02 14:01:24 +00:00
}
else
sTableName = : : dbtools : : quoteName ( aQuote , sTableName ) ;
2013-01-07 08:44:24 -02:00
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
2009-04-23 10:42:05 +00:00
void SAL_CALL OSingleSelectQueryComposer : : appendOrderByColumn ( const Reference < XPropertySet > & column , sal_Bool ascending ) throw ( SQLException , RuntimeException )
{
RTL_LOGFILE_CONTEXT_AUTHOR ( aLogger , " dbaccess " , " Ocke.Janssen@sun.com " , " OSingleSelectQueryComposer::appendOrderByColumn " ) ;
: : osl : : MutexGuard aGuard ( m_aMutex ) ;
2013-01-07 08:44:24 -02:00
OUString sColumnName ( impl_getColumnName_throw ( column ) ) ;
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
2003-12-16 11:40:06 +00:00
void SAL_CALL OSingleSelectQueryComposer : : appendGroupByColumn ( const Reference < XPropertySet > & column ) throw ( SQLException , RuntimeException )
{
2009-04-23 10:42:05 +00:00
RTL_LOGFILE_CONTEXT_AUTHOR ( aLogger , " dbaccess " , " Ocke.Janssen@sun.com " , " OSingleSelectQueryComposer::appendGroupByColumn " ) ;
2003-12-16 11:40:06 +00:00
: : osl : : MutexGuard aGuard ( m_aMutex ) ;
2013-01-07 08:44:24 -02:00
OUString sColumnName ( impl_getColumnName_throw ( column ) ) ;
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
{
2009-04-23 10:42:05 +00:00
RTL_LOGFILE_CONTEXT_AUTHOR ( aLogger , " dbaccess " , " Ocke.Janssen@sun.com " , " OSingleSelectQueryComposer::composeStatementFromParts " ) ;
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
2013-01-07 08:44:24 -02:00
OUString SAL_CALL OSingleSelectQueryComposer : : getElementaryQuery ( ) throw ( : : com : : sun : : star : : uno : : RuntimeException )
2005-01-05 11:27:39 +00:00
{
2009-04-23 10:42:05 +00:00
RTL_LOGFILE_CONTEXT_AUTHOR ( aLogger , " dbaccess " , " Ocke.Janssen@sun.com " , " OSingleSelectQueryComposer::getElementaryQuery " ) ;
2005-01-05 11:27:39 +00:00
return composeStatementFromParts ( m_aElementaryParts ) ;
}
2013-01-07 08:44:24 -02:00
void SAL_CALL OSingleSelectQueryComposer : : setElementaryQuery ( const OUString & _rElementary ) throw ( : : com : : sun : : star : : sdbc : : SQLException , : : com : : sun : : star : : uno : : RuntimeException )
2003-12-16 11:40:06 +00:00
{
2006-08-15 09:42:50 +00:00
RTL_LOGFILE_CONTEXT_AUTHOR ( aLogger , " dbaccess " , " frank.schoenheit@sun.com " , " OSingleSelectQueryComposer::setElementaryQuery " ) ;
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 ) )
aAdditiveClauses [ eLoopParts ] = getSQLPart ( eLoopParts , m_aAdditiveIterator , sal_False ) ;
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 ) )
m_aElementaryParts [ eLoopParts ] = getSQLPart ( eLoopParts , m_aSqlIterator , sal_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 ;
2011-02-25 17:47:41 +01:00
OSL_FAIL ( " 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
{
2013-01-07 08:44:24 -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
{
2009-04-23 10:42:05 +00:00
RTL_LOGFILE_CONTEXT_AUTHOR ( aLogger , " dbaccess " , " Ocke.Janssen@sun.com " , " OSingleSelectQueryComposer::setSingleAdditiveClause " ) ;
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
if ( getSQLPart ( _ePart , m_aAdditiveIterator , sal_False ) = = _rClause )
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 ) )
aClauses . push_back ( getSQLPart ( eLoopParts , m_aSqlIterator , sal_True ) ) ;
// overwrite the one part in question here
2011-09-22 15:00:08 +01:00
SAL_WNODEPRECATED_DECLARATIONS_PUSH
2005-01-05 11:27:39 +00:00
: : std : : auto_ptr < TokenComposer > pComposer ;
2011-09-22 15:00:08 +01:00
SAL_WNODEPRECATED_DECLARATIONS_POP
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 ) ;
if ( _ePart = = Group )
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 ) )
aClauses [ eLoopParts ] = getSQLPart ( eLoopParts , m_aAdditiveIterator , sal_True ) ;
// 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 ;
2011-02-25 17:47:41 +01:00
OSL_FAIL ( " 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
2013-01-07 08:44:24 -02:00
void SAL_CALL OSingleSelectQueryComposer : : setFilter ( const OUString & filter ) throw ( SQLException , RuntimeException )
2005-01-05 11:27:39 +00:00
{
2009-04-23 10:42:05 +00:00
RTL_LOGFILE_CONTEXT_AUTHOR ( aLogger , " dbaccess " , " Ocke.Janssen@sun.com " , " OSingleSelectQueryComposer::setFilter " ) ;
2005-01-05 11:27:39 +00:00
setSingleAdditiveClause ( Where , filter ) ;
}
2013-01-07 08:44:24 -02:00
void SAL_CALL OSingleSelectQueryComposer : : setOrder ( const OUString & order ) throw ( SQLException , RuntimeException )
2005-01-05 11:27:39 +00:00
{
2009-04-23 10:42:05 +00:00
RTL_LOGFILE_CONTEXT_AUTHOR ( aLogger , " dbaccess " , " Ocke.Janssen@sun.com " , " OSingleSelectQueryComposer::setOrder " ) ;
2005-01-05 11:27:39 +00:00
setSingleAdditiveClause ( Order , order ) ;
}
2010-10-12 22:40:56 +02:00
2013-01-07 08:44:24 -02:00
void SAL_CALL OSingleSelectQueryComposer : : setGroup ( const OUString & group ) throw ( SQLException , RuntimeException )
2005-01-05 11:27:39 +00:00
{
2009-04-23 10:42:05 +00:00
RTL_LOGFILE_CONTEXT_AUTHOR ( aLogger , " dbaccess " , " Ocke.Janssen@sun.com " , " OSingleSelectQueryComposer::setGroup " ) ;
2005-01-05 11:27:39 +00:00
setSingleAdditiveClause ( Group , group ) ;
}
2010-10-12 22:40:56 +02:00
2013-01-07 08:44:24 -02:00
void SAL_CALL OSingleSelectQueryComposer : : setHavingClause ( const OUString & filter ) throw ( SQLException , RuntimeException )
2005-01-05 11:27:39 +00:00
{
2009-04-23 10:42:05 +00:00
RTL_LOGFILE_CONTEXT_AUTHOR ( aLogger , " dbaccess " , " Ocke.Janssen@sun.com " , " OSingleSelectQueryComposer::setHavingClause " ) ;
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
Reference < XNameAccess > SAL_CALL OSingleSelectQueryComposer : : getTables ( ) throw ( RuntimeException )
{
2009-04-23 10:42:05 +00:00
RTL_LOGFILE_CONTEXT_AUTHOR ( aLogger , " dbaccess " , " Ocke.Janssen@sun.com " , " OSingleSelectQueryComposer::getTables " ) ;
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
Reference < XNameAccess > SAL_CALL OSingleSelectQueryComposer : : getColumns ( ) throw ( RuntimeException )
{
2009-04-23 10:42:05 +00:00
RTL_LOGFILE_CONTEXT_AUTHOR ( aLogger , " dbaccess " , " Ocke.Janssen@sun.com " , " OSingleSelectQueryComposer::getColumns " ) ;
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 ;
2006-07-10 14:04:12 +00:00
sal_Bool bCase = sal_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 ( ) ;
2013-01-07 07:45:44 -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#
2013-01-07 07:45:44 -02:00
OUString sOriginalWhereClause = getSQLPart ( Where , m_aSqlIterator , sal_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
}
2013-01-07 07:45:44 -02:00
OUString sGroupBy = getSQLPart ( Group , m_aSqlIterator , sal_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 ;
2011-09-22 15:00:08 +01:00
SAL_WNODEPRECATED_DECLARATIONS_PUSH
2009-07-06 09:00:26 +00:00
const : : std : : auto_ptr < OSQLParseNode > pStatementTree ( m_aSqlParser . parseTree ( sError , sSQL , false ) ) ;
2011-09-22 15:00:08 +01:00
SAL_WNODEPRECATED_DECLARATIONS_POP
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 ) ;
const : : comphelper : : TStringMixEqualFunctor aCaseCompareFunctor ( 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 ) ;
2006-07-10 14:04:12 +00:00
sal_Bool bFound = sal_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 ) ;
2006-07-10 14:04:12 +00:00
bFound = sal_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
2009-11-18 13:06:25 +01:00
aFindName = : : std : : find_if ( aNames . begin ( ) , aNames . end ( ) , : : std : : bind2nd ( aCaseCompareFunctor , sColumnName ) ) ;
2006-07-10 14:04:12 +00:00
sal_Int32 j = 0 ;
while ( aFindName ! = aNames . end ( ) )
{
2013-01-07 08:44:24 -02:00
sColumnName + = OUString : : valueOf ( + + j ) ;
2009-11-18 13:06:25 +01:00
aFindName = : : std : : find_if ( aNames . begin ( ) , aNames . end ( ) , : : std : : bind2nd ( aCaseCompareFunctor , 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
//
//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
2005-01-05 11:27:39 +00:00
sal_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
{
2009-04-23 10:42:05 +00:00
RTL_LOGFILE_CONTEXT_AUTHOR ( aLogger , " dbaccess " , " Ocke.Janssen@sun.com " , " OSingleSelectQueryComposer::setORCriteria " ) ;
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 ) )
{
sal_Bool bResult = sal_True ;
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
}
}
2005-01-05 11:27:39 +00:00
sal_Bool OSingleSelectQueryComposer : : setANDCriteria ( OSQLParseNode * pCondition ,
OSQLParseTreeIterator & _rIterator , : : std : : vector < PropertyValue > & rFilter , const Reference < XNumberFormatter > & xFormatter ) const
2003-12-16 11:40:06 +00:00
{
2009-04-23 10:42:05 +00:00
RTL_LOGFILE_CONTEXT_AUTHOR ( aLogger , " dbaccess " , " Ocke.Janssen@sun.com " , " OSingleSelectQueryComposer::setANDCriteria " ) ;
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
2011-02-25 17:47:41 +01:00
OSL_FAIL ( " boolean_primary in And-Criteria " ) ;
2003-12-16 11:40:06 +00:00
return sal_False ;
}
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 ) )
{
2011-03-12 11:27:59 +01:00
OSL_FAIL ( " OSingleSelectQueryComposer::setANDCriteria: in_predicate not implemented! " ) ;
2003-12-16 11:40:06 +00:00
}
else if ( SQL_ISRULE ( pCondition , all_or_any_predicate ) )
{
2011-03-12 11:27:59 +01:00
OSL_FAIL ( " OSingleSelectQueryComposer::setANDCriteria: all_or_any_predicate not implemented! " ) ;
2003-12-16 11:40:06 +00:00
}
else if ( SQL_ISRULE ( pCondition , between_predicate ) )
{
2011-03-12 11:27:59 +01:00
OSL_FAIL ( " OSingleSelectQueryComposer::setANDCriteria: between_predicate not implemented! " ) ;
2003-12-16 11:40:06 +00:00
}
rFilter . push_back ( aItem ) ;
}
else
return sal_False ;
}
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
return sal_False ;
}
else
return sal_False ;
return sal_True ;
}
2010-10-12 22:40:56 +02:00
2003-12-16 11:40:06 +00:00
sal_Int32 OSingleSelectQueryComposer : : getPredicateType ( OSQLParseNode * _pPredicate ) const
{
2009-04-23 10:42:05 +00:00
RTL_LOGFILE_CONTEXT_AUTHOR ( aLogger , " dbaccess " , " Ocke.Janssen@sun.com " , " OSingleSelectQueryComposer::getPredicateType " ) ;
2003-12-16 11:40:06 +00:00
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 :
2011-03-12 12:04:35 +01:00
OSL_FAIL ( " Wrong NodeType! " ) ;
2003-12-16 11:40:06 +00:00
}
return nPredicate ;
}
2010-10-12 22:40:56 +02:00
2005-01-05 11:27:39 +00:00
sal_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
{
2009-04-23 10:42:05 +00:00
RTL_LOGFILE_CONTEXT_AUTHOR ( aLogger , " dbaccess " , " Ocke.Janssen@sun.com " , " OSingleSelectQueryComposer::setComparsionPredicate " ) ;
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
return sal_False ;
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 ) ;
}
return sal_True ;
}
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
{
2009-04-23 10:42:05 +00:00
RTL_LOGFILE_CONTEXT_AUTHOR ( aLogger , " dbaccess " , " Ocke.Janssen@sun.com " , " OSingleSelectQueryComposer::getColumnName " ) ;
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
2013-01-07 08:44:24 -02:00
OUString SAL_CALL OSingleSelectQueryComposer : : getFilter ( ) throw ( RuntimeException )
2003-12-16 11:40:06 +00:00
{
2009-04-23 10:42:05 +00:00
RTL_LOGFILE_CONTEXT_AUTHOR ( aLogger , " dbaccess " , " Ocke.Janssen@sun.com " , " OSingleSelectQueryComposer::getFilter " ) ;
2005-01-05 11:27:39 +00:00
: : connectivity : : checkDisposed ( OSubComponent : : rBHelper . bDisposed ) ;
: : osl : : MutexGuard aGuard ( m_aMutex ) ;
return getSQLPart ( Where , m_aAdditiveIterator , sal_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 SAL_CALL OSingleSelectQueryComposer : : getOrder ( ) throw ( RuntimeException )
2003-12-16 11:40:06 +00:00
{
2009-04-23 10:42:05 +00:00
RTL_LOGFILE_CONTEXT_AUTHOR ( aLogger , " dbaccess " , " Ocke.Janssen@sun.com " , " OSingleSelectQueryComposer::getOrder " ) ;
2005-01-05 11:27:39 +00:00
: : connectivity : : checkDisposed ( OSubComponent : : rBHelper . bDisposed ) ;
: : osl : : MutexGuard aGuard ( m_aMutex ) ;
return getSQLPart ( Order , m_aAdditiveIterator , sal_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 SAL_CALL OSingleSelectQueryComposer : : getGroup ( ) throw ( RuntimeException )
2003-12-16 11:40:06 +00:00
{
2009-04-23 10:42:05 +00:00
RTL_LOGFILE_CONTEXT_AUTHOR ( aLogger , " dbaccess " , " Ocke.Janssen@sun.com " , " OSingleSelectQueryComposer::getGroup " ) ;
2005-01-05 11:27:39 +00:00
: : connectivity : : checkDisposed ( OSubComponent : : rBHelper . bDisposed ) ;
: : osl : : MutexGuard aGuard ( m_aMutex ) ;
return getSQLPart ( Group , m_aAdditiveIterator , sal_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 : : getHavingClause ( ) throw ( RuntimeException )
2003-12-16 11:40:06 +00:00
{
2009-04-23 10:42:05 +00:00
RTL_LOGFILE_CONTEXT_AUTHOR ( aLogger , " dbaccess " , " Ocke.Janssen@sun.com " , " OSingleSelectQueryComposer::getHavingClause " ) ;
2005-01-05 11:27:39 +00:00
: : connectivity : : checkDisposed ( OSubComponent : : rBHelper . bDisposed ) ;
: : osl : : MutexGuard aGuard ( m_aMutex ) ;
return getSQLPart ( Having , m_aAdditiveIterator , sal_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
{
2009-04-23 10:42:05 +00:00
RTL_LOGFILE_CONTEXT_AUTHOR ( aLogger , " dbaccess " , " Ocke.Janssen@sun.com " , " OSingleSelectQueryComposer::getTableAlias " ) ;
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 ( ) ) ;
const OUString * pBegin = aNames . getConstArray ( ) ;
const OUString * 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
{
2006-07-10 14:04:12 +00:00
aComposedName = : : dbtools : : composeTableName ( m_xMetaData , aCatalog , aSchema , aTable , sal_False , : : dbtools : : eInDataManipulation ) ;
2003-12-16 11:40:06 +00:00
// first check if this is the table we want to or has it a tablealias
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 )
{
2013-01-07 08:44:24 -02:00
sReturn = : : dbtools : : composeTableName ( m_xMetaData , aCatalog , aSchema , aTable , sal_True , : : dbtools : : eInDataManipulation ) + " . " ;
2003-12-16 11:40:06 +00:00
}
}
return sReturn ;
}
2010-10-12 22:40:56 +02:00
2003-12-16 11:40:06 +00:00
Reference < XIndexAccess > SAL_CALL OSingleSelectQueryComposer : : getParameters ( ) throw ( RuntimeException )
{
2009-04-23 10:42:05 +00:00
RTL_LOGFILE_CONTEXT_AUTHOR ( aLogger , " dbaccess " , " Ocke.Janssen@sun.com " , " OSingleSelectQueryComposer::getParameters " ) ;
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 ) ) ) ;
2006-08-15 09:42:50 +00:00
m_aCurrentColumns [ ParameterColumns ] = new OPrivateColumns ( aCols , m_xMetaData - > supportsMixedCaseQuotedIdentifiers ( ) , * this , m_aMutex , aNames , sal_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
RTL_LOGFILE_CONTEXT_AUTHOR ( aLogger , " dbaccess " , " Ocke.Janssen@sun.com " , " OSingleSelectQueryComposer::clearColumns " ) ;
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 ( )
{
2009-04-23 10:42:05 +00:00
RTL_LOGFILE_CONTEXT_AUTHOR ( aLogger , " dbaccess " , " Ocke.Janssen@sun.com " , " OSingleSelectQueryComposer::clearCurrentCollections " ) ;
2003-12-16 11:40:06 +00:00
: : 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
{
2009-04-23 10:42:05 +00:00
RTL_LOGFILE_CONTEXT_AUTHOR ( aLogger , " dbaccess " , " Ocke.Janssen@sun.com " , " OSingleSelectQueryComposer::setCurrentColumns " ) ;
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 ) ) ) ;
2006-08-15 09:42:50 +00:00
m_aCurrentColumns [ _eType ] = new OPrivateColumns ( _rCols , m_xMetaData - > supportsMixedCaseQuotedIdentifiers ( ) , * this , m_aMutex , aNames , sal_True ) ;
2003-12-16 11:40:06 +00:00
}
return m_aCurrentColumns [ _eType ] ;
}
2010-10-12 22:40:56 +02:00
2003-12-16 11:40:06 +00:00
Reference < XIndexAccess > SAL_CALL OSingleSelectQueryComposer : : getGroupColumns ( ) throw ( RuntimeException )
{
2009-04-23 10:42:05 +00:00
RTL_LOGFILE_CONTEXT_AUTHOR ( aLogger , " dbaccess " , " Ocke.Janssen@sun.com " , " OSingleSelectQueryComposer::getGroupColumns " ) ;
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
2003-12-16 11:40:06 +00:00
Reference < XIndexAccess > SAL_CALL OSingleSelectQueryComposer : : getOrderColumns ( ) throw ( RuntimeException )
{
2009-04-23 10:42:05 +00:00
RTL_LOGFILE_CONTEXT_AUTHOR ( aLogger , " dbaccess " , " Ocke.Janssen@sun.com " , " OSingleSelectQueryComposer::getOrderColumns " ) ;
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
2013-01-07 08:44:24 -02:00
OUString SAL_CALL OSingleSelectQueryComposer : : getQueryWithSubstitution ( ) throw ( SQLException , RuntimeException )
2006-07-10 14:04:12 +00:00
{
2009-04-23 10:42:05 +00:00
RTL_LOGFILE_CONTEXT_AUTHOR ( aLogger , " dbaccess " , " Ocke.Janssen@sun.com " , " OSingleSelectQueryComposer::getQueryWithSubstitution " ) ;
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
{
2009-04-23 10:42:05 +00:00
RTL_LOGFILE_CONTEXT_AUTHOR ( aLogger , " dbaccess " , " Ocke.Janssen@sun.com " , " OSingleSelectQueryComposer::getStatementPart " ) ;
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
{
2013-01-07 08:44:24 -02:00
OUString lcl_getCondition ( const Sequence < Sequence < PropertyValue > > & filter , const OPredicateInputController & i_aPredicateInputController , const Reference < XNameAccess > & i_xSelectColumns )
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 ;
2011-01-10 13:41:20 +01:00
if ( i_xSelectColumns . is ( ) & & i_xSelectColumns - > hasByName ( pAndIter - > Name ) )
{
Reference < XPropertySet > xColumn ( i_xSelectColumns - > getByName ( pAndIter - > Name ) , UNO_QUERY ) ;
sValue = i_aPredicateInputController . getPredicateValue ( sValue , xColumn , sal_True ) ;
}
else
{
sValue = i_aPredicateInputController . getPredicateValue ( pAndIter - > Name , sValue , sal_True ) ;
}
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 ;
2004-10-22 07:55:36 +00:00
if ( pOrIter ! = pOrEnd & & sRet . getLength ( ) )
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
2003-12-16 11:40:06 +00:00
void SAL_CALL OSingleSelectQueryComposer : : setStructuredFilter ( const Sequence < Sequence < PropertyValue > > & filter ) throw ( SQLException , : : com : : sun : : star : : lang : : IllegalArgumentException , RuntimeException )
{
2009-04-23 10:42:05 +00:00
RTL_LOGFILE_CONTEXT_AUTHOR ( aLogger , " dbaccess " , " Ocke.Janssen@sun.com " , " OSingleSelectQueryComposer::setStructuredFilter " ) ;
2012-11-02 15:13:28 +02:00
OPredicateInputController aPredicateInput ( m_aContext . getUNOContext ( ) , m_xConnection ) ;
2011-01-10 13:41:20 +01:00
setFilter ( lcl_getCondition ( filter , aPredicateInput , getColumns ( ) ) ) ;
2003-12-16 11:40:06 +00:00
}
2010-10-12 22:40:56 +02:00
2005-01-05 11:27:39 +00:00
void SAL_CALL OSingleSelectQueryComposer : : setStructuredHavingClause ( const Sequence < Sequence < PropertyValue > > & filter ) throw ( SQLException , RuntimeException )
2003-12-16 11:40:06 +00:00
{
2009-04-23 10:42:05 +00:00
RTL_LOGFILE_CONTEXT_AUTHOR ( aLogger , " dbaccess " , " Ocke.Janssen@sun.com " , " OSingleSelectQueryComposer::setStructuredHavingClause " ) ;
2012-11-02 15:13:28 +02:00
OPredicateInputController aPredicateInput ( m_aContext . getUNOContext ( ) , m_xConnection ) ;
2011-01-10 13:41:20 +01:00
setHavingClause ( lcl_getCondition ( filter , aPredicateInput , getColumns ( ) ) ) ;
2003-12-16 11:40:06 +00:00
}
2010-10-12 22:40:56 +02:00
2013-01-07 08:44:24 -02:00
void OSingleSelectQueryComposer : : setConditionByColumn ( const Reference < XPropertySet > & column , sal_Bool andCriteria , : : std : : mem_fun1_t < bool , OSingleSelectQueryComposer , OUString > & _aSetFunctor , sal_Int32 filterOperator )
2003-12-16 11:40:06 +00:00
{
2009-04-23 10:42:05 +00:00
RTL_LOGFILE_CONTEXT_AUTHOR ( aLogger , " dbaccess " , " Ocke.Janssen@sun.com " , " OSingleSelectQueryComposer::setConditionByColumn " ) ;
2003-12-16 11:40:06 +00:00
: : connectivity : : checkDisposed ( OSubComponent : : rBHelper . bDisposed ) ;
if ( ! column . is ( )
| | ! column - > getPropertySetInfo ( ) - > hasPropertyByName ( PROPERTY_VALUE )
CWS-TOOLING: integrate CWS dba32e
2009-08-10 13:16:25 +0200 fs r274805 : #i84390# typo corrected
2009-08-10 13:04:28 +0200 fs r274804 : #i103741# properly terminate the last token in a string with a 0 byte
2009-07-24 08:54:05 +0200 msc r274286 : #103219# changed long name
2009-07-24 08:42:28 +0200 msc r274285 : #i79649# changed behaviour of the wizard
2009-07-22 14:17:49 +0200 oj r274238 : GrabFocus
2009-07-22 13:38:01 +0200 oj r274232 : #i102934# mixed up
2009-07-22 13:37:16 +0200 oj r274231 : #i102934# mixed up
2009-07-21 12:30:36 +0200 oj r274176 : crash when using distinct
2009-07-21 10:03:44 +0200 oj r274163 : set last char to 0
2009-07-21 09:31:22 +0200 oj r274161 : mediatype corrected
2009-07-20 11:45:33 +0200 fs r274118 : typo in formatting string
2009-07-20 11:40:39 +0200 fs r274117 : removed unused include
2009-07-20 11:40:01 +0200 fs r274116 : class name corrected
2009-07-16 13:41:45 +0200 oj r274046 : i101587 wrong check for embeddeddatabase url in confguration, have to check path
2009-07-16 13:12:05 +0200 tbo r274044 : #i103219# adjust declarion to new hid.lst
2009-07-16 12:43:48 +0200 oj r274041 : #i102497# check also fot longvarchar
2009-07-16 12:15:41 +0200 oj r274039 : #i103030# handle type description and exceptions as well
2009-07-16 11:14:26 +0200 fs r274035 : let SVN ignore output paths
2009-07-16 09:23:43 +0200 fs r274030 : TransforFormComponentProperties: no need to check for attribute equality
2009-07-10 14:16:23 +0200 oj r273892 : CWS-TOOLING: rebase CWS dba32e to trunk@273858 (milestone: DEV300:m52)
2009-07-01 21:41:50 +0200 fs r273614 : #i10000#
2009-07-01 15:01:10 +0200 fs r273589 : Input required doesn't make sense at all in XML form documents
2009-07-01 12:10:31 +0200 fs r273562 : updated
2009-07-01 11:46:12 +0200 fs r273560 : #i103219# add about 100 missing long names
2009-07-01 10:11:41 +0200 fs r273551 : moved from socket/port usage to pipe/name usage, which is more common nowadays
2009-07-01 09:50:03 +0200 fs r273549 : removed obsolete (empty) folder
2009-07-01 09:47:35 +0200 fs r273548 : copied the code for the Accessibility Workbench herein, formerly located in the old CVS repository, at gsl/awb
2009-06-30 10:07:47 +0200 fs r273493 : merging latest changes from CWS dba32d
2009-06-29 20:46:31 +0200 fs r273482 : #i103138# Rectangle conversions
2009-06-29 10:01:13 +0200 fs r273453 : #i103138#
refactored the code for positioning/zooming the control
Basically, we now allow adjustControlGeometry_throw (formerly known as positionControl_throw and setControlZoom) to
take an additional ViewTransformation parameter, describing the transformation to obtain the actual
control position/size. Consequently, positionControl itself also allows for a ViewTransformation parameter.
This has become necessary since during painting, the device which we created our control for might not necessarily
have a proper MapMode set. In this case, if we would use this map mode for calculating the control's position/size,
this would lead to wrong results.
Note that this problem was introduced by the fix for #i101398#: During the fix, we postponed the control creation
to a later time (when it is really needed). At this later time, the MapMode at the device is broken, at the earlier
time where we formerly crearted the control (createPrimitive2DSequence), it is not yet broken.
Whether or not the MapMode is defined as "broken" might depend on one's point of view, however ...
I consider it broken, since:
- we need the map mode to obtain the proper zoom level, which is to be forwarded to the control
- there are scenarios where the MapMode is *not* set to MAP_PIXEL (in those scenarios, everything works
fine), and there are scenarios where it *is* set to MAP_PIXEL (in those the bug 103138 appears).
It somehow feels wrong that one cannot rely on the device's map mode this way, but on the other hand
one has no possibility to obtain the current zoom by other means.
Note that one issue (still to be submitted) is left: In the page pane of a Draw/Impress document, controls
have a wrong text size. This is because in this pane, the above-mentioned "broken" map mode is used,
which means the controls have a zoom of "1:1" set, which is wrong here.
2009-06-29 09:52:13 +0200 fs r273452 : during #i103138#: belongsToDevice is unused nowadays
2009-06-24 12:40:06 +0200 fs r273329 : #i102888# #i102899#
2009-06-24 12:10:29 +0200 oj r273327 : #i103030# some code changes
2009-06-24 09:44:14 +0200 oj r273311 : #i103030# some code changes
2009-06-24 09:24:42 +0200 oj r273309 : #i103030# add log
2009-06-24 09:03:29 +0200 fs r273308 : if a col's table name is schema.table, properly quote all parts
2009-06-24 08:56:06 +0200 oj r273307 : #i102691# changed string
2009-06-23 13:31:43 +0200 oj r273280 : #i102479# fix date, time and datetime
2009-06-23 12:51:28 +0200 oj r273277 : #i103020# clear old expression when updating to avoid dead pointers in treelist userdata
2009-06-23 12:17:16 +0200 oj r273275 : #i103030# add LogBridge
2009-06-23 11:53:10 +0200 oj r273272 : shawdowed var resolved
2009-06-23 11:48:49 +0200 oj r273270 : #i103030# add :log to uno env if var UNO_ENV_LOG is set
2009-06-23 11:47:47 +0200 oj r273269 : #i103030# add LogBridge
2009-06-23 11:47:11 +0200 oj r273268 : #i103030# add LogBridge
2009-06-23 08:05:08 +0200 oj r273253 : #i102934# add key for collapsing
2009-06-22 13:21:33 +0200 fs r273225 : merging latest changes from CWS dba32d
2009-06-22 13:15:22 +0200 fs r273221 : why restrict to 12 entries?
2009-06-22 08:12:21 +0200 oj r273196 : #i102655# choosen > chosen typo fixed
2009-06-22 08:08:04 +0200 oj r273195 : #i102657# typo fix
2009-06-22 08:06:28 +0200 oj r273194 : #i102934# expanding and collasping of section
2009-06-22 08:05:52 +0200 oj r273193 : #i102930# set focus in treelistbox
2009-06-22 08:04:56 +0200 oj r273192 : #i102929# enable tabstop
2009-06-19 13:18:26 +0200 oj r273157 : remove unused param
2009-06-19 10:07:05 +0200 oj r273149 : CWS-TOOLING: rebase CWS dba32e to trunk@272827 (milestone: DEV300:m50)
2009-06-19 07:32:40 +0200 oj r273146 : merge from dba32d to dba32e
2009-06-19 07:22:56 +0200 oj r273145 : merge from dba32d to dba32e
2009-06-19 07:22:33 +0200 oj r273144 : merge from dba32d to dba32e
2009-06-18 14:09:34 +0200 fs r273116 : merging the latest changes from CWS dba32d (up to revision 273108) herein, which effectively is a rebase to DEV300.m50
2009-06-18 08:50:35 +0200 oj r273098 : #i102894# fix for new line in text
2009-06-18 08:28:48 +0200 oj r273097 : #i102892# check any
2009-06-18 08:21:34 +0200 oj r273096 : check if error is valid
2009-06-16 13:49:28 +0200 fs r273019 : why make a drop down control by default? The form control factory in SVX does this better those days ...
2009-06-10 09:53:20 +0200 oj r272797 : add lic text
2009-06-10 09:48:55 +0200 oj r272796 : test added for i101618
2009-06-09 14:57:39 +0200 oj r272771 : #i101618# access database document only when script container is needed
2009-06-09 12:42:25 +0200 oj r272765 : #i102497# check type property
2009-06-09 12:32:49 +0200 oj r272764 : adjust test cases
2009-06-09 12:31:58 +0200 oj r272763 : adjust test cases
2009-06-09 12:31:22 +0200 oj r272762 : adjust test cases
2009-06-09 11:35:42 +0200 oj r272761 : check if error is valid
2009-06-09 11:29:42 +0200 oj r272760 : #i102497# longvarchar was missing
2009-06-08 14:52:49 +0200 fs r272733 : #i102564# when setting a new field, also set m_nFieldType
2009-06-08 13:51:20 +0200 oj r272730 : add tests
2009-06-05 14:38:01 +0200 oj r272686 : add dep
2009-06-05 14:35:00 +0200 oj r272684 : add new tests
2009-06-05 13:41:18 +0200 oj r272681 : code clean ups
2009-06-05 12:40:51 +0200 oj r272678 : code cleanup
2009-06-05 12:02:57 +0200 oj r272677 : code cleanup
2009-06-05 10:42:38 +0200 oj r272670 : #i49320# impl export of single rows and as RTF and HTML
2009-06-03 14:30:37 +0200 oj r272576 : #i79649# check if file matches filter wildcard
2009-06-03 13:41:57 +0200 oj r272560 : #i102470# impl not b like 'c'
2009-08-26 10:09:17 +00:00
| | ! column - > getPropertySetInfo ( ) - > hasPropertyByName ( PROPERTY_NAME )
| | ! column - > getPropertySetInfo ( ) - > hasPropertyByName ( PROPERTY_TYPE ) )
2004-06-01 09:09:41 +00:00
throw SQLException ( DBACORE_RESSTRING ( RID_STR_COLUMN_NOT_VALID ) , * this , SQLSTATE_GENERAL , 1000 , Any ( ) ) ;
2003-12-16 11:40:06 +00:00
sal_Int32 nType = 0 ;
column - > getPropertyValue ( PROPERTY_TYPE ) > > = nType ;
sal_Int32 nSearchable = dbtools : : getSearchColumnFlag ( m_xConnection , nType ) ;
if ( nSearchable = = ColumnSearch : : NONE )
2004-06-01 09:09:41 +00:00
throw SQLException ( DBACORE_RESSTRING ( RID_STR_COLUMN_NOT_SEARCHABLE ) , * this , SQLSTATE_GENERAL , 1000 , Any ( ) ) ;
2003-12-16 11:40:06 +00:00
: : osl : : MutexGuard aGuard ( m_aMutex ) ;
2013-01-07 08:44:24 -02:00
OUString aName ;
2003-12-16 11:40:06 +00:00
column - > getPropertyValue ( PROPERTY_NAME ) > > = aName ;
Any aValue ;
column - > getPropertyValue ( PROPERTY_VALUE ) > > = aValue ;
2013-01-07 08:44:24 -02:00
OUStringBuffer aSQL ;
const OUString aQuote = m_xMetaData - > getIdentifierQuoteString ( ) ;
2009-09-08 09:50:48 +00:00
getColumns ( ) ;
2003-12-16 11:40:06 +00:00
if ( m_aCurrentColumns [ SelectColumns ] & & 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 ( " AggregateFunction " ) , " Property AggregateFunction not available! " ) ;
2003-12-16 11:40:06 +00:00
2013-01-07 08:44:24 -02:00
OUString sRealName , sTableName ;
2003-12-16 11:40:06 +00:00
xColumn - > getPropertyValue ( PROPERTY_REALNAME ) > > = sRealName ;
xColumn - > getPropertyValue ( PROPERTY_TABLENAME ) > > = sTableName ;
if ( sTableName . indexOf ( ' . ' , 0 ) ! = - 1 )
{
2013-01-07 08:44:24 -02:00
OUString aCatlog , aSchema , aTable ;
2003-12-16 11:40:06 +00:00
: : dbtools : : qualifiedNameComponents ( m_xMetaData , sTableName , aCatlog , aSchema , aTable , : : dbtools : : eInDataManipulation ) ;
2006-07-10 14:04:12 +00:00
sTableName = : : dbtools : : composeTableName ( m_xMetaData , aCatlog , aSchema , aTable , sal_True , : : dbtools : : eInDataManipulation ) ;
2003-12-16 11:40:06 +00:00
}
else
sTableName = : : dbtools : : quoteName ( aQuote , sTableName ) ;
2013-01-07 08:44:24 -02:00
if ( ! : : comphelper : : getBOOL ( xColumn - > getPropertyValue ( " Function " ) ) )
2004-10-22 07:55:36 +00:00
{
2013-01-07 08:44:24 -02:00
aSQL = sTableName + " . " + : : dbtools : : quoteName ( aQuote , sRealName ) ;
2004-10-22 07:55:36 +00:00
}
else
2007-11-21 14:33:37 +00:00
aSQL = sRealName ;
2004-10-22 07:55:36 +00:00
2003-12-16 11:40:06 +00:00
}
else
2007-11-21 14:33:37 +00:00
{
2013-01-07 08:44:24 -02:00
aSQL = getTableAlias ( column ) + : : dbtools : : quoteName ( aQuote , aName ) ;
2007-11-21 14:33:37 +00:00
}
2003-12-16 11:40:06 +00:00
if ( aValue . hasValue ( ) )
{
2007-11-21 14:33:37 +00:00
if ( ! m_xTypeConverter . is ( ) )
2012-08-21 08:07:58 +02:00
m_xTypeConverter . set ( Converter : : create ( m_aContext . getUNOContext ( ) ) ) ;
2003-12-16 11:40:06 +00:00
OSL_ENSURE ( m_xTypeConverter . is ( ) , " NO typeconverter! " ) ;
2010-01-22 08:14:22 +01:00
if ( nType ! = DataType : : BOOLEAN & & DataType : : BIT ! = nType )
{
2013-01-07 08:44:24 -02:00
OUString sEmpty ;
2010-01-22 08:14:22 +01:00
lcl_addFilterCriteria_throw ( filterOperator , sEmpty , aSQL ) ;
}
2003-12-16 11:40:06 +00:00
switch ( nType )
{
case DataType : : VARCHAR :
case DataType : : CHAR :
case DataType : : LONGVARCHAR :
2007-11-21 14:33:37 +00:00
aSQL . append ( DBTypeConversion : : toSQLString ( nType , aValue , sal_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
{
aSQL . append ( DBTypeConversion : : toSQLString ( nType , aValue , sal_True , m_xTypeConverter ) ) ;
}
}
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
{
sal_Bool bValue = sal_False ;
m_xTypeConverter - > convertToSimpleType ( aValue , TypeClass_BOOLEAN ) > > = bValue ;
2013-01-07 08:44:24 -02:00
OUString sColumnExp = aSQL . makeStringAndClear ( ) ;
2007-11-21 14:33:37 +00:00
getBoleanComparisonPredicate ( 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 :
2007-11-21 14:33:37 +00:00
aSQL . append ( DBTypeConversion : : toSQLString ( nType , aValue , sal_True , m_xTypeConverter ) ) ;
break ;
2003-12-16 11:40:06 +00:00
}
}
else
2010-01-22 08:14:22 +01:00
{
sal_Int32 nFilterOp = filterOperator ;
if ( filterOperator ! = SQLFilterOperator : : SQLNULL & & filterOperator ! = SQLFilterOperator : : NOT_SQLNULL )
nFilterOp = SQLFilterOperator : : SQLNULL ;
2013-01-07 08:44:24 -02:00
OUString sEmpty ;
2010-01-22 08:14:22 +01:00
lcl_addFilterCriteria_throw ( nFilterOp , sEmpty , aSQL ) ;
}
2003-12-16 11:40:06 +00:00
2012-03-28 17:24:08 +02:00
// Attach filter
// Construct SELECT without WHERE and ORDER BY
2013-01-07 08:44:24 -02:00
OUString sFilter = getFilter ( ) ;
2003-12-16 11:40:06 +00:00
2011-12-19 18:10:37 -02:00
if ( ! sFilter . isEmpty ( ) & & aSQL . getLength ( ) )
2003-12-16 11:40:06 +00:00
{
2013-01-07 08:44:24 -02:00
OUString sTemp ( L_BRACKET + sFilter + R_BRACKET ) ;
sTemp + = andCriteria ? OUString ( STR_AND ) : OUString ( STR_OR ) ;
2003-12-16 11:40:06 +00:00
sFilter = sTemp ;
}
2007-11-21 14:33:37 +00:00
sFilter + = aSQL . makeStringAndClear ( ) ;
2003-12-16 11:40:06 +00:00
// add the filter and the sort order
_aSetFunctor ( this , sFilter ) ;
}
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
{
2009-04-23 10:42:05 +00:00
RTL_LOGFILE_CONTEXT_AUTHOR ( aLogger , " dbaccess " , " Ocke.Janssen@sun.com " , " OSingleSelectQueryComposer::getStructuredCondition " ) ;
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 ;
2011-09-22 15:00:08 +01:00
SAL_WNODEPRECATED_DECLARATIONS_PUSH
2003-12-16 11:40:06 +00:00
: : std : : auto_ptr < OSQLParseNode > pSqlParseNode ( m_aSqlParser . parseTree ( aErrorMsg , aSql ) ) ;
2011-09-22 15:00:08 +01:00
SAL_WNODEPRECATED_DECLARATIONS_POP
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 ;
2012-08-29 09:32:55 +02:00
Reference < XNumberFormatter > xFormatter ( NumberFormatter : : create ( m_aContext . getUNOContext ( ) ) , 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
{
2009-04-23 10:42:05 +00:00
RTL_LOGFILE_CONTEXT_AUTHOR ( aLogger , " dbaccess " , " Ocke.Janssen@sun.com " , " OSingleSelectQueryComposer::getKeyword " ) ;
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 :
2011-03-12 12:04:35 +01:00
OSL_FAIL ( " 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 ;
}
2013-01-07 08:44:24 -02:00
OUString OSingleSelectQueryComposer : : getSQLPart ( SQLPart _ePart , OSQLParseTreeIterator & _rIterator , sal_Bool _bWithKeyword )
2005-01-05 11:27:39 +00:00
{
2009-04-23 10:42:05 +00:00
RTL_LOGFILE_CONTEXT_AUTHOR ( aLogger , " dbaccess " , " Ocke.Janssen@sun.com " , " OSingleSelectQueryComposer::getSQLPart " ) ;
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 :
2011-03-12 12:04:35 +01:00
OSL_FAIL ( " 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 ;
}
2010-10-12 15:59:03 +02:00
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */