Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * Effective License of whole file:
5 : : *
6 : : * This library is free software; you can redistribute it and/or
7 : : * modify it under the terms of the GNU Lesser General Public
8 : : * License version 2.1, as published by the Free Software Foundation.
9 : : *
10 : : * This library is distributed in the hope that it will be useful,
11 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 : : * Lesser General Public License for more details.
14 : : *
15 : : * You should have received a copy of the GNU Lesser General Public
16 : : * License along with this library; if not, write to the Free Software
17 : : * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
18 : : * MA 02111-1307 USA
19 : : *
20 : : * Parts "Copyright by Sun Microsystems, Inc" prior to August 2011:
21 : : *
22 : : * The Contents of this file are made available subject to the terms of
23 : : * the GNU Lesser General Public License Version 2.1
24 : : *
25 : : * Copyright: 2000 by Sun Microsystems, Inc.
26 : : *
27 : : * Contributor(s): Joerg Budischewski
28 : : *
29 : : * All parts contributed on or after August 2011:
30 : : *
31 : : * Version: MPL 1.1 / GPLv3+ / LGPLv2.1+
32 : : *
33 : : * The contents of this file are subject to the Mozilla Public License Version
34 : : * 1.1 (the "License"); you may not use this file except in compliance with
35 : : * the License or as specified alternatively below. You may obtain a copy of
36 : : * the License at http://www.mozilla.org/MPL/
37 : : *
38 : : * Software distributed under the License is distributed on an "AS IS" basis,
39 : : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
40 : : * for the specific language governing rights and limitations under the
41 : : * License.
42 : : *
43 : : * Major Contributor(s):
44 : : * [ Copyright (C) 2011 Lionel Elie Mamane <lionel@mamane.lu> ]
45 : : *
46 : : * All Rights Reserved.
47 : : *
48 : : * For minor contributions see the git repository.
49 : : *
50 : : * Alternatively, the contents of this file may be used under the terms of
51 : : * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
52 : : * the GNU Lesser General Public License Version 2.1 or later (the "LGPLv2.1+"),
53 : : * in which case the provisions of the GPLv3+ or the LGPLv2.1+ are applicable
54 : : * instead of those above.
55 : : *
56 : : ************************************************************************/
57 : :
58 : : #ifndef _PQ_PREPARED_STATEMENT_HXX_
59 : : #define _PQ_PREPARED_STATEMENT_HXX_
60 : : #include <vector>
61 : :
62 : : #include <libpq-fe.h>
63 : :
64 : : #include <cppuhelper/propshlp.hxx>
65 : : #include <cppuhelper/component.hxx>
66 : :
67 : : #include <com/sun/star/sdbc/XParameters.hpp>
68 : : #include <com/sun/star/sdbc/XMultipleResults.hpp>
69 : : #include <com/sun/star/sdbc/XGeneratedResultSet.hpp>
70 : : #include <com/sun/star/sdbc/XResultSetMetaDataSupplier.hpp>
71 : :
72 : : #include "pq_connection.hxx"
73 : : namespace rtl { class OString; }
74 : : namespace pq_sdbc_driver
75 : : {
76 : :
77 : : static const sal_Int32 PREPARED_STATEMENT_CURSOR_NAME = 0;
78 : : static const sal_Int32 PREPARED_STATEMENT_ESCAPE_PROCESSING = 1;
79 : : static const sal_Int32 PREPARED_STATEMENT_FETCH_DIRECTION = 2;
80 : : static const sal_Int32 PREPARED_STATEMENT_FETCH_SIZE = 3;
81 : : static const sal_Int32 PREPARED_STATEMENT_MAX_FIELD_SIZE = 4;
82 : : static const sal_Int32 PREPARED_STATEMENT_MAX_ROWS = 5;
83 : : static const sal_Int32 PREPARED_STATEMENT_QUERY_TIME_OUT = 6;
84 : : static const sal_Int32 PREPARED_STATEMENT_RESULT_SET_CONCURRENCY = 7;
85 : : static const sal_Int32 PREPARED_STATEMENT_RESULT_SET_TYPE = 8;
86 : :
87 : : #define PREPARED_STATEMENT_SIZE 9
88 : :
89 : : class PreparedStatement : public cppu::OComponentHelper,
90 : : public cppu::OPropertySetHelper,
91 : : public com::sun::star::sdbc::XPreparedStatement,
92 : : public com::sun::star::sdbc::XParameters,
93 : : public com::sun::star::sdbc::XCloseable,
94 : : public com::sun::star::sdbc::XWarningsSupplier,
95 : : public com::sun::star::sdbc::XMultipleResults,
96 : : public com::sun::star::sdbc::XGeneratedResultSet,
97 : : public com::sun::star::sdbc::XResultSetMetaDataSupplier
98 : : {
99 : : private:
100 : : com::sun::star::uno::Any m_props[PREPARED_STATEMENT_SIZE];
101 : : com::sun::star::uno::Reference< com::sun::star::sdbc::XConnection > m_connection;
102 : : ConnectionSettings *m_pSettings;
103 : : ::com::sun::star::uno::Reference< com::sun::star::sdbc::XCloseable > m_lastResultset;
104 : : ::rtl::OString m_stmt;
105 : : ::rtl::OString m_executedStatement;
106 : : ::rtl::Reference< RefCountedMutex > m_refMutex;
107 : : OStringVector m_vars;
108 : : OStringVector m_splittedStatement;
109 : : sal_Bool m_multipleResultAvailable;
110 : : sal_Int32 m_multipleResultUpdateCount;
111 : : sal_Int32 m_lastOidInserted;
112 : : rtl::OUString m_lastTableInserted;
113 : : rtl::OString m_lastQuery;
114 : :
115 : : public:
116 : : /**
117 : : * @param ppConnection The piece of memory, pConnection points to, is accessisble
118 : : * as long as a reference to paramenter con is held.
119 : : */
120 : : PreparedStatement( const rtl::Reference< RefCountedMutex > & refMutex,
121 : : const com::sun::star::uno::Reference< com::sun::star::sdbc::XConnection> & con,
122 : : struct ConnectionSettings *pSettings,
123 : : const rtl::OString &stmt );
124 : :
125 : : virtual ~PreparedStatement();
126 : : public: // XInterface
127 : 0 : virtual void SAL_CALL acquire() throw() { OComponentHelper::acquire(); }
128 : 0 : virtual void SAL_CALL release() throw() { OComponentHelper::release(); }
129 : : virtual com::sun::star::uno::Any SAL_CALL queryInterface( const com::sun::star::uno::Type & reqType )
130 : : throw (com::sun::star::uno::RuntimeException);
131 : :
132 : : public: // XCloseable
133 : : virtual void SAL_CALL close( )
134 : : throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
135 : :
136 : : public: // XPreparedStatement
137 : : virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet > SAL_CALL executeQuery()
138 : : throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
139 : : virtual sal_Int32 SAL_CALL executeUpdate( )
140 : : throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
141 : : virtual sal_Bool SAL_CALL execute( )
142 : : throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
143 : : virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection > SAL_CALL getConnection( )
144 : : throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
145 : : public: // XParameters
146 : : virtual void SAL_CALL setNull( sal_Int32 parameterIndex, sal_Int32 sqlType )
147 : : throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
148 : : virtual void SAL_CALL setObjectNull(
149 : : sal_Int32 parameterIndex, sal_Int32 sqlType, const ::rtl::OUString& typeName )
150 : : throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
151 : : virtual void SAL_CALL setBoolean( sal_Int32 parameterIndex, sal_Bool x )
152 : : throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
153 : : virtual void SAL_CALL setByte( sal_Int32 parameterIndex, sal_Int8 x )
154 : : throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
155 : : virtual void SAL_CALL setShort( sal_Int32 parameterIndex, sal_Int16 x )
156 : : throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
157 : : virtual void SAL_CALL setInt( sal_Int32 parameterIndex, sal_Int32 x )
158 : : throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
159 : : virtual void SAL_CALL setLong( sal_Int32 parameterIndex, sal_Int64 x )
160 : : throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
161 : : virtual void SAL_CALL setFloat( sal_Int32 parameterIndex, float x )
162 : : throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
163 : : virtual void SAL_CALL setDouble( sal_Int32 parameterIndex, double x )
164 : : throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
165 : : virtual void SAL_CALL setString( sal_Int32 parameterIndex, const ::rtl::OUString& x )
166 : : throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
167 : : virtual void SAL_CALL setBytes(
168 : : sal_Int32 parameterIndex, const ::com::sun::star::uno::Sequence< sal_Int8 >& x )
169 : : throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
170 : : virtual void SAL_CALL setDate( sal_Int32 parameterIndex, const ::com::sun::star::util::Date& x )
171 : : throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
172 : : virtual void SAL_CALL setTime( sal_Int32 parameterIndex, const ::com::sun::star::util::Time& x )
173 : : throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
174 : : virtual void SAL_CALL setTimestamp(
175 : : sal_Int32 parameterIndex, const ::com::sun::star::util::DateTime& x )
176 : : throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
177 : : virtual void SAL_CALL setBinaryStream(
178 : : sal_Int32 parameterIndex,
179 : : const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& x,
180 : : sal_Int32 length )
181 : : throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
182 : : virtual void SAL_CALL setCharacterStream(
183 : : sal_Int32 parameterIndex,
184 : : const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& x,
185 : : sal_Int32 length )
186 : : throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
187 : : virtual void SAL_CALL setObject( sal_Int32 parameterIndex, const ::com::sun::star::uno::Any& x )
188 : : throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
189 : : virtual void SAL_CALL setObjectWithInfo(
190 : : sal_Int32 parameterIndex,
191 : : const ::com::sun::star::uno::Any& x,
192 : : sal_Int32 targetSqlType,
193 : : sal_Int32 scale )
194 : : throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
195 : : virtual void SAL_CALL setRef(
196 : : sal_Int32 parameterIndex,
197 : : const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRef >& x )
198 : : throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
199 : : virtual void SAL_CALL setBlob(
200 : : sal_Int32 parameterIndex,
201 : : const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XBlob >& x )
202 : : throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
203 : : virtual void SAL_CALL setClob(
204 : : sal_Int32 parameterIndex,
205 : : const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XClob >& x )
206 : : throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
207 : : virtual void SAL_CALL setArray(
208 : : sal_Int32 parameterIndex,
209 : : const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XArray >& x )
210 : : throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
211 : : virtual void SAL_CALL clearParameters( )
212 : : throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
213 : :
214 : : public: // XWarningsSupplier
215 : : virtual ::com::sun::star::uno::Any SAL_CALL getWarnings( )
216 : : throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
217 : : virtual void SAL_CALL clearWarnings( )
218 : : throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
219 : :
220 : : public: // XTypeProvider, first implemented by OPropertySetHelper
221 : : virtual com::sun::star::uno::Sequence< com::sun::star::uno::Type > SAL_CALL getTypes()
222 : : throw( com::sun::star::uno::RuntimeException );
223 : : virtual com::sun::star::uno::Sequence< sal_Int8> SAL_CALL getImplementationId()
224 : : throw( com::sun::star::uno::RuntimeException );
225 : :
226 : : public: // OPropertySetHelper
227 : : virtual cppu::IPropertyArrayHelper & SAL_CALL getInfoHelper();
228 : :
229 : : virtual sal_Bool SAL_CALL convertFastPropertyValue(
230 : : ::com::sun::star::uno::Any & rConvertedValue,
231 : : ::com::sun::star::uno::Any & rOldValue,
232 : : sal_Int32 nHandle,
233 : : const ::com::sun::star::uno::Any& rValue )
234 : : throw (::com::sun::star::lang::IllegalArgumentException);
235 : :
236 : : virtual void SAL_CALL setFastPropertyValue_NoBroadcast(
237 : : sal_Int32 nHandle,
238 : : const ::com::sun::star::uno::Any& rValue )
239 : : throw (::com::sun::star::uno::Exception);
240 : :
241 : : using ::cppu::OPropertySetHelper::getFastPropertyValue;
242 : :
243 : : void SAL_CALL getFastPropertyValue(
244 : : ::com::sun::star::uno::Any& rValue,
245 : : sal_Int32 nHandle ) const;
246 : :
247 : : // XPropertySet
248 : : ::com::sun::star::uno::Reference < ::com::sun::star::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo()
249 : : throw(com::sun::star::uno::RuntimeException);
250 : :
251 : : public: // XGeneratedResultSet
252 : : virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet > SAL_CALL
253 : : getGeneratedValues( )
254 : : throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
255 : :
256 : : public: // XMultipleResults
257 : : virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet > SAL_CALL getResultSet( )
258 : : throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
259 : : virtual sal_Int32 SAL_CALL getUpdateCount( )
260 : : throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
261 : : virtual sal_Bool SAL_CALL getMoreResults( )
262 : : throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
263 : :
264 : : public: // XResultSetMetaDataSupplier (is required by framework (see
265 : : // dbaccess/source/core/api/preparedstatement.cxx::getMetaData() )
266 : : virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSetMetaData > SAL_CALL getMetaData( )
267 : : throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
268 : :
269 : : public: // OComponentHelper
270 : : virtual void SAL_CALL disposing();
271 : :
272 : : private:
273 : : void checkColumnIndex( sal_Int32 parameterIndex );
274 : : void checkClosed() throw (com::sun::star::sdbc::SQLException, com::sun::star::uno::RuntimeException);
275 : : void raiseSQLException( const char * errorMsg, const char *errorType = 0 )
276 : : throw ( com::sun::star::sdbc::SQLException );
277 : : // PGresult *pgExecute( ::rtl::OString *pQuery );
278 : : };
279 : :
280 : : }
281 : : #endif
|