LCOV - code coverage report
Current view: top level - connectivity/source/drivers/file - fcomp.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 437 0.0 %
Date: 2014-04-14 Functions: 0 15 0.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10