1caf5cd79SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3caf5cd79SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4caf5cd79SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5caf5cd79SAndrew Rist  * distributed with this work for additional information
6caf5cd79SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7caf5cd79SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8caf5cd79SAndrew Rist  * "License"); you may not use this file except in compliance
9caf5cd79SAndrew Rist  * with the License.  You may obtain a copy of the License at
10caf5cd79SAndrew Rist  *
11caf5cd79SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12caf5cd79SAndrew Rist  *
13caf5cd79SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14caf5cd79SAndrew Rist  * software distributed under the License is distributed on an
15caf5cd79SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16caf5cd79SAndrew Rist  * KIND, either express or implied.  See the License for the
17caf5cd79SAndrew Rist  * specific language governing permissions and limitations
18caf5cd79SAndrew Rist  * under the License.
19caf5cd79SAndrew Rist  *
20caf5cd79SAndrew Rist  *************************************************************/
21caf5cd79SAndrew Rist 
22caf5cd79SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #ifndef _CONNECTIVITY_FILE_OSTATEMENT_HXX_
25cdf0e10cSrcweir #define _CONNECTIVITY_FILE_OSTATEMENT_HXX_
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <com/sun/star/sdbc/XStatement.hpp>
28cdf0e10cSrcweir #include <com/sun/star/sdbc/XWarningsSupplier.hpp>
29cdf0e10cSrcweir #include <com/sun/star/sdbc/XMultipleResults.hpp>
30cdf0e10cSrcweir #include <com/sun/star/sdbc/XBatchExecution.hpp>
31cdf0e10cSrcweir #include <com/sun/star/sdbc/XCloseable.hpp>
32cdf0e10cSrcweir #include <com/sun/star/sdbc/SQLWarning.hpp>
33cdf0e10cSrcweir #include <com/sun/star/util/XCancellable.hpp>
34cdf0e10cSrcweir #include <comphelper/proparrhlp.hxx>
35cdf0e10cSrcweir #include <cppuhelper/compbase3.hxx>
36cdf0e10cSrcweir #include <cppuhelper/implbase2.hxx>
37cdf0e10cSrcweir #include <comphelper/uno3.hxx>
38cdf0e10cSrcweir #include "connectivity/CommonTools.hxx"
39cdf0e10cSrcweir #include "file/FConnection.hxx"
40cdf0e10cSrcweir #include "file/filedllapi.hxx"
41cdf0e10cSrcweir #ifndef _LIST_
42cdf0e10cSrcweir #include <list>
43cdf0e10cSrcweir #endif
44cdf0e10cSrcweir #include <com/sun/star/lang/XServiceInfo.hpp>
45cdf0e10cSrcweir #include <comphelper/propertycontainer.hxx>
46cdf0e10cSrcweir #include "file/fanalyzer.hxx"
47cdf0e10cSrcweir #include <comphelper/broadcasthelper.hxx>
48cdf0e10cSrcweir #include "TSortIndex.hxx"
49cdf0e10cSrcweir 
50cdf0e10cSrcweir #define SQL_COLUMN_NOTFOUND STRING_NOTFOUND
51cdf0e10cSrcweir 
52cdf0e10cSrcweir namespace connectivity
53cdf0e10cSrcweir {
54cdf0e10cSrcweir 	namespace file
55cdf0e10cSrcweir 	{
56cdf0e10cSrcweir 		class OResultSet;
57cdf0e10cSrcweir 		class OFileTable;
58cdf0e10cSrcweir         typedef ::cppu::WeakComponentImplHelper3<   ::com::sun::star::sdbc::XWarningsSupplier,
59cdf0e10cSrcweir                                                     ::com::sun::star::util::XCancellable,
60cdf0e10cSrcweir                                                     ::com::sun::star::sdbc::XCloseable> OStatement_BASE;
61cdf0e10cSrcweir 
62cdf0e10cSrcweir 		//**************************************************************
63cdf0e10cSrcweir 		//************ Class: java.sql.Statement
64cdf0e10cSrcweir 		//**************************************************************
65cdf0e10cSrcweir 		class OOO_DLLPUBLIC_FILE OStatement_Base :
66cdf0e10cSrcweir                                         public	comphelper::OBaseMutex,
67cdf0e10cSrcweir 										public	OStatement_BASE,
68cdf0e10cSrcweir 										public	::comphelper::OPropertyContainer,
69cdf0e10cSrcweir 										public	::comphelper::OPropertyArrayUsageHelper<OStatement_Base>
70cdf0e10cSrcweir 
71cdf0e10cSrcweir 		{
72cdf0e10cSrcweir 		protected:
73*07a3d7f1SPedro Giffuni 			::std::vector<sal_Int32>					m_aColMapping; // pos 0 is unused so we don't have to decrement 1 every time
74cdf0e10cSrcweir 			::std::vector<sal_Int32>					m_aParameterIndexes; // maps the parameter index to column index
75cdf0e10cSrcweir 			::std::vector<sal_Int32>					m_aOrderbyColumnNumber;
76cdf0e10cSrcweir             ::std::vector<TAscendingOrder>              m_aOrderbyAscending;
77cdf0e10cSrcweir 
78cdf0e10cSrcweir 			::com::sun::star::sdbc::SQLWarning                                           m_aLastWarning;
79cdf0e10cSrcweir 			::com::sun::star::uno::WeakReference< ::com::sun::star::sdbc::XResultSet>    m_xResultSet;   // The last ResultSet created
80cdf0e10cSrcweir 			::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDatabaseMetaData> m_xDBMetaData;
81cdf0e10cSrcweir 			::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess>	 m_xColNames; // table columns															//  for this Statement
82cdf0e10cSrcweir 
83cdf0e10cSrcweir 
84cdf0e10cSrcweir 			connectivity::OSQLParser					m_aParser;
85cdf0e10cSrcweir 			connectivity::OSQLParseTreeIterator			m_aSQLIterator;
86cdf0e10cSrcweir 
87cdf0e10cSrcweir 			OConnection*								m_pConnection;// The owning Connection object
88cdf0e10cSrcweir 			connectivity::OSQLParseNode*				m_pParseTree;
89cdf0e10cSrcweir 			OSQLAnalyzer*								m_pSQLAnalyzer; //the sql analyzer used by the resultset
90cdf0e10cSrcweir 
91cdf0e10cSrcweir 			::std::vector<sal_Int32>*					m_pEvaluationKeySet;
92cdf0e10cSrcweir 
93cdf0e10cSrcweir 			OFileTable*									m_pTable;		// the current table
94cdf0e10cSrcweir 			OValueRefRow								m_aSelectRow;
95cdf0e10cSrcweir 			OValueRefRow								m_aRow;
96cdf0e10cSrcweir 			OValueRefRow								m_aEvaluateRow; // contains all values of a row
97cdf0e10cSrcweir 			ORefAssignValues							m_aAssignValues; // needed for insert,update and parameters
98cdf0e10cSrcweir 																	// to compare with the restrictions
99cdf0e10cSrcweir 
100cdf0e10cSrcweir 			::rtl::OUString								m_aCursorName;
101cdf0e10cSrcweir 			sal_Int32									m_nMaxFieldSize;
102cdf0e10cSrcweir 			sal_Int32									m_nMaxRows;
103cdf0e10cSrcweir 			sal_Int32									m_nQueryTimeOut;
104cdf0e10cSrcweir 			sal_Int32									m_nFetchSize;
105cdf0e10cSrcweir 			sal_Int32									m_nResultSetType;
106cdf0e10cSrcweir 			sal_Int32									m_nFetchDirection;
107cdf0e10cSrcweir 			sal_Int32									m_nResultSetConcurrency;
108cdf0e10cSrcweir 			sal_Bool									m_bEscapeProcessing;
109cdf0e10cSrcweir 
110cdf0e10cSrcweir             ::cppu::OBroadcastHelper&                   rBHelper;
111cdf0e10cSrcweir 
112cdf0e10cSrcweir 		protected:
113cdf0e10cSrcweir 			// initialize the column index map (mapping select columns to table columns)
114cdf0e10cSrcweir 			void createColumnMapping();
115cdf0e10cSrcweir 			// searches the statement for sort criteria
116cdf0e10cSrcweir 			void anylizeSQL();
117cdf0e10cSrcweir 			void setOrderbyColumn( connectivity::OSQLParseNode* pColumnRef,
118cdf0e10cSrcweir 									 connectivity::OSQLParseNode* pAscendingDescending);
119cdf0e10cSrcweir 
120cdf0e10cSrcweir 			virtual void initializeResultSet(OResultSet* _pResult);
121cdf0e10cSrcweir 			// create the analyzer
122cdf0e10cSrcweir 			virtual OSQLAnalyzer* createAnalyzer();
123cdf0e10cSrcweir 
124cdf0e10cSrcweir             void reset () throw( ::com::sun::star::sdbc::SQLException);
125cdf0e10cSrcweir             void clearMyResultSet () throw( ::com::sun::star::sdbc::SQLException);
126cdf0e10cSrcweir             void setWarning (const  ::com::sun::star::sdbc::SQLWarning &ex) throw( ::com::sun::star::sdbc::SQLException);
127cdf0e10cSrcweir 			sal_Int32 getPrecision ( sal_Int32 sqlType);
128cdf0e10cSrcweir 
129cdf0e10cSrcweir 			void disposeResultSet();
130cdf0e10cSrcweir 			void GetAssignValues();
131cdf0e10cSrcweir 			void SetAssignValue(const String& aColumnName,
132cdf0e10cSrcweir 								   const String& aValue,
133cdf0e10cSrcweir 								   sal_Bool bSetNull = sal_False,
134cdf0e10cSrcweir 								   sal_uInt32 nParameter=SQL_NO_PARAMETER);
135cdf0e10cSrcweir 			void ParseAssignValues(	const ::std::vector< String>& aColumnNameList,
136cdf0e10cSrcweir 									connectivity::OSQLParseNode* pRow_Value_Constructor_Elem,xub_StrLen nIndex);
137cdf0e10cSrcweir 
138cdf0e10cSrcweir 			virtual void parseParamterElem(const String& _sColumnName,OSQLParseNode* pRow_Value_Constructor_Elem);
139cdf0e10cSrcweir 			// factory method for resultset's
140cdf0e10cSrcweir 			virtual OResultSet* createResultSet() = 0;
141cdf0e10cSrcweir 			// OPropertyArrayUsageHelper
142cdf0e10cSrcweir 			virtual ::cppu::IPropertyArrayHelper* createArrayHelper( ) const;
143cdf0e10cSrcweir 			// OPropertySetHelper
144cdf0e10cSrcweir 			virtual ::cppu::IPropertyArrayHelper & SAL_CALL getInfoHelper();
145cdf0e10cSrcweir 			virtual ~OStatement_Base();
146cdf0e10cSrcweir 		public:
getParseTree() const147cdf0e10cSrcweir 			connectivity::OSQLParseNode* getParseTree() const { return m_pParseTree;}
148cdf0e10cSrcweir 
149cdf0e10cSrcweir 			OStatement_Base(OConnection* _pConnection );
150cdf0e10cSrcweir 
getOwnConnection() const151cdf0e10cSrcweir 			OConnection* getOwnConnection() const { return m_pConnection;}
152cdf0e10cSrcweir 
153cdf0e10cSrcweir 			using OStatement_BASE::operator ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >;
154cdf0e10cSrcweir 
155cdf0e10cSrcweir 			virtual void construct(const ::rtl::OUString& sql)  throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
156cdf0e10cSrcweir 
157cdf0e10cSrcweir 			// OComponentHelper
158cdf0e10cSrcweir 			virtual void SAL_CALL disposing(void);
159cdf0e10cSrcweir 			// XInterface
160cdf0e10cSrcweir             //      virtual void SAL_CALL release() throw(::com::sun::star::uno::RuntimeException) = 0;
161cdf0e10cSrcweir 			virtual void SAL_CALL acquire() throw();
162cdf0e10cSrcweir 			// XInterface
163cdf0e10cSrcweir             virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type & rType ) throw(::com::sun::star::uno::RuntimeException);
164cdf0e10cSrcweir 			//XTypeProvider
165cdf0e10cSrcweir             virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL getTypes(  ) throw(::com::sun::star::uno::RuntimeException);
166cdf0e10cSrcweir 
167cdf0e10cSrcweir 			// XPropertySet
168cdf0e10cSrcweir             virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo(  ) throw(::com::sun::star::uno::RuntimeException);
169cdf0e10cSrcweir 			// XWarningsSupplier
170cdf0e10cSrcweir             virtual ::com::sun::star::uno::Any SAL_CALL getWarnings(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
171cdf0e10cSrcweir             virtual void SAL_CALL clearWarnings(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
172cdf0e10cSrcweir 			// XCancellable
173cdf0e10cSrcweir             virtual void SAL_CALL cancel(  ) throw(::com::sun::star::uno::RuntimeException);
174cdf0e10cSrcweir 			// XCloseable
175cdf0e10cSrcweir             virtual void SAL_CALL close(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
176cdf0e10cSrcweir 		};
177cdf0e10cSrcweir 
178cdf0e10cSrcweir 		class OOO_DLLPUBLIC_FILE OStatement_BASE2 :
179cdf0e10cSrcweir                                     public OStatement_Base,
180cdf0e10cSrcweir 									public connectivity::OSubComponent<OStatement_BASE2, OStatement_BASE>
181cdf0e10cSrcweir 
182cdf0e10cSrcweir 		{
183cdf0e10cSrcweir 			friend class connectivity::OSubComponent<OStatement_BASE2, OStatement_BASE>;
184cdf0e10cSrcweir 		public:
OStatement_BASE2(OConnection * _pConnection)185cdf0e10cSrcweir 			OStatement_BASE2(OConnection* _pConnection ) :  OStatement_Base(_pConnection ),
186cdf0e10cSrcweir 									connectivity::OSubComponent<OStatement_BASE2, OStatement_BASE>((::cppu::OWeakObject*)_pConnection, this){}
187cdf0e10cSrcweir 			// OComponentHelper
188cdf0e10cSrcweir 			virtual void SAL_CALL disposing(void);
189cdf0e10cSrcweir 			// XInterface
190cdf0e10cSrcweir             virtual void SAL_CALL release() throw();
191cdf0e10cSrcweir 		};
192cdf0e10cSrcweir 
193cdf0e10cSrcweir 		typedef ::cppu::ImplHelper2< ::com::sun::star::sdbc::XStatement,::com::sun::star::lang::XServiceInfo > OStatement_XStatement;
194cdf0e10cSrcweir 		class OOO_DLLPUBLIC_FILE OStatement :
195cdf0e10cSrcweir                             public OStatement_BASE2,
196cdf0e10cSrcweir 							public OStatement_XStatement
197cdf0e10cSrcweir 		{
198cdf0e10cSrcweir 		protected:
199cdf0e10cSrcweir 			// factory method for resultset's
200cdf0e10cSrcweir 			virtual OResultSet* createResultSet();
201cdf0e10cSrcweir 		public:
202cdf0e10cSrcweir 			// ein Konstruktor, der fuer das Returnen des Objektes benoetigt wird:
OStatement(OConnection * _pConnection)203cdf0e10cSrcweir 			OStatement( OConnection* _pConnection) : OStatement_BASE2( _pConnection){}
204cdf0e10cSrcweir 			DECLARE_SERVICE_INFO();
205cdf0e10cSrcweir 
206cdf0e10cSrcweir             virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type & rType ) throw(::com::sun::star::uno::RuntimeException);
207cdf0e10cSrcweir 			virtual void SAL_CALL acquire() throw();
208cdf0e10cSrcweir             virtual void SAL_CALL release() throw();
209cdf0e10cSrcweir 
210cdf0e10cSrcweir 			// XStatement
211cdf0e10cSrcweir             virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet > SAL_CALL executeQuery( const ::rtl::OUString& sql ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) ;
212cdf0e10cSrcweir             virtual sal_Int32 SAL_CALL executeUpdate( const ::rtl::OUString& sql ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) ;
213cdf0e10cSrcweir             virtual sal_Bool SAL_CALL execute( const ::rtl::OUString& sql ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) ;
214cdf0e10cSrcweir             virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection > SAL_CALL getConnection(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) ;
215cdf0e10cSrcweir 		};
216cdf0e10cSrcweir 	}
217cdf0e10cSrcweir }
218cdf0e10cSrcweir #endif // _CONNECTIVITY_FILE_OSTATEMENT_HXX_
219cdf0e10cSrcweir 
220