1*caf5cd79SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*caf5cd79SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*caf5cd79SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*caf5cd79SAndrew Rist * distributed with this work for additional information 6*caf5cd79SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*caf5cd79SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*caf5cd79SAndrew Rist * "License"); you may not use this file except in compliance 9*caf5cd79SAndrew Rist * with the License. You may obtain a copy of the License at 10*caf5cd79SAndrew Rist * 11*caf5cd79SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*caf5cd79SAndrew Rist * 13*caf5cd79SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*caf5cd79SAndrew Rist * software distributed under the License is distributed on an 15*caf5cd79SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*caf5cd79SAndrew Rist * KIND, either express or implied. See the License for the 17*caf5cd79SAndrew Rist * specific language governing permissions and limitations 18*caf5cd79SAndrew Rist * under the License. 19*caf5cd79SAndrew Rist * 20*caf5cd79SAndrew Rist *************************************************************/ 21*caf5cd79SAndrew Rist 22*caf5cd79SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir #ifndef _CONNECTIVITY_FILE_FCODE_HXX_ 25cdf0e10cSrcweir #define _CONNECTIVITY_FILE_FCODE_HXX_ 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include "connectivity/sqliterator.hxx" 28cdf0e10cSrcweir #include <com/sun/star/sdbc/DataType.hpp> 29cdf0e10cSrcweir #include "connectivity/CommonTools.hxx" 30cdf0e10cSrcweir #include <tools/rtti.hxx> 31cdf0e10cSrcweir #include <com/sun/star/container/XNameAccess.hpp> 32cdf0e10cSrcweir #include <com/sun/star/container/XIndexAccess.hpp> 33cdf0e10cSrcweir #include "connectivity/FValue.hxx" 34cdf0e10cSrcweir #include "file/filedllapi.hxx" 35cdf0e10cSrcweir 36cdf0e10cSrcweir namespace connectivity 37cdf0e10cSrcweir { 38cdf0e10cSrcweir class OSQLParseNode; 39cdf0e10cSrcweir namespace dbase 40cdf0e10cSrcweir { 41cdf0e10cSrcweir class ODbaseIndex; 42cdf0e10cSrcweir } 43cdf0e10cSrcweir namespace file 44cdf0e10cSrcweir { 45cdf0e10cSrcweir 46cdf0e10cSrcweir class OOperand; 47cdf0e10cSrcweir typedef ::std::stack<OOperand*> OCodeStack; 48cdf0e10cSrcweir class OBoolOperator; 49cdf0e10cSrcweir typedef ::std::map<sal_Int32,sal_Int32> OEvaluateSet; 50cdf0e10cSrcweir 51cdf0e10cSrcweir typedef ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess> OFileColumns; 52cdf0e10cSrcweir 53cdf0e10cSrcweir 54cdf0e10cSrcweir class OOO_DLLPUBLIC_FILE OCode 55cdf0e10cSrcweir { 56cdf0e10cSrcweir public: 57cdf0e10cSrcweir OCode(); 58cdf0e10cSrcweir virtual ~OCode(); 59cdf0e10cSrcweir operator new(size_t nSize)60cdf0e10cSrcweir inline static void * SAL_CALL operator new( size_t nSize ) SAL_THROW( () ) 61cdf0e10cSrcweir { return ::rtl_allocateMemory( nSize ); } operator new(size_t,void * _pHint)62cdf0e10cSrcweir inline static void * SAL_CALL operator new( size_t /*nSize*/,void* _pHint ) SAL_THROW( () ) 63cdf0e10cSrcweir { return _pHint; } operator delete(void * pMem)64cdf0e10cSrcweir inline static void SAL_CALL operator delete( void * pMem ) SAL_THROW( () ) 65cdf0e10cSrcweir { ::rtl_freeMemory( pMem ); } operator delete(void *,void *)66cdf0e10cSrcweir inline static void SAL_CALL operator delete( void * /*pMem*/,void* /*_pHint*/ ) SAL_THROW( () ) 67cdf0e10cSrcweir { } 68cdf0e10cSrcweir 69cdf0e10cSrcweir TYPEINFO(); 70cdf0e10cSrcweir }; 71cdf0e10cSrcweir 72cdf0e10cSrcweir 73cdf0e10cSrcweir // operands that the parsetree generate 74cdf0e10cSrcweir class OOO_DLLPUBLIC_FILE OOperand : public OCode 75cdf0e10cSrcweir { 76cdf0e10cSrcweir protected: 77cdf0e10cSrcweir sal_Int32 m_eDBType; 78cdf0e10cSrcweir OOperand(const sal_Int32 & _rType)79cdf0e10cSrcweir OOperand(const sal_Int32& _rType) : m_eDBType(_rType){} OOperand()80cdf0e10cSrcweir OOperand() : m_eDBType(::com::sun::star::sdbc::DataType::OTHER){} 81cdf0e10cSrcweir 82cdf0e10cSrcweir public: 83cdf0e10cSrcweir virtual const ORowSetValue& getValue() const = 0; 84cdf0e10cSrcweir virtual void setValue(const ORowSetValue& _rVal) = 0; 85cdf0e10cSrcweir getDBType() const86cdf0e10cSrcweir virtual sal_Int32 getDBType() const {return m_eDBType;} 87cdf0e10cSrcweir virtual OEvaluateSet* preProcess(OBoolOperator* pOp, OOperand* pRight = 0); 88cdf0e10cSrcweir inline sal_Bool isValid() const; 89cdf0e10cSrcweir 90cdf0e10cSrcweir TYPEINFO(); 91cdf0e10cSrcweir }; 92cdf0e10cSrcweir 93cdf0e10cSrcweir class OOO_DLLPUBLIC_FILE OOperandRow : public OOperand 94cdf0e10cSrcweir { 95cdf0e10cSrcweir sal_uInt16 m_nRowPos; 96cdf0e10cSrcweir protected: 97cdf0e10cSrcweir OValueRefRow m_pRow; 98cdf0e10cSrcweir 99cdf0e10cSrcweir OOperandRow(sal_uInt16 _nPos, sal_Int32 _rType); 100cdf0e10cSrcweir public: getRowPos() const101cdf0e10cSrcweir sal_uInt16 getRowPos() const {return m_nRowPos;} 102cdf0e10cSrcweir virtual const ORowSetValue& getValue() const; 103cdf0e10cSrcweir virtual void setValue(const ORowSetValue& _rVal); 104cdf0e10cSrcweir void bindValue(const OValueRefRow& _pRow); // Bindung an den Wert, den der Operand repraesentiert 105cdf0e10cSrcweir 106cdf0e10cSrcweir TYPEINFO(); 107cdf0e10cSrcweir }; 108cdf0e10cSrcweir 109cdf0e10cSrcweir // Attribute aus einer Ergebniszeile 110cdf0e10cSrcweir class OOO_DLLPUBLIC_FILE OOperandAttr : public OOperandRow 111cdf0e10cSrcweir { 112cdf0e10cSrcweir protected: 113cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet> m_xColumn; 114cdf0e10cSrcweir 115cdf0e10cSrcweir public: 116cdf0e10cSrcweir OOperandAttr(sal_uInt16 _nPos, 117cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>& _xColumn); 118cdf0e10cSrcweir 119cdf0e10cSrcweir virtual sal_Bool isIndexed() const; 120cdf0e10cSrcweir virtual OEvaluateSet* preProcess(OBoolOperator* pOp, OOperand* pRight = 0); 121cdf0e10cSrcweir TYPEINFO(); 122cdf0e10cSrcweir }; 123cdf0e10cSrcweir 124cdf0e10cSrcweir // Parameter fuer ein Praedikat 125cdf0e10cSrcweir class OOperandParam : public OOperandRow 126cdf0e10cSrcweir { 127cdf0e10cSrcweir public: 128cdf0e10cSrcweir OOperandParam(connectivity::OSQLParseNode* pNode, sal_Int32 _nPos); 129cdf0e10cSrcweir void describe(const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>& _xColumn, ::vos::ORef<connectivity::OSQLColumns> _xParamColumns); 130cdf0e10cSrcweir 131cdf0e10cSrcweir TYPEINFO(); 132cdf0e10cSrcweir }; 133cdf0e10cSrcweir 134cdf0e10cSrcweir // WerteOperanden 135cdf0e10cSrcweir class OOperandValue : public OOperand 136cdf0e10cSrcweir { 137cdf0e10cSrcweir protected: 138cdf0e10cSrcweir ORowSetValue m_aValue; 139cdf0e10cSrcweir 140cdf0e10cSrcweir protected: OOperandValue()141cdf0e10cSrcweir OOperandValue(){} OOperandValue(const ORowSetValue & _rVar,sal_Int32 eDbType)142cdf0e10cSrcweir OOperandValue(const ORowSetValue& _rVar, sal_Int32 eDbType) 143cdf0e10cSrcweir : OOperand(eDbType) 144cdf0e10cSrcweir , m_aValue(_rVar) 145cdf0e10cSrcweir {} 146cdf0e10cSrcweir OOperandValue(sal_Int32 eDbType)147cdf0e10cSrcweir OOperandValue(sal_Int32 eDbType) :OOperand(eDbType){} 148cdf0e10cSrcweir public: 149cdf0e10cSrcweir virtual const ORowSetValue& getValue() const; 150cdf0e10cSrcweir virtual void setValue(const ORowSetValue& _rVal); 151cdf0e10cSrcweir 152cdf0e10cSrcweir TYPEINFO(); 153cdf0e10cSrcweir }; 154cdf0e10cSrcweir 155cdf0e10cSrcweir 156cdf0e10cSrcweir // Konstanten 157cdf0e10cSrcweir class OOperandConst : public OOperandValue 158cdf0e10cSrcweir { 159cdf0e10cSrcweir public: 160cdf0e10cSrcweir OOperandConst(const connectivity::OSQLParseNode& rColumnRef, const rtl::OUString& aStrValue); 161cdf0e10cSrcweir 162cdf0e10cSrcweir TYPEINFO(); 163cdf0e10cSrcweir }; 164cdf0e10cSrcweir 165cdf0e10cSrcweir 166cdf0e10cSrcweir // Ergebnis Operanden 167cdf0e10cSrcweir class OOperandResult : public OOperandValue 168cdf0e10cSrcweir { 169cdf0e10cSrcweir protected: OOperandResult(const ORowSetValue & _rVar,sal_Int32 eDbType)170cdf0e10cSrcweir OOperandResult(const ORowSetValue& _rVar, sal_Int32 eDbType) 171cdf0e10cSrcweir :OOperandValue(_rVar, eDbType) {} OOperandResult(sal_Int32 eDbType)172cdf0e10cSrcweir OOperandResult(sal_Int32 eDbType) 173cdf0e10cSrcweir :OOperandValue(eDbType) {} 174cdf0e10cSrcweir public: OOperandResult(const ORowSetValue & _rVar)175cdf0e10cSrcweir OOperandResult(const ORowSetValue& _rVar) 176cdf0e10cSrcweir :OOperandValue(_rVar, _rVar.getTypeKind()) {} 177cdf0e10cSrcweir TYPEINFO(); 178cdf0e10cSrcweir }; 179cdf0e10cSrcweir 180cdf0e10cSrcweir 181cdf0e10cSrcweir class OOperandResultBOOL : public OOperandResult 182cdf0e10cSrcweir { 183cdf0e10cSrcweir public: OOperandResultBOOL(sal_Bool bResult)184cdf0e10cSrcweir OOperandResultBOOL(sal_Bool bResult) : OOperandResult(::com::sun::star::sdbc::DataType::BIT) 185cdf0e10cSrcweir { 186cdf0e10cSrcweir m_aValue = bResult ? 1.0 : 0.0; 187cdf0e10cSrcweir m_aValue.setBound(sal_True); 188cdf0e10cSrcweir } 189cdf0e10cSrcweir }; 190cdf0e10cSrcweir 191cdf0e10cSrcweir class OOperandResultNUM : public OOperandResult 192cdf0e10cSrcweir { 193cdf0e10cSrcweir public: OOperandResultNUM(double fNum)194cdf0e10cSrcweir OOperandResultNUM(double fNum) : OOperandResult(::com::sun::star::sdbc::DataType::DOUBLE) 195cdf0e10cSrcweir { 196cdf0e10cSrcweir m_aValue = fNum; 197cdf0e10cSrcweir m_aValue.setBound(sal_True); 198cdf0e10cSrcweir } 199cdf0e10cSrcweir }; 200cdf0e10cSrcweir 201cdf0e10cSrcweir /** special stop operand 202cdf0e10cSrcweir is appended when a list of arguments ends 203cdf0e10cSrcweir */ 204cdf0e10cSrcweir class OStopOperand : public OOperandValue 205cdf0e10cSrcweir { 206cdf0e10cSrcweir public: OStopOperand()207cdf0e10cSrcweir OStopOperand(){} 208cdf0e10cSrcweir TYPEINFO(); 209cdf0e10cSrcweir }; 210cdf0e10cSrcweir 211cdf0e10cSrcweir // Operatoren 212cdf0e10cSrcweir class OOO_DLLPUBLIC_FILE OOperator : public OCode 213cdf0e10cSrcweir { 214cdf0e10cSrcweir public: 215cdf0e10cSrcweir virtual void Exec(OCodeStack&) = 0; 216cdf0e10cSrcweir virtual sal_uInt16 getRequestedOperands() const; // Anzahl benoetigter Operanden 217cdf0e10cSrcweir // Standard ist 2 218cdf0e10cSrcweir TYPEINFO(); 219cdf0e10cSrcweir }; 220cdf0e10cSrcweir 221cdf0e10cSrcweir 222cdf0e10cSrcweir // boolsche Operatoren 223cdf0e10cSrcweir 224cdf0e10cSrcweir class OOO_DLLPUBLIC_FILE OBoolOperator : public OOperator 225cdf0e10cSrcweir { 226cdf0e10cSrcweir public: 227cdf0e10cSrcweir TYPEINFO(); 228cdf0e10cSrcweir virtual void Exec(OCodeStack&); 229cdf0e10cSrcweir virtual sal_Bool operate(const OOperand*, const OOperand*) const; 230cdf0e10cSrcweir }; 231cdf0e10cSrcweir 232cdf0e10cSrcweir class OOp_NOT : public OBoolOperator 233cdf0e10cSrcweir { 234cdf0e10cSrcweir public: 235cdf0e10cSrcweir TYPEINFO(); 236cdf0e10cSrcweir 237cdf0e10cSrcweir protected: 238cdf0e10cSrcweir virtual void Exec(OCodeStack&); 239cdf0e10cSrcweir virtual sal_Bool operate(const OOperand*, const OOperand* = NULL) const; 240cdf0e10cSrcweir virtual sal_uInt16 getRequestedOperands() const; 241cdf0e10cSrcweir }; 242cdf0e10cSrcweir 243cdf0e10cSrcweir class OOp_AND : public OBoolOperator 244cdf0e10cSrcweir { 245cdf0e10cSrcweir public: 246cdf0e10cSrcweir TYPEINFO(); 247cdf0e10cSrcweir 248cdf0e10cSrcweir protected: 249cdf0e10cSrcweir virtual sal_Bool operate(const OOperand*, const OOperand*) const; 250cdf0e10cSrcweir }; 251cdf0e10cSrcweir 252cdf0e10cSrcweir class OOp_OR : public OBoolOperator 253cdf0e10cSrcweir { 254cdf0e10cSrcweir public: 255cdf0e10cSrcweir TYPEINFO(); 256cdf0e10cSrcweir protected: 257cdf0e10cSrcweir virtual sal_Bool operate(const OOperand*, const OOperand*) const; 258cdf0e10cSrcweir }; 259cdf0e10cSrcweir 260cdf0e10cSrcweir class OOO_DLLPUBLIC_FILE OOp_ISNULL : public OBoolOperator 261cdf0e10cSrcweir { 262cdf0e10cSrcweir public: 263cdf0e10cSrcweir TYPEINFO(); 264cdf0e10cSrcweir public: 265cdf0e10cSrcweir virtual void Exec(OCodeStack&); 266cdf0e10cSrcweir virtual sal_uInt16 getRequestedOperands() const; 267cdf0e10cSrcweir virtual sal_Bool operate(const OOperand*, const OOperand* = NULL) const; 268cdf0e10cSrcweir }; 269cdf0e10cSrcweir 270cdf0e10cSrcweir class OOO_DLLPUBLIC_FILE OOp_ISNOTNULL : public OOp_ISNULL 271cdf0e10cSrcweir { 272cdf0e10cSrcweir public: 273cdf0e10cSrcweir TYPEINFO(); 274cdf0e10cSrcweir virtual sal_Bool operate(const OOperand*, const OOperand* = NULL) const; 275cdf0e10cSrcweir }; 276cdf0e10cSrcweir 277cdf0e10cSrcweir class OOO_DLLPUBLIC_FILE OOp_LIKE : public OBoolOperator 278cdf0e10cSrcweir { 279cdf0e10cSrcweir public: 280cdf0e10cSrcweir TYPEINFO(); 281cdf0e10cSrcweir protected: 282cdf0e10cSrcweir const sal_Unicode cEscape; 283cdf0e10cSrcweir 284cdf0e10cSrcweir public: OOp_LIKE(const sal_Unicode cEsc=L'\\0')285cdf0e10cSrcweir OOp_LIKE(const sal_Unicode cEsc = L'\0'):cEscape(cEsc){}; 286cdf0e10cSrcweir 287cdf0e10cSrcweir virtual sal_Bool operate(const OOperand*, const OOperand*) const; 288cdf0e10cSrcweir }; 289cdf0e10cSrcweir 290cdf0e10cSrcweir class OOp_NOTLIKE : public OOp_LIKE 291cdf0e10cSrcweir { 292cdf0e10cSrcweir public: 293cdf0e10cSrcweir TYPEINFO(); 294cdf0e10cSrcweir public: OOp_NOTLIKE(const sal_Unicode cEsc=L'\\0')295cdf0e10cSrcweir OOp_NOTLIKE(const sal_Unicode cEsc = L'\0'):OOp_LIKE(cEsc){}; 296cdf0e10cSrcweir 297cdf0e10cSrcweir virtual sal_Bool operate(const OOperand*, const OOperand*) const; 298cdf0e10cSrcweir }; 299cdf0e10cSrcweir 300cdf0e10cSrcweir class OOO_DLLPUBLIC_FILE OOp_COMPARE : public OBoolOperator 301cdf0e10cSrcweir { 302cdf0e10cSrcweir sal_Int32 aPredicateType; 303cdf0e10cSrcweir 304cdf0e10cSrcweir public: 305cdf0e10cSrcweir TYPEINFO(); OOp_COMPARE(sal_Int32 aPType)306cdf0e10cSrcweir OOp_COMPARE(sal_Int32 aPType) 307cdf0e10cSrcweir :aPredicateType(aPType) {} 308cdf0e10cSrcweir getPredicateType() const309cdf0e10cSrcweir inline sal_Int32 getPredicateType() const { return aPredicateType; } 310cdf0e10cSrcweir virtual sal_Bool operate(const OOperand*, const OOperand*) const; 311cdf0e10cSrcweir }; 312cdf0e10cSrcweir 313cdf0e10cSrcweir // numerische Operatoren 314cdf0e10cSrcweir 315cdf0e10cSrcweir class ONumOperator : public OOperator 316cdf0e10cSrcweir { 317cdf0e10cSrcweir public: 318cdf0e10cSrcweir virtual void Exec(OCodeStack&); 319cdf0e10cSrcweir 320cdf0e10cSrcweir TYPEINFO(); 321cdf0e10cSrcweir 322cdf0e10cSrcweir protected: 323cdf0e10cSrcweir virtual double operate(const double& fLeft,const double& fRight) const = 0; 324cdf0e10cSrcweir }; 325cdf0e10cSrcweir 326cdf0e10cSrcweir class OOp_ADD : public ONumOperator 327cdf0e10cSrcweir { 328cdf0e10cSrcweir protected: 329cdf0e10cSrcweir virtual double operate(const double& fLeft,const double& fRight) const; 330cdf0e10cSrcweir }; 331cdf0e10cSrcweir 332cdf0e10cSrcweir class OOp_SUB : public ONumOperator 333cdf0e10cSrcweir { 334cdf0e10cSrcweir protected: 335cdf0e10cSrcweir virtual double operate(const double& fLeft,const double& fRight) const; 336cdf0e10cSrcweir }; 337cdf0e10cSrcweir 338cdf0e10cSrcweir class OOp_MUL : public ONumOperator 339cdf0e10cSrcweir { 340cdf0e10cSrcweir protected: 341cdf0e10cSrcweir virtual double operate(const double& fLeft,const double& fRight) const; 342cdf0e10cSrcweir }; 343cdf0e10cSrcweir 344cdf0e10cSrcweir class OOp_DIV : public ONumOperator 345cdf0e10cSrcweir { 346cdf0e10cSrcweir protected: 347cdf0e10cSrcweir virtual double operate(const double& fLeft,const double& fRight) const; 348cdf0e10cSrcweir }; 349cdf0e10cSrcweir isValid() const350cdf0e10cSrcweir inline sal_Bool OOperand::isValid() const 351cdf0e10cSrcweir { 352cdf0e10cSrcweir return getValue().getDouble() != double(0.0); 353cdf0e10cSrcweir } 354cdf0e10cSrcweir 355cdf0e10cSrcweir // operator 356cdf0e10cSrcweir class ONthOperator : public OOperator 357cdf0e10cSrcweir { 358cdf0e10cSrcweir public: 359cdf0e10cSrcweir virtual void Exec(OCodeStack&); 360cdf0e10cSrcweir 361cdf0e10cSrcweir TYPEINFO(); 362cdf0e10cSrcweir 363cdf0e10cSrcweir protected: 364cdf0e10cSrcweir virtual ORowSetValue operate(const ::std::vector<ORowSetValue>& lhs) const = 0; 365cdf0e10cSrcweir }; 366cdf0e10cSrcweir 367cdf0e10cSrcweir class OBinaryOperator : public OOperator 368cdf0e10cSrcweir { 369cdf0e10cSrcweir public: 370cdf0e10cSrcweir virtual void Exec(OCodeStack&); 371cdf0e10cSrcweir 372cdf0e10cSrcweir TYPEINFO(); 373cdf0e10cSrcweir 374cdf0e10cSrcweir protected: 375cdf0e10cSrcweir virtual ORowSetValue operate(const ORowSetValue& lhs,const ORowSetValue& rhs) const = 0; 376cdf0e10cSrcweir }; 377cdf0e10cSrcweir 378cdf0e10cSrcweir class OUnaryOperator : public OOperator 379cdf0e10cSrcweir { 380cdf0e10cSrcweir public: 381cdf0e10cSrcweir virtual void Exec(OCodeStack&); 382cdf0e10cSrcweir virtual sal_uInt16 getRequestedOperands() const; 383cdf0e10cSrcweir virtual ORowSetValue operate(const ORowSetValue& lhs) const = 0; 384cdf0e10cSrcweir 385cdf0e10cSrcweir TYPEINFO(); 386cdf0e10cSrcweir 387cdf0e10cSrcweir }; 388cdf0e10cSrcweir } 389cdf0e10cSrcweir } 390cdf0e10cSrcweir 391cdf0e10cSrcweir #endif // _CONNECTIVITY_FILE_FCODE_HXX_ 392cdf0e10cSrcweir 393