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