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 
28 #ifndef _CONNECTIVITY_ADO_ASTATEMENT_HXX_
29 #define _CONNECTIVITY_ADO_ASTATEMENT_HXX_
30 
31 #include <com/sun/star/sdbc/XStatement.hpp>
32 #include <com/sun/star/sdbc/XWarningsSupplier.hpp>
33 #include <com/sun/star/sdbc/XMultipleResults.hpp>
34 #include <com/sun/star/sdbc/XBatchExecution.hpp>
35 #include <com/sun/star/sdbc/XCloseable.hpp>
36 #include <com/sun/star/sdbc/SQLWarning.hpp>
37 #include <com/sun/star/util/XCancellable.hpp>
38 #include <cppuhelper/compbase5.hxx>
39 #include <comphelper/proparrhlp.hxx>
40 #include <comphelper/uno3.hxx>
41 #include <comphelper/broadcasthelper.hxx>
42 #include "ado/AConnection.hxx"
43 #ifndef _LIST_
44 #include <list>
45 #endif
46 #include "ado/Awrapado.hxx"
47 #include <com/sun/star/lang/XServiceInfo.hpp>
48 
49 namespace connectivity
50 {
51 	namespace ado
52 	{
53         typedef ::cppu::WeakComponentImplHelper5<   ::com::sun::star::sdbc::XStatement,
54                                                     ::com::sun::star::sdbc::XWarningsSupplier,
55                                                     ::com::sun::star::util::XCancellable,
56                                                     ::com::sun::star::sdbc::XCloseable,
57                                                     ::com::sun::star::sdbc::XMultipleResults> OStatement_BASE;
58 
59 		//**************************************************************
60 		//************ Class: java.sql.Statement
61 		//**************************************************************
62 		class OStatement_Base		:	public comphelper::OBaseMutex,
63 										public	OStatement_BASE,
64 										public	::cppu::OPropertySetHelper,
65 										public	::comphelper::OPropertyArrayUsageHelper<OStatement_Base>,
66 										public  connectivity::OSubComponent<OStatement_Base, OStatement_BASE>
67 
68 		{
69 			friend class connectivity::OSubComponent<OStatement_Base, OStatement_BASE>;
70 			friend class OResultSet;
71 
72 			::com::sun::star::sdbc::SQLWarning			m_aLastWarning;
73 
74 		protected:
75 			::std::list< ::rtl::OUString>				m_aBatchList;
76 
77             ::com::sun::star::uno::WeakReference< ::com::sun::star::sdbc::XResultSet>    m_xResultSet;   // The last ResultSet created
78 																		//  for this Statement
79 
80 			OConnection*								m_pConnection;// The owning Connection object
81 			WpADOCommand								m_Command;
82 			WpADORecordset								m_RecordSet;
83 			OLEVariant									m_RecordsAffected;
84 			OLEVariant									m_Parameters;
85 			::std::vector<connectivity::OTypeInfo>		m_aTypeInfo;	// Hashtable containing an entry
86 																		//  for each row returned by
87 																		//  DatabaseMetaData.getTypeInfo.
88 			sal_Int32									m_nMaxRows;
89 			sal_Int32									m_nFetchSize;
90 			LockTypeEnum								m_eLockType;
91 			CursorTypeEnum								m_eCursorType;
92 
93 			using OStatement_BASE::rBHelper;
94 		private:
95 
96 			sal_Int32 getQueryTimeOut()         const throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
97             sal_Int32 getMaxFieldSize()         const throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
98             sal_Int32 getMaxRows()              const throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
99             sal_Int32 getResultSetConcurrency() const throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
100             sal_Int32 getResultSetType()        const throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
101             sal_Int32 getFetchDirection()       const throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
102             sal_Int32 getFetchSize()            const throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
103             ::rtl::OUString getCursorName()     const throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
104 
105             void setQueryTimeOut(sal_Int32 _par0)           throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
106             void setMaxFieldSize(sal_Int32 _par0)           throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
107             void setMaxRows(sal_Int32 _par0)                throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
108             void setResultSetConcurrency(sal_Int32 _par0)   throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
109             void setResultSetType(sal_Int32 _par0)          throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
110             void setFetchDirection(sal_Int32 _par0)         throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
111             void setFetchSize(sal_Int32 _par0)              throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
112             void setCursorName(const ::rtl::OUString &_par0) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
113 
114 		protected:
115 
116 			void assignRecordSet( ADORecordset* _pRS );
117 
118             void reset () throw( ::com::sun::star::sdbc::SQLException);
119             void clearMyResultSet () throw( ::com::sun::star::sdbc::SQLException);
120             void setWarning (const  ::com::sun::star::sdbc::SQLWarning &ex) throw( ::com::sun::star::sdbc::SQLException);
121             sal_Int32 getColumnCount () throw( ::com::sun::star::sdbc::SQLException);
122             sal_Int32 getRowCount () throw( ::com::sun::star::sdbc::SQLException);
123 			sal_Int32 getPrecision ( sal_Int32 sqlType);
124 
125 			void disposeResultSet();
126 
127 			// OPropertyArrayUsageHelper
128 			virtual ::cppu::IPropertyArrayHelper* createArrayHelper( ) const;
129 			// OPropertySetHelper
130 			virtual ::cppu::IPropertyArrayHelper & SAL_CALL getInfoHelper();
131 			virtual sal_Bool SAL_CALL convertFastPropertyValue(
132                                 ::com::sun::star::uno::Any & rConvertedValue,
133                                 ::com::sun::star::uno::Any & rOldValue,
134 								sal_Int32 nHandle,
135                                 const ::com::sun::star::uno::Any& rValue )
136 									throw (::com::sun::star::lang::IllegalArgumentException);
137 			virtual void SAL_CALL setFastPropertyValue_NoBroadcast(
138 									sal_Int32 nHandle,
139                                     const ::com::sun::star::uno::Any& rValue
140 									)
141                                     throw (::com::sun::star::uno::Exception);
142 			virtual void SAL_CALL getFastPropertyValue(
143                                     ::com::sun::star::uno::Any& rValue,
144 									sal_Int32 nHandle
145 									) const;
146 		public:
147 			OStatement_Base(OConnection* _pConnection );
148 
149 			using OStatement_BASE::operator ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >;
150 			// OComponentHelper
151 			virtual void SAL_CALL disposing(void);
152 			// XInterface
153             virtual void SAL_CALL acquire() throw();
154 			virtual void SAL_CALL release() throw();
155             virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type & rType ) throw(::com::sun::star::uno::RuntimeException);
156 			//XTypeProvider
157             virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL getTypes(  ) throw(::com::sun::star::uno::RuntimeException);
158 
159 			// XPropertySet
160             virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo(  ) throw(::com::sun::star::uno::RuntimeException);
161 			// XStatement
162             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) ;
163             virtual sal_Int32 SAL_CALL executeUpdate( const ::rtl::OUString& sql ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) ;
164             virtual sal_Bool SAL_CALL execute( const ::rtl::OUString& sql ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) ;
165             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) ;
166 			// XWarningsSupplier
167             virtual ::com::sun::star::uno::Any SAL_CALL getWarnings(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
168             virtual void SAL_CALL clearWarnings(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
169 			// XCancellable
170             virtual void SAL_CALL cancel(  ) throw(::com::sun::star::uno::RuntimeException);
171 			// XCloseable
172             virtual void SAL_CALL close(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
173 			// XMultipleResults
174             virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet > SAL_CALL getResultSet(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
175             virtual sal_Int32 SAL_CALL getUpdateCount(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
176             virtual sal_Bool SAL_CALL getMoreResults(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
177 		};
178 
179 		class OStatement :	public OStatement_Base,
180                             public ::com::sun::star::sdbc::XBatchExecution,
181                             public ::com::sun::star::lang::XServiceInfo
182 		{
183 		public:
184 			// ein Konstruktor, der fuer das Returnen des Objektes benoetigt wird:
185 			OStatement( OConnection* _pConnection) : OStatement_Base( _pConnection){};
186 			~OStatement();
187 
188 			DECLARE_SERVICE_INFO();
189 
190 			virtual void SAL_CALL acquire() throw();
191             virtual void SAL_CALL release() throw();
192             virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type & rType ) throw(::com::sun::star::uno::RuntimeException);
193 			// XBatchExecution
194             virtual void SAL_CALL addBatch( const ::rtl::OUString& sql ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
195             virtual void SAL_CALL clearBatch(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
196             virtual ::com::sun::star::uno::Sequence< sal_Int32 > SAL_CALL executeBatch(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
197 		};
198 	}
199 }
200 #endif // _CONNECTIVITY_ADO_ASTATEMENT_HXX_
201 
202