xref: /AOO41X/main/connectivity/source/inc/odbc/OStatement.hxx (revision caf5cd79edad04a48dcaf209068b3b89eae4622e)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef _CONNECTIVITY_ODBC_OSTATEMENT_HXX_
25 #define _CONNECTIVITY_ODBC_OSTATEMENT_HXX_
26 
27 #include <com/sun/star/sdbc/XStatement.hpp>
28 #include <com/sun/star/sdbc/XWarningsSupplier.hpp>
29 #include <com/sun/star/sdbc/XMultipleResults.hpp>
30 #include <com/sun/star/sdbc/XBatchExecution.hpp>
31 #include <com/sun/star/sdbc/XCloseable.hpp>
32 #include <com/sun/star/sdbc/SQLWarning.hpp>
33 #include <com/sun/star/sdbc/XGeneratedResultSet.hpp>
34 #include <com/sun/star/util/XCancellable.hpp>
35 #include <comphelper/proparrhlp.hxx>
36 #include <cppuhelper/compbase6.hxx>
37 #include <comphelper/uno3.hxx>
38 #include "connectivity/CommonTools.hxx"
39 #include "odbc/OFunctions.hxx"
40 #include "odbc/OConnection.hxx"
41 #include "odbc/odbcbasedllapi.hxx"
42 #include <list>
43 #include <com/sun/star/lang/XServiceInfo.hpp>
44 #include <comphelper/broadcasthelper.hxx>
45 
46 namespace connectivity
47 {
48     namespace odbc
49     {
50 
51         typedef ::cppu::WeakComponentImplHelper6<   ::com::sun::star::sdbc::XStatement,
52                                                     ::com::sun::star::sdbc::XWarningsSupplier,
53                                                     ::com::sun::star::util::XCancellable,
54                                                     ::com::sun::star::sdbc::XCloseable,
55                                                     ::com::sun::star::sdbc::XGeneratedResultSet,
56                                                     ::com::sun::star::sdbc::XMultipleResults> OStatement_BASE;
57 
58         class OResultSet;
59         //**************************************************************
60         //************ Class: java.sql.Statement
61         //**************************************************************
62         class OOO_DLLPUBLIC_ODBCBASE OStatement_Base :
63                                         public comphelper::OBaseMutex,
64                                         public  OStatement_BASE,
65                                         public  ::cppu::OPropertySetHelper,
66                                         public  ::comphelper::OPropertyArrayUsageHelper<OStatement_Base>
67 
68         {
69         ::com::sun::star::sdbc::SQLWarning                                           m_aLastWarning;
70         protected:
71             ::com::sun::star::uno::WeakReference< ::com::sun::star::sdbc::XResultSet>   m_xResultSet;   // The last ResultSet created
72             ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XStatement>       m_xGeneratedStatement;
73             //  for this Statement
74 
75             ::std::list< ::rtl::OUString>   m_aBatchList;
76             ::rtl::OUString                 m_sSqlStatement;
77 
78             OConnection*                    m_pConnection;// The owning Connection object
79             SQLHANDLE                       m_aStatementHandle;
80             SQLUSMALLINT*                   m_pRowStatusArray;
81             ::cppu::OBroadcastHelper&       rBHelper;
82 
83         protected:
84 
85             sal_Int32 getQueryTimeOut()         const;
86             sal_Int32 getMaxFieldSize()         const;
87             sal_Int32 getMaxRows()              const;
88             sal_Int32 getResultSetConcurrency() const;
89             sal_Int32 getResultSetType()        const;
90             sal_Int32 getFetchDirection()       const;
91             sal_Int32 getFetchSize()            const;
92             ::rtl::OUString getCursorName()     const;
93             sal_Bool isUsingBookmarks()         const;
94             sal_Bool getEscapeProcessing()      const;
95             sal_Int32 getStmtOption (short fOption) const;
96 
97             void setQueryTimeOut(sal_Int32 _par0)           ;
98             void setMaxFieldSize(sal_Int32 _par0)           ;
99             void setMaxRows(sal_Int32 _par0)                ;
100             void setFetchDirection(sal_Int32 _par0)         ;
101             void setFetchSize(sal_Int32 _par0)              ;
102             void setCursorName(const ::rtl::OUString &_par0);
103             void setEscapeProcessing( const sal_Bool _bEscapeProc );
104 
105             virtual void setResultSetConcurrency(sal_Int32 _par0)   ;
106             virtual void setResultSetType(sal_Int32 _par0)          ;
107             virtual void setUsingBookmarks(sal_Bool _bUseBookmark)  ;
108 
109             void reset () throw( ::com::sun::star::sdbc::SQLException);
110             void clearMyResultSet () throw( ::com::sun::star::sdbc::SQLException);
111             void setWarning (const  ::com::sun::star::sdbc::SQLWarning &ex) throw( ::com::sun::star::sdbc::SQLException);
112             sal_Bool lockIfNecessary (const ::rtl::OUString& sql) throw( ::com::sun::star::sdbc::SQLException);
113             sal_Int32 getColumnCount () throw( ::com::sun::star::sdbc::SQLException);
114 
115             //--------------------------------------------------------------------
116             // getResultSet
117             // getResultSet returns the current result as a ResultSet.  It
118             // returns NULL if the current result is not a ResultSet.
119             //--------------------------------------------------------------------
120             ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet > getResultSet (sal_Bool checkCount) throw( ::com::sun::star::sdbc::SQLException);
121             /**
122                 creates the driver specific resultset (factory)
123             */
124             virtual OResultSet* createResulSet();
125 
126             SQLLEN getRowCount () throw( ::com::sun::star::sdbc::SQLException);
127 
128 
129             void disposeResultSet();
130 
131             // OPropertyArrayUsageHelper
132             virtual ::cppu::IPropertyArrayHelper* createArrayHelper( ) const;
133             // OPropertySetHelper
134             virtual ::cppu::IPropertyArrayHelper & SAL_CALL getInfoHelper();
135             virtual sal_Bool SAL_CALL convertFastPropertyValue(
136                                 ::com::sun::star::uno::Any & rConvertedValue,
137                                 ::com::sun::star::uno::Any & rOldValue,
138                                 sal_Int32 nHandle,
139                                 const ::com::sun::star::uno::Any& rValue )
140                             throw (::com::sun::star::lang::IllegalArgumentException);
141             virtual void SAL_CALL setFastPropertyValue_NoBroadcast(
142                                     sal_Int32 nHandle,
143                                     const ::com::sun::star::uno::Any& rValue
144                                                      )
145                                  throw (::com::sun::star::uno::Exception);
146             virtual void SAL_CALL getFastPropertyValue(
147                                     ::com::sun::star::uno::Any& rValue,
148                                     sal_Int32 nHandle
149                                          ) const;
150             virtual ~OStatement_Base();
151 
152         public:
153             OStatement_Base(OConnection* _pConnection );
154             using OStatement_BASE::operator ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >;
155 
getOdbcFunction(sal_Int32 _nIndex) const156             inline oslGenericFunction getOdbcFunction(sal_Int32 _nIndex)  const
157             {
158                 return m_pConnection->getOdbcFunction(_nIndex);
159             }
160             // OComponentHelper
161             virtual void SAL_CALL disposing(void);
162             // XInterface
163             virtual void SAL_CALL release() throw();
164             virtual void SAL_CALL acquire() throw();
165             // XInterface
166             virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type & rType ) throw(::com::sun::star::uno::RuntimeException);
167             //XTypeProvider
168             virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL getTypes(  ) throw(::com::sun::star::uno::RuntimeException);
169 
170             // XPropertySet
171             virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo(  ) throw(::com::sun::star::uno::RuntimeException);
172             // XStatement
173             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) ;
174             virtual sal_Int32 SAL_CALL executeUpdate( const ::rtl::OUString& sql ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) ;
175             virtual sal_Bool SAL_CALL execute( const ::rtl::OUString& sql ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) ;
176             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) ;
177             // XWarningsSupplier
178             virtual ::com::sun::star::uno::Any SAL_CALL getWarnings(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
179             virtual void SAL_CALL clearWarnings(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
180             // XCancellable
181             virtual void SAL_CALL cancel(  ) throw(::com::sun::star::uno::RuntimeException);
182             // XCloseable
183             virtual void SAL_CALL close(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
184             // XMultipleResults
185             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);
186             virtual sal_Int32 SAL_CALL getUpdateCount(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
187             virtual sal_Bool SAL_CALL getMoreResults(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
188             //XGeneratedResultSet
189             virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet > SAL_CALL getGeneratedValues(  ) throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
190 
191             // other methods
getConnectionHandle()192             SQLHANDLE getConnectionHandle() { return m_pConnection->getConnection(); }
getOwnConnection() const193             OConnection* getOwnConnection() const { return m_pConnection;}
194             /** getCursorProperties return the properties for a specific cursor type
195                 @param _nCursorType     the CursorType
196                 @param bFirst           when true the first property set is returned
197 
198                 @return the cursor properties
199             */
200             SQLUINTEGER getCursorProperties(SQLINTEGER _nCursorType,sal_Bool bFirst);
201 
202         protected:
203             using OPropertySetHelper::getFastPropertyValue;
204         };
205 
206         class OOO_DLLPUBLIC_ODBCBASE OStatement_BASE2 :
207                                  public OStatement_Base
208                                 ,public ::connectivity::OSubComponent<OStatement_BASE2, OStatement_BASE>
209 
210         {
211             friend class OSubComponent<OStatement_BASE2, OStatement_BASE>;
212         public:
OStatement_BASE2(OConnection * _pConnection)213             OStatement_BASE2(OConnection* _pConnection ) :  OStatement_Base(_pConnection ),
214                                     ::connectivity::OSubComponent<OStatement_BASE2, OStatement_BASE>((::cppu::OWeakObject*)_pConnection, this){}
215             // OComponentHelper
216             virtual void SAL_CALL disposing(void);
217             // XInterface
218             virtual void SAL_CALL release() throw();
219         };
220 
221         class OOO_DLLPUBLIC_ODBCBASE OStatement :
222                             public OStatement_BASE2,
223                             public ::com::sun::star::sdbc::XBatchExecution,
224                             public ::com::sun::star::lang::XServiceInfo
225         {
226         protected:
~OStatement()227             virtual ~OStatement(){}
228         public:
229             // ein Konstruktor, der fuer das Returnen des Objektes benoetigt wird:
OStatement(OConnection * _pConnection)230             OStatement( OConnection* _pConnection) : OStatement_BASE2( _pConnection){}
231             DECLARE_SERVICE_INFO();
232 
233             virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type & rType ) throw(::com::sun::star::uno::RuntimeException);
234             virtual void SAL_CALL acquire() throw();
235             virtual void SAL_CALL release() throw();
236             // XBatchExecution
237             virtual void SAL_CALL addBatch( const ::rtl::OUString& sql ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
238             virtual void SAL_CALL clearBatch(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
239             virtual ::com::sun::star::uno::Sequence< sal_Int32 > SAL_CALL executeBatch(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
240         };
241     }
242 }
243 #endif // _CONNECTIVITY_ODBC_OSTATEMENT_HXX_
244 
245