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,
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 * This Source Code Form is subject to the terms of the Mozilla Public
32 * License, v. 2.0. If a copy of the MPL was not distributed with this
33 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
35 ************************************************************************/
37 #ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_POSTGRESQL_PQ_PREPAREDSTATEMENT_HXX
38 #define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_POSTGRESQL_PQ_PREPAREDSTATEMENT_HXX
43 #include <cppuhelper/propshlp.hxx>
44 #include <cppuhelper/component.hxx>
46 #include <com/sun/star/sdbc/XParameters.hpp>
47 #include <com/sun/star/sdbc/XMultipleResults.hpp>
48 #include <com/sun/star/sdbc/XGeneratedResultSet.hpp>
49 #include <com/sun/star/sdbc/XResultSetMetaDataSupplier.hpp>
51 #include "pq_connection.hxx"
52 namespace pq_sdbc_driver
55 static const sal_Int32 PREPARED_STATEMENT_CURSOR_NAME
= 0;
56 static const sal_Int32 PREPARED_STATEMENT_ESCAPE_PROCESSING
= 1;
57 static const sal_Int32 PREPARED_STATEMENT_FETCH_DIRECTION
= 2;
58 static const sal_Int32 PREPARED_STATEMENT_FETCH_SIZE
= 3;
59 static const sal_Int32 PREPARED_STATEMENT_MAX_FIELD_SIZE
= 4;
60 static const sal_Int32 PREPARED_STATEMENT_MAX_ROWS
= 5;
61 static const sal_Int32 PREPARED_STATEMENT_QUERY_TIME_OUT
= 6;
62 static const sal_Int32 PREPARED_STATEMENT_RESULT_SET_CONCURRENCY
= 7;
63 static const sal_Int32 PREPARED_STATEMENT_RESULT_SET_TYPE
= 8;
65 #define PREPARED_STATEMENT_SIZE 9
67 typedef ::cppu::WeakComponentImplHelper
< css::sdbc::XPreparedStatement
,
68 css::sdbc::XParameters
,
69 css::sdbc::XCloseable
,
70 css::sdbc::XWarningsSupplier
,
71 css::sdbc::XMultipleResults
,
72 css::sdbc::XGeneratedResultSet
,
73 css::sdbc::XResultSetMetaDataSupplier
74 > PreparedStatement_BASE
;
75 class PreparedStatement
: public PreparedStatement_BASE
,
76 public cppu::OPropertySetHelper
79 css::uno::Any m_props
[PREPARED_STATEMENT_SIZE
];
80 css::uno::Reference
< css::sdbc::XConnection
> m_connection
;
81 ConnectionSettings
*m_pSettings
;
82 css::uno::Reference
< css::sdbc::XCloseable
> m_lastResultset
;
84 OString m_executedStatement
;
85 ::rtl::Reference
< comphelper::RefCountedMutex
> m_xMutex
;
86 std::vector
< OString
> m_vars
;
87 std::vector
< OString
> m_splittedStatement
;
88 bool m_multipleResultAvailable
;
89 sal_Int32 m_multipleResultUpdateCount
;
90 sal_Int32 m_lastOidInserted
;
91 OUString m_lastTableInserted
;
96 * @param ppConnection The piece of memory, pConnection points to, is accessible
97 * as long as a reference to parameter con is held.
99 PreparedStatement( const rtl::Reference
< comphelper::RefCountedMutex
> & refMutex
,
100 const css::uno::Reference
< css::sdbc::XConnection
> & con
,
101 struct ConnectionSettings
*pSettings
,
102 const OString
&stmt
);
104 virtual ~PreparedStatement() override
;
105 public: // XInterface
106 virtual void SAL_CALL
acquire() throw() override
{ PreparedStatement_BASE::acquire(); }
107 virtual void SAL_CALL
release() throw() override
{ PreparedStatement_BASE::release(); }
108 virtual css::uno::Any SAL_CALL
queryInterface( const css::uno::Type
& reqType
) override
;
110 public: // XCloseable
111 virtual void SAL_CALL
close( ) override
;
113 public: // XPreparedStatement
114 virtual css::uno::Reference
< css::sdbc::XResultSet
> SAL_CALL
executeQuery() override
;
115 virtual sal_Int32 SAL_CALL
executeUpdate( ) override
;
116 virtual sal_Bool SAL_CALL
execute( ) override
;
117 virtual css::uno::Reference
< css::sdbc::XConnection
> SAL_CALL
getConnection( ) override
;
118 public: // XParameters
119 virtual void SAL_CALL
setNull( sal_Int32 parameterIndex
, sal_Int32 sqlType
) override
;
120 virtual void SAL_CALL
setObjectNull(
121 sal_Int32 parameterIndex
, sal_Int32 sqlType
, const OUString
& typeName
) override
;
122 virtual void SAL_CALL
setBoolean( sal_Int32 parameterIndex
, sal_Bool x
) override
;
123 virtual void SAL_CALL
setByte( sal_Int32 parameterIndex
, sal_Int8 x
) override
;
124 virtual void SAL_CALL
setShort( sal_Int32 parameterIndex
, sal_Int16 x
) override
;
125 virtual void SAL_CALL
setInt( sal_Int32 parameterIndex
, sal_Int32 x
) override
;
126 virtual void SAL_CALL
setLong( sal_Int32 parameterIndex
, sal_Int64 x
) override
;
127 virtual void SAL_CALL
setFloat( sal_Int32 parameterIndex
, float x
) override
;
128 virtual void SAL_CALL
setDouble( sal_Int32 parameterIndex
, double x
) override
;
129 virtual void SAL_CALL
setString( sal_Int32 parameterIndex
, const OUString
& x
) override
;
130 virtual void SAL_CALL
setBytes(
131 sal_Int32 parameterIndex
, const css::uno::Sequence
< sal_Int8
>& x
) override
;
132 virtual void SAL_CALL
setDate( sal_Int32 parameterIndex
, const css::util::Date
& x
) override
;
133 virtual void SAL_CALL
setTime( sal_Int32 parameterIndex
, const css::util::Time
& x
) override
;
134 virtual void SAL_CALL
setTimestamp(
135 sal_Int32 parameterIndex
, const css::util::DateTime
& x
) override
;
136 virtual void SAL_CALL
setBinaryStream(
137 sal_Int32 parameterIndex
,
138 const css::uno::Reference
< css::io::XInputStream
>& x
,
139 sal_Int32 length
) override
;
140 virtual void SAL_CALL
setCharacterStream(
141 sal_Int32 parameterIndex
,
142 const css::uno::Reference
< css::io::XInputStream
>& x
,
143 sal_Int32 length
) override
;
144 virtual void SAL_CALL
setObject( sal_Int32 parameterIndex
, const css::uno::Any
& x
) override
;
145 virtual void SAL_CALL
setObjectWithInfo(
146 sal_Int32 parameterIndex
,
147 const css::uno::Any
& x
,
148 sal_Int32 targetSqlType
,
149 sal_Int32 scale
) override
;
150 virtual void SAL_CALL
setRef(
151 sal_Int32 parameterIndex
,
152 const css::uno::Reference
< css::sdbc::XRef
>& x
) override
;
153 virtual void SAL_CALL
setBlob(
154 sal_Int32 parameterIndex
,
155 const css::uno::Reference
< css::sdbc::XBlob
>& x
) override
;
156 virtual void SAL_CALL
setClob(
157 sal_Int32 parameterIndex
,
158 const css::uno::Reference
< css::sdbc::XClob
>& x
) override
;
159 virtual void SAL_CALL
setArray(
160 sal_Int32 parameterIndex
,
161 const css::uno::Reference
< css::sdbc::XArray
>& x
) override
;
162 virtual void SAL_CALL
clearParameters( ) override
;
164 public: // XWarningsSupplier
165 virtual css::uno::Any SAL_CALL
getWarnings( ) override
;
166 virtual void SAL_CALL
clearWarnings( ) override
;
168 public: // XTypeProvider, first implemented by OPropertySetHelper
169 virtual css::uno::Sequence
< css::uno::Type
> SAL_CALL
getTypes() override
;
170 virtual css::uno::Sequence
< sal_Int8
> SAL_CALL
getImplementationId() override
;
172 public: // OPropertySetHelper
173 virtual cppu::IPropertyArrayHelper
& SAL_CALL
getInfoHelper() override
;
175 virtual sal_Bool SAL_CALL
convertFastPropertyValue(
176 css::uno::Any
& rConvertedValue
,
177 css::uno::Any
& rOldValue
,
179 const css::uno::Any
& rValue
) override
;
181 virtual void SAL_CALL
setFastPropertyValue_NoBroadcast(
183 const css::uno::Any
& rValue
) override
;
185 using ::cppu::OPropertySetHelper::getFastPropertyValue
;
187 void SAL_CALL
getFastPropertyValue(
188 css::uno::Any
& rValue
,
189 sal_Int32 nHandle
) const override
;
192 css::uno::Reference
< css::beans::XPropertySetInfo
> SAL_CALL
getPropertySetInfo() override
;
194 public: // XGeneratedResultSet
195 virtual css::uno::Reference
< css::sdbc::XResultSet
> SAL_CALL
196 getGeneratedValues( ) override
;
198 public: // XMultipleResults
199 virtual css::uno::Reference
< css::sdbc::XResultSet
> SAL_CALL
getResultSet( ) override
;
200 virtual sal_Int32 SAL_CALL
getUpdateCount( ) override
;
201 virtual sal_Bool SAL_CALL
getMoreResults( ) override
;
203 public: // XResultSetMetaDataSupplier (is required by framework (see
204 // dbaccess/source/core/api/preparedstatement.cxx::getMetaData() )
205 virtual css::uno::Reference
< css::sdbc::XResultSetMetaData
> SAL_CALL
getMetaData( ) override
;
207 public: // OComponentHelper
208 virtual void SAL_CALL
disposing() override
;
211 void checkColumnIndex( sal_Int32 parameterIndex
);
212 /// @throws css::sdbc::SQLException
213 /// @throws css::uno::RuntimeException
215 /// @throws css::sdbc::SQLException
216 void raiseSQLException( const char * errorMsg
);
217 // PGresult *pgExecute( OString *pQuery );
223 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */