xref: /trunk/main/connectivity/source/inc/odbc/OStatement.hxx (revision 91144cd0085a7583d2099b982122deb2184ab956)
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 ();
110             void clearMyResultSet ();
111             void setWarning (const  ::com::sun::star::sdbc::SQLWarning &ex);
112             sal_Bool lockIfNecessary (const ::rtl::OUString& sql);
113             sal_Int32 getColumnCount ();
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);
121             /**
122                 creates the driver specific resultset (factory)
123             */
124             virtual OResultSet* createResulSet();
125 
126             SQLLEN getRowCount ();
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             virtual void SAL_CALL setFastPropertyValue_NoBroadcast(
141                                     sal_Int32 nHandle,
142                                     const ::com::sun::star::uno::Any& rValue
143                                                      );
144             virtual void SAL_CALL getFastPropertyValue(
145                                     ::com::sun::star::uno::Any& rValue,
146                                     sal_Int32 nHandle
147                                          ) const;
148             virtual ~OStatement_Base();
149 
150         public:
151             OStatement_Base(OConnection* _pConnection );
152             using OStatement_BASE::operator ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >;
153 
getOdbcFunction(sal_Int32 _nIndex) const154             inline oslGenericFunction getOdbcFunction(sal_Int32 _nIndex)  const
155             {
156                 return m_pConnection->getOdbcFunction(_nIndex);
157             }
158             // OComponentHelper
159             virtual void SAL_CALL disposing(void);
160             // XInterface
161             virtual void SAL_CALL release() throw();
162             virtual void SAL_CALL acquire() throw();
163             // XInterface
164             virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type & rType );
165             //XTypeProvider
166             virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL getTypes(  );
167 
168             // XPropertySet
169             virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo(  );
170             // XStatement
171             virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet > SAL_CALL executeQuery( const ::rtl::OUString& sql ) ;
172             virtual sal_Int32 SAL_CALL executeUpdate( const ::rtl::OUString& sql ) ;
173             virtual sal_Bool SAL_CALL execute( const ::rtl::OUString& sql ) ;
174             virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection > SAL_CALL getConnection(  ) ;
175             // XWarningsSupplier
176             virtual ::com::sun::star::uno::Any SAL_CALL getWarnings(  );
177             virtual void SAL_CALL clearWarnings(  );
178             // XCancellable
179             virtual void SAL_CALL cancel(  );
180             // XCloseable
181             virtual void SAL_CALL close(  );
182             // XMultipleResults
183             virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet > SAL_CALL getResultSet(  );
184             virtual sal_Int32 SAL_CALL getUpdateCount(  );
185             virtual sal_Bool SAL_CALL getMoreResults(  );
186             //XGeneratedResultSet
187             virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet > SAL_CALL getGeneratedValues(  );
188 
189             // other methods
getConnectionHandle()190             SQLHANDLE getConnectionHandle() { return m_pConnection->getConnection(); }
getOwnConnection() const191             OConnection* getOwnConnection() const { return m_pConnection;}
192             /** getCursorProperties return the properties for a specific cursor type
193                 @param _nCursorType     the CursorType
194                 @param bFirst           when true the first property set is returned
195 
196                 @return the cursor properties
197             */
198             SQLUINTEGER getCursorProperties(SQLINTEGER _nCursorType,sal_Bool bFirst);
199 
200         protected:
201             using OPropertySetHelper::getFastPropertyValue;
202         };
203 
204         class OOO_DLLPUBLIC_ODBCBASE OStatement_BASE2 :
205                                  public OStatement_Base
206                                 ,public ::connectivity::OSubComponent<OStatement_BASE2, OStatement_BASE>
207 
208         {
209             friend class OSubComponent<OStatement_BASE2, OStatement_BASE>;
210         public:
OStatement_BASE2(OConnection * _pConnection)211             OStatement_BASE2(OConnection* _pConnection ) :  OStatement_Base(_pConnection ),
212                                     ::connectivity::OSubComponent<OStatement_BASE2, OStatement_BASE>((::cppu::OWeakObject*)_pConnection, this){}
213             // OComponentHelper
214             virtual void SAL_CALL disposing(void);
215             // XInterface
216             virtual void SAL_CALL release() throw();
217         };
218 
219         class OOO_DLLPUBLIC_ODBCBASE OStatement :
220                             public OStatement_BASE2,
221                             public ::com::sun::star::sdbc::XBatchExecution,
222                             public ::com::sun::star::lang::XServiceInfo
223         {
224         protected:
~OStatement()225             virtual ~OStatement(){}
226         public:
227             // ein Konstruktor, der fuer das Returnen des Objektes benoetigt wird:
OStatement(OConnection * _pConnection)228             OStatement( OConnection* _pConnection) : OStatement_BASE2( _pConnection){}
229             DECLARE_SERVICE_INFO();
230 
231             virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type & rType );
232             virtual void SAL_CALL acquire() throw();
233             virtual void SAL_CALL release() throw();
234             // XBatchExecution
235             virtual void SAL_CALL addBatch( const ::rtl::OUString& sql );
236             virtual void SAL_CALL clearBatch(  );
237             virtual ::com::sun::star::uno::Sequence< sal_Int32 > SAL_CALL executeBatch(  );
238         };
239     }
240 }
241 #endif // _CONNECTIVITY_ODBC_OSTATEMENT_HXX_
242