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