1*079eb577SAndrew Rist /**************************************************************
2*079eb577SAndrew Rist  *
3*079eb577SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*079eb577SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*079eb577SAndrew Rist  * distributed with this work for additional information
6*079eb577SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*079eb577SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*079eb577SAndrew Rist  * "License"); you may not use this file except in compliance
9*079eb577SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*079eb577SAndrew Rist  *
11*079eb577SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*079eb577SAndrew Rist  *
13*079eb577SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*079eb577SAndrew Rist  * software distributed under the License is distributed on an
15*079eb577SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*079eb577SAndrew Rist  * KIND, either express or implied.  See the License for the
17*079eb577SAndrew Rist  * specific language governing permissions and limitations
18*079eb577SAndrew Rist  * under the License.
19*079eb577SAndrew Rist  *
20*079eb577SAndrew Rist  *************************************************************/
21cdf0e10cSrcweir #ifndef MYSQLC_STATEMENT_HXX
22cdf0e10cSrcweir #define MYSQLC_STATEMENT_HXX
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #include "mysqlc_connection.hxx"
25cdf0e10cSrcweir #include "mysqlc_subcomponent.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <com/sun/star/lang/XServiceInfo.hpp>
28cdf0e10cSrcweir #include <com/sun/star/sdbc/SQLWarning.hpp>
29cdf0e10cSrcweir #include <com/sun/star/sdbc/XBatchExecution.hpp>
30cdf0e10cSrcweir #include <com/sun/star/sdbc/XCloseable.hpp>
31cdf0e10cSrcweir #include <com/sun/star/sdbc/XMultipleResults.hpp>
32cdf0e10cSrcweir #include <com/sun/star/sdbc/XStatement.hpp>
33cdf0e10cSrcweir #include <com/sun/star/sdbc/XWarningsSupplier.hpp>
34cdf0e10cSrcweir #include <com/sun/star/util/XCancellable.hpp>
35cdf0e10cSrcweir 
36cdf0e10cSrcweir #include <preextstl.h>
37cdf0e10cSrcweir #include <cppconn/statement.h>
38cdf0e10cSrcweir #include <postextstl.h>
39cdf0e10cSrcweir #include <cppuhelper/compbase5.hxx>
40cdf0e10cSrcweir #include <list>
41cdf0e10cSrcweir 
42cdf0e10cSrcweir namespace connectivity
43cdf0e10cSrcweir {
44cdf0e10cSrcweir 	namespace mysqlc
45cdf0e10cSrcweir 	{
46cdf0e10cSrcweir 		using ::com::sun::star::sdbc::SQLWarning;
47cdf0e10cSrcweir 		using ::com::sun::star::sdbc::SQLException;
48cdf0e10cSrcweir 		using ::com::sun::star::uno::Any;
49cdf0e10cSrcweir 		using ::com::sun::star::uno::RuntimeException;
50cdf0e10cSrcweir 		using ::rtl::OUString;
51cdf0e10cSrcweir 
52cdf0e10cSrcweir         typedef ::cppu::WeakComponentImplHelper5<	::com::sun::star::sdbc::XStatement,
53cdf0e10cSrcweir                                                     ::com::sun::star::sdbc::XWarningsSupplier,
54cdf0e10cSrcweir                                                     ::com::sun::star::util::XCancellable,
55cdf0e10cSrcweir                                                     ::com::sun::star::sdbc::XCloseable,
56cdf0e10cSrcweir                                                     ::com::sun::star::sdbc::XMultipleResults> OCommonStatement_IBase;
57cdf0e10cSrcweir 
58cdf0e10cSrcweir         class OCommonStatement;
59cdf0e10cSrcweir         typedef OSubComponent< OCommonStatement, OCommonStatement_IBase >   OStatement_CBase;
60cdf0e10cSrcweir 
61cdf0e10cSrcweir 		//**************************************************************
62cdf0e10cSrcweir 		//************ Class: OCommonStatement
63cdf0e10cSrcweir 		// is a base class for the normal statement and for the prepared statement
64cdf0e10cSrcweir 		//**************************************************************
65cdf0e10cSrcweir         class OCommonStatement  :public OBase_Mutex
66cdf0e10cSrcweir                                 ,public OCommonStatement_IBase
67cdf0e10cSrcweir                                 ,public ::cppu::OPropertySetHelper
68cdf0e10cSrcweir                                 ,public OPropertyArrayUsageHelper<OCommonStatement>
69cdf0e10cSrcweir                                 ,public OStatement_CBase
70cdf0e10cSrcweir 
71cdf0e10cSrcweir 		{
72cdf0e10cSrcweir             friend class OSubComponent< OCommonStatement, OCommonStatement_IBase >;
73cdf0e10cSrcweir 
74cdf0e10cSrcweir         private:
75cdf0e10cSrcweir 			SQLWarning m_aLastWarning;
76cdf0e10cSrcweir 
77cdf0e10cSrcweir 		protected:
78cdf0e10cSrcweir 			::std::list< OUString>	m_aBatchList;
79cdf0e10cSrcweir 
80cdf0e10cSrcweir 			OConnection*			m_pConnection;	// The owning Connection object
81cdf0e10cSrcweir 
82cdf0e10cSrcweir 			sql::Statement			*cppStatement;
83cdf0e10cSrcweir 
84cdf0e10cSrcweir 		protected:
85cdf0e10cSrcweir 			void disposeResultSet();
86cdf0e10cSrcweir 
87cdf0e10cSrcweir 			// OPropertyArrayUsageHelper
88cdf0e10cSrcweir 			::cppu::IPropertyArrayHelper* createArrayHelper( ) const;
89cdf0e10cSrcweir 
90cdf0e10cSrcweir 			// OPropertySetHelper
91cdf0e10cSrcweir 			::cppu::IPropertyArrayHelper & SAL_CALL getInfoHelper();
92cdf0e10cSrcweir 			sal_Bool SAL_CALL convertFastPropertyValue(Any & rConvertedValue, Any & rOldValue,
93cdf0e10cSrcweir 															   sal_Int32 nHandle, const Any& rValue)
94cdf0e10cSrcweir 												throw (::com::sun::star::lang::IllegalArgumentException);
95cdf0e10cSrcweir 
96cdf0e10cSrcweir 			void SAL_CALL setFastPropertyValue_NoBroadcast(sal_Int32 nHandle, const Any& rValue)
97cdf0e10cSrcweir 												throw(::com::sun::star::uno::Exception);
98cdf0e10cSrcweir 
99cdf0e10cSrcweir 			void SAL_CALL getFastPropertyValue(Any& rValue, sal_Int32 nHandle) const;
100cdf0e10cSrcweir 			virtual ~OCommonStatement();
101cdf0e10cSrcweir 
102cdf0e10cSrcweir         protected:
103cdf0e10cSrcweir 			OCommonStatement(OConnection* _pConnection, sql::Statement *_cppStatement);
104cdf0e10cSrcweir 
105cdf0e10cSrcweir 		public:
106cdf0e10cSrcweir 			::cppu::OBroadcastHelper& rBHelper;
107cdf0e10cSrcweir 			using OCommonStatement_IBase::operator ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >;
108cdf0e10cSrcweir 
109cdf0e10cSrcweir 			// OComponentHelper
110cdf0e10cSrcweir 			void SAL_CALL disposing(void);
111cdf0e10cSrcweir 
112cdf0e10cSrcweir 			// XInterface
113cdf0e10cSrcweir 			void SAL_CALL release() 			throw();
114cdf0e10cSrcweir 
115cdf0e10cSrcweir 			void SAL_CALL acquire() 			throw();
116cdf0e10cSrcweir 
117cdf0e10cSrcweir 			// XInterface
118cdf0e10cSrcweir 			Any SAL_CALL queryInterface(const ::com::sun::star::uno::Type & rType)
119cdf0e10cSrcweir 												throw(RuntimeException);
120cdf0e10cSrcweir 
121cdf0e10cSrcweir 			//XTypeProvider
122cdf0e10cSrcweir 			::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL getTypes()
123cdf0e10cSrcweir 												throw(RuntimeException);
124cdf0e10cSrcweir 
125cdf0e10cSrcweir 			// XPropertySet
126cdf0e10cSrcweir 			::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo()
127cdf0e10cSrcweir 												throw(RuntimeException);
128cdf0e10cSrcweir 
129cdf0e10cSrcweir 			// XStatement
130cdf0e10cSrcweir 			::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet > SAL_CALL executeQuery(const OUString& sql)
131cdf0e10cSrcweir 												throw(SQLException, RuntimeException);
132cdf0e10cSrcweir 
133cdf0e10cSrcweir 			sal_Int32 SAL_CALL executeUpdate(const OUString& sql)
134cdf0e10cSrcweir 												throw(SQLException, RuntimeException);
135cdf0e10cSrcweir 
136cdf0e10cSrcweir 			sal_Bool SAL_CALL execute( const OUString& sql )
137cdf0e10cSrcweir 												throw(SQLException, RuntimeException);
138cdf0e10cSrcweir 
139cdf0e10cSrcweir 			::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection > SAL_CALL getConnection()
140cdf0e10cSrcweir 												throw(SQLException, RuntimeException);
141cdf0e10cSrcweir 
142cdf0e10cSrcweir 			// XWarningsSupplier
143cdf0e10cSrcweir 			Any SAL_CALL getWarnings() 		throw(SQLException, RuntimeException);
144cdf0e10cSrcweir 
145cdf0e10cSrcweir 			void SAL_CALL clearWarnings() 		throw(SQLException, RuntimeException);
146cdf0e10cSrcweir 
147cdf0e10cSrcweir 			// XCancellable
148cdf0e10cSrcweir 			void SAL_CALL cancel() 				throw(RuntimeException);
149cdf0e10cSrcweir 
150cdf0e10cSrcweir 			// XCloseable
151cdf0e10cSrcweir 			void SAL_CALL close() 				throw(SQLException, RuntimeException);
152cdf0e10cSrcweir 
153cdf0e10cSrcweir 			// XMultipleResults
154cdf0e10cSrcweir 			::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet > SAL_CALL getResultSet()
155cdf0e10cSrcweir 												throw(SQLException, RuntimeException);
156cdf0e10cSrcweir 
157cdf0e10cSrcweir 			sal_Int32 SAL_CALL getUpdateCount() throw(SQLException, RuntimeException);
158cdf0e10cSrcweir 
159cdf0e10cSrcweir 			sal_Bool SAL_CALL getMoreResults()	throw(SQLException, RuntimeException);
160cdf0e10cSrcweir 
161cdf0e10cSrcweir 			// other methods
getOwnConnection() const162cdf0e10cSrcweir 			OConnection* getOwnConnection() const { return m_pConnection;}
163cdf0e10cSrcweir 
164cdf0e10cSrcweir 		private:
165cdf0e10cSrcweir 			using ::cppu::OPropertySetHelper::getFastPropertyValue;
166cdf0e10cSrcweir 		};
167cdf0e10cSrcweir 
168cdf0e10cSrcweir 
169cdf0e10cSrcweir 		class OStatement :	public OCommonStatement,
170cdf0e10cSrcweir 							public ::com::sun::star::sdbc::XBatchExecution,
171cdf0e10cSrcweir 							public ::com::sun::star::lang::XServiceInfo
172cdf0e10cSrcweir 
173cdf0e10cSrcweir 		{
174cdf0e10cSrcweir 		protected:
~OStatement()175cdf0e10cSrcweir 			virtual ~OStatement(){}
176cdf0e10cSrcweir 
177cdf0e10cSrcweir 		public:
178cdf0e10cSrcweir 			// ein Konstruktor, der fuer das Returnen des Objektes benoetigt wird:
OStatement(OConnection * _pConnection,sql::Statement * _cppStatement)179cdf0e10cSrcweir 			OStatement(OConnection* _pConnection, sql::Statement *_cppStatement) : OCommonStatement(_pConnection, _cppStatement) {}
180cdf0e10cSrcweir 			DECLARE_SERVICE_INFO();
181cdf0e10cSrcweir 
182cdf0e10cSrcweir 			Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type & rType )
183cdf0e10cSrcweir 												throw(RuntimeException);
184cdf0e10cSrcweir 
185cdf0e10cSrcweir 			void SAL_CALL acquire() 			throw();
186cdf0e10cSrcweir 			void SAL_CALL release() 			throw();
187cdf0e10cSrcweir 
188cdf0e10cSrcweir 			// XBatchExecution
189cdf0e10cSrcweir 			void SAL_CALL addBatch(const OUString& sql)
190cdf0e10cSrcweir 												throw(SQLException, RuntimeException);
191cdf0e10cSrcweir 
192cdf0e10cSrcweir 			void SAL_CALL clearBatch()			throw(SQLException, RuntimeException);
193cdf0e10cSrcweir 
194cdf0e10cSrcweir 			::com::sun::star::uno::Sequence< sal_Int32 > SAL_CALL executeBatch()
195cdf0e10cSrcweir 												throw(SQLException, RuntimeException);
196cdf0e10cSrcweir 
197cdf0e10cSrcweir 		};
198cdf0e10cSrcweir 	}
199cdf0e10cSrcweir }
200cdf0e10cSrcweir #endif // MYSQLC_STATEMENT_HXX
201cdf0e10cSrcweir 
202cdf0e10cSrcweir /*
203cdf0e10cSrcweir  * Local variables:
204cdf0e10cSrcweir  * tab-width: 4
205cdf0e10cSrcweir  * c-basic-offset: 4
206cdf0e10cSrcweir  * End:
207cdf0e10cSrcweir  * vim600: noet sw=4 ts=4 fdm=marker
208cdf0e10cSrcweir  * vim<600: noet sw=4 ts=4
209cdf0e10cSrcweir  */
210