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

Generated by: LCOV version 1.10