1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: fcomp.cxx,v $
10 * $Revision: 1.30.30.2 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_connectivity.hxx"
33 #include "file/fcomp.hxx"
34 #include <tools/debug.hxx>
35 #include "TConnection.hxx"
36 #include "connectivity/sqlparse.hxx"
37 #include "file/fanalyzer.hxx"
38 #include <com/sun/star/sdbc/XColumnLocate.hpp>
39 #include <com/sun/star/util/DateTime.hpp>
40 #include <com/sun/star/util/Date.hpp>
41 #include <com/sun/star/util/Time.hpp>
42 #include "connectivity/dbexception.hxx"
43 #include "connectivity/dbconversion.hxx"
44 #include <com/sun/star/sdb/SQLFilterOperator.hpp>
45 #include "resource/file_res.hrc"
46 #include "file/FStringFunctions.hxx"
47 #include "file/FDateFunctions.hxx"
48 #include "file/FNumericFunctions.hxx"
49 #include "file/FConnection.hxx"
50 #include <com/sun/star/sdb/SQLFilterOperator.hpp>
52 using namespace connectivity
;
53 using namespace connectivity::file
;
54 using namespace com::sun::star::uno
;
55 using namespace com::sun::star::sdbc
;
56 using namespace com::sun::star::sdb
;
57 using namespace ::com::sun::star::container
;
58 using namespace ::com::sun::star::util
;
60 DBG_NAME(OPredicateCompiler
)
61 //------------------------------------------------------------------
62 OPredicateCompiler::OPredicateCompiler(OSQLAnalyzer
* pAnalyzer
)//,OCursor& rCurs)
64 : m_pAnalyzer(pAnalyzer
)
66 , m_bORCondition(FALSE
)
68 DBG_CTOR(OPredicateCompiler
,NULL
);
71 //------------------------------------------------------------------
72 OPredicateCompiler::~OPredicateCompiler()
75 DBG_DTOR(OPredicateCompiler
,NULL
);
77 // -----------------------------------------------------------------------------
78 void OPredicateCompiler::dispose()
84 //------------------------------------------------------------------
85 // inline OCursor& OPredicateCompiler::Cursor() const {return m_rCursor;}
86 //------------------------------------------------------------------
87 void OPredicateCompiler::start(OSQLParseNode
* pSQLParseNode
)
93 // Parse Tree analysieren (je nach Statement-Typ)
94 // und Zeiger auf WHERE-Klausel setzen:
95 OSQLParseNode
* pWhereClause
= NULL
;
96 OSQLParseNode
* pOrderbyClause
= NULL
;
98 if (SQL_ISRULE(pSQLParseNode
,select_statement
))
100 DBG_ASSERT(pSQLParseNode
->count() >= 4,"OFILECursor: Fehler im Parse Tree");
102 OSQLParseNode
* pTableExp
= pSQLParseNode
->getChild(3);
103 DBG_ASSERT(pTableExp
!= NULL
,"Fehler im Parse Tree");
104 DBG_ASSERT(SQL_ISRULE(pTableExp
,table_exp
)," Fehler im Parse Tree");
105 DBG_ASSERT(pTableExp
->count() == 5,"Fehler im Parse Tree");
107 // check that we don't use anything other than count(*) as function
108 OSQLParseNode
* pSelection
= pSQLParseNode
->getChild(2);
109 if ( SQL_ISRULE(pSelection
,scalar_exp_commalist
) )
111 for (sal_uInt32 i
= 0; i
< pSelection
->count(); i
++)
113 OSQLParseNode
*pColumnRef
= pSelection
->getChild(i
)->getChild(0);
114 if ( SQL_ISRULE(pColumnRef
,general_set_fct
) && pColumnRef
->count() != 4 )
116 m_pAnalyzer
->getConnection()->throwGenericSQLException(STR_QUERY_COMPLEX_COUNT
,NULL
);
122 pWhereClause
= pTableExp
->getChild(1);
123 pOrderbyClause
= pTableExp
->getChild(4);
125 else if (SQL_ISRULE(pSQLParseNode
,update_statement_searched
))
127 DBG_ASSERT(pSQLParseNode
->count() == 5,"OFILECursor: Fehler im Parse Tree");
128 pWhereClause
= pSQLParseNode
->getChild(4);
130 else if (SQL_ISRULE(pSQLParseNode
,delete_statement_searched
))
132 DBG_ASSERT(pSQLParseNode
->count() == 4,"Fehler im Parse Tree");
133 pWhereClause
= pSQLParseNode
->getChild(3);
136 // Anderes Statement. Keine Selektionskriterien.
139 if (SQL_ISRULE(pWhereClause
,where_clause
))
141 // Wenn es aber eine where_clause ist, dann darf sie nicht leer sein:
142 DBG_ASSERT(pWhereClause
->count() == 2,"OFILECursor: Fehler im Parse Tree");
144 OSQLParseNode
* pComparisonPredicate
= pWhereClause
->getChild(1);
145 DBG_ASSERT(pComparisonPredicate
!= NULL
,"OFILECursor: Fehler im Parse Tree");
147 execute( pComparisonPredicate
);
151 // Die Where Clause ist meistens optional, d. h. es koennte sich auch
152 // um "optional_where_clause" handeln.
153 DBG_ASSERT(SQL_ISRULE(pWhereClause
,opt_where_clause
),"OPredicateCompiler: Fehler im Parse Tree");
157 //------------------------------------------------------------------
158 OOperand
* OPredicateCompiler::execute(OSQLParseNode
* pPredicateNode
)
160 OOperand
* pOperand
= NULL
;
161 if (pPredicateNode
->count() == 3 && // Ausdruck is geklammert
162 SQL_ISPUNCTUATION(pPredicateNode
->getChild(0),"(") &&
163 SQL_ISPUNCTUATION(pPredicateNode
->getChild(2),")"))
165 execute(pPredicateNode
->getChild(1));
167 else if ((SQL_ISRULE(pPredicateNode
,search_condition
) || (SQL_ISRULE(pPredicateNode
,boolean_term
)))
168 && // AND/OR-Verknuepfung:
169 pPredicateNode
->count() == 3)
171 execute(pPredicateNode
->getChild(0)); // Bearbeiten des linken Zweigs
172 execute(pPredicateNode
->getChild(2)); // Bearbeiten des rechten Zweigs
174 if (SQL_ISTOKEN(pPredicateNode
->getChild(1),OR
)) // OR-Operator
176 m_aCodeList
.push_back(new OOp_OR());
177 m_bORCondition
= sal_True
;
179 else if (SQL_ISTOKEN(pPredicateNode
->getChild(1),AND
)) // AND-Operator
180 m_aCodeList
.push_back(new OOp_AND());
183 DBG_ERROR("OPredicateCompiler: Fehler im Parse Tree");
186 else if (SQL_ISRULE(pPredicateNode
,boolean_factor
))
188 execute(pPredicateNode
->getChild(1));
189 m_aCodeList
.push_back(new OOp_NOT());
191 else if (SQL_ISRULE(pPredicateNode
,comparison_predicate
))
193 execute_COMPARE(pPredicateNode
);
195 else if (SQL_ISRULE(pPredicateNode
,like_predicate
))
197 execute_LIKE(pPredicateNode
);
199 else if (SQL_ISRULE(pPredicateNode
,between_predicate
))
201 execute_BETWEEN(pPredicateNode
);
203 else if (SQL_ISRULE(pPredicateNode
,test_for_null
))
205 execute_ISNULL(pPredicateNode
);
207 else if(SQL_ISRULE(pPredicateNode
,num_value_exp
))
209 execute(pPredicateNode
->getChild(0)); // Bearbeiten des linken Zweigs
210 execute(pPredicateNode
->getChild(2)); // Bearbeiten des rechten Zweigs
211 if (SQL_ISPUNCTUATION(pPredicateNode
->getChild(1),"+"))
213 m_aCodeList
.push_back(new OOp_ADD());
215 else if (SQL_ISPUNCTUATION(pPredicateNode
->getChild(1),"-"))
216 m_aCodeList
.push_back(new OOp_SUB());
219 DBG_ERROR("OPredicateCompiler: Fehler im Parse Tree num_value_exp");
222 else if(SQL_ISRULE(pPredicateNode
,term
))
224 execute(pPredicateNode
->getChild(0)); // Bearbeiten des linken Zweigs
225 execute(pPredicateNode
->getChild(2)); // Bearbeiten des rechten Zweigs
226 if (SQL_ISPUNCTUATION(pPredicateNode
->getChild(1),"*"))
228 m_aCodeList
.push_back(new OOp_MUL());
230 else if (SQL_ISPUNCTUATION(pPredicateNode
->getChild(1),"/"))
231 m_aCodeList
.push_back(new OOp_DIV());
234 DBG_ERROR("OPredicateCompiler: Fehler im Parse Tree num_value_exp");
238 pOperand
= execute_Operand(pPredicateNode
); // jetzt werden nur einfache Operanden verarbeitet
243 //------------------------------------------------------------------
244 OOperand
* OPredicateCompiler::execute_COMPARE(OSQLParseNode
* pPredicateNode
) throw(SQLException
, RuntimeException
)
246 DBG_ASSERT(pPredicateNode
->count() == 3,"OFILECursor: Fehler im Parse Tree");
248 if ( !(SQL_ISRULE(pPredicateNode
->getChild(0),column_ref
) ||
249 pPredicateNode
->getChild(2)->getNodeType() == SQL_NODE_STRING
||
250 pPredicateNode
->getChild(2)->getNodeType() == SQL_NODE_INTNUM
||
251 pPredicateNode
->getChild(2)->getNodeType() == SQL_NODE_APPROXNUM
||
252 SQL_ISTOKEN(pPredicateNode
->getChild(2),TRUE
) ||
253 SQL_ISTOKEN(pPredicateNode
->getChild(2),FALSE
) ||
254 SQL_ISRULE(pPredicateNode
->getChild(2),parameter
) ||
256 SQL_ISRULE(pPredicateNode
->getChild(2),set_fct_spec
) ||
257 SQL_ISRULE(pPredicateNode
->getChild(2),position_exp
) ||
258 SQL_ISRULE(pPredicateNode
->getChild(2),char_substring_fct
) ||
260 SQL_ISRULE(pPredicateNode
->getChild(2),fold
)) )
262 m_pAnalyzer
->getConnection()->throwGenericSQLException(STR_QUERY_TOO_COMPLEX
,NULL
);
266 sal_Int32
ePredicateType( SQLFilterOperator::EQUAL
);
267 OSQLParseNode
*pPrec
= pPredicateNode
->getChild(1);
269 if (pPrec
->getNodeType() == SQL_NODE_EQUAL
)
270 ePredicateType
= SQLFilterOperator::EQUAL
;
271 else if (pPrec
->getNodeType() == SQL_NODE_NOTEQUAL
)
272 ePredicateType
= SQLFilterOperator::NOT_EQUAL
;
273 else if (pPrec
->getNodeType() == SQL_NODE_LESS
)
274 ePredicateType
= SQLFilterOperator::LESS
;
275 else if (pPrec
->getNodeType() == SQL_NODE_LESSEQ
)
276 ePredicateType
= SQLFilterOperator::LESS_EQUAL
;
277 else if (pPrec
->getNodeType() == SQL_NODE_GREATEQ
)
278 ePredicateType
= SQLFilterOperator::GREATER_EQUAL
;
279 else if (pPrec
->getNodeType() == SQL_NODE_GREAT
)
280 ePredicateType
= SQLFilterOperator::GREATER
;
282 OSL_ENSURE( false, "OPredicateCompiler::execute_COMPARE: unexpected node type!" );
284 execute(pPredicateNode
->getChild(0));
285 execute(pPredicateNode
->getChild(2));
286 m_aCodeList
.push_back( new OOp_COMPARE(ePredicateType
) );
291 //------------------------------------------------------------------
292 OOperand
* OPredicateCompiler::execute_LIKE(OSQLParseNode
* pPredicateNode
) throw(SQLException
, RuntimeException
)
294 DBG_ASSERT(pPredicateNode
->count() >= 4,"OFILECursor: Fehler im Parse Tree");
296 sal_Int32 ePredicateType
;
297 sal_Unicode cEscape
= L
'\0';
298 if (pPredicateNode
->count() == 5)
299 ePredicateType
= SQLFilterOperator::NOT_LIKE
;
301 ePredicateType
= SQLFilterOperator::LIKE
;
303 OSQLParseNode
* pAtom
= pPredicateNode
->getChild(pPredicateNode
->count()-2);
304 OSQLParseNode
* pOptEscape
= pPredicateNode
->getChild(pPredicateNode
->count()-1);
306 if (!(pAtom
->getNodeType() == SQL_NODE_STRING
|| SQL_ISRULE(pAtom
,parameter
)))
308 m_pAnalyzer
->getConnection()->throwGenericSQLException(STR_QUERY_INVALID_LIKE_STRING
,NULL
);
310 if (pOptEscape
->count() != 0)
312 if (pOptEscape
->count() != 2)
314 m_pAnalyzer
->getConnection()->throwGenericSQLException(STR_QUERY_INVALID_LIKE_STRING
,NULL
);
316 OSQLParseNode
*pEscNode
= pOptEscape
->getChild(1);
317 if (pEscNode
->getNodeType() != SQL_NODE_STRING
)
319 m_pAnalyzer
->getConnection()->throwGenericSQLException(STR_QUERY_INVALID_LIKE_STRING
,NULL
);
322 cEscape
= pEscNode
->getTokenValue().toChar();
325 execute(pPredicateNode
->getChild(0));
328 OBoolOperator
* pOperator
= (ePredicateType
== SQLFilterOperator::LIKE
)
329 ? new OOp_LIKE(cEscape
)
330 : new OOp_NOTLIKE(cEscape
);
331 m_aCodeList
.push_back(pOperator
);
335 //------------------------------------------------------------------
336 OOperand
* OPredicateCompiler::execute_BETWEEN(OSQLParseNode
* pPredicateNode
) throw(SQLException
, RuntimeException
)
338 DBG_ASSERT(pPredicateNode
->count() == 6,"OFILECursor: Fehler im Parse Tree");
340 OSQLParseNode
* pColumn
= pPredicateNode
->getChild(0);
341 OSQLParseNode
* p1stValue
= pPredicateNode
->getChild(3);
342 OSQLParseNode
* p2ndtValue
= pPredicateNode
->getChild(5);
345 !(p1stValue
->getNodeType() == SQL_NODE_STRING
|| SQL_ISRULE(p1stValue
,parameter
))
346 && !(p2ndtValue
->getNodeType() == SQL_NODE_STRING
|| SQL_ISRULE(p2ndtValue
,parameter
))
349 m_pAnalyzer
->getConnection()->throwGenericSQLException(STR_QUERY_INVALID_BETWEEN
,NULL
);
352 sal_Bool bNot
= SQL_ISTOKEN(pPredicateNode
->getChild(1),NOT
);
354 OOperand
* pColumnOp
= execute(pColumn
);
355 OOperand
* pOb1
= execute(p1stValue
);
356 OBoolOperator
* pOperator
= new OOp_COMPARE(bNot
? SQLFilterOperator::LESS_EQUAL
: SQLFilterOperator::GREATER
);
357 m_aCodeList
.push_back(pOperator
);
360 OOperand
* pOb2
= execute(p2ndtValue
);
361 pOperator
= new OOp_COMPARE(bNot
? SQLFilterOperator::GREATER_EQUAL
: SQLFilterOperator::LESS
);
362 m_aCodeList
.push_back(pOperator
);
364 if ( pColumnOp
&& pOb1
&& pOb2
)
366 switch(pColumnOp
->getDBType())
369 case DataType::VARCHAR
:
370 case DataType::LONGVARCHAR
:
371 pOb1
->setValue(pOb1
->getValue().getString());
372 pOb2
->setValue(pOb2
->getValue().getString());
374 case DataType::DECIMAL
:
375 case DataType::NUMERIC
:
376 pOb1
->setValue((double)pOb1
->getValue());
377 pOb2
->setValue((double)pOb2
->getValue());
379 case DataType::FLOAT
:
380 pOb1
->setValue((float)pOb1
->getValue());
381 pOb2
->setValue((float)pOb2
->getValue());
383 case DataType::DOUBLE
:
385 pOb1
->setValue((double)pOb1
->getValue());
386 pOb2
->setValue((double)pOb2
->getValue());
389 pOb1
->setValue((Date
)pOb1
->getValue());
390 pOb2
->setValue((Date
)pOb2
->getValue());
393 pOb1
->setValue((Time
)pOb1
->getValue());
394 pOb2
->setValue((Time
)pOb2
->getValue());
396 case DataType::TIMESTAMP
:
397 pOb1
->setValue((DateTime
)pOb1
->getValue());
398 pOb2
->setValue((DateTime
)pOb2
->getValue());
405 OBoolOperator
* pBoolOp
= NULL
;
407 pBoolOp
= new OOp_OR();
409 pBoolOp
= new OOp_AND();
410 m_aCodeList
.push_back(pBoolOp
);
414 //------------------------------------------------------------------
415 OOperand
* OPredicateCompiler::execute_ISNULL(OSQLParseNode
* pPredicateNode
) throw(SQLException
, RuntimeException
)
417 DBG_ASSERT(pPredicateNode
->count() >= 3,"OFILECursor: Fehler im Parse Tree");
418 DBG_ASSERT(SQL_ISTOKEN(pPredicateNode
->getChild(1),IS
),"OFILECursor: Fehler im Parse Tree");
420 sal_Int32 ePredicateType
;
421 if (SQL_ISTOKEN(pPredicateNode
->getChild(2),NOT
))
422 ePredicateType
= SQLFilterOperator::NOT_SQLNULL
;
424 ePredicateType
= SQLFilterOperator::SQLNULL
;
426 execute(pPredicateNode
->getChild(0));
427 OBoolOperator
* pOperator
= (ePredicateType
== SQLFilterOperator::SQLNULL
) ?
428 new OOp_ISNULL() : new OOp_ISNOTNULL();
429 m_aCodeList
.push_back(pOperator
);
433 //------------------------------------------------------------------
434 OOperand
* OPredicateCompiler::execute_Operand(OSQLParseNode
* pPredicateNode
) throw(SQLException
, RuntimeException
)
436 OOperand
* pOperand
= NULL
;
438 if (SQL_ISRULE(pPredicateNode
,column_ref
))
440 ::rtl::OUString aColumnName
;
441 if (pPredicateNode
->count() == 1)
443 aColumnName
= pPredicateNode
->getChild(0)->getTokenValue();
445 else if (pPredicateNode
->count() == 3)
447 ::rtl::OUString aTableName
= pPredicateNode
->getChild(0)->getTokenValue();
448 if(SQL_ISRULE(pPredicateNode
->getChild(2),column_val
))
449 aColumnName
= pPredicateNode
->getChild(2)->getChild(0)->getTokenValue();
451 aColumnName
= pPredicateNode
->getChild(2)->getTokenValue();
454 if(!m_orgColumns
->hasByName(aColumnName
))
456 const ::rtl::OUString
sError( m_pAnalyzer
->getConnection()->getResources().getResourceStringWithSubstitution(
457 STR_INVALID_COLUMNNAME
,
458 "$columnname$", aColumnName
460 ::dbtools::throwGenericSQLException( sError
, NULL
);
462 ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySet
> xCol
;
465 if (m_orgColumns
->getByName(aColumnName
) >>= xCol
)
467 pOperand
= m_pAnalyzer
->createOperandAttr(Reference
< XColumnLocate
>(m_orgColumns
,UNO_QUERY
)->findColumn(aColumnName
),xCol
,m_xIndexes
);
470 {// Column existiert nicht im Resultset
471 const ::rtl::OUString
sError( m_pAnalyzer
->getConnection()->getResources().getResourceStringWithSubstitution(
472 STR_INVALID_COLUMNNAME
,
473 "$columnname$", aColumnName
475 ::dbtools::throwGenericSQLException( sError
, NULL
);
480 OSL_ENSURE(0,"OPredicateCompiler::execute_Operand Exception");
483 else if (SQL_ISRULE(pPredicateNode
,parameter
))
485 pOperand
= new OOperandParam(pPredicateNode
, ++m_nParamCounter
);
487 else if (pPredicateNode
->getNodeType() == SQL_NODE_STRING
||
488 pPredicateNode
->getNodeType() == SQL_NODE_INTNUM
||
489 pPredicateNode
->getNodeType() == SQL_NODE_APPROXNUM
||
490 pPredicateNode
->getNodeType() == SQL_NODE_NAME
||
491 SQL_ISTOKEN(pPredicateNode
,TRUE
) ||
492 SQL_ISTOKEN(pPredicateNode
,FALSE
) ||
493 SQL_ISRULE(pPredicateNode
,parameter
))
495 pOperand
= new OOperandConst(*pPredicateNode
, pPredicateNode
->getTokenValue());
497 else if((pPredicateNode
->count() == 2) &&
498 (SQL_ISPUNCTUATION(pPredicateNode
->getChild(0),"+") || SQL_ISPUNCTUATION(pPredicateNode
->getChild(0),"-")) &&
499 pPredicateNode
->getChild(1)->getNodeType() == SQL_NODE_INTNUM
)
500 { // falls -1 bzw. +1 vorhanden ist
501 ::rtl::OUString
aValue(pPredicateNode
->getChild(0)->getTokenValue());
502 aValue
+= pPredicateNode
->getChild(1)->getTokenValue();
503 pOperand
= new OOperandConst(*pPredicateNode
->getChild(1), aValue
);
505 else if( SQL_ISRULE(pPredicateNode
,set_fct_spec
) && SQL_ISPUNCTUATION(pPredicateNode
->getChild(0),"{") )
507 const OSQLParseNode
* pODBCNode
= pPredicateNode
->getChild(1);
508 const OSQLParseNode
* pODBCNodeChild
= pODBCNode
->getChild(0);
511 if (pODBCNodeChild
->getNodeType() == SQL_NODE_KEYWORD
&& (
512 SQL_ISTOKEN(pODBCNodeChild
,D
) ||
513 SQL_ISTOKEN(pODBCNodeChild
,T
) ||
514 SQL_ISTOKEN(pODBCNodeChild
,TS
) ))
516 ::rtl::OUString sDateTime
= pODBCNode
->getChild(1)->getTokenValue();
517 pOperand
= new OOperandConst(*pODBCNode
->getChild(1), sDateTime
);
518 if(SQL_ISTOKEN(pODBCNodeChild
,D
))
520 pOperand
->setValue(::dbtools::DBTypeConversion::toDouble(::dbtools::DBTypeConversion::toDate(sDateTime
)));
522 else if(SQL_ISTOKEN(pODBCNodeChild
,T
))
524 pOperand
->setValue(::dbtools::DBTypeConversion::toDouble(::dbtools::DBTypeConversion::toTime(sDateTime
)));
526 else if(SQL_ISTOKEN(pODBCNodeChild
,TS
))
528 pOperand
->setValue(::dbtools::DBTypeConversion::toDouble(::dbtools::DBTypeConversion::toDateTime(sDateTime
)));
532 m_pAnalyzer
->getConnection()->throwGenericSQLException(STR_QUERY_TOO_COMPLEX
,NULL
);
535 else if( SQL_ISRULE(pPredicateNode
,fold
) )
537 execute_Fold(pPredicateNode
);
539 else if( SQL_ISRULE(pPredicateNode
,set_fct_spec
)
540 || SQL_ISRULE(pPredicateNode
,position_exp
)
541 || SQL_ISRULE(pPredicateNode
,char_substring_fct
)
544 executeFunction(pPredicateNode
);
546 else if( SQL_ISRULE(pPredicateNode
,length_exp
) )
548 executeFunction(pPredicateNode
->getChild(0));
552 m_pAnalyzer
->getConnection()->throwGenericSQLException(STR_QUERY_TOO_COMPLEX
,NULL
);
555 m_aCodeList
.push_back(pOperand
);
559 ////////////////////////////////////////////////////////////////////////////////////////
560 sal_Bool
OPredicateInterpreter::evaluate(OCodeList
& rCodeList
)
562 static sal_Bool bResult
;
564 OCodeList::iterator aIter
= rCodeList
.begin();
566 return sal_True
; // kein Praedikat
568 for(;aIter
!= rCodeList
.end();++aIter
)
570 OOperand
* pOperand
= PTR_CAST(OOperand
,(*aIter
));
572 m_aStack
.push(pOperand
);
574 ((OOperator
*)(*aIter
))->Exec(m_aStack
);
577 OOperand
* pOperand
= m_aStack
.top();
580 DBG_ASSERT(m_aStack
.size() == 0, "StackFehler");
581 DBG_ASSERT(pOperand
, "StackFehler");
583 bResult
= pOperand
->isValid();
584 if (IS_TYPE(OOperandResult
,pOperand
))
588 // -----------------------------------------------------------------------------
589 void OPredicateInterpreter::evaluateSelection(OCodeList
& rCodeList
,ORowSetValueDecoratorRef
& _rVal
)
591 OCodeList::iterator aIter
= rCodeList
.begin();
593 return ; // kein Praedikat
595 for(;aIter
!= rCodeList
.end();++aIter
)
597 OOperand
* pOperand
= PTR_CAST(OOperand
,(*aIter
));
599 m_aStack
.push(pOperand
);
601 ((OOperator
*)(*aIter
))->Exec(m_aStack
);
604 OOperand
* pOperand
= m_aStack
.top();
607 DBG_ASSERT(m_aStack
.size() == 0, "StackFehler");
608 DBG_ASSERT(pOperand
, "StackFehler");
610 (*_rVal
) = pOperand
->getValue();
611 if (IS_TYPE(OOperandResult
,pOperand
))
614 // -----------------------------------------------------------------------------
615 OOperand
* OPredicateCompiler::execute_Fold(OSQLParseNode
* pPredicateNode
) throw(SQLException
, RuntimeException
)
617 DBG_ASSERT(pPredicateNode
->count() >= 4,"OFILECursor: Fehler im Parse Tree");
619 sal_Bool bUpper
= SQL_ISTOKEN(pPredicateNode
->getChild(0),UPPER
);
621 execute(pPredicateNode
->getChild(2));
622 OOperator
* pOperator
= NULL
;
624 pOperator
= new OOp_Upper();
626 pOperator
= new OOp_Lower();
628 m_aCodeList
.push_back(pOperator
);
631 // -----------------------------------------------------------------------------
632 OOperand
* OPredicateCompiler::executeFunction(OSQLParseNode
* pPredicateNode
) throw(SQLException
, RuntimeException
)
634 OOperator
* pOperator
= NULL
;
636 OSL_ENSURE(pPredicateNode
->getChild(0)->isToken(),"The first one must be the name of the function!");
637 sal_Int32 nTokenId
= pPredicateNode
->getChild(0)->getTokenID();
640 case SQL_TOKEN_CHAR_LENGTH
:
641 case SQL_TOKEN_CHARACTER_LENGTH
:
642 case SQL_TOKEN_LENGTH
:
643 case SQL_TOKEN_OCTET_LENGTH
:
644 case SQL_TOKEN_ASCII
:
645 case SQL_TOKEN_LCASE
:
646 case SQL_TOKEN_LTRIM
:
647 case SQL_TOKEN_RTRIM
:
648 case SQL_TOKEN_SPACE
:
649 case SQL_TOKEN_UCASE
:
654 case SQL_TOKEN_CEILING
:
656 case SQL_TOKEN_DEGREES
:
658 case SQL_TOKEN_FLOOR
:
659 case SQL_TOKEN_LOG10
:
661 case SQL_TOKEN_RADIANS
:
666 case SQL_TOKEN_DAYNAME
:
667 case SQL_TOKEN_DAYOFMONTH
:
668 case SQL_TOKEN_DAYOFWEEK
:
669 case SQL_TOKEN_DAYOFYEAR
:
671 case SQL_TOKEN_MINUTE
:
672 case SQL_TOKEN_MONTH
:
673 case SQL_TOKEN_MONTHNAME
:
674 case SQL_TOKEN_QUARTER
:
675 case SQL_TOKEN_SECOND
:
678 execute(pPredicateNode
->getChild(2));
682 case SQL_TOKEN_CHAR_LENGTH
:
683 case SQL_TOKEN_CHARACTER_LENGTH
:
684 case SQL_TOKEN_LENGTH
:
685 case SQL_TOKEN_OCTET_LENGTH
:
686 pOperator
= new OOp_CharLength();
688 case SQL_TOKEN_ASCII
:
689 pOperator
= new OOp_Ascii();
691 case SQL_TOKEN_LCASE
:
692 pOperator
= new OOp_Lower();
695 case SQL_TOKEN_LTRIM
:
696 pOperator
= new OOp_LTrim();
698 case SQL_TOKEN_RTRIM
:
699 pOperator
= new OOp_RTrim();
701 case SQL_TOKEN_SPACE
:
702 pOperator
= new OOp_Space();
704 case SQL_TOKEN_UCASE
:
705 pOperator
= new OOp_Upper();
708 pOperator
= new OOp_Abs();
711 pOperator
= new OOp_ACos();
714 pOperator
= new OOp_ASin();
717 pOperator
= new OOp_ATan();
719 case SQL_TOKEN_CEILING
:
720 pOperator
= new OOp_Ceiling();
723 pOperator
= new OOp_Cos();
725 case SQL_TOKEN_DEGREES
:
726 pOperator
= new OOp_Degrees();
729 pOperator
= new OOp_Exp();
731 case SQL_TOKEN_FLOOR
:
732 pOperator
= new OOp_Floor();
734 case SQL_TOKEN_LOG10
:
735 pOperator
= new OOp_Log10();
738 pOperator
= new OOp_Ln();
740 case SQL_TOKEN_RADIANS
:
741 pOperator
= new OOp_Radians();
744 pOperator
= new OOp_Sign();
747 pOperator
= new OOp_Sin();
750 pOperator
= new OOp_Sqrt();
753 pOperator
= new OOp_Tan();
755 case SQL_TOKEN_DAYOFWEEK
:
756 pOperator
= new OOp_DayOfWeek();
758 case SQL_TOKEN_DAYOFMONTH
:
759 pOperator
= new OOp_DayOfMonth();
761 case SQL_TOKEN_DAYOFYEAR
:
762 pOperator
= new OOp_DayOfYear();
764 case SQL_TOKEN_MONTH
:
765 pOperator
= new OOp_Month();
767 case SQL_TOKEN_DAYNAME
:
768 pOperator
= new OOp_DayName();
770 case SQL_TOKEN_MONTHNAME
:
771 pOperator
= new OOp_MonthName();
773 case SQL_TOKEN_QUARTER
:
774 pOperator
= new OOp_Quarter();
777 pOperator
= new OOp_Year();
780 pOperator
= new OOp_Hour();
782 case SQL_TOKEN_MINUTE
:
783 pOperator
= new OOp_Minute();
785 case SQL_TOKEN_SECOND
:
786 pOperator
= new OOp_Second();
789 OSL_ENSURE(0,"Error in switch!");
793 case SQL_TOKEN_CONCAT
:
794 case SQL_TOKEN_INSERT
:
796 case SQL_TOKEN_LOCATE
:
797 case SQL_TOKEN_LOCATE_2
:
798 case SQL_TOKEN_REPEAT
:
799 case SQL_TOKEN_REPLACE
:
800 case SQL_TOKEN_RIGHT
:
802 case SQL_TOKEN_ROUND
:
805 case SQL_TOKEN_POWER
:
806 case SQL_TOKEN_ATAN2
:
808 case SQL_TOKEN_CURDATE
:
809 case SQL_TOKEN_CURTIME
:
813 m_aCodeList
.push_back(new OStopOperand
);
814 OSQLParseNode
* pList
= pPredicateNode
->getChild(2);
815 for (sal_uInt32 i
=0; i
< pList
->count(); ++i
)
816 execute(pList
->getChild(i
));
821 pOperator
= new OOp_Char();
823 case SQL_TOKEN_CONCAT
:
824 pOperator
= new OOp_Concat();
826 case SQL_TOKEN_INSERT
:
827 pOperator
= new OOp_Insert();
830 pOperator
= new OOp_Left();
832 case SQL_TOKEN_LOCATE
:
833 case SQL_TOKEN_LOCATE_2
:
834 pOperator
= new OOp_Locate();
836 case SQL_TOKEN_REPEAT
:
837 pOperator
= new OOp_Repeat();
839 case SQL_TOKEN_REPLACE
:
840 pOperator
= new OOp_Replace();
842 case SQL_TOKEN_RIGHT
:
843 pOperator
= new OOp_Right();
846 pOperator
= new OOp_Mod();
848 case SQL_TOKEN_ROUND
:
849 pOperator
= new OOp_Round();
853 pOperator
= new OOp_Log();
855 case SQL_TOKEN_POWER
:
856 pOperator
= new OOp_Pow();
858 case SQL_TOKEN_ATAN2
:
859 pOperator
= new OOp_ATan2();
862 pOperator
= new OOp_Pi();
864 case SQL_TOKEN_CURDATE
:
865 pOperator
= new OOp_CurDate();
867 case SQL_TOKEN_CURTIME
:
868 pOperator
= new OOp_CurTime();
871 pOperator
= new OOp_Now();
874 pOperator
= new OOp_Week();
877 OSL_ENSURE(0,"Error in switch!");
882 case SQL_TOKEN_SUBSTRING
:
883 m_aCodeList
.push_back(new OStopOperand
);
884 if ( pPredicateNode
->count() == 4 ) //char_substring_fct
886 OSQLParseNode
* pList
= pPredicateNode
->getChild(2);
887 for (sal_uInt32 i
=0; i
< pList
->count(); ++i
)
888 execute(pList
->getChild(i
));
892 execute(pPredicateNode
->getChild(2));
893 execute(pPredicateNode
->getChild(4));
894 execute(pPredicateNode
->getChild(5)->getChild(1));
896 pOperator
= new OOp_SubString();
899 case SQL_TOKEN_POSITION
:
900 m_aCodeList
.push_back(new OStopOperand
);
901 if ( pPredicateNode
->count() == 4 ) //position_exp
903 OSQLParseNode
* pList
= pPredicateNode
->getChild(2);
904 for (sal_uInt32 i
=0; i
< pList
->count(); ++i
)
905 execute(pList
->getChild(i
));
909 execute(pPredicateNode
->getChild(2));
910 execute(pPredicateNode
->getChild(4));
912 pOperator
= new OOp_Locate();
915 m_pAnalyzer
->getConnection()->throwGenericSQLException(STR_QUERY_FUNCTION_NOT_SUPPORTED
,NULL
);
918 m_aCodeList
.push_back(pOperator
);
921 // -----------------------------------------------------------------------------