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

Generated by: LCOV version 1.10