xref: /trunk/main/mysqlc/source/mysqlc_statement.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 #ifndef MYSQLC_STATEMENT_HXX
22 #define MYSQLC_STATEMENT_HXX
23 
24 #include "mysqlc_connection.hxx"
25 #include "mysqlc_subcomponent.hxx"
26 
27 #include <com/sun/star/lang/XServiceInfo.hpp>
28 #include <com/sun/star/sdbc/SQLWarning.hpp>
29 #include <com/sun/star/sdbc/XBatchExecution.hpp>
30 #include <com/sun/star/sdbc/XCloseable.hpp>
31 #include <com/sun/star/sdbc/XMultipleResults.hpp>
32 #include <com/sun/star/sdbc/XStatement.hpp>
33 #include <com/sun/star/sdbc/XWarningsSupplier.hpp>
34 #include <com/sun/star/util/XCancellable.hpp>
35 
36 #include <preextstl.h>
37 #include <cppconn/statement.h>
38 #include <postextstl.h>
39 #include <cppuhelper/compbase5.hxx>
40 #include <list>
41 
42 namespace connectivity
43 {
44     namespace mysqlc
45     {
46         using ::com::sun::star::sdbc::SQLWarning;
47         using ::com::sun::star::sdbc::SQLException;
48         using ::com::sun::star::uno::Any;
49         using ::com::sun::star::uno::RuntimeException;
50         using ::rtl::OUString;
51 
52         typedef ::cppu::WeakComponentImplHelper5<   ::com::sun::star::sdbc::XStatement,
53                                                     ::com::sun::star::sdbc::XWarningsSupplier,
54                                                     ::com::sun::star::util::XCancellable,
55                                                     ::com::sun::star::sdbc::XCloseable,
56                                                     ::com::sun::star::sdbc::XMultipleResults> OCommonStatement_IBase;
57 
58         class OCommonStatement;
59         typedef OSubComponent< OCommonStatement, OCommonStatement_IBase >   OStatement_CBase;
60 
61         //**************************************************************
62         //************ Class: OCommonStatement
63         // is a base class for the normal statement and for the prepared statement
64         //**************************************************************
65         class OCommonStatement  :public OBase_Mutex
66                                 ,public OCommonStatement_IBase
67                                 ,public ::cppu::OPropertySetHelper
68                                 ,public OPropertyArrayUsageHelper<OCommonStatement>
69                                 ,public OStatement_CBase
70 
71         {
72             friend class OSubComponent< OCommonStatement, OCommonStatement_IBase >;
73 
74         private:
75             SQLWarning m_aLastWarning;
76 
77         protected:
78             ::std::list< OUString>  m_aBatchList;
79 
80             OConnection*            m_pConnection;  // The owning Connection object
81 
82             sql::Statement          *cppStatement;
83 
84         protected:
85             void disposeResultSet();
86 
87             // OPropertyArrayUsageHelper
88             ::cppu::IPropertyArrayHelper* createArrayHelper( ) const;
89 
90             // OPropertySetHelper
91             ::cppu::IPropertyArrayHelper & SAL_CALL getInfoHelper();
92             sal_Bool SAL_CALL convertFastPropertyValue(Any & rConvertedValue, Any & rOldValue,
93                                                                sal_Int32 nHandle, const Any& rValue);
94 
95             void SAL_CALL setFastPropertyValue_NoBroadcast(sal_Int32 nHandle, const Any& rValue);
96 
97             void SAL_CALL getFastPropertyValue(Any& rValue, sal_Int32 nHandle) const;
98             virtual ~OCommonStatement();
99 
100         protected:
101             OCommonStatement(OConnection* _pConnection, sql::Statement *_cppStatement);
102 
103         public:
104             ::cppu::OBroadcastHelper& rBHelper;
105             using OCommonStatement_IBase::operator ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >;
106 
107             // OComponentHelper
108             void SAL_CALL disposing(void);
109 
110             // XInterface
111             void SAL_CALL release()             throw();
112 
113             void SAL_CALL acquire()             throw();
114 
115             // XInterface
116             Any SAL_CALL queryInterface(const ::com::sun::star::uno::Type & rType);
117 
118             //XTypeProvider
119             ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL getTypes();
120 
121             // XPropertySet
122             ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo();
123 
124             // XStatement
125             ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet > SAL_CALL executeQuery(const OUString& sql);
126 
127             sal_Int32 SAL_CALL executeUpdate(const OUString& sql);
128 
129             sal_Bool SAL_CALL execute( const OUString& sql );
130 
131             ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection > SAL_CALL getConnection();
132 
133             // XWarningsSupplier
134             Any SAL_CALL getWarnings();
135 
136             void SAL_CALL clearWarnings();
137 
138             // XCancellable
139             void SAL_CALL cancel();
140 
141             // XCloseable
142             void SAL_CALL close();
143 
144             // XMultipleResults
145             ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet > SAL_CALL getResultSet();
146 
147             sal_Int32 SAL_CALL getUpdateCount();
148 
149             sal_Bool SAL_CALL getMoreResults();
150 
151             // other methods
getOwnConnection() const152             OConnection* getOwnConnection() const { return m_pConnection;}
153 
154         private:
155             using ::cppu::OPropertySetHelper::getFastPropertyValue;
156         };
157 
158 
159         class OStatement :  public OCommonStatement,
160                             public ::com::sun::star::sdbc::XBatchExecution,
161                             public ::com::sun::star::lang::XServiceInfo
162 
163         {
164         protected:
~OStatement()165             virtual ~OStatement(){}
166 
167         public:
168             // ein Konstruktor, der fuer das Returnen des Objektes benoetigt wird:
OStatement(OConnection * _pConnection,sql::Statement * _cppStatement)169             OStatement(OConnection* _pConnection, sql::Statement *_cppStatement) : OCommonStatement(_pConnection, _cppStatement) {}
170             DECLARE_SERVICE_INFO();
171 
172             Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type & rType );
173 
174             void SAL_CALL acquire()             throw();
175             void SAL_CALL release()             throw();
176 
177             // XBatchExecution
178             void SAL_CALL addBatch(const OUString& sql);
179 
180             void SAL_CALL clearBatch();
181 
182             ::com::sun::star::uno::Sequence< sal_Int32 > SAL_CALL executeBatch();
183 
184         };
185     }
186 }
187 #endif // MYSQLC_STATEMENT_HXX
188 
189 /*
190  * Local variables:
191  * tab-width: 4
192  * c-basic-offset: 4
193  * End:
194  * vim600: noet sw=4 ts=4 fdm=marker
195  * vim<600: noet sw=4 ts=4
196  */
197