LCOV - code coverage report
Current view: top level - connectivity/source/drivers/file - fcomp.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 99 437 22.7 %
Date: 2015-06-13 12:38:46 Functions: 9 15 60.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 "file/fcomp.hxx"
      21             : #include <tools/debug.hxx>
      22             : #include "TConnection.hxx"
      23             : #include <connectivity/sqlparse.hxx>
      24             : #include "file/fanalyzer.hxx"
      25             : #include <com/sun/star/sdbc/XColumnLocate.hpp>
      26             : #include <com/sun/star/util/DateTime.hpp>
      27             : #include <com/sun/star/util/Date.hpp>
      28             : #include <com/sun/star/util/Time.hpp>
      29             : #include <connectivity/dbexception.hxx>
      30             : #include <connectivity/dbconversion.hxx>
      31             : #include <com/sun/star/sdb/SQLFilterOperator.hpp>
      32             : #include "resource/file_res.hrc"
      33             : #include "file/FStringFunctions.hxx"
      34             : #include "file/FDateFunctions.hxx"
      35             : #include "file/FNumericFunctions.hxx"
      36             : #include "file/FConnection.hxx"
      37             : #include "sqlbison.hxx"
      38             : 
      39             : using namespace connectivity;
      40             : using namespace connectivity::file;
      41             : using namespace com::sun::star::uno;
      42             : using namespace com::sun::star::sdbc;
      43             : using namespace com::sun::star::sdb;
      44             : using namespace ::com::sun::star::container;
      45             : using namespace com::sun::star;
      46             : 
      47          58 : OPredicateCompiler::OPredicateCompiler(OSQLAnalyzer* pAnalyzer)//,OCursor& rCurs)
      48             :                      : m_pAnalyzer(pAnalyzer)
      49             :                      , m_nParamCounter(0)
      50          58 :                      , m_bORCondition(false)
      51             : {
      52          58 : }
      53             : 
      54             : 
      55         174 : OPredicateCompiler::~OPredicateCompiler()
      56             : {
      57          58 :     Clean();
      58         116 : }
      59             : 
      60          58 : void OPredicateCompiler::dispose()
      61             : {
      62          58 :     Clean();
      63          58 :     m_orgColumns        = NULL;
      64          58 :     m_xIndexes.clear();
      65          58 : }
      66             : 
      67          58 : void OPredicateCompiler::start(OSQLParseNode* pSQLParseNode)
      68             : {
      69          58 :     if (!pSQLParseNode)
      70           0 :         return;
      71             : 
      72          58 :     m_nParamCounter = 0;
      73             :     // analyse Parse Tree (depending on Statement-type)
      74             :     // and set pointer on WHERE-clause:
      75          58 :     OSQLParseNode * pWhereClause = NULL;
      76             : 
      77          58 :     if (SQL_ISRULE(pSQLParseNode,select_statement))
      78             :     {
      79          58 :         OSQLParseNode * pOrderbyClause = NULL;
      80             :         DBG_ASSERT(pSQLParseNode->count() >= 4,"OFILECursor: Fehler im Parse Tree");
      81             : 
      82          58 :         OSQLParseNode * pTableExp = pSQLParseNode->getChild(3);
      83             :         DBG_ASSERT(pTableExp != NULL,"Fehler im Parse Tree");
      84             :         DBG_ASSERT(SQL_ISRULE(pTableExp,table_exp)," Fehler im Parse Tree");
      85             :         DBG_ASSERT(pTableExp->count() == TABLE_EXPRESSION_CHILD_COUNT,"Fehler im Parse Tree");
      86             : 
      87             :         // check that we don't use anything other than count(*) as function
      88          58 :         OSQLParseNode* pSelection = pSQLParseNode->getChild(2);
      89          58 :         if ( SQL_ISRULE(pSelection,scalar_exp_commalist) )
      90             :         {
      91          36 :             for (size_t i = 0; i < pSelection->count(); i++)
      92             :             {
      93          20 :                 OSQLParseNode *pColumnRef = pSelection->getChild(i)->getChild(0);
      94          20 :                 if ( SQL_ISRULE(pColumnRef,general_set_fct) && pColumnRef->count() != 4 )
      95             :                 {
      96           0 :                     m_pAnalyzer->getConnection()->throwGenericSQLException(STR_QUERY_COMPLEX_COUNT,NULL);
      97             :                 }
      98             :             }
      99             :         }
     100             : 
     101             : 
     102          58 :         pWhereClause    = pTableExp->getChild(1);
     103          58 :         pOrderbyClause  = pTableExp->getChild(ORDER_BY_CHILD_POS);
     104             :         (void)pOrderbyClause;
     105             :     }
     106           0 :     else if (SQL_ISRULE(pSQLParseNode,update_statement_searched))
     107             :     {
     108             :         DBG_ASSERT(pSQLParseNode->count() == 5,"OFILECursor: Fehler im Parse Tree");
     109           0 :         pWhereClause = pSQLParseNode->getChild(4);
     110             :     }
     111           0 :     else if (SQL_ISRULE(pSQLParseNode,delete_statement_searched))
     112             :     {
     113             :         DBG_ASSERT(pSQLParseNode->count() == 4,"Fehler im Parse Tree");
     114           0 :         pWhereClause = pSQLParseNode->getChild(3);
     115             :     }
     116             :     else
     117             :             // Other Statement. no selection-criteria
     118           0 :         return;
     119             : 
     120          58 :     if (SQL_ISRULE(pWhereClause,where_clause))
     121             :     {
     122             :         // a where-clause is not allowed to be empty:
     123             :         DBG_ASSERT(pWhereClause->count() == 2,"OFILECursor: Fehler im Parse Tree");
     124             : 
     125          35 :         OSQLParseNode * pComparisonPredicate = pWhereClause->getChild(1);
     126             :         DBG_ASSERT(pComparisonPredicate != NULL,"OFILECursor: Fehler im Parse Tree");
     127             : 
     128          35 :         execute( pComparisonPredicate );
     129             :     }
     130             :     else
     131             :     {
     132             :         // The where-clause is optionally in the majority of cases, i.e. it might be an "optional-where-clause".
     133             :         DBG_ASSERT(SQL_ISRULE(pWhereClause,opt_where_clause),"OPredicateCompiler: Fehler im Parse Tree");
     134             :     }
     135             : }
     136             : 
     137             : 
     138         166 : OOperand* OPredicateCompiler::execute(OSQLParseNode* pPredicateNode)
     139             : {
     140         166 :     OOperand* pOperand = NULL;
     141         422 :     if (pPredicateNode->count() == 3 &&                         // Expression is bracketed
     142         313 :         SQL_ISPUNCTUATION(pPredicateNode->getChild(0),"(") &&
     143          98 :         SQL_ISPUNCTUATION(pPredicateNode->getChild(2),")"))
     144             :     {
     145          49 :         execute(pPredicateNode->getChild(1));
     146             :     }
     147         291 :     else if ((SQL_ISRULE(pPredicateNode,search_condition) || (SQL_ISRULE(pPredicateNode,boolean_term)))
     148         120 :                             &&          // AND/OR-linkage:
     149           3 :                             pPredicateNode->count() == 3)
     150             :     {
     151           3 :         execute(pPredicateNode->getChild(0));                           // process the left branch
     152           3 :         execute(pPredicateNode->getChild(2));                           // process the right branch
     153             : 
     154           3 :         if (SQL_ISTOKEN(pPredicateNode->getChild(1),OR))                // OR-Operator
     155             :         {
     156           0 :             m_aCodeList.push_back(new OOp_OR());
     157           0 :             m_bORCondition = true;
     158             :         }
     159           3 :         else if (SQL_ISTOKEN(pPredicateNode->getChild(1),AND))      // AND-Operator
     160           3 :             m_aCodeList.push_back(new OOp_AND());
     161             :         else
     162             :         {
     163             :             OSL_FAIL("OPredicateCompiler: Fehler im Parse Tree");
     164             :         }
     165             :     }
     166         114 :     else if (SQL_ISRULE(pPredicateNode,boolean_factor))
     167             :     {
     168           0 :         execute(pPredicateNode->getChild(1));
     169           0 :         m_aCodeList.push_back(new OOp_NOT());
     170             :     }
     171         114 :     else if (SQL_ISRULE(pPredicateNode,comparison_predicate))
     172             :     {
     173          38 :         execute_COMPARE(pPredicateNode);
     174             :     }
     175          76 :     else if (SQL_ISRULE(pPredicateNode,like_predicate))
     176             :     {
     177           0 :         execute_LIKE(pPredicateNode);
     178             :     }
     179          76 :     else if (SQL_ISRULE(pPredicateNode,between_predicate))
     180             :     {
     181           0 :         execute_BETWEEN(pPredicateNode);
     182             :     }
     183          76 :     else if (SQL_ISRULE(pPredicateNode,test_for_null))
     184             :     {
     185           0 :         execute_ISNULL(pPredicateNode);
     186             :     }
     187          76 :     else if(SQL_ISRULE(pPredicateNode,num_value_exp))
     188             :     {
     189           0 :         execute(pPredicateNode->getChild(0));                           // process the left branch
     190           0 :         execute(pPredicateNode->getChild(2));                           // process the right branch
     191           0 :         if (SQL_ISPUNCTUATION(pPredicateNode->getChild(1),"+"))
     192             :         {
     193           0 :             m_aCodeList.push_back(new OOp_ADD());
     194             :         }
     195           0 :         else if (SQL_ISPUNCTUATION(pPredicateNode->getChild(1),"-"))
     196           0 :             m_aCodeList.push_back(new OOp_SUB());
     197             :         else
     198             :         {
     199             :             OSL_FAIL("OPredicateCompiler: Fehler im Parse Tree num_value_exp");
     200             :         }
     201             :     }
     202          76 :     else if(SQL_ISRULE(pPredicateNode,term))
     203             :     {
     204           0 :         execute(pPredicateNode->getChild(0));                           // process the left branch
     205           0 :         execute(pPredicateNode->getChild(2));                           // process the right branch
     206           0 :         if (SQL_ISPUNCTUATION(pPredicateNode->getChild(1),"*"))
     207             :         {
     208           0 :             m_aCodeList.push_back(new OOp_MUL());
     209             :         }
     210           0 :         else if (SQL_ISPUNCTUATION(pPredicateNode->getChild(1),"/"))
     211           0 :             m_aCodeList.push_back(new OOp_DIV());
     212             :         else
     213             :         {
     214             :             OSL_FAIL("OPredicateCompiler: Fehler im Parse Tree num_value_exp");
     215             :         }
     216             :     }
     217             :     else
     218          76 :         pOperand = execute_Operand(pPredicateNode);                     // now only simple operands will be processed
     219             : 
     220         166 :     return pOperand;
     221             : }
     222             : 
     223             : 
     224          38 : OOperand* OPredicateCompiler::execute_COMPARE(OSQLParseNode* pPredicateNode)  throw(SQLException, RuntimeException)
     225             : {
     226             :     DBG_ASSERT(pPredicateNode->count() == 3,"OFILECursor: Fehler im Parse Tree");
     227             : 
     228         114 :     if ( !(SQL_ISRULE(pPredicateNode->getChild(0),column_ref)               ||
     229          60 :           pPredicateNode->getChild(2)->getNodeType() == SQL_NODE_STRING     ||
     230          30 :           pPredicateNode->getChild(2)->getNodeType() == SQL_NODE_INTNUM     ||
     231           0 :           pPredicateNode->getChild(2)->getNodeType() == SQL_NODE_APPROXNUM  ||
     232           0 :           SQL_ISTOKEN(pPredicateNode->getChild(2),TRUE)                     ||
     233           0 :           SQL_ISTOKEN(pPredicateNode->getChild(2),FALSE)                    ||
     234           0 :           SQL_ISRULE(pPredicateNode->getChild(2),parameter)                 ||
     235             :           // odbc date
     236           0 :           SQL_ISRULE(pPredicateNode->getChild(2),set_fct_spec)              ||
     237           0 :           SQL_ISRULE(pPredicateNode->getChild(2),position_exp)              ||
     238           0 :           SQL_ISRULE(pPredicateNode->getChild(2),char_substring_fct)        ||
     239             :           // upper, lower etc.
     240          38 :           SQL_ISRULE(pPredicateNode->getChild(2),fold)) )
     241             :     {
     242           0 :         m_pAnalyzer->getConnection()->throwGenericSQLException(STR_QUERY_TOO_COMPLEX,NULL);
     243           0 :         return NULL;
     244             :     }
     245             : 
     246          38 :     sal_Int32 ePredicateType( SQLFilterOperator::EQUAL );
     247          38 :     OSQLParseNode *pPrec = pPredicateNode->getChild(1);
     248             : 
     249          38 :     if (pPrec->getNodeType() == SQL_NODE_EQUAL)
     250          38 :         ePredicateType = SQLFilterOperator::EQUAL;
     251           0 :     else if (pPrec->getNodeType() == SQL_NODE_NOTEQUAL)
     252           0 :         ePredicateType = SQLFilterOperator::NOT_EQUAL;
     253           0 :     else if (pPrec->getNodeType() == SQL_NODE_LESS)
     254           0 :         ePredicateType = SQLFilterOperator::LESS;
     255           0 :     else if (pPrec->getNodeType() == SQL_NODE_LESSEQ)
     256           0 :         ePredicateType = SQLFilterOperator::LESS_EQUAL;
     257           0 :     else if (pPrec->getNodeType() == SQL_NODE_GREATEQ)
     258           0 :         ePredicateType = SQLFilterOperator::GREATER_EQUAL;
     259           0 :     else if (pPrec->getNodeType() == SQL_NODE_GREAT)
     260           0 :         ePredicateType = SQLFilterOperator::GREATER;
     261             :     else
     262             :         OSL_FAIL( "OPredicateCompiler::execute_COMPARE: unexpected node type!" );
     263             : 
     264          38 :     execute(pPredicateNode->getChild(0));
     265          38 :     execute(pPredicateNode->getChild(2));
     266          38 :     m_aCodeList.push_back( new OOp_COMPARE(ePredicateType) );
     267             : 
     268          38 :     return NULL;
     269             : }
     270             : 
     271             : 
     272           0 : OOperand* OPredicateCompiler::execute_LIKE(OSQLParseNode* pPredicateNode) throw(SQLException, RuntimeException)
     273             : {
     274             :     DBG_ASSERT(pPredicateNode->count() == 2,"OFILECursor: Fehler im Parse Tree");
     275           0 :     const OSQLParseNode* pPart2 = pPredicateNode->getChild(1);
     276             : 
     277           0 :     sal_Unicode cEscape = L'\0';
     278           0 :     const bool bNotLike = pPart2->getChild(0)->isToken();
     279             : 
     280           0 :     OSQLParseNode* pAtom        = pPart2->getChild(pPart2->count()-2);
     281           0 :     OSQLParseNode* pOptEscape   = pPart2->getChild(pPart2->count()-1);
     282             : 
     283           0 :     if (!(pAtom->getNodeType() == SQL_NODE_STRING   ||
     284           0 :           SQL_ISRULE(pAtom,parameter)               ||
     285             :           // odbc date
     286           0 :           SQL_ISRULE(pAtom,set_fct_spec)            ||
     287           0 :           SQL_ISRULE(pAtom,position_exp)            ||
     288           0 :           SQL_ISRULE(pAtom,char_substring_fct)      ||
     289             :           // upper, lower etc.
     290           0 :           SQL_ISRULE(pAtom,fold)) )
     291             :     {
     292           0 :         m_pAnalyzer->getConnection()->throwGenericSQLException(STR_QUERY_TOO_COMPLEX,NULL);
     293           0 :         return NULL;
     294             :     }
     295             : 
     296           0 :     if (pOptEscape->count() != 0)
     297             :     {
     298           0 :         if (pOptEscape->count() != 2)
     299             :         {
     300           0 :             m_pAnalyzer->getConnection()->throwGenericSQLException(STR_QUERY_INVALID_LIKE_STRING,NULL);
     301             :         }
     302           0 :         OSQLParseNode *pEscNode = pOptEscape->getChild(1);
     303           0 :         if (pEscNode->getNodeType() != SQL_NODE_STRING)
     304             :         {
     305           0 :             m_pAnalyzer->getConnection()->throwGenericSQLException(STR_QUERY_INVALID_LIKE_STRING,NULL);
     306             :         }
     307             :         else
     308           0 :             cEscape = pEscNode->getTokenValue().toChar();
     309             :     }
     310             : 
     311           0 :     execute(pPredicateNode->getChild(0));
     312           0 :     execute(pAtom);
     313             : 
     314             :     OBoolOperator* pOperator = bNotLike
     315           0 :                                     ? new OOp_NOTLIKE(cEscape)
     316           0 :                                     : new OOp_LIKE(cEscape);
     317           0 :     m_aCodeList.push_back(pOperator);
     318             : 
     319           0 :     return NULL;
     320             : }
     321             : 
     322           0 : OOperand* OPredicateCompiler::execute_BETWEEN(OSQLParseNode* pPredicateNode) throw(SQLException, RuntimeException)
     323             : {
     324             :     DBG_ASSERT(pPredicateNode->count() == 2,"OFILECursor: Fehler im Parse Tree");
     325             : 
     326           0 :     OSQLParseNode* pColumn = pPredicateNode->getChild(0);
     327           0 :     const OSQLParseNode* pPart2 = pPredicateNode->getChild(1);
     328           0 :     OSQLParseNode* p1stValue = pPart2->getChild(2);
     329           0 :     OSQLParseNode* p2ndtValue = pPart2->getChild(4);
     330             : 
     331           0 :     if (
     332           0 :             !(p1stValue->getNodeType() == SQL_NODE_STRING || SQL_ISRULE(p1stValue,parameter))
     333           0 :         &&  !(p2ndtValue->getNodeType() == SQL_NODE_STRING || SQL_ISRULE(p2ndtValue,parameter))
     334             :         )
     335             :     {
     336           0 :         m_pAnalyzer->getConnection()->throwGenericSQLException(STR_QUERY_INVALID_BETWEEN,NULL);
     337             :     }
     338             : 
     339           0 :     bool bNot = SQL_ISTOKEN(pPart2->getChild(0),NOT);
     340             : 
     341           0 :     OOperand* pColumnOp = execute(pColumn);
     342           0 :     OOperand* pOb1 = execute(p1stValue);
     343           0 :     OBoolOperator* pOperator = new OOp_COMPARE(bNot ? SQLFilterOperator::LESS_EQUAL : SQLFilterOperator::GREATER);
     344           0 :     m_aCodeList.push_back(pOperator);
     345             : 
     346           0 :     execute(pColumn);
     347           0 :     OOperand* pOb2 = execute(p2ndtValue);
     348           0 :     pOperator = new OOp_COMPARE(bNot ? SQLFilterOperator::GREATER_EQUAL : SQLFilterOperator::LESS);
     349           0 :     m_aCodeList.push_back(pOperator);
     350             : 
     351           0 :     if ( pColumnOp && pOb1 && pOb2 )
     352             :     {
     353           0 :         switch(pColumnOp->getDBType())
     354             :         {
     355             :             case DataType::CHAR:
     356             :             case DataType::VARCHAR:
     357             :             case DataType::LONGVARCHAR:
     358           0 :                 pOb1->setValue(pOb1->getValue().getString());
     359           0 :                 pOb2->setValue(pOb2->getValue().getString());
     360           0 :                 break;
     361             :             case DataType::DECIMAL:
     362             :             case DataType::NUMERIC:
     363           0 :                 pOb1->setValue((double)pOb1->getValue());
     364           0 :                 pOb2->setValue((double)pOb2->getValue());
     365           0 :                 break;
     366             :             case DataType::FLOAT:
     367           0 :                 pOb1->setValue((float)pOb1->getValue());
     368           0 :                 pOb2->setValue((float)pOb2->getValue());
     369           0 :                 break;
     370             :             case DataType::DOUBLE:
     371             :             case DataType::REAL:
     372           0 :                 pOb1->setValue((double)pOb1->getValue());
     373           0 :                 pOb2->setValue((double)pOb2->getValue());
     374           0 :                 break;
     375             :             case DataType::DATE:
     376           0 :                 pOb1->setValue(static_cast<util::Date>(pOb1->getValue()));
     377           0 :                 pOb2->setValue(static_cast<util::Date>(pOb2->getValue()));
     378           0 :                 break;
     379             :             case DataType::TIME:
     380           0 :                 pOb1->setValue(static_cast<util::Time>(pOb1->getValue()));
     381           0 :                 pOb2->setValue(static_cast<util::Time>(pOb2->getValue()));
     382           0 :                 break;
     383             :             case DataType::TIMESTAMP:
     384           0 :                 pOb1->setValue(static_cast<util::DateTime>(pOb1->getValue()));
     385           0 :                 pOb2->setValue(static_cast<util::DateTime>(pOb2->getValue()));
     386           0 :                 break;
     387             :         }
     388             :     }
     389             : 
     390             : 
     391             : 
     392           0 :     OBoolOperator* pBoolOp = NULL;
     393           0 :     if ( bNot )
     394           0 :         pBoolOp = new OOp_OR();
     395             :     else
     396           0 :         pBoolOp = new OOp_AND();
     397           0 :     m_aCodeList.push_back(pBoolOp);
     398             : 
     399           0 :     return NULL;
     400             : }
     401             : 
     402           0 : OOperand* OPredicateCompiler::execute_ISNULL(OSQLParseNode* pPredicateNode) throw(SQLException, RuntimeException)
     403             : {
     404             :     DBG_ASSERT(pPredicateNode->count() == 2,"OFILECursor: Fehler im Parse Tree");
     405           0 :     const OSQLParseNode* pPart2 = pPredicateNode->getChild(1);
     406             :     DBG_ASSERT(SQL_ISTOKEN(pPart2->getChild(0),IS),"OFILECursor: Fehler im Parse Tree");
     407             : 
     408             :     sal_Int32 ePredicateType;
     409           0 :     if (SQL_ISTOKEN(pPart2->getChild(1),NOT))
     410           0 :         ePredicateType = SQLFilterOperator::NOT_SQLNULL;
     411             :     else
     412           0 :         ePredicateType = SQLFilterOperator::SQLNULL;
     413             : 
     414           0 :     execute(pPredicateNode->getChild(0));
     415             :     OBoolOperator* pOperator = (ePredicateType == SQLFilterOperator::SQLNULL) ?
     416           0 :                                 new OOp_ISNULL() : new OOp_ISNOTNULL();
     417           0 :     m_aCodeList.push_back(pOperator);
     418             : 
     419           0 :     return NULL;
     420             : }
     421             : 
     422          76 : OOperand* OPredicateCompiler::execute_Operand(OSQLParseNode* pPredicateNode) throw(SQLException, RuntimeException)
     423             : {
     424          76 :     OOperand* pOperand = NULL;
     425             : 
     426          76 :     if (SQL_ISRULE(pPredicateNode,column_ref))
     427             :     {
     428           8 :         OUString aColumnName;
     429           8 :         if (pPredicateNode->count() == 1)
     430             :         {
     431           8 :             aColumnName = pPredicateNode->getChild(0)->getTokenValue();
     432             :         }
     433           0 :         else if (pPredicateNode->count() == 3)
     434             :         {
     435           0 :             if(SQL_ISRULE(pPredicateNode->getChild(2),column_val))
     436           0 :                 aColumnName = pPredicateNode->getChild(2)->getChild(0)->getTokenValue();
     437             :             else
     438           0 :                 aColumnName = pPredicateNode->getChild(2)->getTokenValue();
     439             :         }
     440             : 
     441           8 :         if(!m_orgColumns->hasByName(aColumnName))
     442             :         {
     443           0 :             const OUString sError( m_pAnalyzer->getConnection()->getResources().getResourceStringWithSubstitution(
     444             :                     STR_INVALID_COLUMNNAME,
     445             :                     "$columnname$", aColumnName
     446           0 :                  ) );
     447           0 :             ::dbtools::throwGenericSQLException( sError, NULL );
     448             :         }
     449          16 :         ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet> xCol;
     450             :         try
     451             :         {
     452           8 :             if (m_orgColumns->getByName(aColumnName) >>= xCol)
     453             :             {
     454           8 :                 pOperand = OSQLAnalyzer::createOperandAttr(Reference< XColumnLocate>(m_orgColumns,UNO_QUERY)->findColumn(aColumnName),xCol,m_xIndexes);
     455             :             }
     456             :             else
     457             :             {// Column doesn't exist in the Result-set
     458           0 :                 const OUString sError( m_pAnalyzer->getConnection()->getResources().getResourceStringWithSubstitution(
     459             :                     STR_INVALID_COLUMNNAME,
     460             :                     "$columnname$", aColumnName
     461           0 :                  ) );
     462           0 :                 ::dbtools::throwGenericSQLException( sError, NULL );
     463             :             }
     464             :         }
     465           0 :         catch(Exception &)
     466             :         {
     467             :             OSL_FAIL("OPredicateCompiler::execute_Operand Exception");
     468           8 :         }
     469             :     }
     470          68 :     else if (SQL_ISRULE(pPredicateNode,parameter))
     471             :     {
     472           8 :         pOperand = new OOperandParam(pPredicateNode, ++m_nParamCounter);
     473             :     }
     474         180 :     else if (pPredicateNode->getNodeType() == SQL_NODE_STRING ||
     475          60 :              pPredicateNode->getNodeType() == SQL_NODE_INTNUM ||
     476           0 :              pPredicateNode->getNodeType() == SQL_NODE_APPROXNUM ||
     477           0 :              pPredicateNode->getNodeType() == SQL_NODE_NAME ||
     478           0 :              SQL_ISTOKEN(pPredicateNode,TRUE) ||
     479         120 :              SQL_ISTOKEN(pPredicateNode,FALSE) ||
     480           0 :              SQL_ISRULE(pPredicateNode,parameter))
     481             :     {
     482          60 :         pOperand = new OOperandConst(*pPredicateNode, pPredicateNode->getTokenValue());
     483             :     }
     484           0 :     else if((pPredicateNode->count() == 2) &&
     485           0 :             (SQL_ISPUNCTUATION(pPredicateNode->getChild(0),"+") || SQL_ISPUNCTUATION(pPredicateNode->getChild(0),"-")) &&
     486           0 :             pPredicateNode->getChild(1)->getNodeType() == SQL_NODE_INTNUM)
     487             :     { // if -1 or +1 is there
     488           0 :         OUString aValue(pPredicateNode->getChild(0)->getTokenValue());
     489           0 :         aValue += pPredicateNode->getChild(1)->getTokenValue();
     490           0 :         pOperand = new OOperandConst(*pPredicateNode->getChild(1), aValue);
     491             :     }
     492           0 :     else if( SQL_ISRULE(pPredicateNode,set_fct_spec) && SQL_ISPUNCTUATION(pPredicateNode->getChild(0),"{") )
     493             :     {
     494           0 :         const OSQLParseNode* pODBCNode = pPredicateNode->getChild(1);
     495           0 :         const OSQLParseNode* pODBCNodeChild = pODBCNode->getChild(0);
     496             : 
     497             :         // Odbc Date or time
     498           0 :         if (pODBCNodeChild->getNodeType() == SQL_NODE_KEYWORD && (
     499           0 :             SQL_ISTOKEN(pODBCNodeChild,D) ||
     500           0 :             SQL_ISTOKEN(pODBCNodeChild,T) ||
     501           0 :             SQL_ISTOKEN(pODBCNodeChild,TS) ))
     502             :         {
     503           0 :             OUString sDateTime = pODBCNode->getChild(1)->getTokenValue();
     504           0 :             pOperand = new OOperandConst(*pODBCNode->getChild(1), sDateTime);
     505           0 :             if(SQL_ISTOKEN(pODBCNodeChild,D))
     506             :             {
     507           0 :                 pOperand->setValue(::dbtools::DBTypeConversion::toDouble(::dbtools::DBTypeConversion::toDate(sDateTime)));
     508             :             }
     509           0 :             else if(SQL_ISTOKEN(pODBCNodeChild,T))
     510             :             {
     511           0 :                 pOperand->setValue(::dbtools::DBTypeConversion::toDouble(::dbtools::DBTypeConversion::toTime(sDateTime)));
     512             :             }
     513           0 :             else if(SQL_ISTOKEN(pODBCNodeChild,TS))
     514             :             {
     515           0 :                 pOperand->setValue(::dbtools::DBTypeConversion::toDouble(::dbtools::DBTypeConversion::toDateTime(sDateTime)));
     516           0 :             }
     517             :         }
     518             :         else
     519           0 :             m_pAnalyzer->getConnection()->throwGenericSQLException(STR_QUERY_TOO_COMPLEX,NULL);
     520             : 
     521             :     }
     522           0 :     else if( SQL_ISRULE(pPredicateNode,fold) )
     523             :     {
     524           0 :         execute_Fold(pPredicateNode);
     525             :     }
     526           0 :     else if(    SQL_ISRULE(pPredicateNode,set_fct_spec)
     527           0 :             ||  SQL_ISRULE(pPredicateNode,position_exp)
     528           0 :             ||  SQL_ISRULE(pPredicateNode,char_substring_fct)
     529             :             )
     530             :     {
     531           0 :         executeFunction(pPredicateNode);
     532             :     }
     533           0 :     else if( SQL_ISRULE(pPredicateNode,length_exp) )
     534             :     {
     535           0 :         executeFunction(pPredicateNode->getChild(0));
     536             :     }
     537             :     else
     538             :     {
     539           0 :         m_pAnalyzer->getConnection()->throwGenericSQLException(STR_QUERY_TOO_COMPLEX,NULL);
     540             :     }
     541          76 :     if (pOperand)
     542          76 :         m_aCodeList.push_back(pOperand);
     543          76 :     return pOperand;
     544             : }
     545             : 
     546             : 
     547          18 : bool OPredicateInterpreter::evaluate(OCodeList& rCodeList)
     548             : {
     549             :     static bool bResult;
     550             : 
     551          18 :     OCodeList::iterator aIter = rCodeList.begin();
     552          18 :     if (!(*aIter))
     553           0 :         return true;        // no Predicate
     554             : 
     555          72 :     for(;aIter != rCodeList.end();++aIter)
     556             :     {
     557          54 :         OOperand* pOperand = PTR_CAST(OOperand,(*aIter));
     558          54 :         if (pOperand)
     559          36 :             m_aStack.push(pOperand);
     560             :         else
     561          18 :             static_cast<OOperator *>(*aIter)->Exec(m_aStack);
     562             :     }
     563             : 
     564          18 :     OOperand* pOperand = m_aStack.top();
     565          18 :     m_aStack.pop();
     566             : 
     567             :     DBG_ASSERT(m_aStack.empty(), "StackFehler");
     568             :     DBG_ASSERT(pOperand, "StackFehler");
     569             : 
     570          18 :     bResult = pOperand->isValid();
     571          18 :     if (IS_TYPE(OOperandResult,pOperand))
     572          18 :         delete pOperand;
     573          18 :     return bResult;
     574             : }
     575             : 
     576           0 : void OPredicateInterpreter::evaluateSelection(OCodeList& rCodeList,ORowSetValueDecoratorRef& _rVal)
     577             : {
     578           0 :     OCodeList::iterator aIter = rCodeList.begin();
     579           0 :     if (!(*aIter))
     580           0 :         return ;        // no Predicate
     581             : 
     582           0 :     for(;aIter != rCodeList.end();++aIter)
     583             :     {
     584           0 :         OOperand* pOperand = PTR_CAST(OOperand,(*aIter));
     585           0 :         if (pOperand)
     586           0 :             m_aStack.push(pOperand);
     587             :         else
     588           0 :             static_cast<OOperator *>(*aIter)->Exec(m_aStack);
     589             :     }
     590             : 
     591           0 :     OOperand* pOperand = m_aStack.top();
     592           0 :     m_aStack.pop();
     593             : 
     594             :     DBG_ASSERT(m_aStack.empty(), "StackFehler");
     595             :     DBG_ASSERT(pOperand, "StackFehler");
     596             : 
     597           0 :     (*_rVal) = pOperand->getValue();
     598           0 :     if (IS_TYPE(OOperandResult,pOperand))
     599           0 :         delete pOperand;
     600             : }
     601             : 
     602           0 : OOperand* OPredicateCompiler::execute_Fold(OSQLParseNode* pPredicateNode)   throw(SQLException, RuntimeException)
     603             : {
     604             :     DBG_ASSERT(pPredicateNode->count() >= 4,"OFILECursor: Fehler im Parse Tree");
     605             : 
     606           0 :     bool bUpper = SQL_ISTOKEN(pPredicateNode->getChild(0),UPPER);
     607             : 
     608           0 :     execute(pPredicateNode->getChild(2));
     609           0 :     OOperator* pOperator = NULL;
     610           0 :     if ( bUpper )
     611           0 :         pOperator = new OOp_Upper();
     612             :     else
     613           0 :         pOperator = new OOp_Lower();
     614             : 
     615           0 :     m_aCodeList.push_back(pOperator);
     616           0 :     return NULL;
     617             : }
     618             : 
     619           0 : OOperand* OPredicateCompiler::executeFunction(OSQLParseNode* pPredicateNode)    throw(SQLException, RuntimeException)
     620             : {
     621           0 :     OOperator* pOperator = NULL;
     622             : 
     623             :     OSL_ENSURE(pPredicateNode->getChild(0)->isToken(),"The first one must be the name of the function!");
     624           0 :     sal_Int32 nTokenId = pPredicateNode->getChild(0)->getTokenID();
     625           0 :     switch ( nTokenId )
     626             :     {
     627             :         case SQL_TOKEN_CHAR_LENGTH:
     628             :         case SQL_TOKEN_LENGTH:
     629             :         case SQL_TOKEN_OCTET_LENGTH:
     630             :         case SQL_TOKEN_ASCII:
     631             :         case SQL_TOKEN_LCASE:
     632             :         case SQL_TOKEN_LTRIM:
     633             :         case SQL_TOKEN_RTRIM:
     634             :         case SQL_TOKEN_SPACE:
     635             :         case SQL_TOKEN_UCASE:
     636             :         case SQL_TOKEN_ABS:
     637             :         case SQL_TOKEN_ACOS:
     638             :         case SQL_TOKEN_ASIN:
     639             :         case SQL_TOKEN_ATAN:
     640             :         case SQL_TOKEN_CEILING:
     641             :         case SQL_TOKEN_COS:
     642             :         case SQL_TOKEN_DEGREES:
     643             :         case SQL_TOKEN_EXP:
     644             :         case SQL_TOKEN_FLOOR:
     645             :         case SQL_TOKEN_LOG10:
     646             :         case SQL_TOKEN_LN:
     647             :         case SQL_TOKEN_RADIANS:
     648             :         case SQL_TOKEN_SIGN:
     649             :         case SQL_TOKEN_SIN:
     650             :         case SQL_TOKEN_SQRT:
     651             :         case SQL_TOKEN_TAN:
     652             :         case SQL_TOKEN_DAYNAME:
     653             :         case SQL_TOKEN_DAYOFMONTH:
     654             :         case SQL_TOKEN_DAYOFWEEK:
     655             :         case SQL_TOKEN_DAYOFYEAR:
     656             :         case SQL_TOKEN_HOUR:
     657             :         case SQL_TOKEN_MINUTE:
     658             :         case SQL_TOKEN_MONTH:
     659             :         case SQL_TOKEN_MONTHNAME:
     660             :         case SQL_TOKEN_QUARTER:
     661             :         case SQL_TOKEN_SECOND:
     662             :         case SQL_TOKEN_YEAR:
     663             : 
     664           0 :             execute(pPredicateNode->getChild(2));
     665             : 
     666           0 :             switch( nTokenId )
     667             :             {
     668             :                 case SQL_TOKEN_CHAR_LENGTH:
     669             :                 case SQL_TOKEN_LENGTH:
     670             :                 case SQL_TOKEN_OCTET_LENGTH:
     671           0 :                     pOperator = new OOp_CharLength();
     672           0 :                     break;
     673             :                 case SQL_TOKEN_ASCII:
     674           0 :                     pOperator = new OOp_Ascii();
     675           0 :                     break;
     676             :                 case SQL_TOKEN_LCASE:
     677           0 :                     pOperator = new OOp_Lower();
     678           0 :                     break;
     679             : 
     680             :                 case SQL_TOKEN_LTRIM:
     681           0 :                     pOperator = new OOp_LTrim();
     682           0 :                     break;
     683             :                 case SQL_TOKEN_RTRIM:
     684           0 :                     pOperator = new OOp_RTrim();
     685           0 :                     break;
     686             :                 case SQL_TOKEN_SPACE:
     687           0 :                     pOperator = new OOp_Space();
     688           0 :                     break;
     689             :                 case SQL_TOKEN_UCASE:
     690           0 :                     pOperator = new OOp_Upper();
     691           0 :                     break;
     692             :                 case SQL_TOKEN_ABS:
     693           0 :                     pOperator = new OOp_Abs();
     694           0 :                     break;
     695             :                 case SQL_TOKEN_ACOS:
     696           0 :                     pOperator = new OOp_ACos();
     697           0 :                     break;
     698             :                 case SQL_TOKEN_ASIN:
     699           0 :                     pOperator = new OOp_ASin();
     700           0 :                     break;
     701             :                 case SQL_TOKEN_ATAN:
     702           0 :                     pOperator = new OOp_ATan();
     703           0 :                     break;
     704             :                 case SQL_TOKEN_CEILING:
     705           0 :                     pOperator = new OOp_Ceiling();
     706           0 :                     break;
     707             :                 case SQL_TOKEN_COS:
     708           0 :                     pOperator = new OOp_Cos();
     709           0 :                     break;
     710             :                 case SQL_TOKEN_DEGREES:
     711           0 :                     pOperator = new OOp_Degrees();
     712           0 :                     break;
     713             :                 case SQL_TOKEN_EXP:
     714           0 :                     pOperator = new OOp_Exp();
     715           0 :                     break;
     716             :                 case SQL_TOKEN_FLOOR:
     717           0 :                     pOperator = new OOp_Floor();
     718           0 :                     break;
     719             :                 case SQL_TOKEN_LOG10:
     720           0 :                     pOperator = new OOp_Log10();
     721           0 :                     break;
     722             :                 case SQL_TOKEN_LN:
     723           0 :                     pOperator = new OOp_Ln();
     724           0 :                     break;
     725             :                 case SQL_TOKEN_RADIANS:
     726           0 :                     pOperator = new OOp_Radians();
     727           0 :                     break;
     728             :                 case SQL_TOKEN_SIGN:
     729           0 :                     pOperator = new OOp_Sign();
     730           0 :                     break;
     731             :                 case SQL_TOKEN_SIN:
     732           0 :                     pOperator = new OOp_Sin();
     733           0 :                     break;
     734             :                 case SQL_TOKEN_SQRT:
     735           0 :                     pOperator = new OOp_Sqrt();
     736           0 :                     break;
     737             :                 case SQL_TOKEN_TAN:
     738           0 :                     pOperator = new OOp_Tan();
     739           0 :                     break;
     740             :                 case SQL_TOKEN_DAYOFWEEK:
     741           0 :                     pOperator = new OOp_DayOfWeek();
     742           0 :                     break;
     743             :                 case SQL_TOKEN_DAYOFMONTH:
     744           0 :                     pOperator = new OOp_DayOfMonth();
     745           0 :                     break;
     746             :                 case SQL_TOKEN_DAYOFYEAR:
     747           0 :                     pOperator = new OOp_DayOfYear();
     748           0 :                     break;
     749             :                 case SQL_TOKEN_MONTH:
     750           0 :                     pOperator = new OOp_Month();
     751           0 :                     break;
     752             :                 case SQL_TOKEN_DAYNAME:
     753           0 :                     pOperator = new OOp_DayName();
     754           0 :                     break;
     755             :                 case SQL_TOKEN_MONTHNAME:
     756           0 :                     pOperator = new OOp_MonthName();
     757           0 :                     break;
     758             :                 case SQL_TOKEN_QUARTER:
     759           0 :                     pOperator = new OOp_Quarter();
     760           0 :                     break;
     761             :                 case SQL_TOKEN_YEAR:
     762           0 :                     pOperator = new OOp_Year();
     763           0 :                     break;
     764             :                 case SQL_TOKEN_HOUR:
     765           0 :                     pOperator = new OOp_Hour();
     766           0 :                     break;
     767             :                 case SQL_TOKEN_MINUTE:
     768           0 :                     pOperator = new OOp_Minute();
     769           0 :                     break;
     770             :                 case SQL_TOKEN_SECOND:
     771           0 :                     pOperator = new OOp_Second();
     772           0 :                     break;
     773             :                 default:
     774             :                     OSL_FAIL("Error in switch!");
     775             :             }
     776           0 :             break;
     777             :         case SQL_TOKEN_CHAR:
     778             :         case SQL_TOKEN_CONCAT:
     779             :         case SQL_TOKEN_INSERT:
     780             :         case SQL_TOKEN_LEFT:
     781             :         case SQL_TOKEN_LOCATE:
     782             :         case SQL_TOKEN_LOCATE_2:
     783             :         case SQL_TOKEN_REPEAT:
     784             :         case SQL_TOKEN_REPLACE:
     785             :         case SQL_TOKEN_RIGHT:
     786             :         case SQL_TOKEN_MOD:
     787             :         case SQL_TOKEN_ROUND:
     788             :         case SQL_TOKEN_LOGF:
     789             :         case SQL_TOKEN_LOG:
     790             :         case SQL_TOKEN_POWER:
     791             :         case SQL_TOKEN_ATAN2:
     792             :         case SQL_TOKEN_PI:
     793             :         case SQL_TOKEN_CURDATE:
     794             :         case SQL_TOKEN_CURTIME:
     795             :         case SQL_TOKEN_NOW:
     796             :         case SQL_TOKEN_WEEK:
     797             :             {
     798           0 :                 m_aCodeList.push_back(new OStopOperand);
     799           0 :                 OSQLParseNode* pList = pPredicateNode->getChild(2);
     800           0 :                 for (size_t i=0; i < pList->count(); ++i)
     801           0 :                     execute(pList->getChild(i));
     802             : 
     803           0 :                 switch( nTokenId )
     804             :                 {
     805             :                     case SQL_TOKEN_CHAR:
     806           0 :                         pOperator = new OOp_Char();
     807           0 :                         break;
     808             :                     case SQL_TOKEN_CONCAT:
     809           0 :                         pOperator = new OOp_Concat();
     810           0 :                         break;
     811             :                     case SQL_TOKEN_INSERT:
     812           0 :                         pOperator = new OOp_Insert();
     813           0 :                         break;
     814             :                     case SQL_TOKEN_LEFT:
     815           0 :                         pOperator = new OOp_Left();
     816           0 :                         break;
     817             :                     case SQL_TOKEN_LOCATE:
     818             :                     case SQL_TOKEN_LOCATE_2:
     819           0 :                         pOperator = new OOp_Locate();
     820           0 :                         break;
     821             :                     case SQL_TOKEN_REPEAT:
     822           0 :                         pOperator = new OOp_Repeat();
     823           0 :                         break;
     824             :                     case SQL_TOKEN_REPLACE:
     825           0 :                         pOperator = new OOp_Replace();
     826           0 :                         break;
     827             :                     case SQL_TOKEN_RIGHT:
     828           0 :                         pOperator = new OOp_Right();
     829           0 :                         break;
     830             :                     case SQL_TOKEN_MOD:
     831           0 :                         pOperator = new OOp_Mod();
     832           0 :                         break;
     833             :                     case SQL_TOKEN_ROUND:
     834           0 :                         pOperator = new OOp_Round();
     835           0 :                         break;
     836             :                     case SQL_TOKEN_LOGF:
     837             :                     case SQL_TOKEN_LOG:
     838           0 :                         pOperator = new OOp_Log();
     839           0 :                         break;
     840             :                     case SQL_TOKEN_POWER:
     841           0 :                         pOperator = new OOp_Pow();
     842           0 :                         break;
     843             :                     case SQL_TOKEN_ATAN2:
     844           0 :                         pOperator = new OOp_ATan2();
     845           0 :                         break;
     846             :                     case SQL_TOKEN_PI:
     847           0 :                         pOperator = new OOp_Pi();
     848           0 :                         break;
     849             :                     case SQL_TOKEN_CURDATE:
     850           0 :                         pOperator = new OOp_CurDate();
     851           0 :                         break;
     852             :                     case SQL_TOKEN_CURTIME:
     853           0 :                         pOperator = new OOp_CurTime();
     854           0 :                         break;
     855             :                     case SQL_TOKEN_NOW:
     856           0 :                         pOperator = new OOp_Now();
     857           0 :                         break;
     858             :                     case SQL_TOKEN_WEEK:
     859           0 :                         pOperator = new OOp_Week();
     860           0 :                         break;
     861             :                     default:
     862             :                         OSL_FAIL("Error in switch!");
     863             :                 }
     864             :             }
     865           0 :             break;
     866             : 
     867             :         case SQL_TOKEN_SUBSTRING:
     868           0 :             m_aCodeList.push_back(new OStopOperand);
     869           0 :             if ( pPredicateNode->count() == 4 ) //char_substring_fct
     870             :             {
     871           0 :                 OSQLParseNode* pList = pPredicateNode->getChild(2);
     872           0 :                 for (size_t i=0; i < pList->count(); ++i)
     873           0 :                     execute(pList->getChild(i));
     874             :             }
     875             :             else
     876             :             {
     877           0 :                 execute(pPredicateNode->getChild(2));
     878           0 :                 execute(pPredicateNode->getChild(4));
     879           0 :                 execute(pPredicateNode->getChild(5)->getChild(1));
     880             :             }
     881           0 :             pOperator = new OOp_SubString();
     882           0 :             break;
     883             : 
     884             :         case SQL_TOKEN_POSITION:
     885           0 :             m_aCodeList.push_back(new OStopOperand);
     886           0 :             if ( pPredicateNode->count() == 4 ) //position_exp
     887             :             {
     888           0 :                 OSQLParseNode* pList = pPredicateNode->getChild(2);
     889           0 :                 for (size_t i=0; i < pList->count(); ++i)
     890           0 :                     execute(pList->getChild(i));
     891             :             }
     892             :             else
     893             :             {
     894           0 :                 execute(pPredicateNode->getChild(2));
     895           0 :                 execute(pPredicateNode->getChild(4));
     896             :             }
     897           0 :             pOperator = new OOp_Locate();
     898           0 :             break;
     899             :         default:
     900           0 :             m_pAnalyzer->getConnection()->throwGenericSQLException(STR_QUERY_FUNCTION_NOT_SUPPORTED,NULL);
     901             :     }
     902             : 
     903           0 :     m_aCodeList.push_back(pOperator);
     904           0 :     return NULL;
     905             : }
     906             : 
     907             : 
     908             : 
     909             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11