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