LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/connectivity/source/parse - sqlnode.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 424 1252 33.9 %
Date: 2013-07-09 Functions: 42 71 59.2 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include "parse/sqlbison_exports.hxx"
      21             : 
      22             : #include <sal/macros.h>
      23             : #include <connectivity/sqlnode.hxx>
      24             : #include <connectivity/sqlerror.hxx>
      25             : #include <internalnode.hxx>
      26             : #define YYBISON   1
      27             : #include <sqlbison.hxx>
      28             : #include <connectivity/sqlparse.hxx>
      29             : #include <com/sun/star/lang/Locale.hpp>
      30             : #include <com/sun/star/util/XNumberFormatter.hpp>
      31             : #include <com/sun/star/util/XNumberFormatTypes.hpp>
      32             : #include <com/sun/star/i18n/LocaleData.hpp>
      33             : #include <com/sun/star/i18n/NumberFormatIndex.hpp>
      34             : #include <com/sun/star/beans/XPropertySet.hpp>
      35             : #include <com/sun/star/sdbc/XDatabaseMetaData.hpp>
      36             : #include <com/sun/star/sdbc/DataType.hpp>
      37             : #include <com/sun/star/sdb/XQueriesSupplier.hpp>
      38             : #include <com/sun/star/sdb/ErrorCondition.hpp>
      39             : #include <com/sun/star/util/XNumberFormatsSupplier.hpp>
      40             : #include <com/sun/star/util/XNumberFormats.hpp>
      41             : #include <com/sun/star/util/NumberFormat.hpp>
      42             : #include <com/sun/star/i18n/KParseType.hpp>
      43             : #include <com/sun/star/i18n/KParseTokens.hpp>
      44             : #include <com/sun/star/i18n/CharacterClassification.hpp>
      45             : #include "connectivity/dbconversion.hxx"
      46             : #include <com/sun/star/util/DateTime.hpp>
      47             : #include <com/sun/star/util/Time.hpp>
      48             : #include <com/sun/star/util/Date.hpp>
      49             : #include "TConnection.hxx"
      50             : #include "sqlscan.hxx"
      51             : #include <comphelper/numbers.hxx>
      52             : #include <comphelper/processfactory.hxx>
      53             : #include <comphelper/stl_types.hxx>
      54             : #include "connectivity/dbtools.hxx"
      55             : #include "connectivity/dbmetadata.hxx"
      56             : #include <tools/diagnose_ex.h>
      57             : #include <string.h>
      58             : #include <boost/bind.hpp>
      59             : #include <boost/static_assert.hpp>
      60             : #include <algorithm>
      61             : #include <functional>
      62             : #include <rtl/ustrbuf.hxx>
      63             : 
      64             : using namespace ::com::sun::star::sdbc;
      65             : using namespace ::com::sun::star::util;
      66             : using namespace ::com::sun::star::beans;
      67             : using namespace ::com::sun::star::sdb;
      68             : using namespace ::com::sun::star::uno;
      69             : using namespace ::com::sun::star::lang;
      70             : using namespace ::com::sun::star::i18n;
      71             : using namespace ::com::sun::star;
      72             : using namespace ::osl;
      73             : using namespace ::dbtools;
      74             : using namespace ::comphelper;
      75             : 
      76             : 
      77             : namespace
      78             : {
      79             :     // -----------------------------------------------------------------------------
      80           0 :     sal_Bool lcl_saveConvertToNumber(const Reference< XNumberFormatter > & _xFormatter,sal_Int32 _nKey,const OUString& _sValue,double& _nrValue)
      81             :     {
      82           0 :         sal_Bool bRet = sal_False;
      83             :         try
      84             :         {
      85           0 :             _nrValue = _xFormatter->convertStringToNumber(_nKey, _sValue);
      86           0 :             bRet = sal_True;
      87             :         }
      88           0 :         catch(Exception&)
      89             :         {
      90             :         }
      91           0 :         return bRet;
      92             :     }
      93             :     // -----------------------------------------------------------------------------
      94          20 :     void replaceAndReset(connectivity::OSQLParseNode*& _pResetNode,connectivity::OSQLParseNode* _pNewNode)
      95             :     {
      96          20 :         _pResetNode->getParent()->replace(_pResetNode, _pNewNode);
      97          20 :         delete _pResetNode;
      98          20 :         _pResetNode = _pNewNode;
      99          20 :     }
     100             :     // -----------------------------------------------------------------------------
     101             :     /** quotes a string and search for quotes inside the string and replace them with the new quote
     102             :         @param  rValue
     103             :             The value to be quoted.
     104             :         @param  rQuot
     105             :             The quote
     106             :         @param  rQuotToReplace
     107             :             The quote to replace with
     108             :         @return
     109             :             The quoted string.
     110             :     */
     111        3019 :     OUString SetQuotation(const OUString& rValue, const OUString& rQuot, const OUString& rQuotToReplace)
     112             :     {
     113        3019 :         OUString rNewValue = rQuot;
     114        3019 :         rNewValue += rValue;
     115        3019 :         sal_Int32 nIndex = (sal_Int32)-1;   // Replace quotes with double quotes or the parser gets into problems
     116             : 
     117        3019 :         if (!rQuot.isEmpty())
     118             :         {
     119        3019 :             do
     120             :             {
     121        3019 :                 nIndex += 2;
     122        3019 :                 nIndex = rNewValue.indexOf(rQuot,nIndex);
     123        3019 :                 if(nIndex != -1)
     124           0 :                     rNewValue = rNewValue.replaceAt(nIndex,rQuot.getLength(),rQuotToReplace);
     125             :             } while (nIndex != -1);
     126             :         }
     127             : 
     128        3019 :         rNewValue += rQuot;
     129        3019 :         return rNewValue;
     130             :     }
     131             : 
     132           0 :     bool columnMatchP(const connectivity::OSQLParseNode* pSubTree, const connectivity::SQLParseNodeParameter& rParam)
     133             :     {
     134             :         using namespace connectivity;
     135             :         assert(SQL_ISRULE(pSubTree,column_ref));
     136             : 
     137           0 :         if(!rParam.xField.is())
     138           0 :             return false;
     139             : 
     140             :         // retrieve the field's name & table range
     141           0 :         OUString aFieldName;
     142             :         try
     143             :         {
     144           0 :             sal_Int32 nNamePropertyId = PROPERTY_ID_NAME;
     145           0 :             if ( rParam.xField->getPropertySetInfo()->hasPropertyByName( OMetaConnection::getPropMap().getNameByIndex( PROPERTY_ID_REALNAME ) ) )
     146           0 :                 nNamePropertyId = PROPERTY_ID_REALNAME;
     147           0 :             rParam.xField->getPropertyValue( OMetaConnection::getPropMap().getNameByIndex( nNamePropertyId ) ) >>= aFieldName;
     148             :         }
     149           0 :         catch ( Exception& )
     150             :         {
     151             :         }
     152             : 
     153           0 :         if(pSubTree->count())
     154             :         {
     155           0 :             const OSQLParseNode* pCol = pSubTree->getChild(pSubTree->count()-1);
     156           0 :             if (SQL_ISRULE(pCol,column_val))
     157             :             {
     158             :                 assert(pCol->count() == 1);
     159           0 :                 pCol = pCol->getChild(0);
     160             :             }
     161           0 :             const OSQLParseNode* pTable(NULL);
     162           0 :             switch (pSubTree->count())
     163             :             {
     164             :             case 1:
     165           0 :                 break;
     166             :             case 3:
     167           0 :                 pTable = pSubTree->getChild(0);
     168           0 :                 break;
     169             :             case 5:
     170             :             case 7:
     171             :                 SAL_WARN("connectivity.parse", "SQL: catalog and/or schema in column_ref in predicate");
     172           0 :                 break;
     173             :             default:
     174             :                 SAL_WARN("connectivity.parse", "columnMatchP: SQL grammar changed; column_ref has " << pSubTree->count() << " children");
     175             :                 assert(false);
     176           0 :                 break;
     177             :             }
     178             :             // TODO: not all DBMS match column names case-insensitively...
     179             :             // see XDatabaseMetaData::supportsMixedCaseIdentifiers()
     180             :             // and XDatabaseMetaData::supportsMixedCaseQuotedIdentifiers()
     181           0 :             if  (   // table name matches (or no table name)?
     182           0 :                     ( !pTable || pTable->getTokenValue().equalsIgnoreAsciiCase(rParam.sPredicateTableAlias) )
     183           0 :                  && // column name matches?
     184           0 :                     pCol->getTokenValue().equalsIgnoreAsciiCase(aFieldName)
     185             :                 )
     186           0 :                 return true;
     187             :         }
     188           0 :         return false;
     189             :     }
     190             : }
     191             : 
     192             : namespace connectivity
     193             : {
     194             : 
     195             : //=============================================================================
     196             : //= SQLParseNodeParameter
     197             : //=============================================================================
     198             : //-----------------------------------------------------------------------------
     199        1621 : SQLParseNodeParameter::SQLParseNodeParameter( const Reference< XConnection >& _rxConnection,
     200             :         const Reference< XNumberFormatter >& _xFormatter, const Reference< XPropertySet >& _xField,
     201             :         const OUString &_sPredicateTableAlias,
     202             :         const Locale& _rLocale, const IParseContext* _pContext,
     203             :         bool _bIntl, bool _bQuote, sal_Char _cDecSep, bool _bPredicate, bool _bParseToSDBC )
     204             :     :rLocale(_rLocale)
     205             :     ,aMetaData( _rxConnection )
     206             :     ,pParser( NULL )
     207        1621 :     ,pSubQueryHistory( new QueryNameSet )
     208             :     ,xFormatter(_xFormatter)
     209             :     ,xField(_xField)
     210             :     ,sPredicateTableAlias(_sPredicateTableAlias)
     211             :     ,m_rContext( _pContext ? (const IParseContext&)(*_pContext) : (const IParseContext&)OSQLParser::s_aDefaultContext )
     212             :     ,cDecSep(_cDecSep)
     213             :     ,bQuote(_bQuote)
     214             :     ,bInternational(_bIntl)
     215             :     ,bPredicate(_bPredicate)
     216        3242 :     ,bParseToSDBCLevel( _bParseToSDBC )
     217             : {
     218        1621 : }
     219             : 
     220             : //-----------------------------------------------------------------------------
     221       12691 : SQLParseNodeParameter::~SQLParseNodeParameter()
     222             : {
     223       12691 : }
     224             : 
     225             : //=============================================================================
     226             : //= OSQLParseNode
     227             : //=============================================================================
     228             : //-----------------------------------------------------------------------------
     229           0 : OUString OSQLParseNode::convertDateString(const SQLParseNodeParameter& rParam, const OUString& rString) const
     230             : {
     231             :     SAL_INFO( "connectivity.parse", "parse Ocke.Janssen@sun.com OSQLParseNode::convertDateString" );
     232           0 :     Date aDate = DBTypeConversion::toDate(rString);
     233           0 :     Reference< XNumberFormatsSupplier > xSupplier(rParam.xFormatter->getNumberFormatsSupplier());
     234           0 :     Reference< XNumberFormatTypes >     xTypes(xSupplier->getNumberFormats(), UNO_QUERY);
     235             : 
     236           0 :     double fDate = DBTypeConversion::toDouble(aDate,DBTypeConversion::getNULLDate(xSupplier));
     237           0 :     sal_Int32 nKey = xTypes->getStandardIndex(rParam.rLocale) + 36; // XXX hack
     238           0 :     return rParam.xFormatter->convertNumberToString(nKey, fDate);
     239             : }
     240             : 
     241             : //-----------------------------------------------------------------------------
     242           0 : OUString OSQLParseNode::convertDateTimeString(const SQLParseNodeParameter& rParam, const OUString& rString) const
     243             : {
     244             :     SAL_INFO( "connectivity.parse", "parse Ocke.Janssen@sun.com OSQLParseNode::convertDateTimeString" );
     245           0 :     DateTime aDate = DBTypeConversion::toDateTime(rString);
     246           0 :     Reference< XNumberFormatsSupplier >  xSupplier(rParam.xFormatter->getNumberFormatsSupplier());
     247           0 :     Reference< XNumberFormatTypes >  xTypes(xSupplier->getNumberFormats(), UNO_QUERY);
     248             : 
     249           0 :     double fDateTime = DBTypeConversion::toDouble(aDate,DBTypeConversion::getNULLDate(xSupplier));
     250           0 :     sal_Int32 nKey = xTypes->getStandardIndex(rParam.rLocale) + 51; // XXX hack
     251           0 :     return rParam.xFormatter->convertNumberToString(nKey, fDateTime);
     252             : }
     253             : 
     254             : //-----------------------------------------------------------------------------
     255           0 : OUString OSQLParseNode::convertTimeString(const SQLParseNodeParameter& rParam, const OUString& rString) const
     256             : {
     257             :     SAL_INFO( "connectivity.parse", "parse Ocke.Janssen@sun.com OSQLParseNode::convertTimeString" );
     258           0 :     Time aTime = DBTypeConversion::toTime(rString);
     259           0 :     Reference< XNumberFormatsSupplier >  xSupplier(rParam.xFormatter->getNumberFormatsSupplier());
     260             : 
     261           0 :     Reference< XNumberFormatTypes >  xTypes(xSupplier->getNumberFormats(), UNO_QUERY);
     262             : 
     263           0 :     double fTime = DBTypeConversion::toDouble(aTime);
     264           0 :     sal_Int32 nKey = xTypes->getStandardIndex(rParam.rLocale) + 41; // XXX hack
     265           0 :     return rParam.xFormatter->convertNumberToString(nKey, fTime);
     266             : }
     267             : 
     268             : //-----------------------------------------------------------------------------
     269        1528 : void OSQLParseNode::parseNodeToStr(OUString& rString,
     270             :                                    const Reference< XConnection >& _rxConnection,
     271             :                                    const IParseContext* pContext,
     272             :                                    bool _bIntl,
     273             :                                    bool _bQuote) const
     274             : {
     275             :     SAL_INFO( "connectivity.parse", "parse Ocke.Janssen@sun.com OSQLParseNode::parseNodeToStr" );
     276             : 
     277             :     parseNodeToStr(
     278             :         rString, _rxConnection, NULL, NULL, OUString(),
     279        1528 :         pContext ? pContext->getPreferredLocale() : OParseContext::getDefaultLocale(),
     280        3056 :         pContext, _bIntl, _bQuote, '.', false, false );
     281        1528 : }
     282             : 
     283             : //-----------------------------------------------------------------------------
     284          36 : void OSQLParseNode::parseNodeToPredicateStr(OUString& rString,
     285             :                                               const Reference< XConnection >& _rxConnection,
     286             :                                               const Reference< XNumberFormatter > & xFormatter,
     287             :                                               const ::com::sun::star::lang::Locale& rIntl,
     288             :                                               sal_Char _cDec,
     289             :                                               const IParseContext* pContext ) const
     290             : {
     291             :     SAL_INFO( "connectivity.parse", "parse Ocke.Janssen@sun.com OSQLParseNode::parseNodeToPredicateStr" );
     292             : 
     293             :     OSL_ENSURE(xFormatter.is(), "OSQLParseNode::parseNodeToPredicateStr:: no formatter!");
     294             : 
     295          36 :     if (xFormatter.is())
     296          36 :         parseNodeToStr(rString, _rxConnection, xFormatter, NULL, OUString(), rIntl, pContext, sal_True, sal_True, _cDec, true, false);
     297          36 : }
     298             : 
     299             : //-----------------------------------------------------------------------------
     300           0 : void OSQLParseNode::parseNodeToPredicateStr(OUString& rString,
     301             :                                               const Reference< XConnection > & _rxConnection,
     302             :                                               const Reference< XNumberFormatter > & xFormatter,
     303             :                                               const Reference< XPropertySet > & _xField,
     304             :                                               const OUString &_sPredicateTableAlias,
     305             :                                               const ::com::sun::star::lang::Locale& rIntl,
     306             :                                               sal_Char _cDec,
     307             :                                               const IParseContext* pContext ) const
     308             : {
     309             :     SAL_INFO( "connectivity.parse", "parse Ocke.Janssen@sun.com OSQLParseNode::parseNodeToPredicateStr" );
     310             : 
     311             :     OSL_ENSURE(xFormatter.is(), "OSQLParseNode::parseNodeToPredicateStr:: no formatter!");
     312             : 
     313           0 :     if (xFormatter.is())
     314           0 :         parseNodeToStr( rString, _rxConnection, xFormatter, _xField, _sPredicateTableAlias, rIntl, pContext, true, true, _cDec, true, false );
     315           0 : }
     316             : 
     317             : //-----------------------------------------------------------------------------
     318        1564 : void OSQLParseNode::parseNodeToStr(OUString& rString,
     319             :                       const Reference< XConnection > & _rxConnection,
     320             :                       const Reference< XNumberFormatter > & xFormatter,
     321             :                       const Reference< XPropertySet > & _xField,
     322             :                       const OUString &_sPredicateTableAlias,
     323             :                       const ::com::sun::star::lang::Locale& rIntl,
     324             :                       const IParseContext* pContext,
     325             :                       bool _bIntl,
     326             :                       bool _bQuote,
     327             :                       sal_Char _cDecSep,
     328             :                       bool _bPredicate,
     329             :                       bool _bSubstitute) const
     330             : {
     331             :     SAL_INFO( "connectivity.parse", "parse Ocke.Janssen@sun.com OSQLParseNode::parseNodeToStr" );
     332             : 
     333             :     OSL_ENSURE( _rxConnection.is(), "OSQLParseNode::parseNodeToStr: invalid connection!" );
     334             : 
     335        1564 :     if ( _rxConnection.is() )
     336             :     {
     337        1564 :         OUStringBuffer sBuffer = rString;
     338             :         try
     339             :         {
     340             :             OSQLParseNode::impl_parseNodeToString_throw( sBuffer,
     341             :                 SQLParseNodeParameter(
     342             :                      _rxConnection, xFormatter, _xField, _sPredicateTableAlias, rIntl, pContext,
     343             :                     _bIntl, _bQuote, _cDecSep, _bPredicate, _bSubstitute
     344        1564 :                 ) );
     345             :         }
     346           0 :         catch( const SQLException& )
     347             :         {
     348             :             SAL_WARN( "connectivity.parse", "OSQLParseNode::parseNodeToStr: this should not throw!" );
     349             :             // our callers don't expect this method to throw anything. The only known situation
     350             :             // where impl_parseNodeToString_throw can throw is when there is a cyclic reference
     351             :             // in the sub queries, but this cannot be the case here, as we do not parse to
     352             :             // SDBC level.
     353             :         }
     354        1564 :         rString = sBuffer.makeStringAndClear();
     355             :     }
     356        1564 : }
     357             : //-----------------------------------------------------------------------------
     358          57 : bool OSQLParseNode::parseNodeToExecutableStatement( OUString& _out_rString, const Reference< XConnection >& _rxConnection,
     359             :     OSQLParser& _rParser, ::com::sun::star::sdbc::SQLException* _pErrorHolder ) const
     360             : {
     361             :     SAL_INFO( "connectivity.parse", "parse Ocke.Janssen@sun.com OSQLParseNode::parseNodeToExecutableStatement" );
     362             :     OSL_PRECOND( _rxConnection.is(), "OSQLParseNode::parseNodeToExecutableStatement: invalid connection!" );
     363             :     SQLParseNodeParameter aParseParam( _rxConnection,
     364          57 :         NULL, NULL, OUString(), OParseContext::getDefaultLocale(), NULL, false, true, '.', false, true );
     365             : 
     366          57 :     if ( aParseParam.aMetaData.supportsSubqueriesInFrom() )
     367             :     {
     368           0 :         Reference< XQueriesSupplier > xSuppQueries( _rxConnection, UNO_QUERY );
     369             :         OSL_ENSURE( xSuppQueries.is(), "OSQLParseNode::parseNodeToExecutableStatement: cannot substitute everything without a QueriesSupplier!" );
     370           0 :         if ( xSuppQueries.is() )
     371           0 :             aParseParam.xQueries = xSuppQueries->getQueries();
     372             :     }
     373             : 
     374          57 :     aParseParam.pParser = &_rParser;
     375             : 
     376          57 :     _out_rString = OUString();
     377         114 :     OUStringBuffer sBuffer;
     378          57 :     bool bSuccess = false;
     379             :     try
     380             :     {
     381          57 :         impl_parseNodeToString_throw( sBuffer, aParseParam );
     382          57 :         bSuccess = true;
     383             :     }
     384           0 :     catch( const SQLException& e )
     385             :     {
     386           0 :         if ( _pErrorHolder )
     387           0 :             *_pErrorHolder = e;
     388             :     }
     389          57 :     _out_rString = sBuffer.makeStringAndClear();
     390         114 :     return bSuccess;
     391             : }
     392             : 
     393             : //-----------------------------------------------------------------------------
     394             : namespace
     395             : {
     396           0 :     bool lcl_isAliasNamePresent( const OSQLParseNode& _rTableNameNode )
     397             :     {
     398           0 :         return !OSQLParseNode::getTableRange(_rTableNameNode.getParent()).isEmpty();
     399             :     }
     400             : }
     401             : 
     402             : //-----------------------------------------------------------------------------
     403       13178 : void OSQLParseNode::impl_parseNodeToString_throw(OUStringBuffer& rString, const SQLParseNodeParameter& rParam, bool bSimple) const
     404             : {
     405             :     SAL_INFO( "connectivity.parse", "parse Ocke.Janssen@sun.com OSQLParseNode::impl_parseNodeToString_throw" );
     406       13178 :     if ( isToken() )
     407             :     {
     408        6617 :         parseLeaf(rString,rParam);
     409       19795 :         return;
     410             :     }
     411             : 
     412             :     // Lets see how many nodes this subtree has
     413        6561 :     sal_uInt32 nCount = count();
     414             : 
     415        6561 :     bool bHandled = false;
     416        6561 :     switch ( getKnownRuleID() )
     417             :     {
     418             :     // special handling for parameters
     419             :     case parameter:
     420             :     {
     421          77 :         bSimple=false;
     422          77 :         if(!rString.isEmpty())
     423          39 :             rString.appendAscii(" ");
     424          77 :         if (nCount == 1)    // ?
     425           0 :             m_aChildren[0]->impl_parseNodeToString_throw( rString, rParam, false );
     426          77 :         else if (nCount == 2)   // :Name
     427             :         {
     428          77 :             m_aChildren[0]->impl_parseNodeToString_throw( rString, rParam, false );
     429          77 :             rString.append(m_aChildren[1]->m_aNodeValue);
     430             :         }                   // [Name]
     431             :         else
     432             :         {
     433           0 :             m_aChildren[0]->impl_parseNodeToString_throw( rString, rParam, false );
     434           0 :             rString.append(m_aChildren[1]->m_aNodeValue);
     435           0 :             rString.append(m_aChildren[2]->m_aNodeValue);
     436             :         }
     437          77 :         bHandled = true;
     438             :     }
     439          77 :     break;
     440             : 
     441             :     // table refs
     442             :     case table_ref:
     443         205 :         bSimple=false;
     444         205 :         if (  ( nCount == 2 ) || ( nCount == 3 ) || ( nCount == 5 ) )
     445             :         {
     446         205 :             impl_parseTableRangeNodeToString_throw( rString, rParam );
     447         205 :             bHandled = true;
     448             :         }
     449         205 :         break;
     450             : 
     451             :     // table name - might be a query name
     452             :     case table_name:
     453         205 :         bSimple=false;
     454         205 :         bHandled = impl_parseTableNameNodeToString_throw( rString, rParam );
     455         205 :         break;
     456             : 
     457             :     case as_clause:
     458         138 :         bSimple=false;
     459             :         assert(nCount == 0 || nCount == 2);
     460         138 :         if (nCount == 2)
     461             :         {
     462           0 :             if ( rParam.aMetaData.generateASBeforeCorrelationName() )
     463           0 :                 rString.append(OUString(" AS "));
     464           0 :             m_aChildren[1]->impl_parseNodeToString_throw( rString, rParam, false );
     465             :         }
     466         138 :         bHandled = true;
     467         138 :         break;
     468             : 
     469             :     case opt_as:
     470             :         assert(nCount == 0);
     471          27 :         bHandled = true;
     472          27 :         break;
     473             : 
     474             :     case like_predicate:
     475             :         // Depending on whether international is given, LIKE is treated differently
     476             :         // international: *, ? are placeholders
     477             :         // else SQL92 conform: %, _
     478           0 :         impl_parseLikeNodeToString_throw( rString, rParam, bSimple );
     479           0 :         bHandled = true;
     480           0 :         break;
     481             : 
     482             :     case general_set_fct:
     483             :     case set_fct_spec:
     484             :     case position_exp:
     485             :     case extract_exp:
     486             :     case length_exp:
     487             :     case char_value_fct:
     488             :     {
     489           0 :         bSimple=false;
     490           0 :         if (!addDateValue(rString, rParam))
     491             :         {
     492             :             // Do not quote function name
     493           0 :             SQLParseNodeParameter aNewParam(rParam);
     494           0 :             aNewParam.bQuote = ( SQL_ISRULE(this,length_exp)    || SQL_ISRULE(this,char_value_fct) );
     495             : 
     496           0 :             m_aChildren[0]->impl_parseNodeToString_throw( rString, aNewParam, false );
     497           0 :             aNewParam.bQuote = rParam.bQuote;
     498             :             //aNewParam.bPredicate = sal_False; // disable [ ] around names // look at i73215
     499           0 :             OUStringBuffer aStringPara;
     500           0 :             for (sal_uInt32 i=1; i<nCount; i++)
     501             :             {
     502           0 :                 const OSQLParseNode * pSubTree = m_aChildren[i];
     503           0 :                 if (pSubTree)
     504             :                 {
     505           0 :                     pSubTree->impl_parseNodeToString_throw( aStringPara, aNewParam, false );
     506             : 
     507             :                     // In the comma lists, put commas in-between all subtrees
     508           0 :                     if ((m_eNodeType == SQL_NODE_COMMALISTRULE)     && (i < (nCount - 1)))
     509           0 :                         aStringPara.appendAscii(",");
     510             :                 }
     511             :                 else
     512           0 :                     i++;
     513             :             }
     514           0 :             rString.append(aStringPara.makeStringAndClear());
     515             :         }
     516           0 :         bHandled = true;
     517             :     }
     518             :     case odbc_call_spec:
     519             :     case subquery:
     520             :     case term:
     521             :     case factor:
     522             :     case window_function:
     523             :     case cast_spec:
     524             :     case num_value_exp:
     525           0 :         bSimple = false;
     526             : 
     527           0 :     break;
     528             :     default:
     529        5909 :         break;
     530             :     }   // switch ( getKnownRuleID() )
     531             : 
     532        6561 :     if ( !bHandled )
     533             :     {
     534       40482 :         for (OSQLParseNodes::const_iterator i = m_aChildren.begin();
     535       34368 :             i != m_aChildren.end();)
     536             :         {
     537       11070 :             const OSQLParseNode* pSubTree = *i;
     538       11070 :             if ( !pSubTree )
     539             :             {
     540           0 :                 ++i;
     541           0 :                 continue;
     542             :             }
     543             : 
     544       11070 :             SQLParseNodeParameter aNewParam(rParam);
     545             : 
     546             :             // don't replace the field for subqueries
     547       11070 :             if (rParam.xField.is() && SQL_ISRULE(pSubTree,subquery))
     548           0 :                 aNewParam.xField = NULL;
     549             : 
     550             :             // When we are building a criterion inside a query view,
     551             :             // simplify criterion display by removing:
     552             :             //   "currentFieldName"
     553             :             //   "currentFieldName" =
     554             :             // but only in simple expressions.
     555             :             // This means anything that is made of:
     556             :             // (see the rules conditionalised by inPredicateCheck() in sqlbison.y).
     557             :             //  - parentheses
     558             :             //  - logical operators (and, or, not)
     559             :             //  - comparison operators (IS, =, >, <, BETWEEN, LIKE, ...)
     560             :             // but *not* e.g. in function arguments
     561       11070 :             if (bSimple && rParam.bPredicate && rParam.xField.is() && SQL_ISRULE(pSubTree,column_ref))
     562             :             {
     563           0 :                 if (columnMatchP(pSubTree, rParam))
     564             :                 {
     565             :                     // skip field
     566           0 :                     ++i;
     567             :                     // if the following node is the comparision operator'=',
     568             :                     // we filter it as well
     569           0 :                     if (SQL_ISRULE(this, comparison_predicate))
     570             :                     {
     571           0 :                         if(i != m_aChildren.end())
     572             :                         {
     573           0 :                             pSubTree = *i;
     574           0 :                             if (pSubTree && pSubTree->getNodeType() == SQL_NODE_EQUAL)
     575           0 :                                 ++i;
     576             :                         }
     577             :                     }
     578             :                 }
     579             :                 else
     580             :                 {
     581           0 :                     pSubTree->impl_parseNodeToString_throw( rString, aNewParam, bSimple );
     582           0 :                     ++i;
     583             : 
     584             :                     // In the comma lists, put commas in-between all subtrees
     585           0 :                     if ((m_eNodeType == SQL_NODE_COMMALISTRULE)     && (i != m_aChildren.end()))
     586           0 :                         rString.appendAscii(",");
     587             :                 }
     588             :             }
     589             :             else
     590             :             {
     591       11070 :                 pSubTree->impl_parseNodeToString_throw( rString, aNewParam, bSimple );
     592       11070 :                 ++i;
     593             : 
     594             :                 // In the comma lists, put commas in-between all subtrees
     595       11070 :                 if ((m_eNodeType == SQL_NODE_COMMALISTRULE)     && (i != m_aChildren.end()))
     596             :                 {
     597          54 :                     if (SQL_ISRULE(this,value_exp_commalist) && rParam.bPredicate)
     598           0 :                         rString.appendAscii(";");
     599             :                     else
     600          54 :                         rString.appendAscii(",");
     601             :                 }
     602             :             }
     603             :             // The right hand-side of these operators is not simple
     604       11070 :             switch ( getKnownRuleID() )
     605             :             {
     606             :             case general_set_fct:
     607             :             case set_fct_spec:
     608             :             case position_exp:
     609             :             case extract_exp:
     610             :             case length_exp:
     611             :             case char_value_fct:
     612             :             case odbc_call_spec:
     613             :             case subquery:
     614             :             case comparison_predicate:
     615             :             case between_predicate:
     616             :             case like_predicate:
     617             :             case test_for_null:
     618             :             case in_predicate:
     619             :             case existence_test:
     620             :             case unique_test:
     621             :             case all_or_any_predicate:
     622             :             case join_condition:
     623             :             case boolean_test:
     624             :             case comparison_predicate_part_2:
     625             :             case parenthesized_boolean_value_expression:
     626             :             case other_like_predicate_part_2:
     627             :             case between_predicate_part_2:
     628        2505 :                 bSimple=false;
     629        2505 :                 break;
     630             :             default:
     631        8565 :                 break;
     632             :             }
     633       11070 :         }
     634             :     }
     635             : }
     636             : 
     637             : //-----------------------------------------------------------------------------
     638         205 : bool OSQLParseNode::impl_parseTableNameNodeToString_throw( OUStringBuffer& rString, const SQLParseNodeParameter& rParam ) const
     639             : {
     640             :     SAL_INFO( "connectivity.parse", "parse Ocke.Janssen@sun.com OSQLParseNode::impl_parseTableNameNodeToString_throw" );
     641             :     // is the table_name part of a table_ref?
     642             :     OSL_ENSURE( getParent(), "OSQLParseNode::impl_parseTableNameNodeToString_throw: table_name without parent?" );
     643         205 :     if ( !getParent() || ( getParent()->getKnownRuleID() != table_ref ) )
     644           0 :         return false;
     645             : 
     646             :     // if it's a query, maybe we need to substitute the SQL statement ...
     647         205 :     if ( !rParam.bParseToSDBCLevel )
     648         148 :         return false;
     649             : 
     650          57 :     if ( !rParam.xQueries.is() )
     651             :         // connection does not support queries in queries, or was no query supplier
     652          57 :         return false;
     653             : 
     654             :     try
     655             :     {
     656           0 :         OUString sTableOrQueryName( getChild(0)->getTokenValue() );
     657           0 :         bool bIsQuery = rParam.xQueries->hasByName( sTableOrQueryName );
     658           0 :         if ( !bIsQuery )
     659           0 :             return false;
     660             : 
     661             :         // avoid recursion (e.g. "foo" defined as "SELECT * FROM bar" and "bar" defined as "SELECT * FROM foo".
     662           0 :         if ( rParam.pSubQueryHistory->find( sTableOrQueryName ) != rParam.pSubQueryHistory->end() )
     663             :         {
     664             :             OSL_ENSURE( rParam.pParser, "OSQLParseNode::impl_parseTableNameNodeToString_throw: no parser?" );
     665           0 :             if ( rParam.pParser )
     666             :             {
     667           0 :                 const SQLError& rErrors( rParam.pParser->getErrorHelper() );
     668           0 :                 rErrors.raiseException( sdb::ErrorCondition::PARSER_CYCLIC_SUB_QUERIES );
     669             :             }
     670             :             else
     671             :             {
     672           0 :                 SQLError aErrors( ::comphelper::getProcessComponentContext() );
     673           0 :                 aErrors.raiseException( sdb::ErrorCondition::PARSER_CYCLIC_SUB_QUERIES );
     674             :             }
     675             :         }
     676           0 :         rParam.pSubQueryHistory->insert( sTableOrQueryName );
     677             : 
     678           0 :         Reference< XPropertySet > xQuery( rParam.xQueries->getByName( sTableOrQueryName ), UNO_QUERY_THROW );
     679             : 
     680             :         // substitute the query name with the constituting command
     681           0 :         OUString sCommand;
     682           0 :         OSL_VERIFY( xQuery->getPropertyValue( OMetaConnection::getPropMap().getNameByIndex( PROPERTY_ID_COMMAND ) ) >>= sCommand );
     683             : 
     684           0 :         sal_Bool bEscapeProcessing = sal_False;
     685           0 :         OSL_VERIFY( xQuery->getPropertyValue( OMetaConnection::getPropMap().getNameByIndex( PROPERTY_ID_ESCAPEPROCESSING ) ) >>= bEscapeProcessing );
     686             : 
     687             :         // the query we found here might itself be based on another query, so parse it recursively
     688             :         OSL_ENSURE( rParam.pParser, "OSQLParseNode::impl_parseTableNameNodeToString_throw: cannot analyze sub queries without a parser!" );
     689           0 :         if ( bEscapeProcessing && rParam.pParser )
     690             :         {
     691           0 :             OUString sError;
     692           0 :             ::std::auto_ptr< OSQLParseNode > pSubQueryNode( rParam.pParser->parseTree( sError, sCommand, sal_False ) );
     693           0 :             if ( pSubQueryNode.get() )
     694             :             {
     695             :                 // parse the sub-select to SDBC level, too
     696           0 :                 OUStringBuffer sSubSelect;
     697           0 :                 pSubQueryNode->impl_parseNodeToString_throw( sSubSelect, rParam, false );
     698           0 :                 if ( !sSubSelect.isEmpty() )
     699           0 :                     sCommand = sSubSelect.makeStringAndClear();
     700           0 :             }
     701             :         }
     702             : 
     703           0 :         rString.appendAscii( " ( " );
     704           0 :         rString.append(sCommand);
     705           0 :         rString.appendAscii( " )" );
     706             : 
     707             :         // append the query name as table alias, since it might be referenced in other
     708             :         // parts of the statement - but only if there's no other alias name present
     709           0 :         if ( !lcl_isAliasNamePresent( *this ) )
     710             :         {
     711           0 :             rString.appendAscii( " AS " );
     712           0 :             if ( rParam.bQuote )
     713             :                 rString.append(SetQuotation( sTableOrQueryName,
     714           0 :                     rParam.aMetaData.getIdentifierQuoteString(), rParam.aMetaData.getIdentifierQuoteString() ));
     715             :         }
     716             : 
     717             :         // don't forget to remove the query name from the history, else multiple inclusions
     718             :         // won't work
     719             :         // #i69227# / 2006-10-10 / frank.schoenheit@sun.com
     720           0 :         rParam.pSubQueryHistory->erase( sTableOrQueryName );
     721             : 
     722           0 :         return true;
     723             :     }
     724           0 :     catch( const SQLException& )
     725             :     {
     726           0 :         throw;
     727             :     }
     728           0 :     catch( const Exception& )
     729             :     {
     730             :         DBG_UNHANDLED_EXCEPTION();
     731             :     }
     732           0 :     return false;
     733             : }
     734             : 
     735             : //-----------------------------------------------------------------------------
     736         205 : void OSQLParseNode::impl_parseTableRangeNodeToString_throw(OUStringBuffer& rString, const SQLParseNodeParameter& rParam) const
     737             : {
     738             :     SAL_INFO( "connectivity.parse", "parse Ocke.Janssen@sun.com OSQLParseNode::impl_parseTableRangeNodeToString_throw" );
     739             :     OSL_PRECOND(  ( count() == 2 ) || ( count() == 3 ) || ( count() == 5 ) ,"Illegal count");
     740             : 
     741             :     // rString += OUString(" ");
     742             :     ::std::for_each(m_aChildren.begin(),m_aChildren.end(),
     743         205 :         boost::bind( &OSQLParseNode::impl_parseNodeToString_throw, _1, boost::ref( rString ), boost::cref( rParam ), false ));
     744         205 : }
     745             : 
     746             : //-----------------------------------------------------------------------------
     747           0 : void OSQLParseNode::impl_parseLikeNodeToString_throw( OUStringBuffer& rString, const SQLParseNodeParameter& rParam, bool bSimple ) const
     748             : {
     749             :     SAL_INFO( "connectivity.parse", "parse Ocke.Janssen@sun.com OSQLParseNode::impl_parseLikeNodeToString_throw" );
     750             :     assert(SQL_ISRULE(this,like_predicate));
     751             :     OSL_ENSURE(count() == 2,"count != 2: Prepare for GPF");
     752             : 
     753           0 :     const OSQLParseNode* pEscNode = NULL;
     754           0 :     const OSQLParseNode* pParaNode = NULL;
     755             : 
     756           0 :     SQLParseNodeParameter aNewParam(rParam);
     757             :     //aNewParam.bQuote = sal_True; // why setting this to true? @see http://www.openoffice.org/issues/show_bug.cgi?id=75557
     758             : 
     759           0 :     if ( !(bSimple && rParam.bPredicate && rParam.xField.is() && SQL_ISRULE(m_aChildren[0],column_ref) && columnMatchP(m_aChildren[0], rParam)) )
     760           0 :         m_aChildren[0]->impl_parseNodeToString_throw( rString, aNewParam, bSimple );
     761             : 
     762           0 :     const OSQLParseNode* pPart2 = m_aChildren[1];
     763           0 :     pPart2->getChild(0)->impl_parseNodeToString_throw( rString, aNewParam, false );
     764           0 :     pPart2->getChild(1)->impl_parseNodeToString_throw( rString, aNewParam, false );
     765           0 :     pParaNode = pPart2->getChild(2);
     766           0 :     pEscNode  = pPart2->getChild(3);
     767             : 
     768           0 :     if (pParaNode->isToken())
     769             :     {
     770           0 :         OUString aStr = ConvertLikeToken(pParaNode, pEscNode, rParam.bInternational);
     771           0 :         rString.appendAscii(" ");
     772           0 :         rString.append(SetQuotation(aStr,OUString("\'"),OUString("\'\'")));
     773             :     }
     774             :     else
     775           0 :         pParaNode->impl_parseNodeToString_throw( rString, aNewParam, false );
     776             : 
     777           0 :     pEscNode->impl_parseNodeToString_throw( rString, aNewParam, false );
     778           0 : }
     779             : 
     780             : 
     781             : // -----------------------------------------------------------------------------
     782         212 : sal_Bool OSQLParseNode::getTableComponents(const OSQLParseNode* _pTableNode,
     783             :                                             ::com::sun::star::uno::Any &_rCatalog,
     784             :                                             OUString &_rSchema,
     785             :                                             OUString &_rTable,
     786             :                                             const Reference< XDatabaseMetaData >& _xMetaData)
     787             : {
     788             :     SAL_INFO( "connectivity.parse", "parse Ocke.Janssen@sun.com OSQLParseNode::getTableComponents" );
     789             :     OSL_ENSURE(_pTableNode,"Wrong use of getTableComponents! _pTableNode is not allowed to be null!");
     790         212 :     if(_pTableNode)
     791             :     {
     792         212 :         const sal_Bool bSupportsCatalog = _xMetaData.is() && _xMetaData->supportsCatalogsInDataManipulation();
     793         212 :         const sal_Bool bSupportsSchema = _xMetaData.is() && _xMetaData->supportsSchemasInDataManipulation();
     794         212 :         const OSQLParseNode* pTableNode = _pTableNode;
     795             :         // clear the parameter given
     796         212 :         _rCatalog = Any();
     797         212 :         _rSchema = _rTable = OUString();
     798             :         // see rule catalog_name: in sqlbison.y
     799         212 :         if (SQL_ISRULE(pTableNode,catalog_name))
     800             :         {
     801             :             OSL_ENSURE(pTableNode->getChild(0) && pTableNode->getChild(0)->isToken(),"Invalid parsenode!");
     802           0 :             _rCatalog <<= pTableNode->getChild(0)->getTokenValue();
     803           0 :             pTableNode = pTableNode->getChild(2);
     804             :         }
     805             :         // check if we have schema_name rule
     806         212 :         if(SQL_ISRULE(pTableNode,schema_name))
     807             :         {
     808           0 :             if ( bSupportsCatalog && !bSupportsSchema )
     809           0 :                 _rCatalog <<= pTableNode->getChild(0)->getTokenValue();
     810             :             else
     811           0 :                 _rSchema = pTableNode->getChild(0)->getTokenValue();
     812           0 :             pTableNode = pTableNode->getChild(2);
     813             :         }
     814             :         // check if we have table_name rule
     815         212 :         if(SQL_ISRULE(pTableNode,table_name))
     816             :         {
     817         212 :             _rTable = pTableNode->getChild(0)->getTokenValue();
     818             :         }
     819             :         else
     820             :         {
     821             :             SAL_WARN( "connectivity.parse","Error in parse tree!");
     822             :         }
     823             :     }
     824         212 :     return !_rTable.isEmpty();
     825             : }
     826             : // -----------------------------------------------------------------------------
     827           0 : void OSQLParser::killThousandSeparator(OSQLParseNode* pLiteral)
     828             : {
     829           0 :     if ( pLiteral )
     830             :     {
     831           0 :         if ( s_xLocaleData->getLocaleItem( m_pData->aLocale ).decimalSeparator.toChar() == ',' )
     832             :         {
     833           0 :             pLiteral->m_aNodeValue = pLiteral->m_aNodeValue.replace('.', sal_Unicode());
     834             :             // and replace decimal
     835           0 :             pLiteral->m_aNodeValue = pLiteral->m_aNodeValue.replace(',', '.');
     836             :         }
     837             :         else
     838           0 :             pLiteral->m_aNodeValue = pLiteral->m_aNodeValue.replace(',', sal_Unicode());
     839             :         }
     840           0 : }
     841             : // -----------------------------------------------------------------------------
     842          72 : OSQLParseNode* OSQLParser::convertNode(sal_Int32 nType,OSQLParseNode*& pLiteral)
     843             : {
     844          72 :     if ( !pLiteral )
     845          36 :         return NULL;
     846             : 
     847          36 :     OSQLParseNode* pReturn = pLiteral;
     848             : 
     849          36 :     if ( ( pLiteral->isRule() && !SQL_ISRULE(pLiteral,value_exp) ) || SQL_ISTOKEN(pLiteral,FALSE) || SQL_ISTOKEN(pLiteral,TRUE) )
     850             :     {
     851           0 :         switch(nType)
     852             :         {
     853             :             case DataType::CHAR:
     854             :             case DataType::VARCHAR:
     855             :             case DataType::LONGVARCHAR:
     856             :             case DataType::CLOB:
     857           0 :                 if ( !SQL_ISRULE(pReturn,char_value_exp) && !buildStringNodes(pReturn) )
     858           0 :                     pReturn = NULL;
     859             :             default:
     860           0 :                 break;
     861             :         }
     862             :     }
     863             :     else
     864             :     {
     865          36 :         switch(pLiteral->getNodeType())
     866             :         {
     867             :         case SQL_NODE_STRING:
     868          36 :             switch(nType)
     869             :             {
     870             :                 case DataType::CHAR:
     871             :                 case DataType::VARCHAR:
     872             :                 case DataType::LONGVARCHAR:
     873             :                 case DataType::CLOB:
     874          36 :                     break;
     875             :                 case DataType::DATE:
     876             :                 case DataType::TIME:
     877             :                 case DataType::TIMESTAMP:
     878           0 :                     if (m_xFormatter.is())
     879           0 :                         pReturn = buildDate( nType, pReturn);
     880           0 :                     break;
     881             :                 default:
     882           0 :                     m_sErrorMessage = m_pContext->getErrorMessage(IParseContext::ERROR_INVALID_COMPARE);
     883           0 :                     break;
     884             :             }
     885          36 :             break;
     886             :         case SQL_NODE_ACCESS_DATE:
     887           0 :             switch(nType)
     888             :             {
     889             :                 case DataType::DATE:
     890             :                 case DataType::TIME:
     891             :                 case DataType::TIMESTAMP:
     892           0 :                 if ( m_xFormatter.is() )
     893           0 :                     pReturn = buildDate( nType, pReturn);
     894             :                     else
     895           0 :                         m_sErrorMessage = m_pContext->getErrorMessage(IParseContext::ERROR_INVALID_DATE_COMPARE);
     896           0 :                     break;
     897             :                 default:
     898           0 :                     m_sErrorMessage = m_pContext->getErrorMessage(IParseContext::ERROR_INVALID_COMPARE);
     899           0 :                     break;
     900             :             }
     901           0 :             break;
     902             :         case SQL_NODE_INTNUM:
     903           0 :             switch(nType)
     904             :             {
     905             :                 case DataType::BIT:
     906             :                 case DataType::BOOLEAN:
     907             :                 case DataType::DECIMAL:
     908             :                 case DataType::NUMERIC:
     909             :                 case DataType::TINYINT:
     910             :                 case DataType::SMALLINT:
     911             :                 case DataType::INTEGER:
     912             :                 case DataType::BIGINT:
     913             :                 case DataType::FLOAT:
     914             :                 case DataType::REAL:
     915             :                 case DataType::DOUBLE:
     916             :                     // kill thousand separators if any
     917           0 :                     killThousandSeparator(pReturn);
     918           0 :                     break;
     919             :                 case DataType::CHAR:
     920             :                 case DataType::VARCHAR:
     921             :                 case DataType::LONGVARCHAR:
     922             :                 case DataType::CLOB:
     923           0 :                     pReturn = buildNode_STR_NUM(pReturn);
     924           0 :                     break;
     925             :                 default:
     926           0 :                     m_sErrorMessage = m_pContext->getErrorMessage(IParseContext::ERROR_INVALID_INT_COMPARE);
     927           0 :                     break;
     928             :             }
     929           0 :             break;
     930             :         case SQL_NODE_APPROXNUM:
     931           0 :             switch(nType)
     932             :             {
     933             :                 case DataType::DECIMAL:
     934             :                 case DataType::NUMERIC:
     935             :                 case DataType::FLOAT:
     936             :                 case DataType::REAL:
     937             :                 case DataType::DOUBLE:
     938             :                     // kill thousand separators if any
     939           0 :                     killThousandSeparator(pReturn);
     940           0 :                     break;
     941             :                 case DataType::CHAR:
     942             :                 case DataType::VARCHAR:
     943             :                 case DataType::LONGVARCHAR:
     944             :                 case DataType::CLOB:
     945           0 :                     pReturn = buildNode_STR_NUM(pReturn);
     946           0 :                     break;
     947             :                 case DataType::INTEGER:
     948             :                 default:
     949           0 :                     m_sErrorMessage = m_pContext->getErrorMessage(IParseContext::ERROR_INVALID_REAL_COMPARE);
     950           0 :                     break;
     951             :             }
     952           0 :             break;
     953             :         default:
     954             :             ;
     955             :         }
     956             :     }
     957          36 :     return pReturn;
     958             : }
     959             : // -----------------------------------------------------------------------------
     960          36 : sal_Int16 OSQLParser::buildPredicateRule(OSQLParseNode*& pAppend,OSQLParseNode* pLiteral,OSQLParseNode*& pCompare,OSQLParseNode* pLiteral2)
     961             : {
     962             :     OSL_ENSURE(inPredicateCheck(),"Only in predicate check allowed!");
     963          36 :     sal_Int16 nErg = 0;
     964          36 :     if ( m_xField.is() )
     965             :     {
     966          36 :         sal_Int32 nType = 0;
     967             :         try
     968             :         {
     969          36 :             m_xField->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPE)) >>= nType;
     970             :         }
     971           0 :         catch( Exception& )
     972             :         {
     973           0 :             return nErg;
     974             :         }
     975             : 
     976          36 :         OSQLParseNode* pNode1 = convertNode(nType,pLiteral);
     977          36 :         if ( pNode1 )
     978             :         {
     979          36 :             OSQLParseNode* pNode2 = convertNode(nType,pLiteral2);
     980          36 :             if ( m_sErrorMessage.isEmpty() )
     981          36 :                 nErg = buildNode(pAppend,pCompare,pNode1,pNode2);
     982             :         }
     983             :     }
     984          36 :     if (!pCompare->getParent()) // I have no parent so I was not used and I must die :-)
     985           0 :         delete pCompare;
     986          36 :     return nErg;
     987             : }
     988             : // -----------------------------------------------------------------------------
     989           0 : sal_Int16 OSQLParser::buildLikeRule(OSQLParseNode*& pAppend, OSQLParseNode*& pLiteral, const OSQLParseNode* pEscape)
     990             : {
     991           0 :     sal_Int16 nErg = 0;
     992           0 :     sal_Int32 nType = 0;
     993             : 
     994           0 :     if (!m_xField.is())
     995           0 :         return nErg;
     996             :     try
     997             :     {
     998           0 :         Any aValue;
     999             :         {
    1000           0 :             aValue = m_xField->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPE));
    1001           0 :             aValue >>= nType;
    1002           0 :         }
    1003             :     }
    1004           0 :     catch( Exception& )
    1005             :     {
    1006           0 :         return nErg;
    1007             :     }
    1008             : 
    1009           0 :     switch (nType)
    1010             :     {
    1011             :         case DataType::CHAR:
    1012             :         case DataType::VARCHAR:
    1013             :         case DataType::LONGVARCHAR:
    1014             :         case DataType::CLOB:
    1015           0 :             if(pLiteral->isRule())
    1016             :             {
    1017           0 :                 pAppend->append(pLiteral);
    1018           0 :                 nErg = 1;
    1019             :             }
    1020             :             else
    1021             :             {
    1022           0 :                 switch(pLiteral->getNodeType())
    1023             :                 {
    1024             :                     case SQL_NODE_STRING:
    1025           0 :                         pLiteral->m_aNodeValue = ConvertLikeToken(pLiteral, pEscape, sal_False);
    1026           0 :                         pAppend->append(pLiteral);
    1027           0 :                         nErg = 1;
    1028           0 :                         break;
    1029             :                     case SQL_NODE_APPROXNUM:
    1030           0 :                         if (m_xFormatter.is() && m_nFormatKey)
    1031             :                         {
    1032           0 :                             sal_Int16 nScale = 0;
    1033             :                             try
    1034             :                             {
    1035           0 :                                 Any aValue = getNumberFormatProperty( m_xFormatter, m_nFormatKey, OUString("Decimals") );
    1036           0 :                                 aValue >>= nScale;
    1037             :                             }
    1038           0 :                             catch( Exception& )
    1039             :                             {
    1040             :                             }
    1041             : 
    1042           0 :                             pAppend->append(new OSQLInternalNode(stringToDouble(pLiteral->getTokenValue(),nScale),SQL_NODE_STRING));
    1043             :                         }
    1044             :                         else
    1045           0 :                             pAppend->append(new OSQLInternalNode(pLiteral->getTokenValue(),SQL_NODE_STRING));
    1046             : 
    1047           0 :                         delete pLiteral;
    1048           0 :                         nErg = 1;
    1049           0 :                         break;
    1050             :                     default:
    1051           0 :                         m_sErrorMessage = m_pContext->getErrorMessage(IParseContext::ERROR_VALUE_NO_LIKE);
    1052           0 :                         m_sErrorMessage = m_sErrorMessage.replaceAt(m_sErrorMessage.indexOf("#1"),2,pLiteral->getTokenValue());
    1053           0 :                         break;
    1054             :                 }
    1055             :             }
    1056           0 :             break;
    1057             :         default:
    1058           0 :             m_sErrorMessage = m_pContext->getErrorMessage(IParseContext::ERROR_FIELD_NO_LIKE);
    1059           0 :             break;
    1060             :     }
    1061           0 :     return nErg;
    1062             : }
    1063             : //-----------------------------------------------------------------------------
    1064           0 : OSQLParseNode* OSQLParser::buildNode_Date(const double& fValue, sal_Int32 nType)
    1065             : {
    1066           0 :     OUString aEmptyString;
    1067           0 :     OSQLParseNode* pNewNode = new OSQLInternalNode(aEmptyString, SQL_NODE_RULE,OSQLParser::RuleID(OSQLParseNode::set_fct_spec));
    1068           0 :     pNewNode->append(new OSQLInternalNode(OUString("{"), SQL_NODE_PUNCTUATION));
    1069           0 :     OSQLParseNode* pDateNode = new OSQLInternalNode(aEmptyString, SQL_NODE_RULE,OSQLParser::RuleID(OSQLParseNode::odbc_fct_spec));
    1070           0 :     pNewNode->append(pDateNode);
    1071           0 :     pNewNode->append(new OSQLInternalNode(OUString("}"), SQL_NODE_PUNCTUATION));
    1072             : 
    1073           0 :     switch (nType)
    1074             :     {
    1075             :         case DataType::DATE:
    1076             :         {
    1077           0 :             Date aDate = DBTypeConversion::toDate(fValue,DBTypeConversion::getNULLDate(m_xFormatter->getNumberFormatsSupplier()));
    1078           0 :             OUString aString = DBTypeConversion::toDateString(aDate);
    1079           0 :             pDateNode->append(new OSQLInternalNode(aEmptyString, SQL_NODE_KEYWORD, SQL_TOKEN_D));
    1080           0 :             pDateNode->append(new OSQLInternalNode(aString, SQL_NODE_STRING));
    1081           0 :             break;
    1082             :         }
    1083             :         case DataType::TIME:
    1084             :         {
    1085           0 :             Time aTime = DBTypeConversion::toTime(fValue);
    1086           0 :             OUString aString = DBTypeConversion::toTimeString(aTime);
    1087           0 :             pDateNode->append(new OSQLInternalNode(aEmptyString, SQL_NODE_KEYWORD, SQL_TOKEN_T));
    1088           0 :             pDateNode->append(new OSQLInternalNode(aString, SQL_NODE_STRING));
    1089           0 :             break;
    1090             :         }
    1091             :         case DataType::TIMESTAMP:
    1092             :         {
    1093           0 :             DateTime aDateTime = DBTypeConversion::toDateTime(fValue,DBTypeConversion::getNULLDate(m_xFormatter->getNumberFormatsSupplier()));
    1094           0 :             if (aDateTime.Seconds || aDateTime.Minutes || aDateTime.Hours)
    1095             :             {
    1096           0 :                 OUString aString = DBTypeConversion::toDateTimeString(aDateTime);
    1097           0 :                 pDateNode->append(new OSQLInternalNode(aEmptyString, SQL_NODE_KEYWORD, SQL_TOKEN_TS));
    1098           0 :                 pDateNode->append(new OSQLInternalNode(aString, SQL_NODE_STRING));
    1099             :             }
    1100             :             else
    1101             :             {
    1102           0 :                 Date aDate(aDateTime.Day,aDateTime.Month,aDateTime.Year);
    1103           0 :                 pDateNode->append(new OSQLInternalNode(aEmptyString, SQL_NODE_KEYWORD, SQL_TOKEN_D));
    1104           0 :                 pDateNode->append(new OSQLInternalNode(DBTypeConversion::toDateString(aDate), SQL_NODE_STRING));
    1105             :             }
    1106           0 :             break;
    1107             :         }
    1108             :     }
    1109             : 
    1110           0 :     return pNewNode;
    1111             : }
    1112             : // -----------------------------------------------------------------------------
    1113           0 : OSQLParseNode* OSQLParser::buildNode_STR_NUM(OSQLParseNode*& _pLiteral)
    1114             : {
    1115           0 :     OSQLParseNode* pReturn = NULL;
    1116           0 :     if ( _pLiteral )
    1117             :     {
    1118           0 :         if (m_nFormatKey)
    1119             :         {
    1120           0 :             sal_Int16 nScale = 0;
    1121             :             try
    1122             :             {
    1123           0 :                 Any aValue = getNumberFormatProperty( m_xFormatter, m_nFormatKey, OUString("Decimals") );
    1124           0 :                 aValue >>= nScale;
    1125             :             }
    1126           0 :             catch( Exception& )
    1127             :             {
    1128             :             }
    1129             : 
    1130           0 :             pReturn = new OSQLInternalNode(stringToDouble(_pLiteral->getTokenValue(),nScale),SQL_NODE_STRING);
    1131             :         }
    1132             :         else
    1133           0 :             pReturn = new OSQLInternalNode(_pLiteral->getTokenValue(),SQL_NODE_STRING);
    1134             : 
    1135           0 :         delete _pLiteral;
    1136           0 :         _pLiteral = NULL;
    1137             :     }
    1138           0 :     return pReturn;
    1139             : }
    1140             : // -----------------------------------------------------------------------------
    1141           0 : OUString OSQLParser::stringToDouble(const OUString& _rValue,sal_Int16 _nScale)
    1142             : {
    1143           0 :     OUString aValue;
    1144           0 :     if(!m_xCharClass.is())
    1145           0 :         m_xCharClass  = CharacterClassification::create( m_xContext );
    1146           0 :     if( s_xLocaleData.is() )
    1147             :     {
    1148             :         try
    1149             :         {
    1150           0 :             ParseResult aResult = m_xCharClass->parsePredefinedToken(KParseType::ANY_NUMBER,_rValue,0,m_pData->aLocale,0,OUString(),KParseType::ANY_NUMBER,OUString());
    1151           0 :             if((aResult.TokenType & KParseType::IDENTNAME) && aResult.EndPos == _rValue.getLength())
    1152             :             {
    1153           0 :                 aValue = OUString::valueOf(aResult.Value);
    1154           0 :                 sal_Int32 nPos = aValue.lastIndexOf('.');
    1155           0 :                 if((nPos+_nScale) < aValue.getLength())
    1156           0 :                     aValue = aValue.replaceAt(nPos+_nScale,aValue.getLength()-nPos-_nScale,OUString());
    1157           0 :                 aValue = aValue.replaceAt(aValue.lastIndexOf('.'),1,s_xLocaleData->getLocaleItem(m_pData->aLocale).decimalSeparator);
    1158           0 :                 return aValue;
    1159           0 :             }
    1160             :         }
    1161           0 :         catch(Exception&)
    1162             :         {
    1163             :         }
    1164             :     }
    1165           0 :     return aValue;
    1166             : }
    1167             : // -----------------------------------------------------------------------------
    1168             : 
    1169         803 : ::osl::Mutex& OSQLParser::getMutex()
    1170             : {
    1171         803 :     static ::osl::Mutex aMutex;
    1172         803 :     return aMutex;
    1173             : }
    1174             : 
    1175             : //-----------------------------------------------------------------------------
    1176          36 : OSQLParseNode* OSQLParser::predicateTree(OUString& rErrorMessage, const OUString& rStatement,
    1177             :                                           const Reference< ::com::sun::star::util::XNumberFormatter > & xFormatter,
    1178             :                                          const Reference< XPropertySet > & xField)
    1179             : {
    1180             :     // Guard the parsing
    1181          36 :     ::osl::MutexGuard aGuard(getMutex());
    1182             :     // must be reset
    1183          36 :     setParser(this);
    1184             : 
    1185             : 
    1186             :     // reset the parser
    1187          36 :     m_xField        = xField;
    1188          36 :     m_xFormatter    = xFormatter;
    1189             : 
    1190          36 :     if (m_xField.is())
    1191             :     {
    1192          36 :         sal_Int32 nType=0;
    1193             :         try
    1194             :         {
    1195             :             // get the field name
    1196          36 :             OUString aString;
    1197             : 
    1198             :             // retrieve the fields name
    1199             :             // #75243# use the RealName of the column if there is any otherwise the name which could be the alias
    1200             :             // of the field
    1201          72 :             Reference< XPropertySetInfo> xInfo = m_xField->getPropertySetInfo();
    1202          36 :             if ( xInfo->hasPropertyByName(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_REALNAME)))
    1203          36 :                 m_xField->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_REALNAME)) >>= aString;
    1204             :             else
    1205           0 :                 m_xField->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME)) >>= aString;
    1206             : 
    1207          36 :             m_sFieldName = aString;
    1208             : 
    1209             :             // get the field format key
    1210          36 :             if ( xInfo->hasPropertyByName(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_FORMATKEY)))
    1211           0 :                 m_xField->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_FORMATKEY)) >>= m_nFormatKey;
    1212             :             else
    1213          36 :                 m_nFormatKey = 0;
    1214             : 
    1215             :             // get the field type
    1216          72 :             m_xField->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPE)) >>= nType;
    1217             :         }
    1218           0 :         catch ( Exception& )
    1219             :         {
    1220             :             OSL_ASSERT(0);
    1221             :         }
    1222             : 
    1223          36 :         if (m_nFormatKey && m_xFormatter.is())
    1224             :         {
    1225           0 :             Any aValue = getNumberFormatProperty( m_xFormatter, m_nFormatKey, OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_LOCALE) );
    1226             :             OSL_ENSURE(aValue.getValueType() == ::getCppuType((const ::com::sun::star::lang::Locale*)0), "OSQLParser::PredicateTree : invalid language property !");
    1227             : 
    1228           0 :             if (aValue.getValueType() == ::getCppuType((const ::com::sun::star::lang::Locale*)0))
    1229           0 :                 aValue >>= m_pData->aLocale;
    1230             :         }
    1231             :         else
    1232          36 :             m_pData->aLocale = m_pContext->getPreferredLocale();
    1233             : 
    1234          36 :         if ( m_xFormatter.is() )
    1235             :         {
    1236             :             try
    1237             :             {
    1238          36 :                 Reference< ::com::sun::star::util::XNumberFormatsSupplier >  xFormatSup = m_xFormatter->getNumberFormatsSupplier();
    1239          36 :                 if ( xFormatSup.is() )
    1240             :                 {
    1241          36 :                     Reference< ::com::sun::star::util::XNumberFormats >  xFormats = xFormatSup->getNumberFormats();
    1242          36 :                     if ( xFormats.is() )
    1243             :                     {
    1244          36 :                         ::com::sun::star::lang::Locale aLocale;
    1245          36 :                         aLocale.Language = OUString("en");
    1246          36 :                         aLocale.Country = OUString("US");
    1247          72 :                         OUString sFormat("YYYY-MM-DD");
    1248          36 :                         m_nDateFormatKey = xFormats->queryKey(sFormat,aLocale,sal_False);
    1249          36 :                         if ( m_nDateFormatKey == sal_Int32(-1) )
    1250          36 :                             m_nDateFormatKey = xFormats->addNew(sFormat, aLocale);
    1251          36 :                     }
    1252          36 :                 }
    1253             :             }
    1254           0 :             catch ( Exception& )
    1255             :             {
    1256             :                 SAL_WARN( "connectivity.parse","DateFormatKey");
    1257             :             }
    1258             :         }
    1259             : 
    1260          36 :         switch (nType)
    1261             :         {
    1262             :             case DataType::DATE:
    1263             :             case DataType::TIME:
    1264             :             case DataType::TIMESTAMP:
    1265           0 :                 s_pScanner->SetRule(s_pScanner->GetDATERule());
    1266           0 :                 break;
    1267             :             case DataType::CHAR:
    1268             :             case DataType::VARCHAR:
    1269             :             case DataType::LONGVARCHAR:
    1270             :             case DataType::CLOB:
    1271          36 :                 s_pScanner->SetRule(s_pScanner->GetSTRINGRule());
    1272          36 :                 break;
    1273             :             default:
    1274           0 :                 if ( s_xLocaleData->getLocaleItem( m_pData->aLocale ).decimalSeparator.toChar() == ',' )
    1275           0 :                     s_pScanner->SetRule(s_pScanner->GetGERRule());
    1276             :                 else
    1277           0 :                     s_pScanner->SetRule(s_pScanner->GetENGRule());
    1278             :         }
    1279             : 
    1280             :     }
    1281             :     else
    1282           0 :         s_pScanner->SetRule(s_pScanner->GetSQLRule());
    1283             : 
    1284          36 :     s_pScanner->prepareScan(rStatement, m_pContext, sal_True);
    1285             : 
    1286          36 :     SQLyylval.pParseNode = NULL;
    1287             :     //  SQLyypvt = NULL;
    1288          36 :     m_pParseTree = NULL;
    1289          36 :     m_sErrorMessage= OUString();
    1290             : 
    1291             :     // Start the parser
    1292          36 :     if (SQLyyparse() != 0)
    1293             :     {
    1294           0 :         m_sFieldName= OUString();
    1295           0 :         m_xField.clear();
    1296           0 :         m_xFormatter.clear();
    1297           0 :         m_nFormatKey = 0;
    1298           0 :         m_nDateFormatKey = 0;
    1299             : 
    1300           0 :         if (m_sErrorMessage.isEmpty())
    1301           0 :             m_sErrorMessage = s_pScanner->getErrorMessage();
    1302           0 :         if (m_sErrorMessage.isEmpty())
    1303           0 :             m_sErrorMessage = m_pContext->getErrorMessage(IParseContext::ERROR_GENERAL);
    1304             : 
    1305           0 :         rErrorMessage = m_sErrorMessage;
    1306             : 
    1307             :         // clear the garbage collector
    1308           0 :         (*s_pGarbageCollector)->clearAndDelete();
    1309           0 :         return NULL;
    1310             :     }
    1311             :     else
    1312             :     {
    1313          36 :         (*s_pGarbageCollector)->clear();
    1314             : 
    1315          36 :         m_sFieldName= OUString();
    1316          36 :         m_xField.clear();
    1317          36 :         m_xFormatter.clear();
    1318          36 :         m_nFormatKey = 0;
    1319          36 :         m_nDateFormatKey = 0;
    1320             : 
    1321             :         // Return the result (the root parse node):
    1322             : 
    1323             :         // Instead, the parse method sets the member pParseTree and simply returns that
    1324             :         OSL_ENSURE(m_pParseTree != NULL,"OSQLParser: Parser did not return a ParseTree!");
    1325          36 :         return m_pParseTree;
    1326          36 :     }
    1327             : }
    1328             : 
    1329             : //=============================================================================
    1330             : //-----------------------------------------------------------------------------
    1331         114 : OSQLParser::OSQLParser(const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& rxContext, const IParseContext* _pContext)
    1332             :     :m_pContext(_pContext)
    1333             :     ,m_pParseTree(NULL)
    1334         114 :     ,m_pData( new OSQLParser_Data( rxContext ) )
    1335             :     ,m_nFormatKey(0)
    1336             :     ,m_nDateFormatKey(0)
    1337         228 :     ,m_xContext(rxContext)
    1338             : {
    1339             : 
    1340             : 
    1341         114 :     setParser(this);
    1342             : 
    1343             : #ifdef SQLYYDEBUG
    1344             : #ifdef SQLYYDEBUG_ON
    1345             :     SQLyydebug = 1;
    1346             : #endif
    1347             : #endif
    1348             : 
    1349         114 :     ::osl::MutexGuard aGuard(getMutex());
    1350             :     // Do we have to initialize the data?
    1351         114 :     if (s_nRefCount == 0)
    1352             :     {
    1353          29 :         s_pScanner = new OSQLScanner();
    1354          29 :         s_pScanner->setScanner();
    1355          29 :         s_pGarbageCollector = new OSQLParseNodesGarbageCollector();
    1356             : 
    1357          29 :         if(!s_xLocaleData.is())
    1358          29 :             s_xLocaleData = LocaleData::create(m_xContext);
    1359             : 
    1360             :         // reset to UNKNOWN_RULE
    1361             :         BOOST_STATIC_ASSERT(OSQLParseNode::UNKNOWN_RULE==0);
    1362          29 :         memset(OSQLParser::s_nRuleIDs,0,sizeof(OSQLParser::s_nRuleIDs));
    1363             : 
    1364             :         struct
    1365        2900 :         {
    1366             :             OSQLParseNode::Rule eRule;      // the parse node's ID for the rule
    1367             :             OString      sRuleName;  // the name of the rule ("select_statement")
    1368             :         }   aRuleDescriptions[] =
    1369             :         {
    1370             :             { OSQLParseNode::select_statement, "select_statement" },
    1371             :             { OSQLParseNode::table_exp, "table_exp" },
    1372             :             { OSQLParseNode::table_ref_commalist, "table_ref_commalist" },
    1373             :             { OSQLParseNode::table_ref, "table_ref" },
    1374             :             { OSQLParseNode::catalog_name, "catalog_name" },
    1375             :             { OSQLParseNode::schema_name, "schema_name" },
    1376             :             { OSQLParseNode::table_name, "table_name" },
    1377             :             { OSQLParseNode::opt_column_commalist, "opt_column_commalist" },
    1378             :             { OSQLParseNode::column_commalist, "column_commalist" },
    1379             :             { OSQLParseNode::column_ref_commalist, "column_ref_commalist" },
    1380             :             { OSQLParseNode::column_ref, "column_ref" },
    1381             :             { OSQLParseNode::opt_order_by_clause, "opt_order_by_clause" },
    1382             :             { OSQLParseNode::ordering_spec_commalist, "ordering_spec_commalist" },
    1383             :             { OSQLParseNode::ordering_spec, "ordering_spec" },
    1384             :             { OSQLParseNode::opt_asc_desc, "opt_asc_desc" },
    1385             :             { OSQLParseNode::where_clause, "where_clause" },
    1386             :             { OSQLParseNode::opt_where_clause, "opt_where_clause" },
    1387             :             { OSQLParseNode::search_condition, "search_condition" },
    1388             :             { OSQLParseNode::comparison_predicate, "comparison_predicate" },
    1389             :             { OSQLParseNode::between_predicate, "between_predicate" },
    1390             :             { OSQLParseNode::like_predicate, "like_predicate" },
    1391             :             { OSQLParseNode::opt_escape, "opt_escape" },
    1392             :             { OSQLParseNode::test_for_null, "test_for_null" },
    1393             :             { OSQLParseNode::scalar_exp_commalist, "scalar_exp_commalist" },
    1394             :             { OSQLParseNode::scalar_exp, "scalar_exp" },
    1395             :             { OSQLParseNode::parameter_ref, "parameter_ref" },
    1396             :             { OSQLParseNode::parameter, "parameter" },
    1397             :             { OSQLParseNode::general_set_fct, "general_set_fct" },
    1398             :             { OSQLParseNode::range_variable, "range_variable" },
    1399             :             { OSQLParseNode::column, "column" },
    1400             :             { OSQLParseNode::delete_statement_positioned, "delete_statement_positioned" },
    1401             :             { OSQLParseNode::delete_statement_searched, "delete_statement_searched" },
    1402             :             { OSQLParseNode::update_statement_positioned, "update_statement_positioned" },
    1403             :             { OSQLParseNode::update_statement_searched, "update_statement_searched" },
    1404             :             { OSQLParseNode::assignment_commalist, "assignment_commalist" },
    1405             :             { OSQLParseNode::assignment, "assignment" },
    1406             :             { OSQLParseNode::values_or_query_spec, "values_or_query_spec" },
    1407             :             { OSQLParseNode::insert_statement, "insert_statement" },
    1408             :             { OSQLParseNode::insert_atom_commalist, "insert_atom_commalist" },
    1409             :             { OSQLParseNode::insert_atom, "insert_atom" },
    1410             :             { OSQLParseNode::from_clause, "from_clause" },
    1411             :             { OSQLParseNode::qualified_join, "qualified_join" },
    1412             :             { OSQLParseNode::cross_union, "cross_union" },
    1413             :             { OSQLParseNode::select_sublist, "select_sublist" },
    1414             :             { OSQLParseNode::derived_column, "derived_column" },
    1415             :             { OSQLParseNode::column_val, "column_val" },
    1416             :             { OSQLParseNode::set_fct_spec, "set_fct_spec" },
    1417             :             { OSQLParseNode::boolean_term, "boolean_term" },
    1418             :             { OSQLParseNode::boolean_primary, "boolean_primary" },
    1419             :             { OSQLParseNode::num_value_exp, "num_value_exp" },
    1420             :             { OSQLParseNode::join_type, "join_type" },
    1421             :             { OSQLParseNode::position_exp, "position_exp" },
    1422             :             { OSQLParseNode::extract_exp, "extract_exp" },
    1423             :             { OSQLParseNode::length_exp, "length_exp" },
    1424             :             { OSQLParseNode::char_value_fct, "char_value_fct" },
    1425             :             { OSQLParseNode::odbc_call_spec, "odbc_call_spec" },
    1426             :             { OSQLParseNode::in_predicate, "in_predicate" },
    1427             :             { OSQLParseNode::existence_test, "existence_test" },
    1428             :             { OSQLParseNode::unique_test, "unique_test" },
    1429             :             { OSQLParseNode::all_or_any_predicate, "all_or_any_predicate" },
    1430             :             { OSQLParseNode::named_columns_join, "named_columns_join" },
    1431             :             { OSQLParseNode::join_condition, "join_condition" },
    1432             :             { OSQLParseNode::joined_table, "joined_table" },
    1433             :             { OSQLParseNode::boolean_factor, "boolean_factor" },
    1434             :             { OSQLParseNode::sql_not, "sql_not" },
    1435             :             { OSQLParseNode::boolean_test, "boolean_test" },
    1436             :             { OSQLParseNode::manipulative_statement, "manipulative_statement" },
    1437             :             { OSQLParseNode::subquery, "subquery" },
    1438             :             { OSQLParseNode::value_exp_commalist, "value_exp_commalist" },
    1439             :             { OSQLParseNode::odbc_fct_spec, "odbc_fct_spec" },
    1440             :             { OSQLParseNode::union_statement, "union_statement" },
    1441             :             { OSQLParseNode::outer_join_type, "outer_join_type" },
    1442             :             { OSQLParseNode::char_value_exp, "char_value_exp" },
    1443             :             { OSQLParseNode::term, "term" },
    1444             :             { OSQLParseNode::value_exp_primary, "value_exp_primary" },
    1445             :             { OSQLParseNode::value_exp, "value_exp" },
    1446             :             { OSQLParseNode::selection, "selection" },
    1447             :             { OSQLParseNode::fold, "fold" },
    1448             :             { OSQLParseNode::char_substring_fct, "char_substring_fct" },
    1449             :             { OSQLParseNode::factor, "factor" },
    1450             :             { OSQLParseNode::base_table_def, "base_table_def" },
    1451             :             { OSQLParseNode::base_table_element_commalist, "base_table_element_commalist" },
    1452             :             { OSQLParseNode::data_type, "data_type" },
    1453             :             { OSQLParseNode::column_def, "column_def" },
    1454             :             { OSQLParseNode::table_node, "table_node" },
    1455             :             { OSQLParseNode::as_clause, "as_clause" },
    1456             :             { OSQLParseNode::opt_as, "opt_as" },
    1457             :             { OSQLParseNode::op_column_commalist, "op_column_commalist" },
    1458             :             { OSQLParseNode::table_primary_as_range_column, "table_primary_as_range_column" },
    1459             :             { OSQLParseNode::datetime_primary, "datetime_primary" },
    1460             :             { OSQLParseNode::concatenation, "concatenation" },
    1461             :             { OSQLParseNode::char_factor, "char_factor" },
    1462             :             { OSQLParseNode::bit_value_fct, "bit_value_fct" },
    1463             :             { OSQLParseNode::comparison_predicate_part_2, "comparison_predicate_part_2" },
    1464             :             { OSQLParseNode::parenthesized_boolean_value_expression, "parenthesized_boolean_value_expression" },
    1465             :             { OSQLParseNode::character_string_type, "character_string_type" },
    1466             :             { OSQLParseNode::other_like_predicate_part_2, "other_like_predicate_part_2" },
    1467             :             { OSQLParseNode::between_predicate_part_2, "between_predicate_part_2" },
    1468             :             { OSQLParseNode::cast_spec, "cast_spec" },
    1469             :             { OSQLParseNode::window_function, "window_function" }
    1470        2929 :         };
    1471          29 :         const size_t nRuleMapCount = sizeof( aRuleDescriptions ) / sizeof( aRuleDescriptions[0] );
    1472             :         // added a new rule? Adjust this map!
    1473             :         // +1 for UNKNOWN_RULE
    1474             :         BOOST_STATIC_ASSERT( nRuleMapCount + 1 == static_cast<size_t>(OSQLParseNode::rule_count) );
    1475             : 
    1476        2929 :         for ( size_t mapEntry = 0; mapEntry < nRuleMapCount; ++mapEntry )
    1477             :         {
    1478             :             // look up the rule description in the our identifier map
    1479        2900 :             sal_uInt32 nParserRuleID = StrToRuleID( aRuleDescriptions[ mapEntry ].sRuleName );
    1480             :             // map the parser's rule ID to the OSQLParseNode::Rule
    1481        2900 :             s_aReverseRuleIDLookup[ nParserRuleID ] = aRuleDescriptions[ mapEntry ].eRule;
    1482             :             // and map the OSQLParseNode::Rule to the parser's rule ID
    1483        2900 :             s_nRuleIDs[ aRuleDescriptions[ mapEntry ].eRule ] = nParserRuleID;
    1484        2929 :         }
    1485             :     }
    1486         114 :     ++s_nRefCount;
    1487             : 
    1488         114 :     if (m_pContext == NULL)
    1489             :         // take the default context
    1490          72 :         m_pContext = &s_aDefaultContext;
    1491             : 
    1492         114 :     m_pData->aLocale = m_pContext->getPreferredLocale();
    1493         114 : }
    1494             : 
    1495             : //-----------------------------------------------------------------------------
    1496         224 : OSQLParser::~OSQLParser()
    1497             : {
    1498             :     {
    1499         112 :         ::osl::MutexGuard aGuard(getMutex());
    1500             :         OSL_ENSURE(s_nRefCount > 0, "OSQLParser::~OSQLParser() : suspicious call : has a refcount of 0 !");
    1501         112 :         if (!--s_nRefCount)
    1502             :         {
    1503          28 :             s_pScanner->setScanner(sal_True);
    1504          28 :             delete s_pScanner;
    1505          28 :             s_pScanner = NULL;
    1506             : 
    1507          28 :             delete s_pGarbageCollector;
    1508          28 :             s_pGarbageCollector = NULL;
    1509             :             // Is only set the first time, so we should delete it only when there are no more instances
    1510          28 :             s_xLocaleData = NULL;
    1511             : 
    1512          28 :             RuleIDMap aEmpty;
    1513          28 :             s_aReverseRuleIDLookup.swap( aEmpty );
    1514             :         }
    1515         112 :         m_pParseTree = NULL;
    1516             :     }
    1517         112 : }
    1518             : // -----------------------------------------------------------------------------
    1519           0 : void OSQLParseNode::substituteParameterNames(OSQLParseNode* _pNode)
    1520             : {
    1521             :     SAL_INFO( "connectivity.parse", "parse Ocke.Janssen@sun.com OSQLParseNode::substituteParameterNames" );
    1522           0 :     sal_Int32 nCount = _pNode->count();
    1523           0 :     for(sal_Int32 i=0;i < nCount;++i)
    1524             :     {
    1525           0 :         OSQLParseNode* pChildNode = _pNode->getChild(i);
    1526           0 :         if(SQL_ISRULE(pChildNode,parameter) && pChildNode->count() > 1)
    1527             :         {
    1528           0 :             OSQLParseNode* pNewNode = new OSQLParseNode(OUString("?") ,SQL_NODE_PUNCTUATION,0);
    1529           0 :             delete pChildNode->replace(pChildNode->getChild(0),pNewNode);
    1530           0 :             sal_Int32 nChildCount = pChildNode->count();
    1531           0 :             for(sal_Int32 j=1;j < nChildCount;++j)
    1532           0 :                 delete pChildNode->removeAt(1);
    1533             :         }
    1534             :         else
    1535           0 :             substituteParameterNames(pChildNode);
    1536             : 
    1537             :     }
    1538           0 : }
    1539             : // -----------------------------------------------------------------------------
    1540           0 : bool OSQLParser::extractDate(OSQLParseNode* pLiteral,double& _rfValue)
    1541             : {
    1542           0 :     Reference< XNumberFormatsSupplier > xFormatSup = m_xFormatter->getNumberFormatsSupplier();
    1543           0 :     Reference< XNumberFormatTypes > xFormatTypes;
    1544           0 :     if ( xFormatSup.is() )
    1545           0 :         xFormatTypes = xFormatTypes.query( xFormatSup->getNumberFormats() );
    1546             : 
    1547             :     // if there is no format key, yet, make sure we have a feasible one for our locale
    1548             :     try
    1549             :     {
    1550           0 :         if ( !m_nFormatKey && xFormatTypes.is() )
    1551           0 :             m_nFormatKey = ::dbtools::getDefaultNumberFormat( m_xField, xFormatTypes, m_pData->aLocale );
    1552             :     }
    1553           0 :     catch( Exception& ) { }
    1554           0 :     OUString sValue = pLiteral->getTokenValue();
    1555           0 :     sal_Int32 nTryFormat = m_nFormatKey;
    1556           0 :     bool bSuccess = lcl_saveConvertToNumber( m_xFormatter, nTryFormat, sValue, _rfValue );
    1557             : 
    1558             :     // If our format key didn't do, try the default date format for our locale.
    1559           0 :     if ( !bSuccess && xFormatTypes.is() )
    1560             :     {
    1561             :         try
    1562             :         {
    1563           0 :             nTryFormat = xFormatTypes->getStandardFormat( NumberFormat::DATE, m_pData->aLocale );
    1564             :         }
    1565           0 :         catch( Exception& ) { }
    1566           0 :         bSuccess = lcl_saveConvertToNumber( m_xFormatter, nTryFormat, sValue, _rfValue );
    1567             :     }
    1568             : 
    1569             :     // if this also didn't do, try ISO format
    1570           0 :     if ( !bSuccess && xFormatTypes.is() )
    1571             :     {
    1572             :         try
    1573             :         {
    1574           0 :             nTryFormat = xFormatTypes->getFormatIndex( NumberFormatIndex::DATE_DIN_YYYYMMDD, m_pData->aLocale );
    1575             :         }
    1576           0 :         catch( Exception& ) { }
    1577           0 :         bSuccess = lcl_saveConvertToNumber( m_xFormatter, nTryFormat, sValue, _rfValue );
    1578             :     }
    1579             : 
    1580             :     // if this also didn't do, try fallback date format (en-US)
    1581           0 :     if ( !bSuccess )
    1582             :     {
    1583           0 :         nTryFormat = m_nDateFormatKey;
    1584           0 :         bSuccess = lcl_saveConvertToNumber( m_xFormatter, nTryFormat, sValue, _rfValue );
    1585             :     }
    1586           0 :     return bSuccess;
    1587             : }
    1588             : // -----------------------------------------------------------------------------
    1589           0 : OSQLParseNode* OSQLParser::buildDate(sal_Int32 _nType,OSQLParseNode*& pLiteral)
    1590             : {
    1591             :     // try converting the string into a date, according to our format key
    1592           0 :     double fValue = 0.0;
    1593           0 :     OSQLParseNode* pFCTNode = NULL;
    1594             : 
    1595           0 :     if ( extractDate(pLiteral,fValue) )
    1596           0 :         pFCTNode = buildNode_Date( fValue, _nType);
    1597             : 
    1598           0 :     delete pLiteral;
    1599           0 :     pLiteral = NULL;
    1600             : 
    1601           0 :     if ( !pFCTNode )
    1602           0 :         m_sErrorMessage = m_pContext->getErrorMessage(IParseContext::ERROR_INVALID_DATE_COMPARE);
    1603             : 
    1604           0 :     return pFCTNode;
    1605             : }
    1606             : // -----------------------------------------------------------------------------
    1607             : //-----------------------------------------------------------------------------
    1608        1265 : OSQLParseNode::OSQLParseNode(const sal_Char * pNewValue,
    1609             :                              SQLNodeType eNewNodeType,
    1610             :                              sal_uInt32 nNewNodeID)
    1611             :         :m_pParent(NULL)
    1612        1265 :         ,m_aNodeValue(pNewValue,strlen(pNewValue),RTL_TEXTENCODING_UTF8)
    1613             :         ,m_eNodeType(eNewNodeType)
    1614        2530 :         ,m_nNodeID(nNewNodeID)
    1615             : {
    1616             :     SAL_INFO( "connectivity.parse", "parse Ocke.Janssen@sun.com OSQLParseNode::OSQLParseNode" );
    1617             : 
    1618             :     OSL_ENSURE(m_eNodeType >= SQL_NODE_RULE && m_eNodeType <= SQL_NODE_CONCAT,"OSQLParseNode: created with invalid NodeType");
    1619        1265 : }
    1620             : //-----------------------------------------------------------------------------
    1621           0 : OSQLParseNode::OSQLParseNode(const OString &_rNewValue,
    1622             :                              SQLNodeType eNewNodeType,
    1623             :                              sal_uInt32 nNewNodeID)
    1624             :         :m_pParent(NULL)
    1625             :         ,m_aNodeValue(OStringToOUString(_rNewValue,RTL_TEXTENCODING_UTF8))
    1626             :         ,m_eNodeType(eNewNodeType)
    1627           0 :         ,m_nNodeID(nNewNodeID)
    1628             : {
    1629             :     SAL_INFO( "connectivity.parse", "parse Ocke.Janssen@sun.com OSQLParseNode::OSQLParseNode" );
    1630             : 
    1631             :     OSL_ENSURE(m_eNodeType >= SQL_NODE_RULE && m_eNodeType <= SQL_NODE_CONCAT,"OSQLParseNode: created with invalid NodeType");
    1632           0 : }
    1633             : //-----------------------------------------------------------------------------
    1634       12303 : OSQLParseNode::OSQLParseNode(const OUString &_rNewValue,
    1635             :                                  SQLNodeType eNewNodeType,
    1636             :                                  sal_uInt32 nNewNodeID)
    1637             :         :m_pParent(NULL)
    1638             :         ,m_aNodeValue(_rNewValue)
    1639             :         ,m_eNodeType(eNewNodeType)
    1640       12303 :         ,m_nNodeID(nNewNodeID)
    1641             : {
    1642             :     SAL_INFO( "connectivity.parse", "parse Ocke.Janssen@sun.com OSQLParseNode::OSQLParseNode" );
    1643             : 
    1644             :     OSL_ENSURE(m_eNodeType >= SQL_NODE_RULE && m_eNodeType <= SQL_NODE_CONCAT,"OSQLParseNode: created with invalid NodeType");
    1645       12303 : }
    1646             : //-----------------------------------------------------------------------------
    1647           0 : OSQLParseNode::OSQLParseNode(const OSQLParseNode& rParseNode)
    1648             : {
    1649             :     SAL_INFO( "connectivity.parse", "parse Ocke.Janssen@sun.com OSQLParseNode::OSQLParseNode" );
    1650             : 
    1651             :     // Set the getParent to NULL
    1652           0 :     m_pParent = NULL;
    1653             : 
    1654             :     // Copy the members
    1655           0 :     m_aNodeValue = rParseNode.m_aNodeValue;
    1656           0 :     m_eNodeType  = rParseNode.m_eNodeType;
    1657           0 :     m_nNodeID    = rParseNode.m_nNodeID;
    1658             : 
    1659             : 
    1660             :     // Remember that we derived from Container. According to SV-Help the Container's
    1661             :     // copy ctor creates a new Container with the same pointers for content.
    1662             :     // This means after copying the Container, for all non-NULL pointers a copy is
    1663             :     // created and reattached instead of the old pointer.
    1664             : 
    1665             :     // If not a leaf, then process SubTrees
    1666           0 :     for (OSQLParseNodes::const_iterator i = rParseNode.m_aChildren.begin();
    1667           0 :          i != rParseNode.m_aChildren.end(); ++i)
    1668           0 :         append(new OSQLParseNode(**i));
    1669           0 : }
    1670             : // -----------------------------------------------------------------------------
    1671             : //-----------------------------------------------------------------------------
    1672           0 : OSQLParseNode& OSQLParseNode::operator=(const OSQLParseNode& rParseNode)
    1673             : {
    1674           0 :     if (this != &rParseNode)
    1675             :     {
    1676             :         // Copy the members - pParent remains the same
    1677           0 :         m_aNodeValue = rParseNode.m_aNodeValue;
    1678           0 :         m_eNodeType  = rParseNode.m_eNodeType;
    1679           0 :         m_nNodeID    = rParseNode.m_nNodeID;
    1680             : 
    1681           0 :         for (OSQLParseNodes::const_iterator i = m_aChildren.begin();
    1682           0 :             i != m_aChildren.end(); ++i)
    1683           0 :             delete *i;
    1684             : 
    1685           0 :         m_aChildren.clear();
    1686             : 
    1687           0 :         for (OSQLParseNodes::const_iterator j = rParseNode.m_aChildren.begin();
    1688           0 :              j != rParseNode.m_aChildren.end(); ++j)
    1689           0 :             append(new OSQLParseNode(**j));
    1690             :     }
    1691           0 :     return *this;
    1692             : }
    1693             : 
    1694             : //-----------------------------------------------------------------------------
    1695         504 : sal_Bool OSQLParseNode::operator==(OSQLParseNode& rParseNode) const
    1696             : {
    1697             :     // The members must be equal
    1698         876 :     sal_Bool bResult = (m_nNodeID  == rParseNode.m_nNodeID) &&
    1699         744 :                    (m_eNodeType == rParseNode.m_eNodeType) &&
    1700        1144 :                    (m_aNodeValue == rParseNode.m_aNodeValue) &&
    1701         772 :                     count() == rParseNode.count();
    1702             : 
    1703             :     // Parameters are not equal!
    1704         504 :     bResult = bResult && !SQL_ISRULE(this, parameter);
    1705             : 
    1706             :     // compare children
    1707         772 :     for (sal_uInt32 i=0; bResult && i < count(); i++)
    1708         268 :         bResult = *getChild(i) == *rParseNode.getChild(i);
    1709             : 
    1710         504 :     return bResult;
    1711             : }
    1712             : 
    1713             : //-----------------------------------------------------------------------------
    1714       27008 : OSQLParseNode::~OSQLParseNode()
    1715             : {
    1716       79992 :     for (OSQLParseNodes::const_iterator i = m_aChildren.begin();
    1717       53328 :          i != m_aChildren.end(); ++i)
    1718       13160 :         delete *i;
    1719       13504 :     m_aChildren.clear();
    1720       13504 : }
    1721             : 
    1722             : //-----------------------------------------------------------------------------
    1723       13278 : void OSQLParseNode::append(OSQLParseNode* pNewNode)
    1724             : {
    1725             :     SAL_INFO( "connectivity.parse", "parse Ocke.Janssen@sun.com OSQLParseNode::append" );
    1726             : 
    1727             :     OSL_ENSURE(pNewNode != NULL, "OSQLParseNode: invalid NewSubTree");
    1728             :     OSL_ENSURE(pNewNode->getParent() == NULL, "OSQLParseNode: Node is not an orphan");
    1729             :     OSL_ENSURE(::std::find(m_aChildren.begin(), m_aChildren.end(), pNewNode) == m_aChildren.end(),
    1730             :             "OSQLParseNode::append() Node already element of parent");
    1731             : 
    1732             :     // Create connection to getParent
    1733       13278 :     pNewNode->setParent( this );
    1734             :     // and attach the SubTree at the end
    1735       13278 :     m_aChildren.push_back(pNewNode);
    1736       13278 : }
    1737             : // -----------------------------------------------------------------------------
    1738           0 : sal_Bool OSQLParseNode::addDateValue(OUStringBuffer& rString, const SQLParseNodeParameter& rParam) const
    1739             : {
    1740             :     SAL_INFO( "connectivity.parse", "parse Ocke.Janssen@sun.com OSQLParseNode::addDateValue" );
    1741             :     // special display for date/time values
    1742           0 :     if (SQL_ISRULE(this,set_fct_spec) && SQL_ISPUNCTUATION(m_aChildren[0],"{"))
    1743             :     {
    1744           0 :         const OSQLParseNode* pODBCNode = m_aChildren[1];
    1745           0 :         const OSQLParseNode* pODBCNodeChild = pODBCNode->m_aChildren[0];
    1746             : 
    1747           0 :         if (pODBCNodeChild->getNodeType() == SQL_NODE_KEYWORD && (
    1748           0 :             SQL_ISTOKEN(pODBCNodeChild, D) ||
    1749           0 :             SQL_ISTOKEN(pODBCNodeChild, T) ||
    1750           0 :             SQL_ISTOKEN(pODBCNodeChild, TS) ))
    1751             :         {
    1752           0 :             OUString suQuote(OUString("'"));
    1753           0 :             if (rParam.bPredicate)
    1754             :             {
    1755           0 :                  if (rParam.aMetaData.shouldEscapeDateTime())
    1756             :                  {
    1757           0 :                      suQuote = OUString("#");
    1758             :                  }
    1759             :             }
    1760             :             else
    1761             :             {
    1762           0 :                  if (rParam.aMetaData.shouldEscapeDateTime())
    1763             :                  {
    1764             :                      // suQuote = OUString("'");
    1765           0 :                      return sal_False;
    1766             :                  }
    1767             :             }
    1768             : 
    1769           0 :             if (!rString.isEmpty())
    1770           0 :                 rString.appendAscii(" ");
    1771           0 :             rString.append(suQuote);
    1772           0 :             const OUString sTokenValue = pODBCNode->m_aChildren[1]->getTokenValue();
    1773           0 :             if (SQL_ISTOKEN(pODBCNodeChild, D))
    1774             :             {
    1775           0 :                 rString.append(rParam.bPredicate ? convertDateString(rParam, sTokenValue) : sTokenValue);
    1776             :             }
    1777           0 :             else if (SQL_ISTOKEN(pODBCNodeChild, T))
    1778             :             {
    1779           0 :                 rString.append(rParam.bPredicate ? convertTimeString(rParam, sTokenValue) : sTokenValue);
    1780             :             }
    1781             :             else
    1782             :             {
    1783           0 :                 rString.append(rParam.bPredicate ? convertDateTimeString(rParam, sTokenValue) : sTokenValue);
    1784             :             }
    1785           0 :             rString.append(suQuote);
    1786           0 :             return sal_True;
    1787             :         }
    1788             :     }
    1789           0 :     return sal_False;
    1790             : }
    1791             : // -----------------------------------------------------------------------------
    1792           0 : void OSQLParseNode::replaceNodeValue(const OUString& rTableAlias, const OUString& rColumnName)
    1793             : {
    1794             :     SAL_INFO( "connectivity.parse", "parse Ocke.Janssen@sun.com OSQLParseNode::replaceNodeValue" );
    1795           0 :     for (sal_uInt32 i=0;i<count();++i)
    1796             :     {
    1797           0 :         if (SQL_ISRULE(this,column_ref) && count() == 1 && getChild(0)->getTokenValue() == rColumnName)
    1798             :         {
    1799           0 :             OSQLParseNode * pCol = removeAt((sal_uInt32)0);
    1800           0 :             append(new OSQLParseNode(rTableAlias,SQL_NODE_NAME));
    1801           0 :             append(new OSQLParseNode(OUString("."),SQL_NODE_PUNCTUATION));
    1802           0 :             append(pCol);
    1803             :         }
    1804             :         else
    1805           0 :             getChild(i)->replaceNodeValue(rTableAlias,rColumnName);
    1806             :     }
    1807           0 : }
    1808             : //-----------------------------------------------------------------------------
    1809         180 : OSQLParseNode* OSQLParseNode::getByRule(OSQLParseNode::Rule eRule) const
    1810             : {
    1811             :     SAL_INFO( "connectivity.parse", "parse Ocke.Janssen@sun.com OSQLParseNode::getByRule" );
    1812         180 :     OSQLParseNode* pRetNode = 0;
    1813         180 :     if (isRule() && OSQLParser::RuleID(eRule) == getRuleID())
    1814           0 :         pRetNode = (OSQLParseNode*)this;
    1815             :     else
    1816             :     {
    1817         972 :         for (OSQLParseNodes::const_iterator i = m_aChildren.begin();
    1818         972 :             !pRetNode && i != m_aChildren.end(); ++i)
    1819         144 :             pRetNode = (*i)->getByRule(eRule);
    1820             :     }
    1821         180 :     return pRetNode;
    1822             : }
    1823             : //-----------------------------------------------------------------------------
    1824           0 : OSQLParseNode* MakeANDNode(OSQLParseNode *pLeftLeaf,OSQLParseNode *pRightLeaf)
    1825             : {
    1826           0 :     OSQLParseNode* pNewNode = new OSQLParseNode(OUString(),SQL_NODE_RULE,OSQLParser::RuleID(OSQLParseNode::boolean_term));
    1827           0 :     pNewNode->append(pLeftLeaf);
    1828           0 :     pNewNode->append(new OSQLParseNode(OUString("AND"),SQL_NODE_KEYWORD,SQL_TOKEN_AND));
    1829           0 :     pNewNode->append(pRightLeaf);
    1830           0 :     return pNewNode;
    1831             : }
    1832             : //-----------------------------------------------------------------------------
    1833           0 : OSQLParseNode* MakeORNode(OSQLParseNode *pLeftLeaf,OSQLParseNode *pRightLeaf)
    1834             : {
    1835           0 :     OSQLParseNode* pNewNode = new OSQLParseNode(OUString(),SQL_NODE_RULE,OSQLParser::RuleID(OSQLParseNode::search_condition));
    1836           0 :     pNewNode->append(pLeftLeaf);
    1837           0 :     pNewNode->append(new OSQLParseNode(OUString("OR"),SQL_NODE_KEYWORD,SQL_TOKEN_OR));
    1838           0 :     pNewNode->append(pRightLeaf);
    1839           0 :     return pNewNode;
    1840             : }
    1841             : //-----------------------------------------------------------------------------
    1842          68 : void OSQLParseNode::disjunctiveNormalForm(OSQLParseNode*& pSearchCondition)
    1843             : {
    1844             :     SAL_INFO( "connectivity.parse", "parse Ocke.Janssen@sun.com OSQLParseNode::disjunctiveNormalForm" );
    1845          68 :     if(!pSearchCondition) // no where condition at entry point
    1846          68 :         return;
    1847             : 
    1848          68 :     OSQLParseNode::absorptions(pSearchCondition);
    1849             :     // '(' search_condition ')'
    1850          68 :     if (SQL_ISRULE(pSearchCondition,boolean_primary))
    1851             :     {
    1852           0 :         OSQLParseNode* pLeft    = pSearchCondition->getChild(1);
    1853           0 :         disjunctiveNormalForm(pLeft);
    1854             :     }
    1855             :     // search_condition SQL_TOKEN_OR boolean_term
    1856          68 :     else if (SQL_ISRULE(pSearchCondition,search_condition))
    1857             :     {
    1858          16 :         OSQLParseNode* pLeft    = pSearchCondition->getChild(0);
    1859          16 :         disjunctiveNormalForm(pLeft);
    1860             : 
    1861          16 :         OSQLParseNode* pRight = pSearchCondition->getChild(2);
    1862          16 :         disjunctiveNormalForm(pRight);
    1863             :     }
    1864             :     // boolean_term SQL_TOKEN_AND boolean_factor
    1865          52 :     else if (SQL_ISRULE(pSearchCondition,boolean_term))
    1866             :     {
    1867          16 :         OSQLParseNode* pLeft    = pSearchCondition->getChild(0);
    1868          16 :         disjunctiveNormalForm(pLeft);
    1869             : 
    1870          16 :         OSQLParseNode* pRight = pSearchCondition->getChild(2);
    1871          16 :         disjunctiveNormalForm(pRight);
    1872             : 
    1873          16 :         OSQLParseNode* pNewNode = NULL;
    1874             :         // '(' search_condition ')' on left side
    1875          16 :         if(pLeft->count() == 3 && SQL_ISRULE(pLeft,boolean_primary) && SQL_ISRULE(pLeft->getChild(1),search_condition))
    1876             :         {
    1877             :             // and-or tree  on left side
    1878           0 :             OSQLParseNode* pOr = pLeft->getChild(1);
    1879           0 :             OSQLParseNode* pNewLeft = NULL;
    1880           0 :             OSQLParseNode* pNewRight = NULL;
    1881             : 
    1882             :             // cut right from parent
    1883           0 :             pSearchCondition->removeAt(2);
    1884             : 
    1885           0 :             pNewRight   = MakeANDNode(pOr->removeAt(2)      ,pRight);
    1886           0 :             pNewLeft    = MakeANDNode(pOr->removeAt((sal_uInt32)0)  ,new OSQLParseNode(*pRight));
    1887           0 :             pNewNode    = MakeORNode(pNewLeft,pNewRight);
    1888             :             // and append new Node
    1889           0 :             replaceAndReset(pSearchCondition,pNewNode);
    1890             : 
    1891           0 :             disjunctiveNormalForm(pSearchCondition);
    1892             :         }
    1893          16 :         else if(pRight->count() == 3 && SQL_ISRULE(pRight,boolean_primary) && SQL_ISRULE(pRight->getChild(1),search_condition))
    1894             :         {   // '(' search_condition ')' on right side
    1895             :             // and-or tree  on right side
    1896             :             // a and (b or c)
    1897           0 :             OSQLParseNode* pOr = pRight->getChild(1);
    1898           0 :             OSQLParseNode* pNewLeft = NULL;
    1899           0 :             OSQLParseNode* pNewRight = NULL;
    1900             : 
    1901             :             // cut left from parent
    1902           0 :             pSearchCondition->removeAt((sal_uInt32)0);
    1903             : 
    1904           0 :             pNewRight   = MakeANDNode(pLeft,pOr->removeAt(2));
    1905           0 :             pNewLeft    = MakeANDNode(new OSQLParseNode(*pLeft),pOr->removeAt((sal_uInt32)0));
    1906           0 :             pNewNode    = MakeORNode(pNewLeft,pNewRight);
    1907             : 
    1908             :             // and append new Node
    1909           0 :             replaceAndReset(pSearchCondition,pNewNode);
    1910           0 :             disjunctiveNormalForm(pSearchCondition);
    1911             :         }
    1912          16 :         else if(SQL_ISRULE(pLeft,boolean_primary) && (!SQL_ISRULE(pLeft->getChild(1),search_condition) || !SQL_ISRULE(pLeft->getChild(1),boolean_term)))
    1913           0 :             pSearchCondition->replace(pLeft, pLeft->removeAt(1));
    1914          16 :         else if(SQL_ISRULE(pRight,boolean_primary) && (!SQL_ISRULE(pRight->getChild(1),search_condition) || !SQL_ISRULE(pRight->getChild(1),boolean_term)))
    1915           0 :             pSearchCondition->replace(pRight, pRight->removeAt(1));
    1916             :     }
    1917             : }
    1918             : //-----------------------------------------------------------------------------
    1919          88 : void OSQLParseNode::negateSearchCondition(OSQLParseNode*& pSearchCondition, sal_Bool bNegate)
    1920             : {
    1921             :     SAL_INFO( "connectivity.parse", "parse Ocke.Janssen@sun.com OSQLParseNode::negateSearchCondition" );
    1922          88 :     if(!pSearchCondition) // no where condition at entry point
    1923          88 :         return;
    1924             :     // '(' search_condition ')'
    1925          88 :     if (pSearchCondition->count() == 3 && SQL_ISRULE(pSearchCondition,boolean_primary))
    1926             :     {
    1927          20 :         OSQLParseNode* pRight = pSearchCondition->getChild(1);
    1928          20 :         negateSearchCondition(pRight,bNegate);
    1929             :     }
    1930             :     // search_condition SQL_TOKEN_OR boolean_term
    1931          68 :     else if (SQL_ISRULE(pSearchCondition,search_condition))
    1932             :     {
    1933          16 :         OSQLParseNode* pLeft    = pSearchCondition->getChild(0);
    1934          16 :         OSQLParseNode* pRight = pSearchCondition->getChild(2);
    1935          16 :         if(bNegate)
    1936             :         {
    1937           0 :             OSQLParseNode* pNewNode = new OSQLParseNode(OUString(),SQL_NODE_RULE,OSQLParser::RuleID(OSQLParseNode::boolean_term));
    1938           0 :             pNewNode->append(pSearchCondition->removeAt((sal_uInt32)0));
    1939           0 :             pNewNode->append(new OSQLParseNode(OUString("AND"),SQL_NODE_KEYWORD,SQL_TOKEN_AND));
    1940           0 :             pNewNode->append(pSearchCondition->removeAt((sal_uInt32)1));
    1941           0 :             replaceAndReset(pSearchCondition,pNewNode);
    1942             : 
    1943           0 :             pLeft   = pNewNode->getChild(0);
    1944           0 :             pRight  = pNewNode->getChild(2);
    1945             :         }
    1946             : 
    1947          16 :         negateSearchCondition(pLeft,bNegate);
    1948          16 :         negateSearchCondition(pRight,bNegate);
    1949             :     }
    1950             :     // boolean_term SQL_TOKEN_AND boolean_factor
    1951          52 :     else if (SQL_ISRULE(pSearchCondition,boolean_term))
    1952             :     {
    1953          16 :         OSQLParseNode* pLeft    = pSearchCondition->getChild(0);
    1954          16 :         OSQLParseNode* pRight = pSearchCondition->getChild(2);
    1955          16 :         if(bNegate)
    1956             :         {
    1957           0 :             OSQLParseNode* pNewNode = new OSQLParseNode(OUString(),SQL_NODE_RULE,OSQLParser::RuleID(OSQLParseNode::search_condition));
    1958           0 :             pNewNode->append(pSearchCondition->removeAt((sal_uInt32)0));
    1959           0 :             pNewNode->append(new OSQLParseNode(OUString("OR"),SQL_NODE_KEYWORD,SQL_TOKEN_OR));
    1960           0 :             pNewNode->append(pSearchCondition->removeAt((sal_uInt32)1));
    1961           0 :             replaceAndReset(pSearchCondition,pNewNode);
    1962             : 
    1963           0 :             pLeft   = pNewNode->getChild(0);
    1964           0 :             pRight  = pNewNode->getChild(2);
    1965             :         }
    1966             : 
    1967          16 :         negateSearchCondition(pLeft,bNegate);
    1968          16 :         negateSearchCondition(pRight,bNegate);
    1969             :     }
    1970             :     // SQL_TOKEN_NOT ( boolean_test )
    1971          36 :     else if (SQL_ISRULE(pSearchCondition,boolean_factor))
    1972             :     {
    1973           0 :         OSQLParseNode *pNot = pSearchCondition->removeAt((sal_uInt32)0);
    1974           0 :         delete pNot;
    1975           0 :         OSQLParseNode *pBooleanTest = pSearchCondition->removeAt((sal_uInt32)0);
    1976             :         // TODO is this needed // pBooleanTest->setParent(NULL);
    1977           0 :         replaceAndReset(pSearchCondition,pBooleanTest);
    1978             : 
    1979           0 :         if (!bNegate)
    1980           0 :             negateSearchCondition(pSearchCondition,sal_True); // negate all deeper values
    1981             :     }
    1982             :     // row_value_constructor comparison row_value_constructor
    1983             :     // row_value_constructor comparison any_all_some subquery
    1984          36 :     else if(bNegate && (SQL_ISRULE(pSearchCondition,comparison_predicate) || SQL_ISRULE(pSearchCondition,all_or_any_predicate)))
    1985             :     {
    1986           0 :         OSQLParseNode* pComparison = pSearchCondition->getChild(1);
    1987           0 :         OSQLParseNode* pNewComparison = NULL;
    1988           0 :         switch(pComparison->getNodeType())
    1989             :         {
    1990             :             case SQL_NODE_EQUAL:
    1991           0 :                 pNewComparison = new OSQLParseNode(OUString("<>"),SQL_NODE_NOTEQUAL,SQL_NOTEQUAL);
    1992           0 :                 break;
    1993             :             case SQL_NODE_LESS:
    1994           0 :                 pNewComparison = new OSQLParseNode(OUString(">="),SQL_NODE_GREATEQ,SQL_GREATEQ);
    1995           0 :                 break;
    1996             :             case SQL_NODE_GREAT:
    1997           0 :                 pNewComparison = new OSQLParseNode(OUString("<="),SQL_NODE_LESSEQ,SQL_LESSEQ);
    1998           0 :                 break;
    1999             :             case SQL_NODE_LESSEQ:
    2000           0 :                 pNewComparison = new OSQLParseNode(OUString(">"),SQL_NODE_GREAT,SQL_GREAT);
    2001           0 :                 break;
    2002             :             case SQL_NODE_GREATEQ:
    2003           0 :                 pNewComparison = new OSQLParseNode(OUString("<"),SQL_NODE_LESS,SQL_LESS);
    2004           0 :                 break;
    2005             :             case SQL_NODE_NOTEQUAL:
    2006           0 :                 pNewComparison = new OSQLParseNode(OUString("="),SQL_NODE_EQUAL,SQL_EQUAL);
    2007           0 :                 break;
    2008             :             default:
    2009             :                 SAL_WARN( "connectivity.parse", "OSQLParseNode::negateSearchCondition: unexpected node type!" );
    2010           0 :                 break;
    2011             :         }
    2012           0 :         pSearchCondition->replace(pComparison, pNewComparison);
    2013           0 :         delete pComparison;
    2014             :     }
    2015             : 
    2016          36 :     else if(bNegate && (SQL_ISRULE(pSearchCondition,test_for_null) || SQL_ISRULE(pSearchCondition,in_predicate) ||
    2017           0 :                         SQL_ISRULE(pSearchCondition,between_predicate) || SQL_ISRULE(pSearchCondition,boolean_test) ))
    2018             :     {
    2019           0 :         OSQLParseNode* pPart2 = pSearchCondition;
    2020           0 :         if ( !SQL_ISRULE(pSearchCondition,boolean_test) )
    2021           0 :             pPart2 = pSearchCondition->getChild(1);
    2022           0 :         sal_uInt32 nNotPos = 0;
    2023           0 :         if  ( SQL_ISRULE( pSearchCondition, test_for_null ) )
    2024           0 :             nNotPos = 1;
    2025           0 :         else if ( SQL_ISRULE( pSearchCondition, boolean_test ) )
    2026           0 :             nNotPos = 2;
    2027             : 
    2028           0 :         OSQLParseNode* pNot = pPart2->getChild(nNotPos);
    2029           0 :         OSQLParseNode* pNotNot = NULL;
    2030           0 :         if(pNot->isRule())
    2031           0 :             pNotNot = new OSQLParseNode(OUString("NOT"),SQL_NODE_KEYWORD,SQL_TOKEN_NOT);
    2032             :         else
    2033           0 :             pNotNot = new OSQLParseNode(OUString(),SQL_NODE_RULE,OSQLParser::RuleID(OSQLParseNode::sql_not));
    2034           0 :         pPart2->replace(pNot, pNotNot);
    2035           0 :         delete pNot;
    2036             :     }
    2037          36 :     else if(bNegate && (SQL_ISRULE(pSearchCondition,like_predicate)))
    2038             :     {
    2039           0 :         OSQLParseNode* pNot = pSearchCondition->getChild( 1 )->getChild( 0 );
    2040           0 :         OSQLParseNode* pNotNot = NULL;
    2041           0 :         if(pNot->isRule())
    2042           0 :             pNotNot = new OSQLParseNode(OUString("NOT"),SQL_NODE_KEYWORD,SQL_TOKEN_NOT);
    2043             :         else
    2044           0 :             pNotNot = new OSQLParseNode(OUString(),SQL_NODE_RULE,OSQLParser::RuleID(OSQLParseNode::sql_not));
    2045           0 :         pSearchCondition->getChild( 1 )->replace(pNot, pNotNot);
    2046           0 :         delete pNot;
    2047             :     }
    2048             : }
    2049             : //-----------------------------------------------------------------------------
    2050         840 : void OSQLParseNode::eraseBraces(OSQLParseNode*& pSearchCondition)
    2051             : {
    2052             :     SAL_INFO( "connectivity.parse", "parse Ocke.Janssen@sun.com OSQLParseNode::eraseBraces" );
    2053         860 :     if (pSearchCondition && (SQL_ISRULE(pSearchCondition,boolean_primary) || (pSearchCondition->count() == 3 && SQL_ISPUNCTUATION(pSearchCondition->getChild(0),"(") &&
    2054           0 :          SQL_ISPUNCTUATION(pSearchCondition->getChild(2),")"))))
    2055             :     {
    2056          20 :         OSQLParseNode* pRight = pSearchCondition->getChild(1);
    2057          20 :         absorptions(pRight);
    2058             :         // if child is not a or or and tree then delete () around child
    2059          72 :         if(!(SQL_ISRULE(pSearchCondition->getChild(1),boolean_term) || SQL_ISRULE(pSearchCondition->getChild(1),search_condition)) ||
    2060          64 :             SQL_ISRULE(pSearchCondition->getChild(1),boolean_term) || // and can always stand without ()
    2061           0 :             (SQL_ISRULE(pSearchCondition->getChild(1),search_condition) && SQL_ISRULE(pSearchCondition->getParent(),search_condition)))
    2062             :         {
    2063          20 :             OSQLParseNode* pNode = pSearchCondition->removeAt(1);
    2064          20 :             replaceAndReset(pSearchCondition,pNode);
    2065             :         }
    2066             :     }
    2067         840 : }
    2068             : //-----------------------------------------------------------------------------
    2069         420 : void OSQLParseNode::absorptions(OSQLParseNode*& pSearchCondition)
    2070             : {
    2071             :     SAL_INFO( "connectivity.parse", "parse Ocke.Janssen@sun.com OSQLParseNode::absorptions" );
    2072         420 :     if(!pSearchCondition) // no where condition at entry point
    2073         420 :         return;
    2074             : 
    2075         420 :     eraseBraces(pSearchCondition);
    2076             : 
    2077         420 :     if(SQL_ISRULE(pSearchCondition,boolean_term) || SQL_ISRULE(pSearchCondition,search_condition))
    2078             :     {
    2079         164 :         OSQLParseNode* pLeft = pSearchCondition->getChild(0);
    2080         164 :         absorptions(pLeft);
    2081         164 :         OSQLParseNode* pRight = pSearchCondition->getChild(2);
    2082         164 :         absorptions(pRight);
    2083             :     }
    2084             : 
    2085         420 :     sal_uInt32 nPos = 0;
    2086             :     // a and a || a or a
    2087         420 :     OSQLParseNode* pNewNode = NULL;
    2088        1260 :     if(( SQL_ISRULE(pSearchCondition,boolean_term) || SQL_ISRULE(pSearchCondition,search_condition))
    2089         584 :         && *pSearchCondition->getChild(0) == *pSearchCondition->getChild(2))
    2090             :     {
    2091           0 :         pNewNode = pSearchCondition->removeAt((sal_uInt32)0);
    2092           0 :         replaceAndReset(pSearchCondition,pNewNode);
    2093             :     }
    2094             :     // (a or b) and a || ( b or c ) and a
    2095             :     // a and ( a or b) || a and ( b or c )
    2096        1260 :     else if (   SQL_ISRULE(pSearchCondition,boolean_term)
    2097         528 :             &&  (
    2098         216 :                     (       SQL_ISRULE(pSearchCondition->getChild(nPos = 0),boolean_primary)
    2099         108 :                         ||  SQL_ISRULE(pSearchCondition->getChild(nPos),search_condition)
    2100             :                     )
    2101         108 :                 ||  (       SQL_ISRULE(pSearchCondition->getChild(nPos = 2),boolean_primary)
    2102         108 :                         ||  SQL_ISRULE(pSearchCondition->getChild(nPos),search_condition)
    2103             :                     )
    2104             :                 )
    2105             :             )
    2106             :     {
    2107           0 :         OSQLParseNode* p2ndSearch = pSearchCondition->getChild(nPos);
    2108           0 :         if ( SQL_ISRULE(p2ndSearch,boolean_primary) )
    2109           0 :             p2ndSearch = p2ndSearch->getChild(1);
    2110             : 
    2111           0 :         if ( *p2ndSearch->getChild(0) == *pSearchCondition->getChild(2-nPos) ) // a and ( a or b) -> a or b
    2112             :         {
    2113           0 :             pNewNode = pSearchCondition->removeAt((sal_uInt32)0);
    2114           0 :             replaceAndReset(pSearchCondition,pNewNode);
    2115             : 
    2116             :         }
    2117           0 :         else if ( *p2ndSearch->getChild(2) == *pSearchCondition->getChild(2-nPos) ) // a and ( b or a) -> a or b
    2118             :         {
    2119           0 :             pNewNode = pSearchCondition->removeAt((sal_uInt32)2);
    2120           0 :             replaceAndReset(pSearchCondition,pNewNode);
    2121             :         }
    2122           0 :         else if ( p2ndSearch->getByRule(OSQLParseNode::search_condition) )
    2123             :         {
    2124             :             // a and ( b or c ) -> ( a and b ) or ( a and c )
    2125             :             // ( b or c ) and a -> ( a and b ) or ( a and c )
    2126           0 :             OSQLParseNode* pC = p2ndSearch->removeAt((sal_uInt32)2);
    2127           0 :             OSQLParseNode* pB = p2ndSearch->removeAt((sal_uInt32)0);
    2128           0 :             OSQLParseNode* pA = pSearchCondition->removeAt((sal_uInt32)2-nPos);
    2129             : 
    2130           0 :             OSQLParseNode* p1stAnd = MakeANDNode(pA,pB);
    2131           0 :             OSQLParseNode* p2ndAnd = MakeANDNode(new OSQLParseNode(*pA),pC);
    2132           0 :             pNewNode = MakeORNode(p1stAnd,p2ndAnd);
    2133           0 :             OSQLParseNode* pNode = new OSQLParseNode(OUString(),SQL_NODE_RULE,OSQLParser::RuleID(OSQLParseNode::boolean_primary));
    2134           0 :             pNode->append(new OSQLParseNode(OUString("("),SQL_NODE_PUNCTUATION));
    2135           0 :             pNode->append(pNewNode);
    2136           0 :             pNode->append(new OSQLParseNode(OUString(")"),SQL_NODE_PUNCTUATION));
    2137           0 :             OSQLParseNode::eraseBraces(p1stAnd);
    2138           0 :             OSQLParseNode::eraseBraces(p2ndAnd);
    2139           0 :             replaceAndReset(pSearchCondition,pNode);
    2140             :         }
    2141             :     }
    2142             :     // a or a and b || a or b and a
    2143         420 :     else if(SQL_ISRULE(pSearchCondition,search_condition) && SQL_ISRULE(pSearchCondition->getChild(2),boolean_term))
    2144             :     {
    2145          36 :         if(*pSearchCondition->getChild(2)->getChild(0) == *pSearchCondition->getChild(0))
    2146             :         {
    2147           0 :             pNewNode = pSearchCondition->removeAt((sal_uInt32)0);
    2148           0 :             replaceAndReset(pSearchCondition,pNewNode);
    2149             :         }
    2150          36 :         else if(*pSearchCondition->getChild(2)->getChild(2) == *pSearchCondition->getChild(0))
    2151             :         {
    2152           0 :             pNewNode = pSearchCondition->removeAt((sal_uInt32)0);
    2153           0 :             replaceAndReset(pSearchCondition,pNewNode);
    2154             :         }
    2155             :     }
    2156             :     // a and b or a || b and a or a
    2157         384 :     else if(SQL_ISRULE(pSearchCondition,search_condition) && SQL_ISRULE(pSearchCondition->getChild(0),boolean_term))
    2158             :     {
    2159           0 :         if(*pSearchCondition->getChild(0)->getChild(0) == *pSearchCondition->getChild(2))
    2160             :         {
    2161           0 :             pNewNode = pSearchCondition->removeAt((sal_uInt32)2);
    2162           0 :             replaceAndReset(pSearchCondition,pNewNode);
    2163             :         }
    2164           0 :         else if(*pSearchCondition->getChild(0)->getChild(2) == *pSearchCondition->getChild(2))
    2165             :         {
    2166           0 :             pNewNode = pSearchCondition->removeAt((sal_uInt32)2);
    2167           0 :             replaceAndReset(pSearchCondition,pNewNode);
    2168             :         }
    2169             :     }
    2170         420 :     eraseBraces(pSearchCondition);
    2171             : }
    2172             : //-----------------------------------------------------------------------------
    2173           0 : void OSQLParseNode::compress(OSQLParseNode *&pSearchCondition)
    2174             : {
    2175             :     SAL_INFO( "connectivity.parse", "parse Ocke.Janssen@sun.com OSQLParseNode::compress" );
    2176           0 :     if(!pSearchCondition) // no WHERE condition at entry point
    2177           0 :         return;
    2178             : 
    2179           0 :     OSQLParseNode::eraseBraces(pSearchCondition);
    2180             : 
    2181           0 :     if(SQL_ISRULE(pSearchCondition,boolean_term) || SQL_ISRULE(pSearchCondition,search_condition))
    2182             :     {
    2183           0 :         OSQLParseNode* pLeft = pSearchCondition->getChild(0);
    2184           0 :         compress(pLeft);
    2185             : 
    2186           0 :         OSQLParseNode* pRight = pSearchCondition->getChild(2);
    2187           0 :         compress(pRight);
    2188             :     }
    2189           0 :     else if( SQL_ISRULE(pSearchCondition,boolean_primary) || (pSearchCondition->count() == 3 && SQL_ISPUNCTUATION(pSearchCondition->getChild(0),"(") &&
    2190           0 :              SQL_ISPUNCTUATION(pSearchCondition->getChild(2),")")))
    2191             :     {
    2192           0 :         OSQLParseNode* pRight = pSearchCondition->getChild(1);
    2193           0 :         compress(pRight);
    2194             :         // if child is not a or or and tree then delete () around child
    2195           0 :         if(!(SQL_ISRULE(pSearchCondition->getChild(1),boolean_term) || SQL_ISRULE(pSearchCondition->getChild(1),search_condition)) ||
    2196           0 :             (SQL_ISRULE(pSearchCondition->getChild(1),boolean_term) && SQL_ISRULE(pSearchCondition->getParent(),boolean_term)) ||
    2197           0 :             (SQL_ISRULE(pSearchCondition->getChild(1),search_condition) && SQL_ISRULE(pSearchCondition->getParent(),search_condition)))
    2198             :         {
    2199           0 :             OSQLParseNode* pNode = pSearchCondition->removeAt(1);
    2200           0 :             replaceAndReset(pSearchCondition,pNode);
    2201             :         }
    2202             :     }
    2203             : 
    2204             :     // or with two and trees where one element of the and trees are equal
    2205           0 :     if(SQL_ISRULE(pSearchCondition,search_condition) && SQL_ISRULE(pSearchCondition->getChild(0),boolean_term) && SQL_ISRULE(pSearchCondition->getChild(2),boolean_term))
    2206             :     {
    2207           0 :         if(*pSearchCondition->getChild(0)->getChild(0) == *pSearchCondition->getChild(2)->getChild(0))
    2208             :         {
    2209           0 :             OSQLParseNode* pLeft    = pSearchCondition->getChild(0)->removeAt(2);
    2210           0 :             OSQLParseNode* pRight = pSearchCondition->getChild(2)->removeAt(2);
    2211           0 :             OSQLParseNode* pNode    = MakeORNode(pLeft,pRight);
    2212             : 
    2213           0 :             OSQLParseNode* pNewRule = new OSQLParseNode(OUString(),SQL_NODE_RULE,OSQLParser::RuleID(OSQLParseNode::boolean_primary));
    2214           0 :             pNewRule->append(new OSQLParseNode(OUString("("),SQL_NODE_PUNCTUATION));
    2215           0 :             pNewRule->append(pNode);
    2216           0 :             pNewRule->append(new OSQLParseNode(OUString(")"),SQL_NODE_PUNCTUATION));
    2217             : 
    2218           0 :             OSQLParseNode::eraseBraces(pLeft);
    2219           0 :             OSQLParseNode::eraseBraces(pRight);
    2220             : 
    2221           0 :             pNode = MakeANDNode(pSearchCondition->getChild(0)->removeAt((sal_uInt32)0),pNewRule);
    2222           0 :             replaceAndReset(pSearchCondition,pNode);
    2223             :         }
    2224           0 :         else if(*pSearchCondition->getChild(0)->getChild(2) == *pSearchCondition->getChild(2)->getChild(0))
    2225             :         {
    2226           0 :             OSQLParseNode* pLeft = pSearchCondition->getChild(0)->removeAt((sal_uInt32)0);
    2227           0 :             OSQLParseNode* pRight = pSearchCondition->getChild(2)->removeAt(2);
    2228           0 :             OSQLParseNode* pNode = MakeORNode(pLeft,pRight);
    2229             : 
    2230           0 :             OSQLParseNode* pNewRule = new OSQLParseNode(OUString(),SQL_NODE_RULE,OSQLParser::RuleID(OSQLParseNode::boolean_primary));
    2231           0 :             pNewRule->append(new OSQLParseNode(OUString("("),SQL_NODE_PUNCTUATION));
    2232           0 :             pNewRule->append(pNode);
    2233           0 :             pNewRule->append(new OSQLParseNode(OUString(")"),SQL_NODE_PUNCTUATION));
    2234             : 
    2235           0 :             OSQLParseNode::eraseBraces(pLeft);
    2236           0 :             OSQLParseNode::eraseBraces(pRight);
    2237             : 
    2238           0 :             pNode = MakeANDNode(pSearchCondition->getChild(0)->removeAt(1),pNewRule);
    2239           0 :             replaceAndReset(pSearchCondition,pNode);
    2240             :         }
    2241           0 :         else if(*pSearchCondition->getChild(0)->getChild(0) == *pSearchCondition->getChild(2)->getChild(2))
    2242             :         {
    2243           0 :             OSQLParseNode* pLeft    = pSearchCondition->getChild(0)->removeAt(2);
    2244           0 :             OSQLParseNode* pRight = pSearchCondition->getChild(2)->removeAt((sal_uInt32)0);
    2245           0 :             OSQLParseNode* pNode    = MakeORNode(pLeft,pRight);
    2246             : 
    2247           0 :             OSQLParseNode* pNewRule = new OSQLParseNode(OUString(),SQL_NODE_RULE,OSQLParser::RuleID(OSQLParseNode::boolean_primary));
    2248           0 :             pNewRule->append(new OSQLParseNode(OUString("("),SQL_NODE_PUNCTUATION));
    2249           0 :             pNewRule->append(pNode);
    2250           0 :             pNewRule->append(new OSQLParseNode(OUString(")"),SQL_NODE_PUNCTUATION));
    2251             : 
    2252           0 :             OSQLParseNode::eraseBraces(pLeft);
    2253           0 :             OSQLParseNode::eraseBraces(pRight);
    2254             : 
    2255           0 :             pNode = MakeANDNode(pSearchCondition->getChild(0)->removeAt((sal_uInt32)0),pNewRule);
    2256           0 :             replaceAndReset(pSearchCondition,pNode);
    2257             :         }
    2258           0 :         else if(*pSearchCondition->getChild(0)->getChild(2) == *pSearchCondition->getChild(2)->getChild(2))
    2259             :         {
    2260           0 :             OSQLParseNode* pLeft    = pSearchCondition->getChild(0)->removeAt((sal_uInt32)0);
    2261           0 :             OSQLParseNode* pRight = pSearchCondition->getChild(2)->removeAt((sal_uInt32)0);
    2262           0 :             OSQLParseNode* pNode    = MakeORNode(pLeft,pRight);
    2263             : 
    2264           0 :             OSQLParseNode* pNewRule = new OSQLParseNode(OUString(),SQL_NODE_RULE,OSQLParser::RuleID(OSQLParseNode::boolean_primary));
    2265           0 :             pNewRule->append(new OSQLParseNode(OUString("("),SQL_NODE_PUNCTUATION));
    2266           0 :             pNewRule->append(pNode);
    2267           0 :             pNewRule->append(new OSQLParseNode(OUString(")"),SQL_NODE_PUNCTUATION));
    2268             : 
    2269           0 :             OSQLParseNode::eraseBraces(pLeft);
    2270           0 :             OSQLParseNode::eraseBraces(pRight);
    2271             : 
    2272           0 :             pNode = MakeANDNode(pSearchCondition->getChild(0)->removeAt(1),pNewRule);
    2273           0 :             replaceAndReset(pSearchCondition,pNode);
    2274             :         }
    2275             :     }
    2276             : }
    2277             : #if OSL_DEBUG_LEVEL > 1
    2278             : // -----------------------------------------------------------------------------
    2279             : void OSQLParseNode::showParseTree( OUString& rString ) const
    2280             : {
    2281             :     OUStringBuffer aBuf;
    2282             :     showParseTree( aBuf, 0 );
    2283             :     rString = aBuf.makeStringAndClear();
    2284             : }
    2285             : 
    2286             : // -----------------------------------------------------------------------------
    2287             : void OSQLParseNode::showParseTree( OUStringBuffer& _inout_rBuffer, sal_uInt32 nLevel ) const
    2288             : {
    2289             :     SAL_INFO( "connectivity.parse", "parse Ocke.Janssen@sun.com OSQLParseNode::showParseTree" );
    2290             : 
    2291             :     for ( sal_uInt32 j=0; j<nLevel; ++j)
    2292             :         _inout_rBuffer.appendAscii( "  " );
    2293             : 
    2294             :     if ( !isToken() )
    2295             :     {
    2296             :         // Rule name as rule
    2297             :         _inout_rBuffer.appendAscii( "RULE_ID: " );
    2298             :         _inout_rBuffer.append( (sal_Int32)getRuleID() );
    2299             :         _inout_rBuffer.append( sal_Unicode( '(' ) );
    2300             :         _inout_rBuffer.append( OSQLParser::RuleIDToStr( getRuleID() ) );
    2301             :         _inout_rBuffer.append( sal_Unicode( ')' ) );
    2302             :         _inout_rBuffer.append( sal_Unicode( '\n' ) );
    2303             : 
    2304             :         // Get the first sub tree
    2305             :         for (   OSQLParseNodes::const_iterator i = m_aChildren.begin();
    2306             :                 i != m_aChildren.end();
    2307             :                 ++i
    2308             :              )
    2309             :             (*i)->showParseTree( _inout_rBuffer, nLevel+1 );
    2310             :     }
    2311             :     else
    2312             :     {
    2313             :         // Found a token
    2314             :         switch (m_eNodeType)
    2315             :         {
    2316             : 
    2317             :         case SQL_NODE_KEYWORD:
    2318             :             _inout_rBuffer.appendAscii( "SQL_KEYWORD: " );
    2319             :             _inout_rBuffer.append( OStringToOUString( OSQLParser::TokenIDToStr( getTokenID() ), RTL_TEXTENCODING_UTF8 ) );
    2320             :             _inout_rBuffer.append( sal_Unicode( '\n' ) );
    2321             :             break;
    2322             : 
    2323             :         case SQL_NODE_COMPARISON:
    2324             :             _inout_rBuffer.appendAscii( "SQL_COMPARISON: " );
    2325             :             _inout_rBuffer.append( m_aNodeValue );
    2326             :             _inout_rBuffer.append( sal_Unicode( '\n' ) );
    2327             :             break;
    2328             : 
    2329             :         case SQL_NODE_NAME:
    2330             :             _inout_rBuffer.appendAscii( "SQL_NAME: " );
    2331             :             _inout_rBuffer.append( sal_Unicode( '"' ) );
    2332             :             _inout_rBuffer.append( m_aNodeValue );
    2333             :             _inout_rBuffer.append( sal_Unicode( '"' ) );
    2334             :             _inout_rBuffer.append( sal_Unicode( '\n' ) );
    2335             :              break;
    2336             : 
    2337             :         case SQL_NODE_STRING:
    2338             :             _inout_rBuffer.appendAscii( "SQL_STRING: " );
    2339             :             _inout_rBuffer.append( sal_Unicode( '\'' ) );
    2340             :             _inout_rBuffer.append( m_aNodeValue );
    2341             :             _inout_rBuffer.append( sal_Unicode( '\'' ) );
    2342             :             _inout_rBuffer.append( sal_Unicode( '\n' ) );
    2343             :             break;
    2344             : 
    2345             :         case SQL_NODE_INTNUM:
    2346             :             _inout_rBuffer.appendAscii( "SQL_INTNUM: " );
    2347             :             _inout_rBuffer.append( m_aNodeValue );
    2348             :             _inout_rBuffer.append( sal_Unicode( '\n' ) );
    2349             :             break;
    2350             : 
    2351             :         case SQL_NODE_APPROXNUM:
    2352             :             _inout_rBuffer.appendAscii( "SQL_APPROXNUM: " );
    2353             :             _inout_rBuffer.append( m_aNodeValue );
    2354             :             _inout_rBuffer.append( sal_Unicode( '\n' ) );
    2355             :              break;
    2356             : 
    2357             :         case SQL_NODE_PUNCTUATION:
    2358             :             _inout_rBuffer.appendAscii( "SQL_PUNCTUATION: " );
    2359             :             _inout_rBuffer.append( m_aNodeValue );
    2360             :             _inout_rBuffer.append( sal_Unicode( '\n' ) );
    2361             :             break;
    2362             : 
    2363             :         case SQL_NODE_AMMSC:
    2364             :             _inout_rBuffer.appendAscii( "SQL_AMMSC: " );
    2365             :             _inout_rBuffer.append( m_aNodeValue );
    2366             :             _inout_rBuffer.append( sal_Unicode( '\n' ) );
    2367             :             break;
    2368             : 
    2369             :         case SQL_NODE_EQUAL:
    2370             :         case SQL_NODE_LESS:
    2371             :         case SQL_NODE_GREAT:
    2372             :         case SQL_NODE_LESSEQ:
    2373             :         case SQL_NODE_GREATEQ:
    2374             :         case SQL_NODE_NOTEQUAL:
    2375             :             _inout_rBuffer.append( m_aNodeValue );
    2376             :             _inout_rBuffer.append( sal_Unicode( '\n' ) );
    2377             :             break;
    2378             : 
    2379             :         case SQL_NODE_ACCESS_DATE:
    2380             :             _inout_rBuffer.appendAscii( "SQL_ACCESS_DATE: " );
    2381             :             _inout_rBuffer.append( m_aNodeValue );
    2382             :             _inout_rBuffer.append( sal_Unicode( '\n' ) );
    2383             :             break;
    2384             : 
    2385             :         case SQL_NODE_DATE:
    2386             :             _inout_rBuffer.appendAscii( "SQL_DATE: " );
    2387             :             _inout_rBuffer.append( m_aNodeValue );
    2388             :             _inout_rBuffer.append( sal_Unicode( '\n' ) );
    2389             :             break;
    2390             : 
    2391             :         case SQL_NODE_CONCAT:
    2392             :             _inout_rBuffer.appendAscii( "||" );
    2393             :             _inout_rBuffer.append( sal_Unicode( '\n' ) );
    2394             :             break;
    2395             : 
    2396             :         default:
    2397             :             SAL_INFO( "connectivity.parse", "-- " << int( m_eNodeType ) );
    2398             :             SAL_WARN( "connectivity.parse", "OSQLParser::ShowParseTree: unzulaessiger NodeType" );
    2399             :         }
    2400             :     }
    2401             : }
    2402             : #endif // OSL_DEBUG_LEVEL > 0
    2403             : // -----------------------------------------------------------------------------
    2404             : // Insert methods
    2405             : //-----------------------------------------------------------------------------
    2406           0 : void OSQLParseNode::insert(sal_uInt32 nPos, OSQLParseNode* pNewSubTree)
    2407             : {
    2408             :     SAL_INFO( "connectivity.parse", "parse Ocke.Janssen@sun.com OSQLParseNode::insert" );
    2409             :     OSL_ENSURE(pNewSubTree != NULL, "OSQLParseNode: invalid NewSubTree");
    2410             :     OSL_ENSURE(pNewSubTree->getParent() == NULL, "OSQLParseNode: Node is not an orphan");
    2411             : 
    2412             :     // Create connection to getParent
    2413           0 :     pNewSubTree->setParent( this );
    2414           0 :     m_aChildren.insert(m_aChildren.begin() + nPos, pNewSubTree);
    2415           0 : }
    2416             : 
    2417             : // removeAt methods
    2418             : //-----------------------------------------------------------------------------
    2419          56 : OSQLParseNode* OSQLParseNode::removeAt(sal_uInt32 nPos)
    2420             : {
    2421             :     SAL_INFO( "connectivity.parse", "parse Ocke.Janssen@sun.com OSQLParseNode::removeAt" );
    2422             :     OSL_ENSURE(nPos < m_aChildren.size(),"Illegal position for removeAt");
    2423          56 :     OSQLParseNodes::iterator aPos(m_aChildren.begin() + nPos);
    2424          56 :     OSQLParseNode* pNode = *aPos;
    2425             : 
    2426             :     // Set the getParent of the removed node to NULL
    2427          56 :     pNode->setParent( NULL );
    2428             : 
    2429          56 :     m_aChildren.erase(aPos);
    2430          56 :     return pNode;
    2431             : }
    2432             : 
    2433             : // Replace methods
    2434             : //-----------------------------------------------------------------------------
    2435          20 : OSQLParseNode* OSQLParseNode::replace (OSQLParseNode* pOldSubNode, OSQLParseNode* pNewSubNode )
    2436             : {
    2437             :     SAL_INFO( "connectivity.parse", "parse Ocke.Janssen@sun.com OSQLParseNode::replace " );
    2438             :     OSL_ENSURE(pOldSubNode != NULL && pNewSubNode != NULL, "OSQLParseNode: invalid nodes");
    2439             :     OSL_ENSURE(pNewSubNode->getParent() == NULL, "OSQLParseNode: node already has getParent");
    2440             :     OSL_ENSURE(::std::find(m_aChildren.begin(), m_aChildren.end(), pOldSubNode) != m_aChildren.end(),
    2441             :             "OSQLParseNode::Replace() Node not element of parent");
    2442             :     OSL_ENSURE(::std::find(m_aChildren.begin(), m_aChildren.end(), pNewSubNode) == m_aChildren.end(),
    2443             :             "OSQLParseNode::Replace() Node already element of parent");
    2444             : 
    2445          20 :     pOldSubNode->setParent( NULL );
    2446          20 :     pNewSubNode->setParent( this );
    2447          20 :     ::std::replace(m_aChildren.begin(), m_aChildren.end(), pOldSubNode, pNewSubNode);
    2448          20 :     return pOldSubNode;
    2449             : }
    2450             : // -----------------------------------------------------------------------------
    2451        6617 : void OSQLParseNode::parseLeaf(OUStringBuffer& rString, const SQLParseNodeParameter& rParam) const
    2452             : {
    2453             :     SAL_INFO( "connectivity.parse", "parse Ocke.Janssen@sun.com OSQLParseNode::parseLeaf" );
    2454             :     // Found a leaf
    2455             :     // Append content to the output string
    2456        6617 :     switch (m_eNodeType)
    2457             :     {
    2458             :         case SQL_NODE_KEYWORD:
    2459             :         {
    2460        1178 :             if (!rString.isEmpty())
    2461        1044 :                 rString.appendAscii(" ");
    2462             : 
    2463        1178 :             const OString sT = OSQLParser::TokenIDToStr(m_nNodeID, rParam.bInternational ? &rParam.m_rContext :  NULL);
    2464        1178 :             rString.append(OStringToOUString(sT,RTL_TEXTENCODING_UTF8));
    2465        1178 :         }   break;
    2466             :         case SQL_NODE_STRING:
    2467        1696 :             if (!rString.isEmpty())
    2468         712 :                 rString.appendAscii(" ");
    2469        1696 :             rString.append(SetQuotation(m_aNodeValue,OUString("\'"),OUString("\'\'")));
    2470        1696 :             break;
    2471             :         case SQL_NODE_NAME:
    2472        1335 :             if (!rString.isEmpty())
    2473             :             {
    2474        1274 :                 switch(rString[rString.getLength()-1])
    2475             :                 {
    2476             :                     case ' ' :
    2477         196 :                     case '.' : break;
    2478             :                     default  :
    2479        2156 :                         if  (   rParam.aMetaData.getCatalogSeparator().isEmpty()
    2480        1078 :                                 || rString[rString.getLength() - 1] != rParam.aMetaData.getCatalogSeparator().toChar()
    2481             :                             )
    2482        1078 :                             rString.appendAscii(" "); break;
    2483             :                 }
    2484             :             }
    2485        1335 :             if (rParam.bQuote)
    2486             :             {
    2487        1323 :                 if (rParam.bPredicate)
    2488             :                 {
    2489           0 :                     rString.appendAscii("[");
    2490           0 :                     rString.append(m_aNodeValue);
    2491           0 :                     rString.appendAscii("]");
    2492             :                 }
    2493             :                 else
    2494             :                     rString.append(SetQuotation(m_aNodeValue,
    2495        1323 :                         rParam.aMetaData.getIdentifierQuoteString(), rParam.aMetaData.getIdentifierQuoteString() ));
    2496             :             }
    2497             :             else
    2498          12 :                 rString.append(m_aNodeValue);
    2499        1335 :             break;
    2500             :         case SQL_NODE_ACCESS_DATE:
    2501           0 :             if (!rString.isEmpty())
    2502           0 :                 rString.appendAscii(" ");
    2503           0 :             rString.appendAscii("#");
    2504           0 :             rString.append(m_aNodeValue);
    2505           0 :             rString.appendAscii("#");
    2506           0 :             break;
    2507             : 
    2508             :         case SQL_NODE_INTNUM:
    2509             :         case SQL_NODE_APPROXNUM:
    2510             :             {
    2511         172 :                 OUString aTmp = m_aNodeValue;
    2512         172 :                 if (rParam.bInternational && rParam.bPredicate && rParam.cDecSep != '.')
    2513           0 :                     aTmp = aTmp.replace('.', rParam.cDecSep);
    2514             : 
    2515         172 :                 if (!rString.isEmpty())
    2516          72 :                     rString.appendAscii(" ");
    2517         172 :                 rString.append(aTmp);
    2518             : 
    2519         172 :             }   break;
    2520             :         case SQL_NODE_PUNCTUATION:
    2521        1449 :             if ( getParent() && SQL_ISRULE(getParent(),cast_spec) && m_aNodeValue.toChar() == '(' ) // no spaces in front of '('
    2522             :             {
    2523           0 :                 rString.append(m_aNodeValue);
    2524           0 :                 break;
    2525             :             }
    2526             :             // fall through
    2527             :         default:
    2528        2236 :             if (!rString.isEmpty() && m_aNodeValue.toChar() != '.' && m_aNodeValue.toChar() != ':' )
    2529             :             {
    2530        1981 :                 switch( rString[rString.getLength() - 1] )
    2531             :                 {
    2532             :                     case ' ' :
    2533          33 :                     case '.' : break;
    2534             :                     default  :
    2535        3896 :                         if  (   rParam.aMetaData.getCatalogSeparator().isEmpty()
    2536        1948 :                             ||  rString[rString.getLength() - 1] != rParam.aMetaData.getCatalogSeparator().toChar()
    2537             :                             )
    2538        1948 :                             rString.appendAscii(" "); break;
    2539             :                 }
    2540             :             }
    2541        2236 :             rString.append(m_aNodeValue);
    2542             :     }
    2543        6617 : }
    2544             : 
    2545             : // -----------------------------------------------------------------------------
    2546           0 : sal_Int32 OSQLParser::getFunctionReturnType(const OUString& _sFunctionName, const IParseContext* pContext)
    2547             : {
    2548           0 :     sal_Int32 nType = DataType::VARCHAR;
    2549           0 :     OString sFunctionName(OUStringToOString(_sFunctionName,RTL_TEXTENCODING_UTF8));
    2550             : 
    2551           0 :     if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_ASCII,pContext)))                     nType = DataType::INTEGER;
    2552           0 :     else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_BIT_LENGTH,pContext)))           nType = DataType::INTEGER;
    2553           0 :     else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_CHAR,pContext)))                 nType = DataType::VARCHAR;
    2554           0 :     else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_CHAR_LENGTH,pContext)))          nType = DataType::INTEGER;
    2555           0 :     else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_CONCAT,pContext)))               nType = DataType::VARCHAR;
    2556           0 :     else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_DIFFERENCE,pContext)))           nType = DataType::VARCHAR;
    2557           0 :     else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_INSERT,pContext)))               nType = DataType::VARCHAR;
    2558           0 :     else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_LCASE,pContext)))                nType = DataType::VARCHAR;
    2559           0 :     else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_LEFT,pContext)))                 nType = DataType::VARCHAR;
    2560           0 :     else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_LENGTH,pContext)))               nType = DataType::INTEGER;
    2561           0 :     else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_LOCATE,pContext)))               nType = DataType::VARCHAR;
    2562           0 :     else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_LOCATE_2,pContext)))             nType = DataType::VARCHAR;
    2563           0 :     else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_LTRIM,pContext)))                nType = DataType::VARCHAR;
    2564           0 :     else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_OCTET_LENGTH,pContext)))         nType = DataType::INTEGER;
    2565           0 :     else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_POSITION,pContext)))             nType = DataType::INTEGER;
    2566           0 :     else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_REPEAT,pContext)))               nType = DataType::VARCHAR;
    2567           0 :     else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_REPLACE,pContext)))              nType = DataType::VARCHAR;
    2568           0 :     else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_RIGHT,pContext)))                nType = DataType::VARCHAR;
    2569           0 :     else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_RTRIM,pContext)))                nType = DataType::VARCHAR;
    2570           0 :     else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_SOUNDEX,pContext)))              nType = DataType::VARCHAR;
    2571           0 :     else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_SPACE,pContext)))                nType = DataType::VARCHAR;
    2572           0 :     else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_SUBSTRING,pContext)))            nType = DataType::VARCHAR;
    2573           0 :     else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_UCASE,pContext)))                nType = DataType::VARCHAR;
    2574           0 :     else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_CURRENT_DATE,pContext)))         nType = DataType::DATE;
    2575           0 :     else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_CURRENT_TIME,pContext)))         nType = DataType::TIME;
    2576           0 :     else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_CURRENT_TIMESTAMP,pContext)))    nType = DataType::TIMESTAMP;
    2577           0 :     else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_CURDATE,pContext)))              nType = DataType::DATE;
    2578           0 :     else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_DATEDIFF,pContext)))             nType = DataType::INTEGER;
    2579           0 :     else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_DATEVALUE,pContext)))            nType = DataType::DATE;
    2580           0 :     else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_CURTIME,pContext)))              nType = DataType::TIME;
    2581           0 :     else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_DAYNAME,pContext)))              nType = DataType::VARCHAR;
    2582           0 :     else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_DAYOFMONTH,pContext)))           nType = DataType::INTEGER;
    2583           0 :     else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_DAYOFWEEK,pContext)))            nType = DataType::INTEGER;
    2584           0 :     else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_DAYOFYEAR,pContext)))            nType = DataType::INTEGER;
    2585           0 :     else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_EXTRACT,pContext)))              nType = DataType::VARCHAR;
    2586           0 :     else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_HOUR,pContext)))                 nType = DataType::INTEGER;
    2587           0 :     else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_MINUTE,pContext)))               nType = DataType::INTEGER;
    2588           0 :     else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_MONTH,pContext)))                nType = DataType::INTEGER;
    2589           0 :     else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_MONTHNAME,pContext)))            nType = DataType::VARCHAR;
    2590           0 :     else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_NOW,pContext)))                  nType = DataType::TIMESTAMP;
    2591           0 :     else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_QUARTER,pContext)))              nType = DataType::INTEGER;
    2592           0 :     else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_SECOND,pContext)))               nType = DataType::INTEGER;
    2593           0 :     else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_TIMESTAMPADD,pContext)))         nType = DataType::TIMESTAMP;
    2594           0 :     else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_TIMESTAMPDIFF,pContext)))        nType = DataType::TIMESTAMP;
    2595           0 :     else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_TIMEVALUE,pContext)))            nType = DataType::TIMESTAMP;
    2596           0 :     else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_WEEK,pContext)))                 nType = DataType::INTEGER;
    2597           0 :     else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_YEAR,pContext)))                 nType = DataType::INTEGER;
    2598           0 :     else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_ABS,pContext)))                  nType = DataType::DOUBLE;
    2599           0 :     else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_ACOS,pContext)))                 nType = DataType::DOUBLE;
    2600           0 :     else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_ASIN,pContext)))                 nType = DataType::DOUBLE;
    2601           0 :     else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_ATAN,pContext)))                 nType = DataType::DOUBLE;
    2602           0 :     else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_ATAN2,pContext)))                nType = DataType::DOUBLE;
    2603           0 :     else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_CEILING,pContext)))              nType = DataType::DOUBLE;
    2604           0 :     else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_COS,pContext)))                  nType = DataType::DOUBLE;
    2605           0 :     else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_COT,pContext)))                  nType = DataType::DOUBLE;
    2606           0 :     else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_DEGREES,pContext)))              nType = DataType::DOUBLE;
    2607           0 :     else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_EXP,pContext)))                  nType = DataType::DOUBLE;
    2608           0 :     else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_FLOOR,pContext)))                nType = DataType::DOUBLE;
    2609           0 :     else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_LOGF,pContext)))                 nType = DataType::DOUBLE;
    2610           0 :     else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_LOG,pContext)))                  nType = DataType::DOUBLE;
    2611           0 :     else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_LOG10,pContext)))                nType = DataType::DOUBLE;
    2612           0 :     else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_LN,pContext)))                   nType = DataType::DOUBLE;
    2613           0 :     else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_MOD,pContext)))                  nType = DataType::DOUBLE;
    2614           0 :     else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_PI,pContext)))                   nType = DataType::DOUBLE;
    2615           0 :     else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_POWER,pContext)))                nType = DataType::DOUBLE;
    2616           0 :     else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_RADIANS,pContext)))              nType = DataType::DOUBLE;
    2617           0 :     else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_RAND,pContext)))                 nType = DataType::DOUBLE;
    2618           0 :     else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_ROUND,pContext)))                nType = DataType::DOUBLE;
    2619           0 :     else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_ROUNDMAGIC,pContext)))           nType = DataType::DOUBLE;
    2620           0 :     else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_SIGN,pContext)))                 nType = DataType::DOUBLE;
    2621           0 :     else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_SIN,pContext)))                  nType = DataType::DOUBLE;
    2622           0 :     else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_SQRT,pContext)))                 nType = DataType::DOUBLE;
    2623           0 :     else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_TAN,pContext)))                  nType = DataType::DOUBLE;
    2624           0 :     else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_TRUNCATE,pContext)))             nType = DataType::DOUBLE;
    2625           0 :     else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_COUNT,pContext)))                nType = DataType::INTEGER;
    2626           0 :     else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_MAX,pContext)))                  nType = DataType::DOUBLE;
    2627           0 :     else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_MIN,pContext)))                  nType = DataType::DOUBLE;
    2628           0 :     else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_AVG,pContext)))                  nType = DataType::DOUBLE;
    2629           0 :     else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_SUM,pContext)))                  nType = DataType::DOUBLE;
    2630           0 :     else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_LOWER,pContext)))                nType = DataType::VARCHAR;
    2631           0 :     else if(sFunctionName.equalsIgnoreAsciiCase(TokenIDToStr(SQL_TOKEN_UPPER,pContext)))                nType = DataType::VARCHAR;
    2632             : 
    2633           0 :     return nType;
    2634             : }
    2635             : // -----------------------------------------------------------------------------
    2636           0 : sal_Int32 OSQLParser::getFunctionParameterType(sal_uInt32 _nTokenId, sal_uInt32 _nPos)
    2637             : {
    2638           0 :     sal_Int32 nType = DataType::VARCHAR;
    2639             : 
    2640           0 :     if(_nTokenId == SQL_TOKEN_CHAR)                 nType = DataType::INTEGER;
    2641           0 :     else if(_nTokenId == SQL_TOKEN_INSERT)
    2642             :     {
    2643           0 :         if ( _nPos == 2 || _nPos == 3 )
    2644           0 :             nType = DataType::INTEGER;
    2645             :     }
    2646           0 :     else if(_nTokenId == SQL_TOKEN_LEFT)
    2647             :     {
    2648           0 :         if ( _nPos == 2 )
    2649           0 :             nType = DataType::INTEGER;
    2650             :     }
    2651           0 :     else if(_nTokenId == SQL_TOKEN_LOCATE)
    2652             :     {
    2653           0 :         if ( _nPos == 3 )
    2654           0 :             nType = DataType::INTEGER;
    2655             :     }
    2656           0 :     else if(_nTokenId == SQL_TOKEN_LOCATE_2)
    2657             :     {
    2658           0 :         if ( _nPos == 3 )
    2659           0 :             nType = DataType::INTEGER;
    2660             :     }
    2661           0 :     else if( _nTokenId == SQL_TOKEN_REPEAT || _nTokenId == SQL_TOKEN_RIGHT )
    2662             :     {
    2663           0 :         if ( _nPos == 2 )
    2664           0 :             nType = DataType::INTEGER;
    2665             :     }
    2666           0 :     else if(_nTokenId == SQL_TOKEN_SPACE )
    2667             :     {
    2668           0 :         nType = DataType::INTEGER;
    2669             :     }
    2670           0 :     else if(_nTokenId == SQL_TOKEN_SUBSTRING)
    2671             :     {
    2672           0 :         if ( _nPos != 1 )
    2673           0 :             nType = DataType::INTEGER;
    2674             :     }
    2675           0 :     else if(_nTokenId == SQL_TOKEN_DATEDIFF)
    2676             :     {
    2677           0 :         if ( _nPos != 1 )
    2678           0 :             nType = DataType::TIMESTAMP;
    2679             :     }
    2680           0 :     else if(_nTokenId == SQL_TOKEN_DATEVALUE)
    2681           0 :         nType = DataType::DATE;
    2682           0 :     else if(_nTokenId == SQL_TOKEN_DAYNAME)
    2683           0 :         nType = DataType::DATE;
    2684           0 :     else if(_nTokenId == SQL_TOKEN_DAYOFMONTH)
    2685           0 :         nType = DataType::DATE;
    2686           0 :     else if(_nTokenId == SQL_TOKEN_DAYOFWEEK)
    2687           0 :         nType = DataType::DATE;
    2688           0 :     else if(_nTokenId == SQL_TOKEN_DAYOFYEAR)
    2689           0 :         nType = DataType::DATE;
    2690           0 :     else if(_nTokenId == SQL_TOKEN_EXTRACT)              nType = DataType::VARCHAR;
    2691           0 :     else if(_nTokenId == SQL_TOKEN_HOUR)                 nType = DataType::TIME;
    2692           0 :     else if(_nTokenId == SQL_TOKEN_MINUTE)               nType = DataType::TIME;
    2693           0 :     else if(_nTokenId == SQL_TOKEN_MONTH)                nType = DataType::DATE;
    2694           0 :     else if(_nTokenId == SQL_TOKEN_MONTHNAME)            nType = DataType::DATE;
    2695           0 :     else if(_nTokenId == SQL_TOKEN_NOW)                  nType = DataType::TIMESTAMP;
    2696           0 :     else if(_nTokenId == SQL_TOKEN_QUARTER)              nType = DataType::DATE;
    2697           0 :     else if(_nTokenId == SQL_TOKEN_SECOND)               nType = DataType::TIME;
    2698           0 :     else if(_nTokenId == SQL_TOKEN_TIMESTAMPADD)         nType = DataType::TIMESTAMP;
    2699           0 :     else if(_nTokenId == SQL_TOKEN_TIMESTAMPDIFF)        nType = DataType::TIMESTAMP;
    2700           0 :     else if(_nTokenId == SQL_TOKEN_TIMEVALUE)            nType = DataType::TIMESTAMP;
    2701           0 :     else if(_nTokenId == SQL_TOKEN_WEEK)                 nType = DataType::DATE;
    2702           0 :     else if(_nTokenId == SQL_TOKEN_YEAR)                 nType = DataType::DATE;
    2703             : 
    2704           0 :     else if(_nTokenId == SQL_TOKEN_ABS)                  nType = DataType::DOUBLE;
    2705           0 :     else if(_nTokenId == SQL_TOKEN_ACOS)                 nType = DataType::DOUBLE;
    2706           0 :     else if(_nTokenId == SQL_TOKEN_ASIN)                 nType = DataType::DOUBLE;
    2707           0 :     else if(_nTokenId == SQL_TOKEN_ATAN)                 nType = DataType::DOUBLE;
    2708           0 :     else if(_nTokenId == SQL_TOKEN_ATAN2)                nType = DataType::DOUBLE;
    2709           0 :     else if(_nTokenId == SQL_TOKEN_CEILING)              nType = DataType::DOUBLE;
    2710           0 :     else if(_nTokenId == SQL_TOKEN_COS)                  nType = DataType::DOUBLE;
    2711           0 :     else if(_nTokenId == SQL_TOKEN_COT)                  nType = DataType::DOUBLE;
    2712           0 :     else if(_nTokenId == SQL_TOKEN_DEGREES)              nType = DataType::DOUBLE;
    2713           0 :     else if(_nTokenId == SQL_TOKEN_EXP)                  nType = DataType::DOUBLE;
    2714           0 :     else if(_nTokenId == SQL_TOKEN_FLOOR)                nType = DataType::DOUBLE;
    2715           0 :     else if(_nTokenId == SQL_TOKEN_LOGF)                 nType = DataType::DOUBLE;
    2716           0 :     else if(_nTokenId == SQL_TOKEN_LOG)                  nType = DataType::DOUBLE;
    2717           0 :     else if(_nTokenId == SQL_TOKEN_LOG10)                nType = DataType::DOUBLE;
    2718           0 :     else if(_nTokenId == SQL_TOKEN_LN)                   nType = DataType::DOUBLE;
    2719           0 :     else if(_nTokenId == SQL_TOKEN_MOD)                  nType = DataType::DOUBLE;
    2720           0 :     else if(_nTokenId == SQL_TOKEN_PI)                   nType = DataType::DOUBLE;
    2721           0 :     else if(_nTokenId == SQL_TOKEN_POWER)                nType = DataType::DOUBLE;
    2722           0 :     else if(_nTokenId == SQL_TOKEN_RADIANS)              nType = DataType::DOUBLE;
    2723           0 :     else if(_nTokenId == SQL_TOKEN_RAND)                 nType = DataType::DOUBLE;
    2724           0 :     else if(_nTokenId == SQL_TOKEN_ROUND)                nType = DataType::DOUBLE;
    2725           0 :     else if(_nTokenId == SQL_TOKEN_ROUNDMAGIC)           nType = DataType::DOUBLE;
    2726           0 :     else if(_nTokenId == SQL_TOKEN_SIGN)                 nType = DataType::DOUBLE;
    2727           0 :     else if(_nTokenId == SQL_TOKEN_SIN)                  nType = DataType::DOUBLE;
    2728           0 :     else if(_nTokenId == SQL_TOKEN_SQRT)                 nType = DataType::DOUBLE;
    2729           0 :     else if(_nTokenId == SQL_TOKEN_TAN)                  nType = DataType::DOUBLE;
    2730           0 :     else if(_nTokenId == SQL_TOKEN_TRUNCATE)             nType = DataType::DOUBLE;
    2731           0 :     else if(_nTokenId == SQL_TOKEN_COUNT)                nType = DataType::INTEGER;
    2732           0 :     else if(_nTokenId == SQL_TOKEN_MAX)                  nType = DataType::DOUBLE;
    2733           0 :     else if(_nTokenId == SQL_TOKEN_MIN)                  nType = DataType::DOUBLE;
    2734           0 :     else if(_nTokenId == SQL_TOKEN_AVG)                  nType = DataType::DOUBLE;
    2735           0 :     else if(_nTokenId == SQL_TOKEN_SUM)                  nType = DataType::DOUBLE;
    2736             : 
    2737           0 :     else if(_nTokenId == SQL_TOKEN_LOWER)                nType = DataType::VARCHAR;
    2738           0 :     else if(_nTokenId == SQL_TOKEN_UPPER)                nType = DataType::VARCHAR;
    2739             : 
    2740           0 :     return nType;
    2741             : }
    2742             : 
    2743             : // -----------------------------------------------------------------------------
    2744           0 : const SQLError& OSQLParser::getErrorHelper() const
    2745             : {
    2746           0 :     return m_pData->aErrors;
    2747             : }
    2748             : 
    2749             : // -----------------------------------------------------------------------------
    2750       17836 : OSQLParseNode::Rule OSQLParseNode::getKnownRuleID() const
    2751             : {
    2752       17836 :     if ( !isRule() )
    2753           0 :         return UNKNOWN_RULE;
    2754       17836 :     return OSQLParser::RuleIDToRule( getRuleID() );
    2755             : }
    2756             : // -----------------------------------------------------------------------------
    2757         212 : OUString OSQLParseNode::getTableRange(const OSQLParseNode* _pTableRef)
    2758             : {
    2759             :     SAL_INFO( "connectivity.parse", "parse Ocke.Janssen@sun.com OSQLParseNode::getTableRange" );
    2760             :     OSL_ENSURE(_pTableRef && _pTableRef->count() > 1 && _pTableRef->getKnownRuleID() == OSQLParseNode::table_ref,"Invalid node give, only table ref is allowed!");
    2761         212 :     const sal_uInt32 nCount = _pTableRef->count();
    2762         212 :     OUString sTableRange;
    2763         212 :     if ( nCount == 2 || (nCount == 3 && !_pTableRef->getChild(0)->isToken()) )
    2764             :     {
    2765         212 :         const OSQLParseNode* pNode = _pTableRef->getChild(nCount - (nCount == 2 ? 1 : 2));
    2766             :         OSL_ENSURE(pNode && (pNode->getKnownRuleID() == OSQLParseNode::table_primary_as_range_column
    2767             :                           || pNode->getKnownRuleID() == OSQLParseNode::range_variable)
    2768             :                          ,"SQL grammar changed!");
    2769         212 :         if ( !pNode->isLeaf() )
    2770          52 :             sTableRange = pNode->getChild(1)->getTokenValue();
    2771             :     } // if ( nCount == 2 || nCount == 3 )
    2772             : 
    2773         212 :     return sTableRange;
    2774             : }
    2775             : // -----------------------------------------------------------------------------
    2776          29 : OSQLParseNodesContainer::OSQLParseNodesContainer()
    2777             : {
    2778          29 : }
    2779             : // -----------------------------------------------------------------------------
    2780          28 : OSQLParseNodesContainer::~OSQLParseNodesContainer()
    2781             : {
    2782          28 : }
    2783             : // -----------------------------------------------------------------------------
    2784       13568 : void OSQLParseNodesContainer::push_back(OSQLParseNode* _pNode)
    2785             : {
    2786       13568 :     ::osl::MutexGuard aGuard(m_aMutex);
    2787       13568 :     m_aNodes.push_back(_pNode);
    2788       13568 : }
    2789             : // -----------------------------------------------------------------------------
    2790       13504 : void OSQLParseNodesContainer::erase(OSQLParseNode* _pNode)
    2791             : {
    2792       13504 :     ::osl::MutexGuard aGuard(m_aMutex);
    2793       13504 :     if ( !m_aNodes.empty() )
    2794             :     {
    2795          45 :         ::std::vector< OSQLParseNode* >::iterator aFind = ::std::find(m_aNodes.begin(), m_aNodes.end(),_pNode);
    2796          45 :         if ( aFind != m_aNodes.end() )
    2797          45 :             m_aNodes.erase(aFind);
    2798       13504 :     }
    2799       13504 : }
    2800             : // -----------------------------------------------------------------------------
    2801         288 : void OSQLParseNodesContainer::clear()
    2802             : {
    2803         288 :     ::osl::MutexGuard aGuard(m_aMutex);
    2804         288 :     m_aNodes.clear();
    2805         288 : }
    2806             : // -----------------------------------------------------------------------------
    2807           1 : void OSQLParseNodesContainer::clearAndDelete()
    2808             : {
    2809           1 :     ::osl::MutexGuard aGuard(m_aMutex);
    2810             :     // clear the garbage collector
    2811           4 :     while ( !m_aNodes.empty() )
    2812             :     {
    2813           2 :         OSQLParseNode* pNode = m_aNodes[0];
    2814           6 :         while ( pNode->getParent() )
    2815             :         {
    2816           2 :             pNode = pNode->getParent();
    2817             :         }
    2818           2 :         delete pNode;
    2819           1 :     }
    2820           1 : }
    2821          87 : }   // namespace connectivity
    2822             : 
    2823             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10