1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 #ifndef _CONNECTIVITY_FILE_FCOMP_HXX_
28 #define _CONNECTIVITY_FILE_FCOMP_HXX_
29 
30 #include "file/fcode.hxx"
31 #include "file/filedllapi.hxx"
32 #ifndef _LIST_
33 #include <list>
34 #endif
35 
36 namespace connectivity
37 {
38 	class OSQLParseNode;
39 	namespace file
40 	{
41 		class OCode;
42 		class OOperand;
43 		class OSQLAnalyzer;
44 		typedef::std::vector<OCode*> OCodeList;
45 
46 		class OPredicateCompiler : public ::vos::OReference
47 		{
48 			friend class OPredicateInterpreter;
49 			friend class OSQLAnalyzer;
50 
51 			OCodeList								m_aCodeList;
52 			OFileColumns							m_orgColumns; // in filecurs this are the filecolumns
53 			OSQLAnalyzer*							m_pAnalyzer;
54 			::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess> m_xIndexes;
55 			sal_Int32								m_nParamCounter;
56 			sal_Bool								m_bORCondition;
57 		public:
58 			OPredicateCompiler(OSQLAnalyzer* pAnalyzer);
59 
60 			virtual ~OPredicateCompiler();
61 
62 			inline static void * SAL_CALL operator new( size_t nSize ) SAL_THROW( () )
63 				{ return ::rtl_allocateMemory( nSize ); }
64 			inline static void * SAL_CALL operator new( size_t /*nSize*/,void* _pHint ) SAL_THROW( () )
65 				{ return _pHint; }
66 			inline static void SAL_CALL operator delete( void * pMem ) SAL_THROW( () )
67 				{ ::rtl_freeMemory( pMem ); }
68 			inline static void SAL_CALL operator delete( void * /*pMem*/,void* /*_pHint*/ ) SAL_THROW( () )
69 				{  }
70 			void dispose();
71 
72 			void start(connectivity::OSQLParseNode* pSQLParseNode);
73 			OOperand* execute(connectivity::OSQLParseNode* pPredicateNode);
74 
75 			void Clean();
76 			sal_Bool isClean() const {return m_aCodeList.empty();}
77 			sal_Bool hasCode() const {return !isClean();}
78 			sal_Bool hasORCondition() const {return m_bORCondition;}
79 			void	 setOrigColumns(const OFileColumns& rCols) { m_orgColumns = rCols; }
80 			const OFileColumns getOrigColumns() const { return m_orgColumns; }
81 		protected:
82 			OOperand* execute_COMPARE(connectivity::OSQLParseNode* pPredicateNode) throw( ::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
83 			OOperand* execute_LIKE(connectivity::OSQLParseNode* pPredicateNode) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
84 			OOperand* execute_BETWEEN(connectivity::OSQLParseNode* pPredicateNode) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
85 			OOperand* execute_ISNULL(connectivity::OSQLParseNode* pPredicateNode) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
86 			OOperand* execute_Operand(connectivity::OSQLParseNode* pPredicateNode) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
87 			OOperand* execute_Fold(OSQLParseNode* pPredicateNode) throw( ::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
88 			OOperand* executeFunction(OSQLParseNode* pPredicateNode) throw( ::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
89 		};
90 
91 
92 		class OPredicateInterpreter :
93             public ::vos::OReference
94 		{
95 			OCodeStack			m_aStack;
96 			::vos::ORef<OPredicateCompiler> m_rCompiler;
97 
98 		public:
99 			OPredicateInterpreter(const ::vos::ORef<OPredicateCompiler>& rComp) : m_rCompiler(rComp){}
100 			virtual ~OPredicateInterpreter();
101 
102 			sal_Bool	evaluate(OCodeList& rCodeList);
103 			void		evaluateSelection(OCodeList& rCodeList,ORowSetValueDecoratorRef& _rVal);
104 
105 			inline sal_Bool start()
106 			{
107 				return evaluate(m_rCompiler->m_aCodeList);
108 			}
109 
110 			inline void startSelection(ORowSetValueDecoratorRef& _rVal)
111 			{
112 				evaluateSelection(m_rCompiler->m_aCodeList,_rVal);
113 			}
114 
115 
116 		};
117 	}
118 }
119 #endif // _CONNECTIVITY_FILE_FCOMP_HXX_
120 
121