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