Bump for 3.6-28
[LibreOffice.git] / connectivity / source / drivers / postgresql / pq_preparedstatement.hxx
blobd44bc753f8ad4a177a5ef1c03315ebbfb6d2bb70
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * Effective License of whole file:
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.
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.
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
20 * Parts "Copyright by Sun Microsystems, Inc" prior to August 2011:
22 * The Contents of this file are made available subject to the terms of
23 * the GNU Lesser General Public License Version 2.1
25 * Copyright: 2000 by Sun Microsystems, Inc.
27 * Contributor(s): Joerg Budischewski
29 * All parts contributed on or after August 2011:
31 * Version: MPL 1.1 / GPLv3+ / LGPLv2.1+
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/
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.
43 * Major Contributor(s):
44 * [ Copyright (C) 2011 Lionel Elie Mamane <lionel@mamane.lu> ]
46 * All Rights Reserved.
48 * For minor contributions see the git repository.
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.
56 ************************************************************************/
58 #ifndef _PQ_PREPARED_STATEMENT_HXX_
59 #define _PQ_PREPARED_STATEMENT_HXX_
60 #include <vector>
62 #include <libpq-fe.h>
64 #include <cppuhelper/propshlp.hxx>
65 #include <cppuhelper/component.hxx>
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>
72 #include "pq_connection.hxx"
73 namespace rtl { class OString; }
74 namespace pq_sdbc_driver
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;
87 #define PREPARED_STATEMENT_SIZE 9
88 class ResultSet;
90 class PreparedStatement : public cppu::OComponentHelper,
91 public cppu::OPropertySetHelper,
92 public com::sun::star::sdbc::XPreparedStatement,
93 public com::sun::star::sdbc::XParameters,
94 public com::sun::star::sdbc::XCloseable,
95 public com::sun::star::sdbc::XWarningsSupplier,
96 public com::sun::star::sdbc::XMultipleResults,
97 public com::sun::star::sdbc::XGeneratedResultSet,
98 public com::sun::star::sdbc::XResultSetMetaDataSupplier
100 private:
101 com::sun::star::uno::Any m_props[PREPARED_STATEMENT_SIZE];
102 com::sun::star::uno::Reference< com::sun::star::sdbc::XConnection > m_connection;
103 ConnectionSettings *m_pSettings;
104 ::com::sun::star::uno::Reference< com::sun::star::sdbc::XCloseable > m_lastResultset;
105 ::rtl::OString m_stmt;
106 ::rtl::OString m_executedStatement;
107 ::rtl::Reference< RefCountedMutex > m_refMutex;
108 OStringVector m_vars;
109 OStringVector m_splittedStatement;
110 sal_Bool m_multipleResultAvailable;
111 sal_Int32 m_multipleResultUpdateCount;
112 sal_Int32 m_lastOidInserted;
113 rtl::OUString m_lastTableInserted;
114 rtl::OString m_lastQuery;
116 public:
118 * @param ppConnection The piece of memory, pConnection points to, is accessisble
119 * as long as a reference to paramenter con is held.
121 PreparedStatement( const rtl::Reference< RefCountedMutex > & refMutex,
122 const com::sun::star::uno::Reference< com::sun::star::sdbc::XConnection> & con,
123 struct ConnectionSettings *pSettings,
124 const rtl::OString &stmt );
126 virtual ~PreparedStatement();
127 public: // XInterface
128 virtual void SAL_CALL acquire() throw() { OComponentHelper::acquire(); }
129 virtual void SAL_CALL release() throw() { OComponentHelper::release(); }
130 virtual com::sun::star::uno::Any SAL_CALL queryInterface( const com::sun::star::uno::Type & reqType )
131 throw (com::sun::star::uno::RuntimeException);
133 public: // XCloseable
134 virtual void SAL_CALL close( )
135 throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
137 public: // XPreparedStatement
138 virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet > SAL_CALL executeQuery()
139 throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
140 virtual sal_Int32 SAL_CALL executeUpdate( )
141 throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
142 virtual sal_Bool SAL_CALL execute( )
143 throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
144 virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection > SAL_CALL getConnection( )
145 throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
146 public: // XParameters
147 virtual void SAL_CALL setNull( sal_Int32 parameterIndex, sal_Int32 sqlType )
148 throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
149 virtual void SAL_CALL setObjectNull(
150 sal_Int32 parameterIndex, sal_Int32 sqlType, const ::rtl::OUString& typeName )
151 throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
152 virtual void SAL_CALL setBoolean( sal_Int32 parameterIndex, sal_Bool x )
153 throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
154 virtual void SAL_CALL setByte( sal_Int32 parameterIndex, sal_Int8 x )
155 throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
156 virtual void SAL_CALL setShort( sal_Int32 parameterIndex, sal_Int16 x )
157 throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
158 virtual void SAL_CALL setInt( sal_Int32 parameterIndex, sal_Int32 x )
159 throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
160 virtual void SAL_CALL setLong( sal_Int32 parameterIndex, sal_Int64 x )
161 throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
162 virtual void SAL_CALL setFloat( sal_Int32 parameterIndex, float x )
163 throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
164 virtual void SAL_CALL setDouble( sal_Int32 parameterIndex, double x )
165 throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
166 virtual void SAL_CALL setString( sal_Int32 parameterIndex, const ::rtl::OUString& x )
167 throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
168 virtual void SAL_CALL setBytes(
169 sal_Int32 parameterIndex, const ::com::sun::star::uno::Sequence< sal_Int8 >& x )
170 throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
171 virtual void SAL_CALL setDate( sal_Int32 parameterIndex, const ::com::sun::star::util::Date& x )
172 throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
173 virtual void SAL_CALL setTime( sal_Int32 parameterIndex, const ::com::sun::star::util::Time& x )
174 throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
175 virtual void SAL_CALL setTimestamp(
176 sal_Int32 parameterIndex, const ::com::sun::star::util::DateTime& x )
177 throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
178 virtual void SAL_CALL setBinaryStream(
179 sal_Int32 parameterIndex,
180 const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& x,
181 sal_Int32 length )
182 throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
183 virtual void SAL_CALL setCharacterStream(
184 sal_Int32 parameterIndex,
185 const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& x,
186 sal_Int32 length )
187 throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
188 virtual void SAL_CALL setObject( sal_Int32 parameterIndex, const ::com::sun::star::uno::Any& x )
189 throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
190 virtual void SAL_CALL setObjectWithInfo(
191 sal_Int32 parameterIndex,
192 const ::com::sun::star::uno::Any& x,
193 sal_Int32 targetSqlType,
194 sal_Int32 scale )
195 throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
196 virtual void SAL_CALL setRef(
197 sal_Int32 parameterIndex,
198 const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRef >& x )
199 throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
200 virtual void SAL_CALL setBlob(
201 sal_Int32 parameterIndex,
202 const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XBlob >& x )
203 throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
204 virtual void SAL_CALL setClob(
205 sal_Int32 parameterIndex,
206 const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XClob >& x )
207 throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
208 virtual void SAL_CALL setArray(
209 sal_Int32 parameterIndex,
210 const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XArray >& x )
211 throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
212 virtual void SAL_CALL clearParameters( )
213 throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
215 public: // XWarningsSupplier
216 virtual ::com::sun::star::uno::Any SAL_CALL getWarnings( )
217 throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
218 virtual void SAL_CALL clearWarnings( )
219 throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
221 public: // XTypeProvider, first implemented by OPropertySetHelper
222 virtual com::sun::star::uno::Sequence< com::sun::star::uno::Type > SAL_CALL getTypes()
223 throw( com::sun::star::uno::RuntimeException );
224 virtual com::sun::star::uno::Sequence< sal_Int8> SAL_CALL getImplementationId()
225 throw( com::sun::star::uno::RuntimeException );
227 public: // OPropertySetHelper
228 virtual cppu::IPropertyArrayHelper & SAL_CALL getInfoHelper();
230 virtual sal_Bool SAL_CALL convertFastPropertyValue(
231 ::com::sun::star::uno::Any & rConvertedValue,
232 ::com::sun::star::uno::Any & rOldValue,
233 sal_Int32 nHandle,
234 const ::com::sun::star::uno::Any& rValue )
235 throw (::com::sun::star::lang::IllegalArgumentException);
237 virtual void SAL_CALL setFastPropertyValue_NoBroadcast(
238 sal_Int32 nHandle,
239 const ::com::sun::star::uno::Any& rValue )
240 throw (::com::sun::star::uno::Exception);
242 using ::cppu::OPropertySetHelper::getFastPropertyValue;
244 void SAL_CALL getFastPropertyValue(
245 ::com::sun::star::uno::Any& rValue,
246 sal_Int32 nHandle ) const;
248 // XPropertySet
249 ::com::sun::star::uno::Reference < ::com::sun::star::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo()
250 throw(com::sun::star::uno::RuntimeException);
252 public: // XGeneratedResultSet
253 virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet > SAL_CALL
254 getGeneratedValues( )
255 throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
257 public: // XMultipleResults
258 virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet > SAL_CALL getResultSet( )
259 throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
260 virtual sal_Int32 SAL_CALL getUpdateCount( )
261 throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
262 virtual sal_Bool SAL_CALL getMoreResults( )
263 throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
265 public: // XResultSetMetaDataSupplier (is required by framework (see
266 // dbaccess/source/core/api/preparedstatement.cxx::getMetaData() )
267 virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSetMetaData > SAL_CALL getMetaData( )
268 throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
270 public: // OComponentHelper
271 virtual void SAL_CALL disposing();
273 private:
274 void checkColumnIndex( sal_Int32 parameterIndex );
275 void checkClosed() throw (com::sun::star::sdbc::SQLException, com::sun::star::uno::RuntimeException);
276 void raiseSQLException( const char * errorMsg, const char *errorType = 0 )
277 throw ( com::sun::star::sdbc::SQLException );
278 // PGresult *pgExecute( ::rtl::OString *pQuery );
282 #endif