tdf#150789 - FILEOPEN PPTX: fix text in SmartArt vertically off
[LibreOffice.git] / connectivity / source / drivers / file / fcomp.cxx
blob86ed7d4cf8c5b4f3db3164b198622c7762dd902e
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <file/fcomp.hxx>
21 #include <tools/debug.hxx>
22 #include <connectivity/sqlparse.hxx>
23 #include <file/fanalyzer.hxx>
24 #include <com/sun/star/sdbc/XColumnLocate.hpp>
25 #include <connectivity/dbexception.hxx>
26 #include <connectivity/dbconversion.hxx>
27 #include <com/sun/star/sdb/SQLFilterOperator.hpp>
28 #include <file/FStringFunctions.hxx>
29 #include <file/FDateFunctions.hxx>
30 #include <file/FNumericFunctions.hxx>
31 #include <file/FConnection.hxx>
32 #include <comphelper/diagnose_ex.hxx>
33 #include <sqlbison.hxx>
34 #include <strings.hrc>
36 using namespace connectivity;
37 using namespace connectivity::file;
38 using namespace com::sun::star::uno;
39 using namespace com::sun::star::sdbc;
40 using namespace com::sun::star::sdb;
41 using namespace ::com::sun::star::container;
42 using namespace com::sun::star;
44 OPredicateCompiler::OPredicateCompiler(OSQLAnalyzer* pAnalyzer)//,OCursor& rCurs)
45 : m_pAnalyzer(pAnalyzer)
46 , m_nParamCounter(0)
51 OPredicateCompiler::~OPredicateCompiler()
53 Clean();
56 void OPredicateCompiler::dispose()
58 Clean();
59 m_orgColumns = nullptr;
62 void OPredicateCompiler::start(OSQLParseNode const * pSQLParseNode)
64 if (!pSQLParseNode)
65 return;
67 m_nParamCounter = 0;
68 // analyse Parse Tree (depending on Statement-type)
69 // and set pointer on WHERE-clause:
70 OSQLParseNode * pWhereClause = nullptr;
72 if (SQL_ISRULE(pSQLParseNode,select_statement))
74 OSQLParseNode * pOrderbyClause = nullptr;
75 DBG_ASSERT(pSQLParseNode->count() >= 4,"OFILECursor: Error in Parse Tree");
77 OSQLParseNode * pTableExp = pSQLParseNode->getChild(3);
78 assert(pTableExp && "Error in Parse Tree");
79 DBG_ASSERT(SQL_ISRULE(pTableExp,table_exp)," Error in Parse Tree");
80 DBG_ASSERT(pTableExp->count() == TABLE_EXPRESSION_CHILD_COUNT,"Error in Parse Tree");
82 // check that we don't use anything other than count(*) as function
83 OSQLParseNode* pSelection = pSQLParseNode->getChild(2);
84 if ( SQL_ISRULE(pSelection,scalar_exp_commalist) )
86 for (size_t i = 0; i < pSelection->count(); i++)
88 OSQLParseNode *pColumnRef = pSelection->getChild(i)->getChild(0);
89 if ( SQL_ISRULE(pColumnRef,general_set_fct) && pColumnRef->count() != 4 )
91 m_pAnalyzer->getConnection()->throwGenericSQLException(STR_QUERY_COMPLEX_COUNT,nullptr);
97 pWhereClause = pTableExp->getChild(1);
98 pOrderbyClause = pTableExp->getChild(ORDER_BY_CHILD_POS);
99 (void)pOrderbyClause;
101 else if (SQL_ISRULE(pSQLParseNode,update_statement_searched))
103 DBG_ASSERT(pSQLParseNode->count() == 5,"OFILECursor: Error in Parse Tree");
104 pWhereClause = pSQLParseNode->getChild(4);
106 else if (SQL_ISRULE(pSQLParseNode,delete_statement_searched))
108 DBG_ASSERT(pSQLParseNode->count() == 4,"Error in Parse Tree");
109 pWhereClause = pSQLParseNode->getChild(3);
111 else
112 // Other Statement. no selection-criteria
113 return;
115 if (SQL_ISRULE(pWhereClause,where_clause))
117 // a where-clause is not allowed to be empty:
118 DBG_ASSERT(pWhereClause->count() == 2,"OFILECursor: Error in Parse Tree");
120 OSQLParseNode * pComparisonPredicate = pWhereClause->getChild(1);
121 DBG_ASSERT(pComparisonPredicate != nullptr,"OFILECursor: Error in Parse Tree");
123 execute( pComparisonPredicate );
125 else
127 // The where-clause is optionally in the majority of cases, i.e. it might be an "optional-where-clause".
128 DBG_ASSERT(SQL_ISRULE(pWhereClause,opt_where_clause),"OPredicateCompiler: Error in Parse Tree");
133 OOperand* OPredicateCompiler::execute(OSQLParseNode const * pPredicateNode)
135 OOperand* pOperand = nullptr;
136 if (pPredicateNode->count() == 3 && // Expression is bracketed
137 SQL_ISPUNCTUATION(pPredicateNode->getChild(0),"(") &&
138 SQL_ISPUNCTUATION(pPredicateNode->getChild(2),")"))
140 execute(pPredicateNode->getChild(1));
142 else if ((SQL_ISRULE(pPredicateNode,search_condition) || SQL_ISRULE(pPredicateNode,boolean_term))
143 && // AND/OR-linkage:
144 pPredicateNode->count() == 3)
146 execute(pPredicateNode->getChild(0)); // process the left branch
147 execute(pPredicateNode->getChild(2)); // process the right branch
149 if (SQL_ISTOKEN(pPredicateNode->getChild(1),OR)) // OR-Operator
151 m_aCodeList.emplace_back(new OOp_OR);
153 else if (SQL_ISTOKEN(pPredicateNode->getChild(1),AND)) // AND-Operator
154 m_aCodeList.emplace_back(new OOp_AND);
155 else
157 OSL_FAIL("OPredicateCompiler: Error in Parse Tree");
160 else if (SQL_ISRULE(pPredicateNode,boolean_factor))
162 execute(pPredicateNode->getChild(1));
163 m_aCodeList.emplace_back(new OOp_NOT);
165 else if (SQL_ISRULE(pPredicateNode,comparison_predicate))
167 execute_COMPARE(pPredicateNode);
169 else if (SQL_ISRULE(pPredicateNode,like_predicate))
171 execute_LIKE(pPredicateNode);
173 else if (SQL_ISRULE(pPredicateNode,between_predicate))
175 execute_BETWEEN(pPredicateNode);
177 else if (SQL_ISRULE(pPredicateNode,test_for_null))
179 execute_ISNULL(pPredicateNode);
181 else if(SQL_ISRULE(pPredicateNode,num_value_exp))
183 execute(pPredicateNode->getChild(0)); // process the left branch
184 execute(pPredicateNode->getChild(2)); // process the right branch
185 if (SQL_ISPUNCTUATION(pPredicateNode->getChild(1),"+"))
187 m_aCodeList.emplace_back(new OOp_ADD);
189 else if (SQL_ISPUNCTUATION(pPredicateNode->getChild(1),"-"))
190 m_aCodeList.emplace_back(new OOp_SUB);
191 else
193 OSL_FAIL("OPredicateCompiler: Error in Parse Tree num_value_exp");
196 else if(SQL_ISRULE(pPredicateNode,term))
198 execute(pPredicateNode->getChild(0)); // process the left branch
199 execute(pPredicateNode->getChild(2)); // process the right branch
200 if (SQL_ISPUNCTUATION(pPredicateNode->getChild(1),"*"))
202 m_aCodeList.emplace_back(new OOp_MUL);
204 else if (SQL_ISPUNCTUATION(pPredicateNode->getChild(1),"/"))
205 m_aCodeList.emplace_back(new OOp_DIV);
206 else
208 OSL_FAIL("OPredicateCompiler: Error in Parse Tree num_value_exp");
211 else
212 pOperand = execute_Operand(pPredicateNode); // now only simple operands will be processed
214 return pOperand;
218 void OPredicateCompiler::execute_COMPARE(OSQLParseNode const * pPredicateNode)
220 DBG_ASSERT(pPredicateNode->count() == 3,"OFILECursor: Error in Parse Tree");
222 if ( !(SQL_ISRULE(pPredicateNode->getChild(0),column_ref) ||
223 pPredicateNode->getChild(2)->getNodeType() == SQLNodeType::String ||
224 pPredicateNode->getChild(2)->getNodeType() == SQLNodeType::IntNum ||
225 pPredicateNode->getChild(2)->getNodeType() == SQLNodeType::ApproxNum ||
226 SQL_ISTOKEN(pPredicateNode->getChild(2),TRUE) ||
227 SQL_ISTOKEN(pPredicateNode->getChild(2),FALSE) ||
228 SQL_ISRULE(pPredicateNode->getChild(2),parameter) ||
229 // odbc date
230 SQL_ISRULE(pPredicateNode->getChild(2),set_fct_spec) ||
231 SQL_ISRULE(pPredicateNode->getChild(2),position_exp) ||
232 SQL_ISRULE(pPredicateNode->getChild(2),char_substring_fct) ||
233 // upper, lower etc.
234 SQL_ISRULE(pPredicateNode->getChild(2),fold)) )
236 m_pAnalyzer->getConnection()->throwGenericSQLException(STR_QUERY_TOO_COMPLEX,nullptr);
237 return;
240 sal_Int32 ePredicateType( SQLFilterOperator::EQUAL );
241 OSQLParseNode *pPrec = pPredicateNode->getChild(1);
243 if (pPrec->getNodeType() == SQLNodeType::Equal)
244 ePredicateType = SQLFilterOperator::EQUAL;
245 else if (pPrec->getNodeType() == SQLNodeType::NotEqual)
246 ePredicateType = SQLFilterOperator::NOT_EQUAL;
247 else if (pPrec->getNodeType() == SQLNodeType::Less)
248 ePredicateType = SQLFilterOperator::LESS;
249 else if (pPrec->getNodeType() == SQLNodeType::LessEq)
250 ePredicateType = SQLFilterOperator::LESS_EQUAL;
251 else if (pPrec->getNodeType() == SQLNodeType::GreatEq)
252 ePredicateType = SQLFilterOperator::GREATER_EQUAL;
253 else if (pPrec->getNodeType() == SQLNodeType::Great)
254 ePredicateType = SQLFilterOperator::GREATER;
255 else
256 OSL_FAIL( "OPredicateCompiler::execute_COMPARE: unexpected node type!" );
258 execute(pPredicateNode->getChild(0));
259 execute(pPredicateNode->getChild(2));
260 m_aCodeList.emplace_back( new OOp_COMPARE(ePredicateType) );
264 void OPredicateCompiler::execute_LIKE(OSQLParseNode const * pPredicateNode)
266 DBG_ASSERT(pPredicateNode->count() == 2,"OFILECursor: Error in Parse Tree");
267 const OSQLParseNode* pPart2 = pPredicateNode->getChild(1);
269 sal_Unicode cEscape = L'\0';
270 const bool bNotLike = pPart2->getChild(0)->isToken();
272 OSQLParseNode* pAtom = pPart2->getChild(pPart2->count()-2);
273 OSQLParseNode* pOptEscape = pPart2->getChild(pPart2->count()-1);
275 if (!(pAtom->getNodeType() == SQLNodeType::String ||
276 SQL_ISRULE(pAtom,parameter) ||
277 // odbc date
278 SQL_ISRULE(pAtom,set_fct_spec) ||
279 SQL_ISRULE(pAtom,position_exp) ||
280 SQL_ISRULE(pAtom,char_substring_fct) ||
281 // upper, lower etc.
282 SQL_ISRULE(pAtom,fold)) )
284 m_pAnalyzer->getConnection()->throwGenericSQLException(STR_QUERY_TOO_COMPLEX,nullptr);
285 return;
288 if (pOptEscape->count() != 0)
290 if (pOptEscape->count() != 2)
292 m_pAnalyzer->getConnection()->throwGenericSQLException(STR_QUERY_INVALID_LIKE_STRING,nullptr);
294 OSQLParseNode *pEscNode = pOptEscape->getChild(1);
295 if (pEscNode->getNodeType() != SQLNodeType::String)
297 m_pAnalyzer->getConnection()->throwGenericSQLException(STR_QUERY_INVALID_LIKE_STRING,nullptr);
299 else
300 cEscape = pEscNode->getTokenValue().toChar();
303 execute(pPredicateNode->getChild(0));
304 execute(pAtom);
306 OBoolOperator* pOperator = bNotLike
307 ? new OOp_NOTLIKE(cEscape)
308 : new OOp_LIKE(cEscape);
309 m_aCodeList.emplace_back(pOperator);
312 void OPredicateCompiler::execute_BETWEEN(OSQLParseNode const * pPredicateNode)
314 DBG_ASSERT(pPredicateNode->count() == 2,"OFILECursor: Error in Parse Tree");
316 OSQLParseNode* pColumn = pPredicateNode->getChild(0);
317 const OSQLParseNode* pPart2 = pPredicateNode->getChild(1);
318 OSQLParseNode* p1stValue = pPart2->getChild(2);
319 OSQLParseNode* p2ndtValue = pPart2->getChild(4);
321 if (
322 !(p1stValue->getNodeType() == SQLNodeType::String || SQL_ISRULE(p1stValue,parameter))
323 && !(p2ndtValue->getNodeType() == SQLNodeType::String || SQL_ISRULE(p2ndtValue,parameter))
326 m_pAnalyzer->getConnection()->throwGenericSQLException(STR_QUERY_INVALID_BETWEEN,nullptr);
329 bool bNot = SQL_ISTOKEN(pPart2->getChild(0),NOT);
331 OOperand* pColumnOp = execute(pColumn);
332 OOperand* pOb1 = execute(p1stValue);
333 OBoolOperator* pOperator = new OOp_COMPARE(bNot ? SQLFilterOperator::LESS : SQLFilterOperator::GREATER_EQUAL);
334 m_aCodeList.emplace_back(pOperator);
336 execute(pColumn);
337 OOperand* pOb2 = execute(p2ndtValue);
338 pOperator = new OOp_COMPARE(bNot ? SQLFilterOperator::GREATER : SQLFilterOperator::LESS_EQUAL);
339 m_aCodeList.emplace_back(pOperator);
341 if ( pColumnOp && pOb1 && pOb2 )
343 switch(pColumnOp->getDBType())
345 case DataType::CHAR:
346 case DataType::VARCHAR:
347 case DataType::LONGVARCHAR:
348 pOb1->setValue(pOb1->getValue().getString());
349 pOb2->setValue(pOb2->getValue().getString());
350 break;
351 case DataType::DECIMAL:
352 case DataType::NUMERIC:
353 case DataType::DOUBLE:
354 case DataType::REAL:
355 pOb1->setValue(pOb1->getValue().getDouble());
356 pOb2->setValue(pOb2->getValue().getDouble());
357 break;
358 case DataType::FLOAT:
359 pOb1->setValue(pOb1->getValue().getFloat());
360 pOb2->setValue(pOb2->getValue().getFloat());
361 break;
362 case DataType::DATE:
363 pOb1->setValue(pOb1->getValue().getDate());
364 pOb2->setValue(pOb2->getValue().getDate());
365 break;
366 case DataType::TIME:
367 pOb1->setValue(pOb1->getValue().getTime());
368 pOb2->setValue(pOb2->getValue().getTime());
369 break;
370 case DataType::TIMESTAMP:
371 pOb1->setValue(pOb1->getValue().getDateTime());
372 pOb2->setValue(pOb2->getValue().getDateTime());
373 break;
378 OBoolOperator* pBoolOp = nullptr;
379 if ( bNot )
380 pBoolOp = new OOp_OR;
381 else
382 pBoolOp = new OOp_AND;
383 m_aCodeList.emplace_back(pBoolOp);
386 void OPredicateCompiler::execute_ISNULL(OSQLParseNode const * pPredicateNode)
388 DBG_ASSERT(pPredicateNode->count() == 2,"OFILECursor: Error in Parse Tree");
389 const OSQLParseNode* pPart2 = pPredicateNode->getChild(1);
390 DBG_ASSERT(SQL_ISTOKEN(pPart2->getChild(0),IS),"OFILECursor: Error in Parse Tree");
392 sal_Int32 ePredicateType;
393 if (SQL_ISTOKEN(pPart2->getChild(1),NOT))
394 ePredicateType = SQLFilterOperator::NOT_SQLNULL;
395 else
396 ePredicateType = SQLFilterOperator::SQLNULL;
398 execute(pPredicateNode->getChild(0));
399 OBoolOperator* pOperator = (ePredicateType == SQLFilterOperator::SQLNULL) ?
400 new OOp_ISNULL : new OOp_ISNOTNULL;
401 m_aCodeList.emplace_back(pOperator);
404 OOperand* OPredicateCompiler::execute_Operand(OSQLParseNode const * pPredicateNode)
406 OOperand* pOperand = nullptr;
408 if (SQL_ISRULE(pPredicateNode,column_ref))
410 OUString aColumnName;
411 if (pPredicateNode->count() == 1)
413 aColumnName = pPredicateNode->getChild(0)->getTokenValue();
415 else if (pPredicateNode->count() == 3)
417 if(SQL_ISRULE(pPredicateNode->getChild(2),column_val))
418 aColumnName = pPredicateNode->getChild(2)->getChild(0)->getTokenValue();
419 else
420 aColumnName = pPredicateNode->getChild(2)->getTokenValue();
423 if(!m_orgColumns->hasByName(aColumnName))
425 const OUString sError( m_pAnalyzer->getConnection()->getResources().getResourceStringWithSubstitution(
426 STR_INVALID_COLUMNNAME,
427 "$columnname$", aColumnName
428 ) );
429 ::dbtools::throwGenericSQLException( sError, nullptr );
431 css::uno::Reference< css::beans::XPropertySet> xCol;
434 if (m_orgColumns->getByName(aColumnName) >>= xCol)
436 pOperand = OSQLAnalyzer::createOperandAttr(Reference< XColumnLocate>(m_orgColumns,UNO_QUERY_THROW)->findColumn(aColumnName),xCol);
438 else
439 {// Column doesn't exist in the Result-set
440 const OUString sError( m_pAnalyzer->getConnection()->getResources().getResourceStringWithSubstitution(
441 STR_INVALID_COLUMNNAME,
442 "$columnname$", aColumnName
443 ) );
444 ::dbtools::throwGenericSQLException( sError, nullptr );
447 catch(Exception &)
449 TOOLS_WARN_EXCEPTION( "connectivity.drivers", "OPredicateCompiler::execute_Operand Exception");
452 else if (SQL_ISRULE(pPredicateNode,parameter))
454 pOperand = new OOperandParam(++m_nParamCounter);
456 else if (pPredicateNode->getNodeType() == SQLNodeType::String ||
457 pPredicateNode->getNodeType() == SQLNodeType::IntNum ||
458 pPredicateNode->getNodeType() == SQLNodeType::ApproxNum ||
459 pPredicateNode->getNodeType() == SQLNodeType::Name ||
460 SQL_ISTOKEN(pPredicateNode,TRUE) ||
461 SQL_ISTOKEN(pPredicateNode,FALSE) ||
462 SQL_ISRULE(pPredicateNode,parameter))
464 pOperand = new OOperandConst(*pPredicateNode, pPredicateNode->getTokenValue());
466 else if((pPredicateNode->count() == 2) &&
467 (SQL_ISPUNCTUATION(pPredicateNode->getChild(0),"+") || SQL_ISPUNCTUATION(pPredicateNode->getChild(0),"-")) &&
468 pPredicateNode->getChild(1)->getNodeType() == SQLNodeType::IntNum)
469 { // if -1 or +1 is there
470 OUString aValue = pPredicateNode->getChild(0)->getTokenValue() + pPredicateNode->getChild(1)->getTokenValue();
471 pOperand = new OOperandConst(*pPredicateNode->getChild(1), aValue);
473 else if( SQL_ISRULE(pPredicateNode,set_fct_spec) && SQL_ISPUNCTUATION(pPredicateNode->getChild(0),"{") )
475 const OSQLParseNode* pODBCNode = pPredicateNode->getChild(1);
476 const OSQLParseNode* pODBCNodeChild = pODBCNode->getChild(0);
478 // Odbc Date or time
479 if (pODBCNodeChild->getNodeType() == SQLNodeType::Keyword && (
480 SQL_ISTOKEN(pODBCNodeChild,D) ||
481 SQL_ISTOKEN(pODBCNodeChild,T) ||
482 SQL_ISTOKEN(pODBCNodeChild,TS) ))
484 OUString sDateTime = pODBCNode->getChild(1)->getTokenValue();
485 pOperand = new OOperandConst(*pODBCNode->getChild(1), sDateTime);
486 if(SQL_ISTOKEN(pODBCNodeChild,D))
488 pOperand->setValue(::dbtools::DBTypeConversion::toDouble(::dbtools::DBTypeConversion::toDate(sDateTime)));
490 else if(SQL_ISTOKEN(pODBCNodeChild,T))
492 pOperand->setValue(::dbtools::DBTypeConversion::toDouble(::dbtools::DBTypeConversion::toTime(sDateTime)));
494 else if(SQL_ISTOKEN(pODBCNodeChild,TS))
496 pOperand->setValue(::dbtools::DBTypeConversion::toDouble(::dbtools::DBTypeConversion::toDateTime(sDateTime)));
499 else
500 m_pAnalyzer->getConnection()->throwGenericSQLException(STR_QUERY_TOO_COMPLEX,nullptr);
503 else if( SQL_ISRULE(pPredicateNode,fold) )
505 execute_Fold(pPredicateNode);
507 else if( SQL_ISRULE(pPredicateNode,set_fct_spec)
508 || SQL_ISRULE(pPredicateNode,position_exp)
509 || SQL_ISRULE(pPredicateNode,char_substring_fct)
512 executeFunction(pPredicateNode);
514 else if( SQL_ISRULE(pPredicateNode,length_exp) )
516 executeFunction(pPredicateNode->getChild(0));
518 else
520 m_pAnalyzer->getConnection()->throwGenericSQLException(STR_QUERY_TOO_COMPLEX,nullptr);
522 if (pOperand)
523 m_aCodeList.emplace_back(pOperand);
524 return pOperand;
528 bool OPredicateInterpreter::evaluate(OCodeList& rCodeList)
530 if (!(rCodeList[0]))
531 return true; // no Predicate
533 for (auto const& code : rCodeList)
535 OOperand* pOperand = dynamic_cast<OOperand* >(code.get());
536 if (pOperand)
537 m_aStack.push(pOperand);
538 else
539 static_cast<OOperator *>(code.get())->Exec(m_aStack);
542 OOperand* pOperand = m_aStack.top();
543 m_aStack.pop();
545 DBG_ASSERT(m_aStack.empty(), "Stack error");
546 assert(pOperand && "Stack error");
548 const bool bResult = pOperand->isValid();
549 if (typeid(OOperandResult) == typeid(*pOperand))
550 delete pOperand;
551 return bResult;
554 void OPredicateInterpreter::evaluateSelection(OCodeList& rCodeList, ORowSetValueDecoratorRef const & _rVal)
556 if (!(rCodeList[0]))
557 return ; // no Predicate
559 for (auto const& code : rCodeList)
561 OOperand* pOperand = dynamic_cast<OOperand* >(code.get());
562 if (pOperand)
563 m_aStack.push(pOperand);
564 else
565 static_cast<OOperator *>(code.get())->Exec(m_aStack);
568 OOperand* pOperand = m_aStack.top();
569 m_aStack.pop();
571 DBG_ASSERT(m_aStack.empty(), "Stack error");
572 assert(pOperand && "Stack error");
574 (*_rVal) = pOperand->getValue();
575 if (typeid(OOperandResult) == typeid(*pOperand))
576 delete pOperand;
579 void OPredicateCompiler::execute_Fold(OSQLParseNode const * pPredicateNode)
581 DBG_ASSERT(pPredicateNode->count() >= 4,"OFILECursor: Error in Parse Tree");
583 bool bUpper = SQL_ISTOKEN(pPredicateNode->getChild(0),UPPER);
585 execute(pPredicateNode->getChild(2));
586 OOperator* pOperator = nullptr;
587 if ( bUpper )
588 pOperator = new OOp_Upper;
589 else
590 pOperator = new OOp_Lower;
592 m_aCodeList.emplace_back(pOperator);
595 void OPredicateCompiler::executeFunction(OSQLParseNode const * pPredicateNode)
597 OOperator* pOperator = nullptr;
599 OSL_ENSURE(pPredicateNode->getChild(0)->isToken(),"The first one must be the name of the function!");
600 sal_Int32 nTokenId = pPredicateNode->getChild(0)->getTokenID();
601 switch ( nTokenId )
603 case SQL_TOKEN_CHAR_LENGTH:
604 case SQL_TOKEN_LENGTH:
605 case SQL_TOKEN_OCTET_LENGTH:
606 case SQL_TOKEN_ASCII:
607 case SQL_TOKEN_LCASE:
608 case SQL_TOKEN_LTRIM:
609 case SQL_TOKEN_RTRIM:
610 case SQL_TOKEN_SPACE:
611 case SQL_TOKEN_UCASE:
612 case SQL_TOKEN_ABS:
613 case SQL_TOKEN_ACOS:
614 case SQL_TOKEN_ASIN:
615 case SQL_TOKEN_ATAN:
616 case SQL_TOKEN_CEILING:
617 case SQL_TOKEN_COS:
618 case SQL_TOKEN_DEGREES:
619 case SQL_TOKEN_EXP:
620 case SQL_TOKEN_FLOOR:
621 case SQL_TOKEN_LOG10:
622 case SQL_TOKEN_LN:
623 case SQL_TOKEN_RADIANS:
624 case SQL_TOKEN_SIGN:
625 case SQL_TOKEN_SIN:
626 case SQL_TOKEN_SQRT:
627 case SQL_TOKEN_TAN:
628 case SQL_TOKEN_DAYNAME:
629 case SQL_TOKEN_DAYOFMONTH:
630 case SQL_TOKEN_DAYOFWEEK:
631 case SQL_TOKEN_DAYOFYEAR:
632 case SQL_TOKEN_HOUR:
633 case SQL_TOKEN_MINUTE:
634 case SQL_TOKEN_MONTH:
635 case SQL_TOKEN_MONTHNAME:
636 case SQL_TOKEN_QUARTER:
637 case SQL_TOKEN_SECOND:
638 case SQL_TOKEN_YEAR:
640 execute(pPredicateNode->getChild(2));
642 switch( nTokenId )
644 case SQL_TOKEN_CHAR_LENGTH:
645 case SQL_TOKEN_LENGTH:
646 case SQL_TOKEN_OCTET_LENGTH:
647 pOperator = new OOp_CharLength;
648 break;
649 case SQL_TOKEN_ASCII:
650 pOperator = new OOp_Ascii;
651 break;
652 case SQL_TOKEN_LCASE:
653 pOperator = new OOp_Lower;
654 break;
656 case SQL_TOKEN_LTRIM:
657 pOperator = new OOp_LTrim;
658 break;
659 case SQL_TOKEN_RTRIM:
660 pOperator = new OOp_RTrim;
661 break;
662 case SQL_TOKEN_SPACE:
663 pOperator = new OOp_Space;
664 break;
665 case SQL_TOKEN_UCASE:
666 pOperator = new OOp_Upper;
667 break;
668 case SQL_TOKEN_ABS:
669 pOperator = new OOp_Abs;
670 break;
671 case SQL_TOKEN_ACOS:
672 pOperator = new OOp_ACos;
673 break;
674 case SQL_TOKEN_ASIN:
675 pOperator = new OOp_ASin;
676 break;
677 case SQL_TOKEN_ATAN:
678 pOperator = new OOp_ATan;
679 break;
680 case SQL_TOKEN_CEILING:
681 pOperator = new OOp_Ceiling;
682 break;
683 case SQL_TOKEN_COS:
684 pOperator = new OOp_Cos;
685 break;
686 case SQL_TOKEN_DEGREES:
687 pOperator = new OOp_Degrees;
688 break;
689 case SQL_TOKEN_EXP:
690 pOperator = new OOp_Exp;
691 break;
692 case SQL_TOKEN_FLOOR:
693 pOperator = new OOp_Floor;
694 break;
695 case SQL_TOKEN_LOG10:
696 pOperator = new OOp_Log10;
697 break;
698 case SQL_TOKEN_LN:
699 pOperator = new OOp_Ln;
700 break;
701 case SQL_TOKEN_RADIANS:
702 pOperator = new OOp_Radians;
703 break;
704 case SQL_TOKEN_SIGN:
705 pOperator = new OOp_Sign;
706 break;
707 case SQL_TOKEN_SIN:
708 pOperator = new OOp_Sin;
709 break;
710 case SQL_TOKEN_SQRT:
711 pOperator = new OOp_Sqrt;
712 break;
713 case SQL_TOKEN_TAN:
714 pOperator = new OOp_Tan;
715 break;
716 case SQL_TOKEN_DAYOFWEEK:
717 pOperator = new OOp_DayOfWeek;
718 break;
719 case SQL_TOKEN_DAYOFMONTH:
720 pOperator = new OOp_DayOfMonth;
721 break;
722 case SQL_TOKEN_DAYOFYEAR:
723 pOperator = new OOp_DayOfYear;
724 break;
725 case SQL_TOKEN_MONTH:
726 pOperator = new OOp_Month;
727 break;
728 case SQL_TOKEN_DAYNAME:
729 pOperator = new OOp_DayName;
730 break;
731 case SQL_TOKEN_MONTHNAME:
732 pOperator = new OOp_MonthName;
733 break;
734 case SQL_TOKEN_QUARTER:
735 pOperator = new OOp_Quarter;
736 break;
737 case SQL_TOKEN_YEAR:
738 pOperator = new OOp_Year;
739 break;
740 case SQL_TOKEN_HOUR:
741 pOperator = new OOp_Hour;
742 break;
743 case SQL_TOKEN_MINUTE:
744 pOperator = new OOp_Minute;
745 break;
746 case SQL_TOKEN_SECOND:
747 pOperator = new OOp_Second;
748 break;
749 default:
750 OSL_FAIL("Error in switch!");
752 break;
753 case SQL_TOKEN_CHAR:
754 case SQL_TOKEN_CONCAT:
755 case SQL_TOKEN_INSERT:
756 case SQL_TOKEN_LEFT:
757 case SQL_TOKEN_LOCATE:
758 case SQL_TOKEN_LOCATE_2:
759 case SQL_TOKEN_REPEAT:
760 case SQL_TOKEN_REPLACE:
761 case SQL_TOKEN_RIGHT:
762 case SQL_TOKEN_MOD:
763 case SQL_TOKEN_ROUND:
764 case SQL_TOKEN_LOGF:
765 case SQL_TOKEN_LOG:
766 case SQL_TOKEN_POWER:
767 case SQL_TOKEN_ATAN2:
768 case SQL_TOKEN_PI:
769 case SQL_TOKEN_CURDATE:
770 case SQL_TOKEN_CURTIME:
771 case SQL_TOKEN_NOW:
772 case SQL_TOKEN_WEEK:
774 m_aCodeList.emplace_back(new OStopOperand);
775 OSQLParseNode* pList = pPredicateNode->getChild(2);
776 for (size_t i=0; i < pList->count(); ++i)
777 execute(pList->getChild(i));
779 switch( nTokenId )
781 case SQL_TOKEN_CHAR:
782 pOperator = new OOp_Char;
783 break;
784 case SQL_TOKEN_CONCAT:
785 pOperator = new OOp_Concat;
786 break;
787 case SQL_TOKEN_INSERT:
788 pOperator = new OOp_Insert;
789 break;
790 case SQL_TOKEN_LEFT:
791 pOperator = new OOp_Left;
792 break;
793 case SQL_TOKEN_LOCATE:
794 case SQL_TOKEN_LOCATE_2:
795 pOperator = new OOp_Locate;
796 break;
797 case SQL_TOKEN_REPEAT:
798 pOperator = new OOp_Repeat;
799 break;
800 case SQL_TOKEN_REPLACE:
801 pOperator = new OOp_Replace;
802 break;
803 case SQL_TOKEN_RIGHT:
804 pOperator = new OOp_Right;
805 break;
806 case SQL_TOKEN_MOD:
807 pOperator = new OOp_Mod;
808 break;
809 case SQL_TOKEN_ROUND:
810 pOperator = new OOp_Round;
811 break;
812 case SQL_TOKEN_LOGF:
813 case SQL_TOKEN_LOG:
814 pOperator = new OOp_Log;
815 break;
816 case SQL_TOKEN_POWER:
817 pOperator = new OOp_Pow;
818 break;
819 case SQL_TOKEN_ATAN2:
820 pOperator = new OOp_ATan2;
821 break;
822 case SQL_TOKEN_PI:
823 pOperator = new OOp_Pi;
824 break;
825 case SQL_TOKEN_CURDATE:
826 pOperator = new OOp_CurDate;
827 break;
828 case SQL_TOKEN_CURTIME:
829 pOperator = new OOp_CurTime;
830 break;
831 case SQL_TOKEN_NOW:
832 pOperator = new OOp_Now;
833 break;
834 case SQL_TOKEN_WEEK:
835 pOperator = new OOp_Week;
836 break;
837 default:
838 OSL_FAIL("Error in switch!");
841 break;
843 case SQL_TOKEN_SUBSTRING:
844 m_aCodeList.emplace_back(new OStopOperand);
845 if ( pPredicateNode->count() == 4 ) //char_substring_fct
847 OSQLParseNode* pList = pPredicateNode->getChild(2);
848 for (size_t i=0; i < pList->count(); ++i)
849 execute(pList->getChild(i));
851 else
853 execute(pPredicateNode->getChild(2));
854 execute(pPredicateNode->getChild(4));
855 execute(pPredicateNode->getChild(5)->getChild(1));
857 pOperator = new OOp_SubString;
858 break;
860 case SQL_TOKEN_POSITION:
861 m_aCodeList.emplace_back(new OStopOperand);
862 if ( pPredicateNode->count() == 4 ) //position_exp
864 OSQLParseNode* pList = pPredicateNode->getChild(2);
865 for (size_t i=0; i < pList->count(); ++i)
866 execute(pList->getChild(i));
868 else
870 execute(pPredicateNode->getChild(2));
871 execute(pPredicateNode->getChild(4));
873 pOperator = new OOp_Locate;
874 break;
875 default:
876 m_pAnalyzer->getConnection()->throwGenericSQLException(STR_QUERY_FUNCTION_NOT_SUPPORTED,nullptr);
879 m_aCodeList.emplace_back(pOperator);
883 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */