1*9b5730f6SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*9b5730f6SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*9b5730f6SAndrew Rist * or more contributor license agreements. See the NOTICE file
5*9b5730f6SAndrew Rist * distributed with this work for additional information
6*9b5730f6SAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*9b5730f6SAndrew Rist * to you under the Apache License, Version 2.0 (the
8*9b5730f6SAndrew Rist * "License"); you may not use this file except in compliance
9*9b5730f6SAndrew Rist * with the License. You may obtain a copy of the License at
10cdf0e10cSrcweir *
11*9b5730f6SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir *
13*9b5730f6SAndrew Rist * Unless required by applicable law or agreed to in writing,
14*9b5730f6SAndrew Rist * software distributed under the License is distributed on an
15*9b5730f6SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*9b5730f6SAndrew Rist * KIND, either express or implied. See the License for the
17*9b5730f6SAndrew Rist * specific language governing permissions and limitations
18*9b5730f6SAndrew Rist * under the License.
19cdf0e10cSrcweir *
20*9b5730f6SAndrew Rist *************************************************************/
21*9b5730f6SAndrew Rist
22*9b5730f6SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_connectivity.hxx"
26cdf0e10cSrcweir #include "file/fcode.hxx"
27cdf0e10cSrcweir #include <osl/diagnose.h>
28cdf0e10cSrcweir #include "connectivity/sqlparse.hxx"
29cdf0e10cSrcweir #include <i18npool/mslangid.hxx>
30cdf0e10cSrcweir #include <tools/debug.hxx>
31cdf0e10cSrcweir #include <tools/string.hxx>
32cdf0e10cSrcweir #include "TConnection.hxx"
33cdf0e10cSrcweir #include <com/sun/star/sdb/SQLFilterOperator.hpp>
34cdf0e10cSrcweir #include <comphelper/types.hxx>
35cdf0e10cSrcweir #include <com/sun/star/sdb/SQLFilterOperator.hpp>
36cdf0e10cSrcweir #include <rtl/logfile.hxx>
37cdf0e10cSrcweir
38cdf0e10cSrcweir using namespace ::comphelper;
39cdf0e10cSrcweir using namespace connectivity;
40cdf0e10cSrcweir using namespace connectivity::file;
41cdf0e10cSrcweir //using namespace ::com::sun::star::uno;
42cdf0e10cSrcweir //using namespace ::com::sun::star::lang;
43cdf0e10cSrcweir using namespace ::com::sun::star::sdbc;
44cdf0e10cSrcweir using namespace ::com::sun::star::sdb;
45cdf0e10cSrcweir //using namespace ::com::sun::star::container;
46cdf0e10cSrcweir //using namespace ::com::sun::star::beans;
47cdf0e10cSrcweir //using namespace ::com::sun::star::sdbcx;
48cdf0e10cSrcweir
49cdf0e10cSrcweir TYPEINIT0(OCode);
50cdf0e10cSrcweir TYPEINIT1(OOperand, OCode);
51cdf0e10cSrcweir TYPEINIT1(OOperandRow, OOperand);
52cdf0e10cSrcweir TYPEINIT1(OOperandAttr, OOperandRow);
53cdf0e10cSrcweir TYPEINIT1(OOperandParam, OOperandRow);
54cdf0e10cSrcweir TYPEINIT1(OOperandValue, OOperand);
55cdf0e10cSrcweir TYPEINIT1(OOperandConst, OOperandValue);
56cdf0e10cSrcweir TYPEINIT1(OOperandResult, OOperandValue);
57cdf0e10cSrcweir TYPEINIT1(OStopOperand, OOperandValue);
58cdf0e10cSrcweir
59cdf0e10cSrcweir TYPEINIT1(OOperator, OCode);
60cdf0e10cSrcweir TYPEINIT1(OBoolOperator,OOperator);
61cdf0e10cSrcweir TYPEINIT1(OOp_NOT, OBoolOperator);
62cdf0e10cSrcweir TYPEINIT1(OOp_AND, OBoolOperator);
63cdf0e10cSrcweir TYPEINIT1(OOp_OR, OBoolOperator);
64cdf0e10cSrcweir TYPEINIT1(OOp_ISNULL, OBoolOperator);
65cdf0e10cSrcweir TYPEINIT1(OOp_ISNOTNULL, OOp_ISNULL);
66cdf0e10cSrcweir TYPEINIT1(OOp_LIKE, OBoolOperator);
67cdf0e10cSrcweir TYPEINIT1(OOp_NOTLIKE, OOp_LIKE);
68cdf0e10cSrcweir TYPEINIT1(OOp_COMPARE, OBoolOperator);
69cdf0e10cSrcweir TYPEINIT1(ONumOperator, OOperator);
70cdf0e10cSrcweir TYPEINIT1(ONthOperator, OOperator);
71cdf0e10cSrcweir TYPEINIT1(OBinaryOperator, OOperator);
72cdf0e10cSrcweir TYPEINIT1(OUnaryOperator, OOperator);
73cdf0e10cSrcweir
74cdf0e10cSrcweir //------------------------------------------------------------------
DBG_NAME(OCode)75cdf0e10cSrcweir DBG_NAME(OCode )
76cdf0e10cSrcweir OCode::OCode()
77cdf0e10cSrcweir {
78cdf0e10cSrcweir DBG_CTOR(OCode ,NULL);
79cdf0e10cSrcweir }
80cdf0e10cSrcweir // -----------------------------------------------------------------------------
~OCode()81cdf0e10cSrcweir OCode::~OCode()
82cdf0e10cSrcweir {
83cdf0e10cSrcweir DBG_DTOR(OCode,NULL);
84cdf0e10cSrcweir }
85cdf0e10cSrcweir
86cdf0e10cSrcweir //------------------------------------------------------------------
preProcess(OBoolOperator *,OOperand *)87cdf0e10cSrcweir OEvaluateSet* OOperand::preProcess(OBoolOperator* /*pOp*/, OOperand* /*pRight*/)
88cdf0e10cSrcweir {
89cdf0e10cSrcweir return NULL;
90cdf0e10cSrcweir }
91cdf0e10cSrcweir // -----------------------------------------------------------------------------
OOperandRow(sal_uInt16 _nPos,sal_Int32 _rType)92cdf0e10cSrcweir OOperandRow::OOperandRow(sal_uInt16 _nPos, sal_Int32 _rType)
93cdf0e10cSrcweir : OOperand(_rType)
94cdf0e10cSrcweir , m_nRowPos(_nPos)
95cdf0e10cSrcweir {}
96cdf0e10cSrcweir //------------------------------------------------------------------
bindValue(const OValueRefRow & _pRow)97cdf0e10cSrcweir void OOperandRow::bindValue(const OValueRefRow& _pRow)
98cdf0e10cSrcweir {
99cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OOperandRow::OOperandRow" );
100cdf0e10cSrcweir OSL_ENSURE(_pRow.isValid(),"NO EMPTY row allowed!");
101cdf0e10cSrcweir m_pRow = _pRow;
102cdf0e10cSrcweir OSL_ENSURE(m_pRow.isValid() && m_nRowPos < m_pRow->get().size(),"Invalid RowPos is >= vector.size()");
103cdf0e10cSrcweir (m_pRow->get())[m_nRowPos]->setBound(sal_True);
104cdf0e10cSrcweir }
105cdf0e10cSrcweir // -----------------------------------------------------------------------------
setValue(const ORowSetValue & _rVal)106cdf0e10cSrcweir void OOperandRow::setValue(const ORowSetValue& _rVal)
107cdf0e10cSrcweir {
108cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OOperandRow::setValue" );
109cdf0e10cSrcweir OSL_ENSURE(m_pRow.isValid() && m_nRowPos < m_pRow->get().size(),"Invalid RowPos is >= vector.size()");
110cdf0e10cSrcweir (*(m_pRow->get())[m_nRowPos]) = _rVal;
111cdf0e10cSrcweir }
112cdf0e10cSrcweir //------------------------------------------------------------------
getValue() const113cdf0e10cSrcweir const ORowSetValue& OOperandRow::getValue() const
114cdf0e10cSrcweir {
115cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OOperandRow::getValue" );
116cdf0e10cSrcweir OSL_ENSURE(m_pRow.isValid() && m_nRowPos < m_pRow->get().size(),"Invalid RowPos is >= vector.size()");
117cdf0e10cSrcweir return (m_pRow->get())[m_nRowPos]->getValue();
118cdf0e10cSrcweir }
119cdf0e10cSrcweir
120cdf0e10cSrcweir // -----------------------------------------------------------------------------
setValue(const ORowSetValue & _rVal)121cdf0e10cSrcweir void OOperandValue::setValue(const ORowSetValue& _rVal)
122cdf0e10cSrcweir {
123cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OOperandValue::setValue" );
124cdf0e10cSrcweir m_aValue = _rVal;
125cdf0e10cSrcweir }
126cdf0e10cSrcweir // -------------------------------------------------------------------------
isIndexed() const127cdf0e10cSrcweir sal_Bool OOperandAttr::isIndexed() const
128cdf0e10cSrcweir {
129cdf0e10cSrcweir return sal_False;
130cdf0e10cSrcweir }
131cdf0e10cSrcweir //------------------------------------------------------------------
OOperandParam(OSQLParseNode * pNode,sal_Int32 _nPos)132cdf0e10cSrcweir OOperandParam::OOperandParam(OSQLParseNode* pNode, sal_Int32 _nPos)
133cdf0e10cSrcweir : OOperandRow(static_cast<sal_uInt16>(_nPos), DataType::VARCHAR) // Standard-Typ
134cdf0e10cSrcweir {
135cdf0e10cSrcweir OSL_ENSURE(SQL_ISRULE(pNode,parameter),"Argument ist kein Parameter");
136cdf0e10cSrcweir OSL_ENSURE(pNode->count() > 0,"Fehler im Parse Tree");
137cdf0e10cSrcweir OSQLParseNode *pMark = pNode->getChild(0);
138cdf0e10cSrcweir
139cdf0e10cSrcweir String aParameterName;
140cdf0e10cSrcweir if (SQL_ISPUNCTUATION(pMark,"?"))
141cdf0e10cSrcweir aParameterName = '?';
142cdf0e10cSrcweir else if (SQL_ISPUNCTUATION(pMark,":"))
143cdf0e10cSrcweir aParameterName = pNode->getChild(1)->getTokenValue();
144cdf0e10cSrcweir else
145cdf0e10cSrcweir {
146cdf0e10cSrcweir OSL_ASSERT("Fehler im Parse Tree");
147cdf0e10cSrcweir }
148cdf0e10cSrcweir
149cdf0e10cSrcweir // Parameter-Column aufsetzen mit defult typ, kann zu einem spaeteren Zeitpunkt ueber DescribeParameter
150cdf0e10cSrcweir // genauer spezifiziert werden
151cdf0e10cSrcweir
152cdf0e10cSrcweir // Identitaet merken (hier eigentlich nicht erforderlich, aber aus
153cdf0e10cSrcweir // Symmetriegruenden ...)
154cdf0e10cSrcweir
155cdf0e10cSrcweir // todo
156cdf0e10cSrcweir // OColumn* pColumn = new OFILEColumn(aParameterName,eDBType,255,0,SQL_FLAGS_NULLALLOWED);
157cdf0e10cSrcweir // rParamColumns->AddColumn(pColumn);
158cdf0e10cSrcweir
159cdf0e10cSrcweir // der Wert wird erst kurz vor der Auswertung gesetzt
160cdf0e10cSrcweir }
161cdf0e10cSrcweir
162cdf0e10cSrcweir
163cdf0e10cSrcweir //------------------------------------------------------------------
getValue() const164cdf0e10cSrcweir const ORowSetValue& OOperandValue::getValue() const
165cdf0e10cSrcweir {
166cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OOperandValue::getValue" );
167cdf0e10cSrcweir return m_aValue;
168cdf0e10cSrcweir }
169cdf0e10cSrcweir
170cdf0e10cSrcweir //------------------------------------------------------------------
OOperandConst(const OSQLParseNode & rColumnRef,const rtl::OUString & aStrValue)171cdf0e10cSrcweir OOperandConst::OOperandConst(const OSQLParseNode& rColumnRef, const rtl::OUString& aStrValue)
172cdf0e10cSrcweir {
173cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OOperandConst::OOperandConst" );
174cdf0e10cSrcweir switch (rColumnRef.getNodeType())
175cdf0e10cSrcweir {
176cdf0e10cSrcweir case SQL_NODE_STRING:
177cdf0e10cSrcweir m_aValue = aStrValue;
178cdf0e10cSrcweir m_eDBType = DataType::VARCHAR;
179cdf0e10cSrcweir m_aValue.setBound(sal_True);
180cdf0e10cSrcweir return;
181cdf0e10cSrcweir case SQL_NODE_INTNUM:
182cdf0e10cSrcweir case SQL_NODE_APPROXNUM:
183cdf0e10cSrcweir {
184cdf0e10cSrcweir m_aValue = aStrValue.toDouble();
185cdf0e10cSrcweir m_eDBType = DataType::DOUBLE;
186cdf0e10cSrcweir m_aValue.setBound(sal_True);
187cdf0e10cSrcweir return;
188cdf0e10cSrcweir }
189cdf0e10cSrcweir default:
190cdf0e10cSrcweir break;
191cdf0e10cSrcweir }
192cdf0e10cSrcweir
193cdf0e10cSrcweir if (SQL_ISTOKEN(&rColumnRef,TRUE))
194cdf0e10cSrcweir {
195cdf0e10cSrcweir m_aValue = 1.0;
196cdf0e10cSrcweir m_eDBType = DataType::BIT;
197cdf0e10cSrcweir }
198cdf0e10cSrcweir else if (SQL_ISTOKEN(&rColumnRef,FALSE))
199cdf0e10cSrcweir {
200cdf0e10cSrcweir m_aValue = 0.0;
201cdf0e10cSrcweir m_eDBType = DataType::BIT;
202cdf0e10cSrcweir }
203cdf0e10cSrcweir else
204cdf0e10cSrcweir {
205cdf0e10cSrcweir OSL_ASSERT("Parse Error");
206cdf0e10cSrcweir }
207cdf0e10cSrcweir m_aValue.setBound(sal_True);
208cdf0e10cSrcweir }
209cdf0e10cSrcweir
210cdf0e10cSrcweir /////////////////////////////////////////////////////////////////////////////////////////
211cdf0e10cSrcweir // Implementation of the operators
212cdf0e10cSrcweir
213cdf0e10cSrcweir //------------------------------------------------------------------
getRequestedOperands() const214cdf0e10cSrcweir sal_uInt16 OOperator::getRequestedOperands() const {return 2;}
215cdf0e10cSrcweir
216cdf0e10cSrcweir //------------------------------------------------------------------
operate(const OOperand *,const OOperand *) const217cdf0e10cSrcweir sal_Bool OBoolOperator::operate(const OOperand*, const OOperand*) const
218cdf0e10cSrcweir {
219cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OBoolOperator::operate" );
220cdf0e10cSrcweir return sal_False;
221cdf0e10cSrcweir }
222cdf0e10cSrcweir
223cdf0e10cSrcweir
224cdf0e10cSrcweir //------------------------------------------------------------------
Exec(OCodeStack & rCodeStack)225cdf0e10cSrcweir void OBoolOperator::Exec(OCodeStack& rCodeStack)
226cdf0e10cSrcweir {
227cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OBoolOperator::Exec" );
228cdf0e10cSrcweir OOperand *pRight = rCodeStack.top();
229cdf0e10cSrcweir rCodeStack.pop();
230cdf0e10cSrcweir OOperand *pLeft = rCodeStack.top();
231cdf0e10cSrcweir rCodeStack.pop();
232cdf0e10cSrcweir
233cdf0e10cSrcweir rCodeStack.push(new OOperandResultBOOL(operate(pLeft, pRight)));
234cdf0e10cSrcweir if (IS_TYPE(OOperandResult,pLeft))
235cdf0e10cSrcweir delete pLeft;
236cdf0e10cSrcweir if (IS_TYPE(OOperandResult,pRight))
237cdf0e10cSrcweir delete pRight;
238cdf0e10cSrcweir }
239cdf0e10cSrcweir //------------------------------------------------------------------
operate(const OOperand * pLeft,const OOperand *) const240cdf0e10cSrcweir sal_Bool OOp_NOT::operate(const OOperand* pLeft, const OOperand* ) const
241cdf0e10cSrcweir {
242cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OOp_AND::operate" );
243cdf0e10cSrcweir return !pLeft->isValid();
244cdf0e10cSrcweir }
245cdf0e10cSrcweir //------------------------------------------------------------------
Exec(OCodeStack & rCodeStack)246cdf0e10cSrcweir void OOp_NOT::Exec(OCodeStack& rCodeStack)
247cdf0e10cSrcweir {
248cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OOp_ISNULL::Exec" );
249cdf0e10cSrcweir OOperand* pOperand = rCodeStack.top();
250cdf0e10cSrcweir rCodeStack.pop();
251cdf0e10cSrcweir
252cdf0e10cSrcweir rCodeStack.push(new OOperandResultBOOL(operate(pOperand)));
253cdf0e10cSrcweir if (IS_TYPE(OOperandResult,pOperand))
254cdf0e10cSrcweir delete pOperand;
255cdf0e10cSrcweir }
256cdf0e10cSrcweir //------------------------------------------------------------------
getRequestedOperands() const257cdf0e10cSrcweir sal_uInt16 OOp_NOT::getRequestedOperands() const
258cdf0e10cSrcweir {
259cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OOp_NOT::getRequestedOperands" );
260cdf0e10cSrcweir return 1;
261cdf0e10cSrcweir }
262cdf0e10cSrcweir
263cdf0e10cSrcweir //------------------------------------------------------------------
operate(const OOperand * pLeft,const OOperand * pRight) const264cdf0e10cSrcweir sal_Bool OOp_AND::operate(const OOperand* pLeft, const OOperand* pRight) const
265cdf0e10cSrcweir {
266cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OOp_AND::operate" );
267cdf0e10cSrcweir return pLeft->isValid() && pRight->isValid();
268cdf0e10cSrcweir }
269cdf0e10cSrcweir
270cdf0e10cSrcweir //------------------------------------------------------------------
operate(const OOperand * pLeft,const OOperand * pRight) const271cdf0e10cSrcweir sal_Bool OOp_OR::operate(const OOperand* pLeft, const OOperand* pRight) const
272cdf0e10cSrcweir {
273cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OOp_OR::operate" );
274cdf0e10cSrcweir return pLeft->isValid() || pRight->isValid();
275cdf0e10cSrcweir }
276cdf0e10cSrcweir
277cdf0e10cSrcweir //------------------------------------------------------------------
getRequestedOperands() const278cdf0e10cSrcweir sal_uInt16 OOp_ISNULL::getRequestedOperands() const
279cdf0e10cSrcweir {
280cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OOp_ISNULL::getRequestedOperands" );
281cdf0e10cSrcweir return 1;
282cdf0e10cSrcweir }
283cdf0e10cSrcweir
284cdf0e10cSrcweir //------------------------------------------------------------------
Exec(OCodeStack & rCodeStack)285cdf0e10cSrcweir void OOp_ISNULL::Exec(OCodeStack& rCodeStack)
286cdf0e10cSrcweir {
287cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OOp_ISNULL::Exec" );
288cdf0e10cSrcweir OOperand* pOperand = rCodeStack.top();
289cdf0e10cSrcweir rCodeStack.pop();
290cdf0e10cSrcweir
291cdf0e10cSrcweir rCodeStack.push(new OOperandResultBOOL(operate(pOperand)));
292cdf0e10cSrcweir if (IS_TYPE(OOperandResult,pOperand))
293cdf0e10cSrcweir delete pOperand;
294cdf0e10cSrcweir }
295cdf0e10cSrcweir
296cdf0e10cSrcweir //------------------------------------------------------------------
operate(const OOperand * pOperand,const OOperand *) const297cdf0e10cSrcweir sal_Bool OOp_ISNULL::operate(const OOperand* pOperand, const OOperand*) const
298cdf0e10cSrcweir {
299cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OOp_ISNULL::operate" );
300cdf0e10cSrcweir return pOperand->getValue().isNull();
301cdf0e10cSrcweir }
302cdf0e10cSrcweir
303cdf0e10cSrcweir //------------------------------------------------------------------
operate(const OOperand * pOperand,const OOperand *) const304cdf0e10cSrcweir sal_Bool OOp_ISNOTNULL::operate(const OOperand* pOperand, const OOperand*) const
305cdf0e10cSrcweir {
306cdf0e10cSrcweir return !OOp_ISNULL::operate(pOperand);
307cdf0e10cSrcweir }
308cdf0e10cSrcweir
309cdf0e10cSrcweir //------------------------------------------------------------------
operate(const OOperand * pLeft,const OOperand * pRight) const310cdf0e10cSrcweir sal_Bool OOp_LIKE::operate(const OOperand* pLeft, const OOperand* pRight) const
311cdf0e10cSrcweir {
312cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OOp_ISNULL::operate" );
313cdf0e10cSrcweir sal_Bool bMatch;
314cdf0e10cSrcweir ORowSetValue aLH(pLeft->getValue());
315cdf0e10cSrcweir ORowSetValue aRH(pRight->getValue());
316cdf0e10cSrcweir
317cdf0e10cSrcweir if (aLH.isNull() || aRH.isNull())
318cdf0e10cSrcweir bMatch = sal_False;
319cdf0e10cSrcweir else
320cdf0e10cSrcweir {
321cdf0e10cSrcweir bMatch = match(aRH.getString(), aLH.getString(), cEscape);
322cdf0e10cSrcweir }
323cdf0e10cSrcweir return bMatch;
324cdf0e10cSrcweir }
325cdf0e10cSrcweir
326cdf0e10cSrcweir //------------------------------------------------------------------
operate(const OOperand * pLeft,const OOperand * pRight) const327cdf0e10cSrcweir sal_Bool OOp_NOTLIKE::operate(const OOperand* pLeft, const OOperand* pRight) const
328cdf0e10cSrcweir {
329cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OOp_NOTLIKE::operate" );
330cdf0e10cSrcweir return !OOp_LIKE::operate(pLeft, pRight);
331cdf0e10cSrcweir }
332cdf0e10cSrcweir
333cdf0e10cSrcweir //------------------------------------------------------------------
operate(const OOperand * pLeft,const OOperand * pRight) const334cdf0e10cSrcweir sal_Bool OOp_COMPARE::operate(const OOperand* pLeft, const OOperand* pRight) const
335cdf0e10cSrcweir {
336cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OOp_COMPARE::operate" );
337cdf0e10cSrcweir ORowSetValue aLH(pLeft->getValue());
338cdf0e10cSrcweir ORowSetValue aRH(pRight->getValue());
339cdf0e10cSrcweir
340cdf0e10cSrcweir if (aLH.isNull() || aRH.isNull()) // if (!aLH.getValue() || !aRH.getValue())
341cdf0e10cSrcweir return sal_False;
342cdf0e10cSrcweir
343cdf0e10cSrcweir sal_Bool bResult = sal_False;
344cdf0e10cSrcweir sal_Int32 eDBType = pLeft->getDBType();
345cdf0e10cSrcweir
346cdf0e10cSrcweir // Vergleich (je nach Datentyp):
347cdf0e10cSrcweir switch (eDBType)
348cdf0e10cSrcweir {
349cdf0e10cSrcweir case DataType::CHAR:
350cdf0e10cSrcweir case DataType::VARCHAR:
351cdf0e10cSrcweir case DataType::LONGVARCHAR:
352cdf0e10cSrcweir {
353cdf0e10cSrcweir rtl::OUString sLH = aLH, sRH = aRH;
354cdf0e10cSrcweir sal_Int32 nRes = rtl_ustr_compareIgnoreAsciiCase_WithLength
355cdf0e10cSrcweir (
356cdf0e10cSrcweir sLH.pData->buffer,
357cdf0e10cSrcweir sLH.pData->length,
358cdf0e10cSrcweir sRH.pData->buffer,
359cdf0e10cSrcweir sRH.pData->length );
360cdf0e10cSrcweir switch(aPredicateType)
361cdf0e10cSrcweir {
362cdf0e10cSrcweir case SQLFilterOperator::EQUAL: bResult = (nRes == 0); break;
363cdf0e10cSrcweir case SQLFilterOperator::NOT_EQUAL: bResult = (nRes != 0); break;
364cdf0e10cSrcweir case SQLFilterOperator::LESS: bResult = (nRes < 0); break;
365cdf0e10cSrcweir case SQLFilterOperator::LESS_EQUAL: bResult = (nRes <= 0); break;
366cdf0e10cSrcweir case SQLFilterOperator::GREATER: bResult = (nRes > 0); break;
367cdf0e10cSrcweir case SQLFilterOperator::GREATER_EQUAL: bResult = (nRes >= 0); break;
368cdf0e10cSrcweir default: bResult = sal_False;
369cdf0e10cSrcweir }
370cdf0e10cSrcweir } break;
371cdf0e10cSrcweir case DataType::TINYINT:
372cdf0e10cSrcweir case DataType::SMALLINT:
373cdf0e10cSrcweir case DataType::INTEGER:
374cdf0e10cSrcweir case DataType::DECIMAL:
375cdf0e10cSrcweir case DataType::NUMERIC:
376cdf0e10cSrcweir case DataType::REAL:
377cdf0e10cSrcweir case DataType::DOUBLE:
378cdf0e10cSrcweir case DataType::BIT:
379cdf0e10cSrcweir case DataType::TIMESTAMP:
380cdf0e10cSrcweir case DataType::DATE:
381cdf0e10cSrcweir case DataType::TIME:
382cdf0e10cSrcweir {
383cdf0e10cSrcweir double n = aLH ,m = aRH;
384cdf0e10cSrcweir
385cdf0e10cSrcweir switch (aPredicateType)
386cdf0e10cSrcweir {
387cdf0e10cSrcweir case SQLFilterOperator::EQUAL: bResult = (n == m); break;
388cdf0e10cSrcweir case SQLFilterOperator::LIKE: bResult = (n == m); break;
389cdf0e10cSrcweir case SQLFilterOperator::NOT_EQUAL: bResult = (n != m); break;
390cdf0e10cSrcweir case SQLFilterOperator::NOT_LIKE: bResult = (n != m); break;
391cdf0e10cSrcweir case SQLFilterOperator::LESS: bResult = (n < m); break;
392cdf0e10cSrcweir case SQLFilterOperator::LESS_EQUAL: bResult = (n <= m); break;
393cdf0e10cSrcweir case SQLFilterOperator::GREATER: bResult = (n > m); break;
394cdf0e10cSrcweir case SQLFilterOperator::GREATER_EQUAL: bResult = (n >= m); break;
395cdf0e10cSrcweir default: bResult = sal_False;
396cdf0e10cSrcweir }
397cdf0e10cSrcweir } break;
398cdf0e10cSrcweir default:
399cdf0e10cSrcweir bResult = aLH == aRH;
400cdf0e10cSrcweir }
401cdf0e10cSrcweir return bResult;
402cdf0e10cSrcweir }
403cdf0e10cSrcweir
404cdf0e10cSrcweir //------------------------------------------------------------------
Exec(OCodeStack & rCodeStack)405cdf0e10cSrcweir void ONumOperator::Exec(OCodeStack& rCodeStack)
406cdf0e10cSrcweir {
407cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "ONumOperator::Exec" );
408cdf0e10cSrcweir
409cdf0e10cSrcweir OOperand *pRight = rCodeStack.top();
410cdf0e10cSrcweir rCodeStack.pop();
411cdf0e10cSrcweir OOperand *pLeft = rCodeStack.top();
412cdf0e10cSrcweir rCodeStack.pop();
413cdf0e10cSrcweir
414cdf0e10cSrcweir rCodeStack.push(new OOperandResultNUM(operate(pLeft->getValue(), pRight->getValue())));
415cdf0e10cSrcweir if (IS_TYPE(OOperandResult,pLeft))
416cdf0e10cSrcweir delete pLeft;
417cdf0e10cSrcweir if (IS_TYPE(OOperandResult,pRight))
418cdf0e10cSrcweir delete pRight;
419cdf0e10cSrcweir }
420cdf0e10cSrcweir //------------------------------------------------------------------
operate(const double & fLeft,const double & fRight) const421cdf0e10cSrcweir double OOp_ADD::operate(const double& fLeft,const double& fRight) const
422cdf0e10cSrcweir {
423cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OOp_ADD::operate" );
424cdf0e10cSrcweir return fLeft + fRight;
425cdf0e10cSrcweir }
426cdf0e10cSrcweir
427cdf0e10cSrcweir //------------------------------------------------------------------
operate(const double & fLeft,const double & fRight) const428cdf0e10cSrcweir double OOp_SUB::operate(const double& fLeft,const double& fRight) const
429cdf0e10cSrcweir {
430cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OOp_SUB::operate" );
431cdf0e10cSrcweir return fLeft - fRight;
432cdf0e10cSrcweir }
433cdf0e10cSrcweir
434cdf0e10cSrcweir //------------------------------------------------------------------
operate(const double & fLeft,const double & fRight) const435cdf0e10cSrcweir double OOp_MUL::operate(const double& fLeft,const double& fRight) const
436cdf0e10cSrcweir {
437cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OOp_MUL::operate" );
438cdf0e10cSrcweir return fLeft * fRight;
439cdf0e10cSrcweir }
440cdf0e10cSrcweir
441cdf0e10cSrcweir //------------------------------------------------------------------
operate(const double & fLeft,const double & fRight) const442cdf0e10cSrcweir double OOp_DIV::operate(const double& fLeft,const double& fRight) const
443cdf0e10cSrcweir {
444cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OOp_DIV::operate" );
445cdf0e10cSrcweir return fLeft / fRight;
446cdf0e10cSrcweir }
447cdf0e10cSrcweir // -----------------------------------------------------------------------------
preProcess(OBoolOperator *,OOperand *)448cdf0e10cSrcweir OEvaluateSet* OOperandAttr::preProcess(OBoolOperator* /*pOp*/, OOperand* /*pRight*/)
449cdf0e10cSrcweir {
450cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OOperandAttr::preProcess" );
451cdf0e10cSrcweir return NULL;
452cdf0e10cSrcweir }
453cdf0e10cSrcweir //------------------------------------------------------------------
Exec(OCodeStack & rCodeStack)454cdf0e10cSrcweir void ONthOperator::Exec(OCodeStack& rCodeStack)
455cdf0e10cSrcweir {
456cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "ONthOperator::Exec" );
457cdf0e10cSrcweir ::std::vector<ORowSetValue> aValues;
458cdf0e10cSrcweir ::std::vector<OOperand*> aOperands;
459cdf0e10cSrcweir OOperand* pOperand;
460cdf0e10cSrcweir do
461cdf0e10cSrcweir {
462cdf0e10cSrcweir OSL_ENSURE(!rCodeStack.empty(),"Stack must be none empty!");
463cdf0e10cSrcweir pOperand = rCodeStack.top();
464cdf0e10cSrcweir rCodeStack.pop();
465cdf0e10cSrcweir if ( !IS_TYPE(OStopOperand,pOperand) )
466cdf0e10cSrcweir aValues.push_back( pOperand->getValue() );
467cdf0e10cSrcweir aOperands.push_back( pOperand );
468cdf0e10cSrcweir }
469cdf0e10cSrcweir while ( !IS_TYPE(OStopOperand,pOperand) );
470cdf0e10cSrcweir
471cdf0e10cSrcweir rCodeStack.push(new OOperandResult(operate(aValues)));
472cdf0e10cSrcweir
473cdf0e10cSrcweir ::std::vector<OOperand*>::iterator aIter = aOperands.begin();
474cdf0e10cSrcweir ::std::vector<OOperand*>::iterator aEnd = aOperands.end();
475cdf0e10cSrcweir for (; aIter != aEnd; ++aIter)
476cdf0e10cSrcweir {
477cdf0e10cSrcweir if (IS_TYPE(OOperandResult,*aIter))
478cdf0e10cSrcweir delete *aIter;
479cdf0e10cSrcweir }
480cdf0e10cSrcweir }
481cdf0e10cSrcweir //------------------------------------------------------------------
Exec(OCodeStack & rCodeStack)482cdf0e10cSrcweir void OBinaryOperator::Exec(OCodeStack& rCodeStack)
483cdf0e10cSrcweir {
484cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OBinaryOperator::Exec" );
485cdf0e10cSrcweir OOperand *pRight = rCodeStack.top();
486cdf0e10cSrcweir rCodeStack.pop();
487cdf0e10cSrcweir OOperand *pLeft = rCodeStack.top();
488cdf0e10cSrcweir rCodeStack.pop();
489cdf0e10cSrcweir
490cdf0e10cSrcweir if ( !rCodeStack.empty() && IS_TYPE(OStopOperand,rCodeStack.top()) )
491cdf0e10cSrcweir rCodeStack.pop();
492cdf0e10cSrcweir
493cdf0e10cSrcweir rCodeStack.push(new OOperandResult(operate(pLeft->getValue(),pRight->getValue())));
494cdf0e10cSrcweir if (IS_TYPE(OOperandResult,pRight))
495cdf0e10cSrcweir delete pRight;
496cdf0e10cSrcweir if (IS_TYPE(OOperandResult,pLeft))
497cdf0e10cSrcweir delete pLeft;
498cdf0e10cSrcweir }
499cdf0e10cSrcweir //------------------------------------------------------------------
Exec(OCodeStack & rCodeStack)500cdf0e10cSrcweir void OUnaryOperator::Exec(OCodeStack& rCodeStack)
501cdf0e10cSrcweir {
502cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OUnaryOperator::Exec" );
503cdf0e10cSrcweir OSL_ENSURE(!rCodeStack.empty(),"Stack is empty!");
504cdf0e10cSrcweir OOperand* pOperand = rCodeStack.top();
505cdf0e10cSrcweir rCodeStack.pop();
506cdf0e10cSrcweir
507cdf0e10cSrcweir rCodeStack.push(new OOperandResult(operate(pOperand->getValue())));
508cdf0e10cSrcweir if (IS_TYPE(OOperandResult,pOperand))
509cdf0e10cSrcweir delete pOperand;
510cdf0e10cSrcweir }
511cdf0e10cSrcweir // -----------------------------------------------------------------------------
getRequestedOperands() const512cdf0e10cSrcweir sal_uInt16 OUnaryOperator::getRequestedOperands() const {return 1;}
513cdf0e10cSrcweir
514cdf0e10cSrcweir
515cdf0e10cSrcweir
516