/connectivity/source/parse/sqlnode.cxx
C++ | 2829 lines | 2333 code | 241 blank | 255 comment | 779 complexity | 7147a23ca9fe06cd985031abbf1341a9 MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception, LGPL-3.0, AGPL-1.0, BSD-3-Clause-No-Nuclear-License-2014, GPL-3.0, GPL-2.0, BSD-3-Clause, LGPL-2.1
Large files files are truncated, but you can click here to view the full file
- /*************************************************************************
- *
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * Copyright 2000, 2010 Oracle and/or its affiliates.
- *
- * OpenOffice.org - a multi-platform office productivity suite
- *
- * This file is part of OpenOffice.org.
- *
- * OpenOffice.org is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License version 3
- * only, as published by the Free Software Foundation.
- *
- * OpenOffice.org is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License version 3 for more details
- * (a copy is included in the LICENSE file that accompanied this code).
- *
- * You should have received a copy of the GNU Lesser General Public License
- * version 3 along with OpenOffice.org. If not, see
- * <http://www.openoffice.org/license.html>
- * for a copy of the LGPLv3 License.
- *
- ************************************************************************/
- // MARKER(update_precomp.py): autogen include statement, do not remove
- #include "precompiled_connectivity.hxx"
- #include <connectivity/sqlnode.hxx>
- #include <connectivity/sqlerror.hxx>
- #include <internalnode.hxx>
- #define YYBISON 1
- #ifndef BISON_INCLUDED
- #define BISON_INCLUDED
- #include <sqlbison.hxx>
- #endif
- #include <connectivity/sqlparse.hxx>
- #include <com/sun/star/lang/Locale.hpp>
- #include <com/sun/star/util/XNumberFormatter.hpp>
- #include <com/sun/star/util/XNumberFormatTypes.hpp>
- #include <com/sun/star/i18n/NumberFormatIndex.hpp>
- #include <com/sun/star/beans/XPropertySet.hpp>
- #include <com/sun/star/sdbc/XDatabaseMetaData.hpp>
- #include <com/sun/star/sdbc/DataType.hpp>
- #include <com/sun/star/sdb/XQueriesSupplier.hpp>
- #include <com/sun/star/sdb/ErrorCondition.hpp>
- #include <com/sun/star/util/XNumberFormatter.hpp>
- #include <com/sun/star/util/XNumberFormatsSupplier.hpp>
- #include <com/sun/star/util/XNumberFormats.hpp>
- #include <com/sun/star/util/NumberFormat.hpp>
- #include <com/sun/star/util/XNumberFormatTypes.hpp>
- #include <com/sun/star/lang/Locale.hpp>
- #include <com/sun/star/i18n/KParseType.hpp>
- #include <com/sun/star/i18n/KParseTokens.hpp>
- #include "connectivity/dbconversion.hxx"
- #include <com/sun/star/util/DateTime.hpp>
- #include <com/sun/star/util/Time.hpp>
- #include <com/sun/star/util/Date.hpp>
- #include "TConnection.hxx"
- #include "sqlscan.hxx"
- #include <comphelper/numbers.hxx>
- #include <comphelper/processfactory.hxx>
- #include <comphelper/stl_types.hxx>
- #include "connectivity/dbtools.hxx"
- #include "connectivity/dbmetadata.hxx"
- #include "connectivity/sqlerror.hxx"
- #include <tools/diagnose_ex.h>
- #include <string.h>
- #include <boost/bind.hpp>
- #include <algorithm>
- #include <functional>
- #include <rtl/logfile.hxx>
- #include <rtl/ustrbuf.hxx>
- using namespace ::com::sun::star::sdbc;
- using namespace ::com::sun::star::util;
- using namespace ::com::sun::star::beans;
- using namespace ::com::sun::star::sdb;
- using namespace ::com::sun::star::uno;
- using namespace ::com::sun::star::lang;
- using namespace ::com::sun::star::i18n;
- using namespace ::com::sun::star;
- using namespace ::osl;
- using namespace ::dbtools;
- using namespace ::comphelper;
- extern int SQLyyparse (void);
- extern ::rtl::OUString ConvertLikeToken(const ::connectivity::OSQLParseNode* pTokenNode, const ::connectivity::OSQLParseNode* pEscapeNode, sal_Bool bInternational);
- extern void setParser( ::connectivity::OSQLParser* );
- namespace
- {
- // -----------------------------------------------------------------------------
- sal_Bool lcl_saveConvertToNumber(const Reference< XNumberFormatter > & _xFormatter,sal_Int32 _nKey,const ::rtl::OUString& _sValue,double& _nrValue)
- {
- sal_Bool bRet = sal_False;
- try
- {
- _nrValue = _xFormatter->convertStringToNumber(_nKey, _sValue);
- bRet = sal_True;
- }
- catch(Exception&)
- {
- }
- return bRet;
- }
- // -----------------------------------------------------------------------------
- void replaceAndReset(connectivity::OSQLParseNode*& _pResetNode,connectivity::OSQLParseNode* _pNewNode)
- {
- _pResetNode->getParent()->replace(_pResetNode, _pNewNode);
- delete _pResetNode;
- _pResetNode = _pNewNode;
- }
- // -----------------------------------------------------------------------------
- /** quotes a string and search for quotes inside the string and replace them with the new quote
- @param rValue
- The value to be quoted.
- @param rQuot
- The quote
- @param rQuotToReplace
- The quote to replace with
- @return
- The quoted string.
- */
- ::rtl::OUString SetQuotation(const ::rtl::OUString& rValue, const ::rtl::OUString& rQuot, const ::rtl::OUString& rQuotToReplace)
- {
- ::rtl::OUString rNewValue = rQuot;
- rNewValue += rValue;
- sal_Int32 nIndex = (sal_Int32)-1; // Quotes durch zweifache Quotes ersetzen, sonst kriegt der Parser Probleme
- if (rQuot.getLength())
- {
- do
- {
- nIndex += 2;
- nIndex = rNewValue.indexOf(rQuot,nIndex);
- if(nIndex != -1)
- rNewValue = rNewValue.replaceAt(nIndex,rQuot.getLength(),rQuotToReplace);
- } while (nIndex != -1);
- }
- rNewValue += rQuot;
- return rNewValue;
- }
- }
- namespace connectivity
- {
- //=============================================================================
- struct OSQLParser_Data
- {
- ::com::sun::star::lang::Locale aLocale;
- ::connectivity::SQLError aErrors;
- OSQLParser_Data( const Reference< XMultiServiceFactory >& _xServiceFactory )
- :aErrors( _xServiceFactory )
- {
- }
- };
- //=============================================================================
- //= SQLParseNodeParameter
- //=============================================================================
- //-----------------------------------------------------------------------------
- SQLParseNodeParameter::SQLParseNodeParameter( const Reference< XConnection >& _rxConnection,
- const Reference< XNumberFormatter >& _xFormatter, const Reference< XPropertySet >& _xField,
- const Locale& _rLocale, const IParseContext* _pContext,
- bool _bIntl, bool _bQuote, sal_Char _cDecSep, bool _bPredicate, bool _bParseToSDBC )
- :rLocale(_rLocale)
- ,aMetaData( _rxConnection )
- ,pParser( NULL )
- ,pSubQueryHistory( new QueryNameSet )
- ,xFormatter(_xFormatter)
- ,xField(_xField)
- ,m_rContext( _pContext ? (const IParseContext&)(*_pContext) : (const IParseContext&)OSQLParser::s_aDefaultContext )
- ,cDecSep(_cDecSep)
- ,bQuote(_bQuote)
- ,bInternational(_bIntl)
- ,bPredicate(_bPredicate)
- ,bParseToSDBCLevel( _bParseToSDBC )
- {
- }
- //-----------------------------------------------------------------------------
- SQLParseNodeParameter::~SQLParseNodeParameter()
- {
- }
- //=============================================================================
- //= OSQLParseNode
- //=============================================================================
- //-----------------------------------------------------------------------------
- ::rtl::OUString OSQLParseNode::convertDateString(const SQLParseNodeParameter& rParam, const ::rtl::OUString& rString) const
- {
- RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "parse", "Ocke.Janssen@sun.com", "OSQLParseNode::convertDateString" );
- Date aDate = DBTypeConversion::toDate(rString);
- Reference< XNumberFormatsSupplier > xSupplier(rParam.xFormatter->getNumberFormatsSupplier());
- Reference< XNumberFormatTypes > xTypes(xSupplier->getNumberFormats(), UNO_QUERY);
- double fDate = DBTypeConversion::toDouble(aDate,DBTypeConversion::getNULLDate(xSupplier));
- sal_Int32 nKey = xTypes->getStandardIndex(rParam.rLocale) + 36; // XXX hack
- return rParam.xFormatter->convertNumberToString(nKey, fDate);
- }
- //-----------------------------------------------------------------------------
- ::rtl::OUString OSQLParseNode::convertDateTimeString(const SQLParseNodeParameter& rParam, const ::rtl::OUString& rString) const
- {
- RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "parse", "Ocke.Janssen@sun.com", "OSQLParseNode::convertDateTimeString" );
- DateTime aDate = DBTypeConversion::toDateTime(rString);
- Reference< XNumberFormatsSupplier > xSupplier(rParam.xFormatter->getNumberFormatsSupplier());
- Reference< XNumberFormatTypes > xTypes(xSupplier->getNumberFormats(), UNO_QUERY);
- double fDateTime = DBTypeConversion::toDouble(aDate,DBTypeConversion::getNULLDate(xSupplier));
- sal_Int32 nKey = xTypes->getStandardIndex(rParam.rLocale) + 51; // XXX hack
- return rParam.xFormatter->convertNumberToString(nKey, fDateTime);
- }
- //-----------------------------------------------------------------------------
- ::rtl::OUString OSQLParseNode::convertTimeString(const SQLParseNodeParameter& rParam, const ::rtl::OUString& rString) const
- {
- RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "parse", "Ocke.Janssen@sun.com", "OSQLParseNode::convertTimeString" );
- Time aTime = DBTypeConversion::toTime(rString);
- Reference< XNumberFormatsSupplier > xSupplier(rParam.xFormatter->getNumberFormatsSupplier());
- Reference< XNumberFormatTypes > xTypes(xSupplier->getNumberFormats(), UNO_QUERY);
- double fTime = DBTypeConversion::toDouble(aTime);
- sal_Int32 nKey = xTypes->getStandardIndex(rParam.rLocale) + 41; // XXX hack
- return rParam.xFormatter->convertNumberToString(nKey, fTime);
- }
- //-----------------------------------------------------------------------------
- void OSQLParseNode::parseNodeToStr(::rtl::OUString& rString,
- const Reference< XConnection >& _rxConnection,
- const IParseContext* pContext,
- sal_Bool _bIntl,
- sal_Bool _bQuote) const
- {
- RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "parse", "Ocke.Janssen@sun.com", "OSQLParseNode::parseNodeToStr" );
- parseNodeToStr(
- rString, _rxConnection, NULL, NULL,
- pContext ? pContext->getPreferredLocale() : OParseContext::getDefaultLocale(),
- pContext, _bIntl, _bQuote, '.', false, false );
- }
- //-----------------------------------------------------------------------------
- void OSQLParseNode::parseNodeToPredicateStr(::rtl::OUString& rString,
- const Reference< XConnection >& _rxConnection,
- const Reference< XNumberFormatter > & xFormatter,
- const ::com::sun::star::lang::Locale& rIntl,
- sal_Char _cDec,
- const IParseContext* pContext ) const
- {
- RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "parse", "Ocke.Janssen@sun.com", "OSQLParseNode::parseNodeToPredicateStr" );
- OSL_ENSURE(xFormatter.is(), "OSQLParseNode::parseNodeToPredicateStr:: no formatter!");
- if (xFormatter.is())
- parseNodeToStr(rString, _rxConnection, xFormatter, NULL, rIntl, pContext, sal_True, sal_True, _cDec, true, false);
- }
- //-----------------------------------------------------------------------------
- void OSQLParseNode::parseNodeToPredicateStr(::rtl::OUString& rString,
- const Reference< XConnection > & _rxConnection,
- const Reference< XNumberFormatter > & xFormatter,
- const Reference< XPropertySet > & _xField,
- const ::com::sun::star::lang::Locale& rIntl,
- sal_Char _cDec,
- const IParseContext* pContext ) const
- {
- RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "parse", "Ocke.Janssen@sun.com", "OSQLParseNode::parseNodeToPredicateStr" );
- OSL_ENSURE(xFormatter.is(), "OSQLParseNode::parseNodeToPredicateStr:: no formatter!");
- if (xFormatter.is())
- parseNodeToStr( rString, _rxConnection, xFormatter, _xField, rIntl, pContext, true, true, _cDec, true, false );
- }
- //-----------------------------------------------------------------------------
- void OSQLParseNode::parseNodeToStr(::rtl::OUString& rString,
- const Reference< XConnection > & _rxConnection,
- const Reference< XNumberFormatter > & xFormatter,
- const Reference< XPropertySet > & _xField,
- const ::com::sun::star::lang::Locale& rIntl,
- const IParseContext* pContext,
- bool _bIntl,
- bool _bQuote,
- sal_Char _cDecSep,
- bool _bPredicate,
- bool _bSubstitute) const
- {
- RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "parse", "Ocke.Janssen@sun.com", "OSQLParseNode::parseNodeToStr" );
- OSL_ENSURE( _rxConnection.is(), "OSQLParseNode::parseNodeToStr: invalid connection!" );
- if ( _rxConnection.is() )
- {
- ::rtl::OUStringBuffer sBuffer = rString;
- try
- {
- OSQLParseNode::impl_parseNodeToString_throw( sBuffer,
- SQLParseNodeParameter(
- _rxConnection, xFormatter, _xField, rIntl, pContext,
- _bIntl, _bQuote, _cDecSep, _bPredicate, _bSubstitute
- ) );
- }
- catch( const SQLException& )
- {
- OSL_ENSURE( false, "OSQLParseNode::parseNodeToStr: this should not throw!" );
- // our callers don't expect this method to throw anything. The only known situation
- // where impl_parseNodeToString_throw can throw is when there is a cyclic reference
- // in the sub queries, but this cannot be the case here, as we do not parse to
- // SDBC level.
- }
- rString = sBuffer.makeStringAndClear();
- }
- }
- //-----------------------------------------------------------------------------
- bool OSQLParseNode::parseNodeToExecutableStatement( ::rtl::OUString& _out_rString, const Reference< XConnection >& _rxConnection,
- OSQLParser& _rParser, ::com::sun::star::sdbc::SQLException* _pErrorHolder ) const
- {
- RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "parse", "Ocke.Janssen@sun.com", "OSQLParseNode::parseNodeToExecutableStatement" );
- OSL_PRECOND( _rxConnection.is(), "OSQLParseNode::parseNodeToExecutableStatement: invalid connection!" );
- SQLParseNodeParameter aParseParam( _rxConnection,
- NULL, NULL, OParseContext::getDefaultLocale(), NULL, false, true, '.', false, true );
- if ( aParseParam.aMetaData.supportsSubqueriesInFrom() )
- {
- Reference< XQueriesSupplier > xSuppQueries( _rxConnection, UNO_QUERY );
- OSL_ENSURE( xSuppQueries.is(), "OSQLParseNode::parseNodeToExecutableStatement: cannot substitute everything without a QueriesSupplier!" );
- if ( xSuppQueries.is() )
- aParseParam.xQueries = xSuppQueries->getQueries();
- }
- aParseParam.pParser = &_rParser;
- _out_rString = ::rtl::OUString();
- ::rtl::OUStringBuffer sBuffer;
- bool bSuccess = false;
- try
- {
- impl_parseNodeToString_throw( sBuffer, aParseParam );
- bSuccess = true;
- }
- catch( const SQLException& e )
- {
- if ( _pErrorHolder )
- *_pErrorHolder = e;
- }
- _out_rString = sBuffer.makeStringAndClear();
- return bSuccess;
- }
- //-----------------------------------------------------------------------------
- namespace
- {
- bool lcl_isAliasNamePresent( const OSQLParseNode& _rTableNameNode )
- {
- return OSQLParseNode::getTableRange(_rTableNameNode.getParent()).getLength() != 0;
- }
- }
- //-----------------------------------------------------------------------------
- void OSQLParseNode::impl_parseNodeToString_throw(::rtl::OUStringBuffer& rString, const SQLParseNodeParameter& rParam) const
- {
- RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "parse", "Ocke.Janssen@sun.com", "OSQLParseNode::getTableRange" );
- if ( isToken() )
- {
- parseLeaf(rString,rParam);
- return;
- }
- // einmal auswerten wieviel Subtrees dieser Knoten besitzt
- sal_uInt32 nCount = count();
- bool bHandled = false;
- switch ( getKnownRuleID() )
- {
- // special handling for parameters
- case parameter:
- {
- if(rString.getLength())
- rString.appendAscii(" ");
- if (nCount == 1) // ?
- m_aChildren[0]->impl_parseNodeToString_throw( rString, rParam );
- else if (nCount == 2) // :Name
- {
- m_aChildren[0]->impl_parseNodeToString_throw( rString, rParam );
- rString.append(m_aChildren[1]->m_aNodeValue);
- } // [Name]
- else
- {
- m_aChildren[0]->impl_parseNodeToString_throw( rString, rParam );
- rString.append(m_aChildren[1]->m_aNodeValue);
- rString.append(m_aChildren[2]->m_aNodeValue);
- }
- bHandled = true;
- }
- break;
- // table refs
- case table_ref:
- if ( ( nCount == 2 ) || ( nCount == 3 ) || ( nCount == 5 ) )
- {
- impl_parseTableRangeNodeToString_throw( rString, rParam );
- bHandled = true;
- }
- break;
- // table name - might be a query name
- case table_name:
- bHandled = impl_parseTableNameNodeToString_throw( rString, rParam );
- break;
- case as:
- if ( rParam.aMetaData.generateASBeforeCorrelationName() )
- rString.append(::rtl::OUString::createFromAscii( " AS" ));
- bHandled = true;
- break;
- case like_predicate:
- // je nachdem ob international angegeben wird oder nicht wird like anders behandelt
- // interanational: *, ? sind Platzhalter
- // sonst SQL92 konform: %, _
- impl_parseLikeNodeToString_throw( rString, rParam );
- bHandled = true;
- break;
- case general_set_fct:
- case set_fct_spec:
- case position_exp:
- case extract_exp:
- case length_exp:
- case char_value_fct:
- {
- if (!addDateValue(rString, rParam))
- {
- // Funktionsname nicht quoten
- SQLParseNodeParameter aNewParam(rParam);
- aNewParam.bQuote = ( SQL_ISRULE(this,length_exp) || SQL_ISRULE(this,char_value_fct) );
- m_aChildren[0]->impl_parseNodeToString_throw( rString, aNewParam );
- aNewParam.bQuote = rParam.bQuote;
- //aNewParam.bPredicate = sal_False; // disable [ ] around names // look at i73215
- ::rtl::OUStringBuffer aStringPara;
- for (sal_uInt32 i=1; i<nCount; i++)
- {
- const OSQLParseNode * pSubTree = m_aChildren[i];
- if (pSubTree)
- {
- pSubTree->impl_parseNodeToString_throw( aStringPara, aNewParam );
- // bei den CommaListen zwischen alle Subtrees Commas setzen
- if ((m_eNodeType == SQL_NODE_COMMALISTRULE) && (i < (nCount - 1)))
- aStringPara.appendAscii(",");
- }
- else
- i++;
- }
- rString.append(aStringPara.makeStringAndClear());
- }
- bHandled = true;
- }
- break;
- default:
- break;
- } // switch ( getKnownRuleID() )
- if ( !bHandled )
- {
- for (OSQLParseNodes::const_iterator i = m_aChildren.begin();
- i != m_aChildren.end();)
- {
- const OSQLParseNode* pSubTree = *i;
- if ( !pSubTree )
- {
- ++i;
- continue;
- }
- SQLParseNodeParameter aNewParam(rParam);
- // don't replace the field for subqueries
- if (rParam.xField.is() && SQL_ISRULE(pSubTree,subquery))
- aNewParam.xField = NULL;
- // if there is a field given we don't display the fieldname, if there is any
- if (rParam.xField.is() && SQL_ISRULE(pSubTree,column_ref))
- {
- sal_Bool bFilter = sal_False;
- // retrieve the fields name
- ::rtl::OUString aFieldName;
- try
- {
- sal_Int32 nNamePropertyId = PROPERTY_ID_NAME;
- if ( rParam.xField->getPropertySetInfo()->hasPropertyByName( OMetaConnection::getPropMap().getNameByIndex( PROPERTY_ID_REALNAME ) ) )
- nNamePropertyId = PROPERTY_ID_REALNAME;
- rParam.xField->getPropertyValue( OMetaConnection::getPropMap().getNameByIndex( nNamePropertyId ) ) >>= aFieldName;
- }
- catch ( Exception& )
- {
- }
- if(pSubTree->count())
- {
- const OSQLParseNode* pCol = pSubTree->m_aChildren[pSubTree->count()-1];
- if ( ( SQL_ISRULE(pCol,column_val)
- && pCol->getChild(0)->getTokenValue().equalsIgnoreAsciiCase(aFieldName)
- )
- || pCol->getTokenValue().equalsIgnoreAsciiCase(aFieldName)
- )
- bFilter = sal_True;
- }
- // ok we found the field, if the following node is the
- // comparision operator '=' we filter it as well
- if (bFilter)
- {
- if (SQL_ISRULE(this, comparison_predicate))
- {
- ++i;
- if(i != m_aChildren.end())
- {
- pSubTree = *i;
- if (pSubTree && pSubTree->getNodeType() == SQL_NODE_EQUAL)
- i++;
- }
- }
- else
- i++;
- }
- else
- {
- pSubTree->impl_parseNodeToString_throw( rString, aNewParam );
- i++;
- // bei den CommaListen zwischen alle Subtrees Commas setzen
- if ((m_eNodeType == SQL_NODE_COMMALISTRULE) && (i != m_aChildren.end()))
- rString.appendAscii(",");
- }
- }
- else
- {
- pSubTree->impl_parseNodeToString_throw( rString, aNewParam );
- i++;
- // bei den CommaListen zwischen alle Subtrees Commas setzen
- if ((m_eNodeType == SQL_NODE_COMMALISTRULE) && (i != m_aChildren.end()))
- {
- if (SQL_ISRULE(this,value_exp_commalist) && rParam.bPredicate)
- rString.appendAscii(";");
- else
- rString.appendAscii(",");
- }
- }
- }
- }
- }
- //-----------------------------------------------------------------------------
- bool OSQLParseNode::impl_parseTableNameNodeToString_throw( ::rtl::OUStringBuffer& rString, const SQLParseNodeParameter& rParam ) const
- {
- RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "parse", "Ocke.Janssen@sun.com", "OSQLParseNode::impl_parseTableNameNodeToString_throw" );
- // is the table_name part of a table_ref?
- OSL_ENSURE( getParent(), "OSQLParseNode::impl_parseTableNameNodeToString_throw: table_name without parent?" );
- if ( !getParent() || ( getParent()->getKnownRuleID() != table_ref ) )
- return false;
- // if it's a query, maybe we need to substitute the SQL statement ...
- if ( !rParam.bParseToSDBCLevel )
- return false;
- if ( !rParam.xQueries.is() )
- // connection does not support queries in queries, or was no query supplier
- return false;
- try
- {
- ::rtl::OUString sTableOrQueryName( getChild(0)->getTokenValue() );
- bool bIsQuery = rParam.xQueries->hasByName( sTableOrQueryName );
- if ( !bIsQuery )
- return false;
- // avoid recursion (e.g. "foo" defined as "SELECT * FROM bar" and "bar" defined as "SELECT * FROM foo".
- if ( rParam.pSubQueryHistory->find( sTableOrQueryName ) != rParam.pSubQueryHistory->end() )
- {
- ::rtl::OUString sMessage( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "cyclic sub queries" ) ) );
- OSL_ENSURE( rParam.pParser, "OSQLParseNode::impl_parseTableNameNodeToString_throw: no parser?" );
- if ( rParam.pParser )
- {
- const SQLError& rErrors( rParam.pParser->getErrorHelper() );
- rErrors.raiseException( sdb::ErrorCondition::PARSER_CYCLIC_SUB_QUERIES );
- }
- else
- {
- SQLError aErrors( ::comphelper::getProcessServiceFactory() );
- aErrors.raiseException( sdb::ErrorCondition::PARSER_CYCLIC_SUB_QUERIES );
- }
- }
- rParam.pSubQueryHistory->insert( sTableOrQueryName );
- Reference< XPropertySet > xQuery( rParam.xQueries->getByName( sTableOrQueryName ), UNO_QUERY_THROW );
- // substitute the query name with the constituting command
- ::rtl::OUString sCommand;
- OSL_VERIFY( xQuery->getPropertyValue( OMetaConnection::getPropMap().getNameByIndex( PROPERTY_ID_COMMAND ) ) >>= sCommand );
- sal_Bool bEscapeProcessing = sal_False;
- OSL_VERIFY( xQuery->getPropertyValue( OMetaConnection::getPropMap().getNameByIndex( PROPERTY_ID_ESCAPEPROCESSING ) ) >>= bEscapeProcessing );
- // the query we found here might itself be based on another query, so parse it recursively
- OSL_ENSURE( rParam.pParser, "OSQLParseNode::impl_parseTableNameNodeToString_throw: cannot analyze sub queries without a parser!" );
- if ( bEscapeProcessing && rParam.pParser )
- {
- ::rtl::OUString sError;
- ::std::auto_ptr< OSQLParseNode > pSubQueryNode( rParam.pParser->parseTree( sError, sCommand, sal_False ) );
- if ( pSubQueryNode.get() )
- {
- // parse the sub-select to SDBC level, too
- ::rtl::OUStringBuffer sSubSelect;
- pSubQueryNode->impl_parseNodeToString_throw( sSubSelect, rParam );
- if ( sSubSelect.getLength() )
- sCommand = sSubSelect.makeStringAndClear();
- }
- }
- rString.appendAscii( " ( " );
- rString.append(sCommand);
- rString.appendAscii( " )" );
- // append the query name as table alias, since it might be referenced in other
- // parts of the statement - but only if there's no other alias name present
- if ( !lcl_isAliasNamePresent( *this ) )
- {
- rString.appendAscii( " AS " );
- if ( rParam.bQuote )
- rString.append(SetQuotation( sTableOrQueryName,
- rParam.aMetaData.getIdentifierQuoteString(), rParam.aMetaData.getIdentifierQuoteString() ));
- }
- // don't forget to remove the query name from the history, else multiple inclusions
- // won't work
- // #i69227# / 2006-10-10 / frank.schoenheit@sun.com
- rParam.pSubQueryHistory->erase( sTableOrQueryName );
- return true;
- }
- catch( const SQLException& )
- {
- throw;
- }
- catch( const Exception& )
- {
- DBG_UNHANDLED_EXCEPTION();
- }
- return false;
- }
- //-----------------------------------------------------------------------------
- void OSQLParseNode::impl_parseTableRangeNodeToString_throw(::rtl::OUStringBuffer& rString, const SQLParseNodeParameter& rParam) const
- {
- RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "parse", "Ocke.Janssen@sun.com", "OSQLParseNode::impl_parseTableRangeNodeToString_throw" );
- OSL_PRECOND( ( count() == 2 ) || ( count() == 3 ) || ( count() == 5 ) ,"Illegal count");
-
- // rString += ::rtl::OUString::createFromAscii(" ");
- ::std::for_each(m_aChildren.begin(),m_aChildren.end(),
- boost::bind( &OSQLParseNode::impl_parseNodeToString_throw, _1, boost::ref( rString ), boost::cref( rParam ) ));
- }
- //-----------------------------------------------------------------------------
- void OSQLParseNode::impl_parseLikeNodeToString_throw( ::rtl::OUStringBuffer& rString, const SQLParseNodeParameter& rParam ) const
- {
- RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "parse", "Ocke.Janssen@sun.com", "OSQLParseNode::impl_parseLikeNodeToString_throw" );
- OSL_ENSURE(count() >= 4,"count != 5: Prepare for GPF");
- const OSQLParseNode* pEscNode = NULL;
- const OSQLParseNode* pParaNode = NULL;
- SQLParseNodeParameter aNewParam(rParam);
- //aNewParam.bQuote = sal_True; // why setting this to true? @see http://www.openoffice.org/issues/show_bug.cgi?id=75557
- // if there is a field given we don't display the fieldname, if there are any
- sal_Bool bAddName = sal_True;
- if (rParam.xField.is())
- {
- // retrieve the fields name
- ::rtl::OUString aFieldName;
- try
- {
- // retrieve the fields name
- rtl::OUString aString;
- rParam.xField->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME)) >>= aString;
- aFieldName = aString.getStr();
- }
- catch ( Exception& )
- {
- OSL_ENSURE( false, "OSQLParseNode::impl_parseLikeNodeToString_throw Exception occured!" );
- }
- if ( !m_aChildren[0]->isLeaf() )
- {
- const OSQLParseNode* pCol = m_aChildren[0]->getChild(m_aChildren[0]->count()-1);
- if ((SQL_ISRULE(pCol,column_val) && pCol->getChild(0)->getTokenValue().equalsIgnoreAsciiCase(aFieldName)) ||
- pCol->getTokenValue().equalsIgnoreAsciiCase(aFieldName) )
- bAddName = sal_False;
- }
- }
- if (bAddName)
- m_aChildren[0]->impl_parseNodeToString_throw( rString, aNewParam );
- m_aChildren[1]->impl_parseNodeToString_throw( rString, aNewParam );
- if(count() == 5)
- m_aChildren[2]->impl_parseNodeToString_throw( rString, aNewParam );
- sal_Int32 nCurentPos = m_aChildren.size()-2;
- pParaNode = m_aChildren[nCurentPos];
- pEscNode = m_aChildren[nCurentPos+1];
- if (pParaNode->isToken())
- {
- ::rtl::OUString aStr = ConvertLikeToken(pParaNode, pEscNode, rParam.bInternational);
- rString.appendAscii(" ");
- rString.append(SetQuotation(aStr,::rtl::OUString::createFromAscii("\'"),::rtl::OUString::createFromAscii("\'\'")));
- }
- else
- pParaNode->impl_parseNodeToString_throw( rString, aNewParam );
- pEscNode->impl_parseNodeToString_throw( rString, aNewParam );
- }
- // -----------------------------------------------------------------------------
- sal_Bool OSQLParseNode::getTableComponents(const OSQLParseNode* _pTableNode,
- ::com::sun::star::uno::Any &_rCatalog,
- ::rtl::OUString &_rSchema,
- ::rtl::OUString &_rTable,
- const Reference< XDatabaseMetaData >& _xMetaData)
- {
- RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "parse", "Ocke.Janssen@sun.com", "OSQLParseNode::getTableComponents" );
- OSL_ENSURE(_pTableNode,"Wrong use of getTableComponents! _pTableNode is not allowed to be null!");
- if(_pTableNode)
- {
- const sal_Bool bSupportsCatalog = _xMetaData.is() && _xMetaData->supportsCatalogsInDataManipulation();
- const sal_Bool bSupportsSchema = _xMetaData.is() && _xMetaData->supportsSchemasInDataManipulation();
- const OSQLParseNode* pTableNode = _pTableNode;
- // clear the parameter given
- _rCatalog = Any();
- _rSchema = _rTable = ::rtl::OUString();
- // see rule catalog_name: in sqlbison.y
- if (SQL_ISRULE(pTableNode,catalog_name))
- {
- OSL_ENSURE(pTableNode->getChild(0) && pTableNode->getChild(0)->isToken(),"Invalid parsenode!");
- _rCatalog <<= pTableNode->getChild(0)->getTokenValue();
- pTableNode = pTableNode->getChild(2);
- }
- // check if we have schema_name rule
- if(SQL_ISRULE(pTableNode,schema_name))
- {
- if ( bSupportsCatalog && !bSupportsSchema )
- _rCatalog <<= pTableNode->getChild(0)->getTokenValue();
- else
- _rSchema = pTableNode->getChild(0)->getTokenValue();
- pTableNode = pTableNode->getChild(2);
- }
- // check if we have table_name rule
- if(SQL_ISRULE(pTableNode,table_name))
- {
- _rTable = pTableNode->getChild(0)->getTokenValue();
- }
- else
- {
- OSL_ENSURE(0,"Error in parse tree!");
- }
- }
- return _rTable.getLength() != 0;
- }
- // -----------------------------------------------------------------------------
- void OSQLParser::killThousandSeparator(OSQLParseNode* pLiteral)
- {
- if ( pLiteral )
- {
- if ( s_xLocaleData->getLocaleItem( m_pData->aLocale ).decimalSeparator.toChar() == ',' )
- {
- pLiteral->m_aNodeValue = pLiteral->m_aNodeValue.replace('.', sal_Unicode());
- // and replace decimal
- pLiteral->m_aNodeValue = pLiteral->m_aNodeValue.replace(',', '.');
- }
- else
- pLiteral->m_aNodeValue = pLiteral->m_aNodeValue.replace(',', sal_Unicode());
- }
- }
- // -----------------------------------------------------------------------------
- OSQLParseNode* OSQLParser::convertNode(sal_Int32 nType,OSQLParseNode*& pLiteral)
- {
- if ( !pLiteral )
- return NULL;
- OSQLParseNode* pReturn = pLiteral;
- if ( ( pLiteral->isRule() && !SQL_ISRULE(pLiteral,value_exp) ) || SQL_ISTOKEN(pLiteral,FALSE) || SQL_ISTOKEN(pLiteral,TRUE) )
- {
- switch(nType)
- {
- case DataType::CHAR:
- case DataType::VARCHAR:
- case DataType::LONGVARCHAR:
- case DataType::CLOB:
- if ( !SQL_ISRULE(pReturn,char_value_exp) && !buildStringNodes(pReturn) )
- pReturn = NULL;
- default:
- break;
- }
- }
- else
- {
- switch(pLiteral->getNodeType())
- {
- case SQL_NODE_STRING:
- switch(nType)
- {
- case DataType::CHAR:
- case DataType::VARCHAR:
- case DataType::LONGVARCHAR:
- case DataType::CLOB:
- break;
- case DataType::DATE:
- case DataType::TIME:
- case DataType::TIMESTAMP:
- if (m_xFormatter.is())
- pReturn = buildDate( nType, pReturn);
- break;
- default:
- m_sErrorMessage = m_pContext->getErrorMessage(IParseContext::ERROR_INVALID_COMPARE);
- break;
- }
- break;
- case SQL_NODE_ACCESS_DATE:
- switch(nType)
- {
- case DataType::DATE:
- case DataType::TIME:
- case DataType::TIMESTAMP:
- if ( m_xFormatter.is() )
- pReturn = buildDate( nType, pReturn);
- else
- m_sErrorMessage = m_pContext->getErrorMessage(IParseContext::ERROR_INVALID_DATE_COMPARE);
- break;
- default:
- m_sErrorMessage = m_pContext->getErrorMessage(IParseContext::ERROR_INVALID_COMPARE);
- break;
- }
- break;
- case SQL_NODE_INTNUM:
- switch(nType)
- {
- case DataType::BIT:
- case DataType::BOOLEAN:
- case DataType::DECIMAL:
- case DataType::NUMERIC:
- case DataType::TINYINT:
- case DataType::SMALLINT:
- case DataType::INTEGER:
- case DataType::BIGINT:
- case DataType::FLOAT:
- case DataType::REAL:
- case DataType::DOUBLE:
- // kill thousand seperators if any
- killThousandSeparator(pReturn);
- break;
- case DataType::CHAR:
- case DataType::VARCHAR:
- case DataType::LONGVARCHAR:
- case DataType::CLOB:
- pReturn = buildNode_STR_NUM(pReturn);
- break;
- default:
- m_sErrorMessage = m_pContext->getErrorMessage(IParseContext::ERROR_INVALID_INT_COMPARE);
- break;
- }
- break;
- case SQL_NODE_APPROXNUM:
- switch(nType)
- {
- case DataType::DECIMAL:
- case DataType::NUMERIC:
- case DataType::FLOAT:
- case DataType::REAL:
- case DataType::DOUBLE:
- // kill thousand seperators if any
- killThousandSeparator(pReturn);
- break;
- case DataType::CHAR:
- case DataType::VARCHAR:
- case DataType::LONGVARCHAR:
- case DataType::CLOB:
- pReturn = buildNode_STR_NUM(pReturn);
- break;
- case DataType::INTEGER:
- default:
- m_sErrorMessage = m_pContext->getErrorMessage(IParseContext::ERROR_INVALID_REAL_COMPARE);
- break;
- }
- break;
- default:
- ;
- }
- }
- return pReturn;
- }
- // -----------------------------------------------------------------------------
- sal_Int16 OSQLParser::buildPredicateRule(OSQLParseNode*& pAppend,OSQLParseNode* pLiteral,OSQLParseNode*& pCompare,OSQLParseNode* pLiteral2)
- {
- OSL_ENSURE(inPredicateCheck(),"Only in predicate check allowed!");
- sal_Int16 nErg = 0;
- if ( m_xField.is() )
- {
- sal_Int32 nType = 0;
- try
- {
- m_xField->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPE)) >>= nType;
- }
- catch( Exception& )
- {
- return nErg;
- }
- OSQLParseNode* pNode1 = convertNode(nType,pLiteral);
- if ( pNode1 )
- {
- OSQLParseNode* pNode2 = convertNode(nType,pLiteral2);
- if ( !m_sErrorMessage.getLength() )
- nErg = buildNode(pAppend,pCompare,pNode1,pNode2);
- }
- }
- if (!pCompare->getParent()) // I have no parent so I was not used and I must die :-)
- delete pCompare;
- return nErg;
- }
- // -----------------------------------------------------------------------------
- sal_Int16 OSQLParser::buildLikeRule(OSQLParseNode*& pAppend, OSQLParseNode*& pLiteral, const OSQLParseNode* pEscape)
- {
- sal_Int16 nErg = 0;
- sal_Int32 nType = 0;
- if (!m_xField.is())
- return nErg;
- try
- {
- Any aValue;
- {
- aValue = m_xField->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPE));
- aValue >>= nType;
- }
- }
- catch( Exception& )
- {
- return nErg;
- }
- switch (nType)
- {
- case DataType::CHAR:
- case DataType::VARCHAR:
- case DataType::LONGVARCHAR:
- case DataType::CLOB:
- if(pLiteral->isRule())
- {
- pAppend->append(pLiteral);
- nErg = 1;
- }
- else
- {
- switch(pLiteral->getNodeType())
- {
- case SQL_NODE_STRING:
- pLiteral->m_aNodeValue = ConvertLikeToken(pLiteral, pEscape, sal_False);
- pAppend->append(pLiteral);
- nErg = 1;
- break;
- case SQL_NODE_APPROXNUM:
- if (m_xFormatter.is() && m_nFormatKey)
- {
- sal_Int16 nScale = 0;
- try
- {
- Any aValue = getNumberFormatProperty( m_xFormatter, m_nFormatKey, ::rtl::OUString::createFromAscii("Decimals") );
- aValue >>= nScale;
- }
- catch( Exception& )
- {
- }
- pAppend->append(new OSQLInternalNode(stringToDouble(pLiteral->getTokenValue(),nScale),SQL_NODE_STRING));
- }
- else
- pAppend->append(new OSQLInternalNode(pLiteral->getTokenValue(),SQL_NODE_STRING));
- delete pLiteral;
- nErg = 1;
- break;
- default:
- m_sErrorMessage = m_pContext->getErrorMessage(IParseContext::ERROR_VALUE_NO_LIKE);
- m_sErrorMessage = m_sErrorMessage.replaceAt(m_sErrorMessage.indexOf(::rtl::OUString::createFromAscii("#1")),2,pLiteral->getTokenValue());
- break;
- }
- }
- break;
- default:
- m_sErrorMessage = m_pContext->getErrorMessage(IParseContext::ERROR_FIELD_NO_LIKE);
- break;
- }
- return nErg;
- }
- //-----------------------------------------------------------------------------
- OSQLParseNode* OSQLParser::buildNode_Date(const double& fValue, sal_Int32 nType)
- {
- ::rtl::OUString aEmptyString;
- OSQLParseNode* pNewNode = new OSQLInternalNode(aEmptyString, SQL_NODE_RULE,OSQLParser::RuleID(OSQLParseNode::set_fct_spec));
- pNewNode->append(new OSQLInternalNode(::rtl::OUString::createFromAscii("{"), SQL_NODE_PUNCTUATION));
- OSQLParseNode* pDateNode = new OSQLInternalNode(aEmptyString, SQL_NODE_RULE,OSQLParser::RuleID(OSQLParseNode::odbc_fct_spec));
- pNewNode->append(pDateNode);
- pNewNode->append(new OSQLInternalNode(::rtl::OUString::createFromAscii("}"), SQL_NODE_PUNCTUATION));
- switch (nType)
- {
- case DataType::DATE:
- {
- Date aDate = DBTypeConversion::toDate(fValue,DBTypeConversion::getNULLDate(m_xFormatter->getNumberFormatsSupplier()));
- ::rtl::OUString aString = DBTypeConversion::toDateString(aDate);
- pDateNode->append(new OSQLInternalNode(aEmptyString, SQL_NODE_KEYWORD, SQL_TOKEN_D));
- pDateNode->append(new OSQLInternalNode(aString, SQL_NODE_STRING));
- break;
- }
- case DataType::TIME:
- {
- Time aTime = DBTypeConversion::toTime(fValue);
- ::rtl::OUString aString = DBTypeConversion::toTimeString(aTime);
- pDateNode->append(new OSQLInternalNode(aEmptyString, SQL_NODE_KEYWORD, SQL_TOKEN_T));
- pDateNode->append(new OSQLInternalNode(aString, SQL_NODE_STRING));
- break;
- }
- case DataType::TIMESTAMP:
- {
- DateTime aDateTime = DBTypeConversion::toDateTime(fValue,DBTypeConversion::getNULLDate(m_xFormatter->getNumberFormatsSupplier()));
- if (aDateTime.Seconds || aDateTime.Minutes || aDateTime.Hours)
- {
- ::rtl::OUString aString = DBTypeConversion::toDateTimeString(aDateTime);
- pDateNode->append(new OSQLInternalNode(aEmptyString, SQL_NODE_KEYWORD, SQL_TOKEN_TS));
- pDateNode->append(new OSQLInternalNode(aString, SQL_NODE_STRING));
- }
- else
- {
- Date aDate(aDateTime.Day,aDateTime.Month,aDateTime.Year);
- pDateNode->append(new OSQLInternalNode(aEmptyString, SQL_NODE_KEYWORD, SQL_TOKEN_D));
- pDateNode->append(new OSQLInternalNode(DBTypeConversion::toDateString(aDate), SQL_NODE_STRING));
- }
- break;
- }
- }
- return pNewNode;
- }
- // -----------------------------------------------------------------------------
- OSQLParseNode* OSQLParser::buildNode_STR_NUM(OSQLParseNode*& _pLiteral)
- {
- OSQLParseNode* pReturn = NULL;
- if ( _pLiteral )
- {
- if (m_nFormatKey)
- {
- sal_Int16 nScale = 0;
- ::rtl::OUString aDec;
- try
- {
- Any aValue = getNumberFormatProperty( m_xFormatter, m_nFormatKey, ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Decimals")) );
- aValue >>= nScale;
- }
- catch( Exception& )
- {
- }
- pReturn = new OSQLInternalNode(stringToDouble(_pLiteral->getTokenValue(),nScale),SQL_NODE_STRING);
- }
- else
- pReturn = new OSQLInternalNode(_pLiteral->getTokenValue(),SQL_NODE_STRING);
- delete _pLiteral;
- _pLiteral = NULL;
- }
- return pReturn;
- }
- // -----------------------------------------------------------------------------
- ::rtl::OUString OSQLParser::stringToDouble(const ::rtl::OUString& _rValue,sal_Int16 _nScale)
- {
- ::rtl::OUString aValue;
- if(!m_xCharClass.is())
- m_xCharClass = Reference<XCharacterClassification>(m_xServiceFactory->createInstance(::rtl::OUString::createFromAscii("com.sun.star.i18n.CharacterClassification")),UNO_QUERY);
- if(m_xCharClass.is() && s_xLocaleData.is())
- {
- try
- {
- ParseResult aResult = m_xCharClass->parsePredefinedToken(KParseType::ANY_NUMBER,_rValue,0,m_pData->aLocale,0,::rtl::OUString(),KParseType::ANY_NUMBER,::rtl::OUString());
- if((aResult.TokenType & KParseType::IDENTNAME) && aResult.EndPos == _rValue.getLength())
- {
- aValue = ::rtl::OUString::valueOf(aResult.Value);
- sal_Int32 nPos = aValue.lastIndexOf(::rtl::OUString::createFromAscii("."));
- if((nPos+_nScale) < aValue.getLength())
- aValue = aValue.replaceAt(nPos+_nScale,aValue.getLength()-nPos-_nScale,::rtl::OUString());
- aValue = aValue.replaceAt(aValue.lastIndexOf(::rtl::OUString::createFromAscii(".")),1,s_xLocaleData->getLocaleItem(m_pData->aLocale).decimalSeparator);
- return aValue;
- }
- }
- catch(Exception&)
- {
- }
- }
- return aValue;
- }
- // -----------------------------------------------------------------------------
- ::osl::Mutex& OSQLParser::getMutex()
- {
- static ::osl::Mutex aMutex;
- return aMutex;
- }
- //-----------------------------------------------------------------------------
- OSQLParseNode* OSQLParser::predicateTree(::rtl::OUString& rErrorMessage, const ::rtl::OUString& rStatement,
- const Reference< ::com::sun::star::util::XNumberFormatter > & xFormatter,
- const Reference< XPropertySet > & xField)
- {
- // mutex for parsing
- static ::osl::Mutex aMutex;
- // Guard the parsing
- ::osl::MutexGuard aGuard(getMutex());
- // must be reset
- setParser(this);
- // reset the parser
- m_xField = xField;
- m_xFormatter = xFormatter;
- if (m_xField.is())
- {
- sal_Int32 nType=0;
- try
- {
- // get the field name
- rtl::OUString aString;
- // retrieve the fields name
- // #75243# use the RealName of the column if there is any otherwise the name which could be the alias
- // of the field
- Reference< XPropertySetInfo> xInfo = m_xField->getPropertySetInfo();
- if ( xInfo->hasPropertyByName(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_REALNAME)))
- m_xField->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_REALNAME)) >>= aString;
- else
- m_xField->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME)) >>= aString;
- m_sFieldName = aString;
- // get the field format key
- if ( xInfo->hasPropertyByName(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_FORMATKEY)))
- m_xField->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_FORMATKEY)) >>= m_nFormatKey;
- else
- m_nFormatKey = 0;
- // get the field type
- m_xField->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPE)) >>= nType;
- }
- catch ( Exception& )
- {
- OSL_ASSERT(0);
- }
- if (m_nFormatKey && m_xFormatter.is())
- {
- Any aValue = getNumberFormatProperty( m_xFormatter, m_nFormatKey, OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_LOCALE) );
- OSL_ENSURE(aValue.getValueType() == ::getCppuType((const ::com::sun::star::lang::Locale*)0), "OSQLParser::PredicateTree : invalid language property !");
- if (aValue.getValueType() == ::getCppuType((const ::com::sun::star::lang::Locale*)0))
- aValue >>= m_pData->aLocale;
- }
- else
- m_pData->aLocale = m_pContext->getPreferredLocale();
- if ( m_xFormatter.is() )
- {
- try
- {
- Reference< ::com::sun::star::util::XNumberFormatsSupplier > xFormatSup = m_xFormatter->getNumberFormatsSupplier();
- if ( xFormatSup.is() )
- {
- Reference< ::com::sun::star::util::XNumberFormats > xFormats = xFormatSup->getNumberFormats();
- if ( xFormats.is() )
- {
- ::com::sun::star::lang::Locale aLocale;
- aLocale.Language = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("en"));
- aLocale.Country = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("US"));
- ::rtl::OUString sFormat(RTL_CONSTASCII_USTRINGPARAM("YYYY-MM-DD"));
- m_nDateFormatKey = xFormats->queryKey(sFormat,aLocale,sal_False);
- if ( m_nDateFormatKey == sal_Int32(-1) )
- m_nDateFormatKey = xFormats->addNew(sFormat, aLocale);
- }
- }
- }
- catch ( Exception& )
- {
- OSL_ENSURE(0,"DateFormatKey");
- }
- }
- switch (nType)
- {
- case DataType::DATE:
- case DataType::TIME:
- case DataType::TIMESTAMP:
- s_pScanner->SetRule(s_pScanner->GetDATERule());
- break;
- case DataType::CHAR:
- case DataType::VARCHAR:
- case DataType::LONGVARCHAR:
- case DataType::CLOB:
- s_pScanner->SetRule(s_pScanner->GetSTRINGRule());
- break;
- default:
- if ( s_xLocaleData->getLocaleItem( m_pData->aLocale ).decimalSeparator.toChar() == ',' )
- s_pScanner->SetRule(s_pScanner->GetGERRule());
- else
- s_pScanner->SetRule(s_pScanner->GetENGRule());
- }
- }
- else
- s_pScanner->SetRule(s_pScanner->GetSQLRule());
- s_pScanner->prepareScan(rStatement, m_pContext, sal_True);
- SQLyylval.pParseNode = NULL;
- // SQLyypvt = NULL;
- m_pParseTree = NULL;
- m_sErrorMessage= ::rtl::OUString();
- // ... und den Parser anwerfen ...
- if (SQLyyparse() != 0)
- {
- m_sFieldName= ::rtl::OUString();
- m_xField.clear();
- m_xFormatter.clear();
- m_nFormatKey = 0;
- m_nDateFormatKey = 0;
- if (!m_sErrorMessage.getLength())
- m_sErrorMessage = s_pScanner->getErrorMessage();
- if (!m_sErrorMessage.getLength())
- m_sErrorMessage = m_pContext->getErrorMessage(IParseContext::ERROR_GENERAL);
- rErrorMessage = m_sErrorMessage;
- // clear the garbage collector
- (*s_pGarbageCollector)->clearAndDelete();
- return NULL;
- }
- else
- {
- (*s_pGarbageCollector)->clear();
- m_sFieldName= ::rtl::OUString();
- m_xField.clear();
- m_xFormatter.clear();
- m_nFormatKey = 0;
- m_nDateFormatKey = 0;
- // Das Ergebnis liefern (den Root Parse Node):
- // Stattdessen setzt die Parse-Routine jetzt den Member pParseTree
- // - einfach diesen zurueckliefern:
- OSL_ENSURE(m_pParseTree != NULL,"OSQLParser: Parser hat keinen ParseTree geliefert");
- return m_pParseTree;
- }
- }
- //=============================================================================
- //-----------------------------------------------------------------------------
- OSQLParser::OSQLParser(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _xServiceFactory,const IParseContext* _pContext)
- :m_pContext(_pContext)
- ,m_pParseTree(NULL)
- ,m_pData( new OSQLParser_Data( _xServiceFactory ) )
- ,m_nFormatKey(0)
- ,m_nDateFormatKey(0)
- ,m_xServiceFactory(_xServiceFactory)
- {
- setParser(this);
- #ifdef SQLYYDEBUG
- #ifdef SQLYYDEBUG_ON
- SQLyydebug = 1;
- #endif
- #endif
- ::osl::MutexGuard aGuard(getMutex());
- // do we have to initialize the data
- if (s_nRefCount == 0)
- {
- s_pScanner = new OSQLScanner();
- s_pScanner->setScanner();
- s_pGarbageCollector = new OSQLParseNodesGarbageCollector();
- if(!s_xLocaleData.is())
- s_xLocaleData = Reference<XLocaleData>(m_xServiceFactory->createInstance(::rtl::OUString::createFromAscii("com.sun.star.i18n.LocaleData")),UNO_QUERY);
- // auf 0 zuruecksetzen
- memset(OSQLParser::s_nRuleIDs,0,sizeof(OSQLParser::s_nRuleIDs[0]) * (OSQLParseNode::rule_count+1));
- struct
- {
- OSQLParseNode::Rule eRule; // the parse node's ID for the rule
- ::rtl::OString sRuleName; // the name of the rule ("select_statement")
- } aRuleDescriptions[] =
- {
- { OSQLParseNode::select_statement, "select_statement" },
- { OSQLParseNode::table_exp, "table_exp" },
- { OSQLParseNode::table_ref_commalist, "table_ref_commalist" },
- { OSQLParseNode::table_ref, "table_ref" },
- { OSQLParseNode::catalog_name, "catalog_name" },
- { OSQLParseNode::schema_name, "schema_name" },
- { OSQLParseNode::table_name, "table_name" },
- { OSQLParseNode::opt_column_commalist, "opt_column_commalist" },
- { OSQLParseNode::column_commalist, "column_commalist" },
- { OSQLParseNode::column_ref_commalist, "column_ref_commalist" },
- { OSQLParseNode::column_ref, "column_ref" },
- { OSQLParseNode::opt_order_by_clause, "opt_order_by_clause" },
- { OSQLParseNode::ordering_spec_commalist, "ordering_spec_commalist" },
- { OSQLParseNode::ordering_spec, "ordering_spec" },
- { OSQLParseNode::opt_asc_desc, "opt_asc_desc" },
- { OSQLParseNode::where_clause, "where_clause" },
- { OSQLParseNode::opt_where_clause, "opt_where_clause" },
- { OSQLParseNode::search_condition, "search_condition" },
- { OSQLParseNode::comparison_predicate, "comparison_predicate" },
- { OSQLParseNode::between_predicate, "between_predicate" },
- { OSQLParseNode::like_predicate, "like_predicate" },
- { OSQLParseNode::opt_escape, "opt_escape" },
- { OSQLParseNode::test_for_null, "test_for_null" },
- { OSQLParseNode::scalar_exp_commalist, "scalar_exp_commalist" },
- { OSQLParseNode::scalar_exp, "scalar_exp" },
- { OSQLParseNode::parameter_ref, "parameter_ref" },
- { OSQLParseNode::parameter, "parameter" },
- { OSQLParseNode::general_set_fct, "general_set_fct" },
- { OSQLParseNode::range_vari…
Large files files are truncated, but you can click here to view the full file