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 ************************************************************************/
42 #include <cppuhelper/propshlp.hxx>
43 #include <cppuhelper/component.hxx>
45 #include <com/sun/star/sdbc/XParameters.hpp>
46 #include <com/sun/star/sdbc/XMultipleResults.hpp>
47 #include <com/sun/star/sdbc/XGeneratedResultSet.hpp>
48 #include <com/sun/star/sdbc/XResultSetMetaDataSupplier.hpp>
50 #include "pq_connection.hxx"
51 namespace pq_sdbc_driver
54 const sal_Int32 PREPARED_STATEMENT_CURSOR_NAME
= 0;
55 const sal_Int32 PREPARED_STATEMENT_ESCAPE_PROCESSING
= 1;
56 const sal_Int32 PREPARED_STATEMENT_FETCH_DIRECTION
= 2;
57 const sal_Int32 PREPARED_STATEMENT_FETCH_SIZE
= 3;
58 const sal_Int32 PREPARED_STATEMENT_MAX_FIELD_SIZE
= 4;
59 const sal_Int32 PREPARED_STATEMENT_MAX_ROWS
= 5;
60 const sal_Int32 PREPARED_STATEMENT_QUERY_TIME_OUT
= 6;
61 const sal_Int32 PREPARED_STATEMENT_RESULT_SET_CONCURRENCY
= 7;
62 const sal_Int32 PREPARED_STATEMENT_RESULT_SET_TYPE
= 8;
64 #define PREPARED_STATEMENT_SIZE 9
66 typedef ::cppu::WeakComponentImplHelper
< css::sdbc::XPreparedStatement
,
67 css::sdbc::XParameters
,
68 css::sdbc::XCloseable
,
69 css::sdbc::XWarningsSupplier
,
70 css::sdbc::XMultipleResults
,
71 css::sdbc::XGeneratedResultSet
,
72 css::sdbc::XResultSetMetaDataSupplier
73 > PreparedStatement_BASE
;
74 class PreparedStatement
: public PreparedStatement_BASE
,
75 public cppu::OPropertySetHelper
78 css::uno::Any m_props
[PREPARED_STATEMENT_SIZE
];
79 css::uno::Reference
< css::sdbc::XConnection
> m_connection
;
80 ConnectionSettings
*m_pSettings
;
81 css::uno::Reference
< css::sdbc::XCloseable
> m_lastResultset
;
83 OString m_executedStatement
;
84 ::rtl::Reference
< comphelper::RefCountedMutex
> m_xMutex
;
85 std::vector
< OString
> m_vars
;
86 std::vector
< OString
> m_splittedStatement
;
87 bool m_multipleResultAvailable
;
88 sal_Int32 m_multipleResultUpdateCount
;
89 sal_Int32 m_lastOidInserted
;
90 OUString m_lastTableInserted
;
95 * @param ppConnection The piece of memory, pConnection points to, is accessible
96 * as long as a reference to parameter con is held.
98 PreparedStatement( const rtl::Reference
< comphelper::RefCountedMutex
> & refMutex
,
99 const css::uno::Reference
< css::sdbc::XConnection
> & con
,
100 struct ConnectionSettings
*pSettings
,
103 virtual ~PreparedStatement() override
;
104 public: // XInterface
105 virtual void SAL_CALL
acquire() noexcept override
{ PreparedStatement_BASE::acquire(); }
106 virtual void SAL_CALL
release() noexcept override
{ PreparedStatement_BASE::release(); }
107 virtual css::uno::Any SAL_CALL
queryInterface( const css::uno::Type
& reqType
) override
;
109 public: // XCloseable
110 virtual void SAL_CALL
close( ) override
;
112 public: // XPreparedStatement
113 virtual css::uno::Reference
< css::sdbc::XResultSet
> SAL_CALL
executeQuery() override
;
114 virtual sal_Int32 SAL_CALL
executeUpdate( ) override
;
115 virtual sal_Bool SAL_CALL
execute( ) override
;
116 virtual css::uno::Reference
< css::sdbc::XConnection
> SAL_CALL
getConnection( ) override
;
117 public: // XParameters
118 virtual void SAL_CALL
setNull( sal_Int32 parameterIndex
, sal_Int32 sqlType
) override
;
119 virtual void SAL_CALL
setObjectNull(
120 sal_Int32 parameterIndex
, sal_Int32 sqlType
, const OUString
& typeName
) override
;
121 virtual void SAL_CALL
setBoolean( sal_Int32 parameterIndex
, sal_Bool x
) override
;
122 virtual void SAL_CALL
setByte( sal_Int32 parameterIndex
, sal_Int8 x
) override
;
123 virtual void SAL_CALL
setShort( sal_Int32 parameterIndex
, sal_Int16 x
) override
;
124 virtual void SAL_CALL
setInt( sal_Int32 parameterIndex
, sal_Int32 x
) override
;
125 virtual void SAL_CALL
setLong( sal_Int32 parameterIndex
, sal_Int64 x
) override
;
126 virtual void SAL_CALL
setFloat( sal_Int32 parameterIndex
, float x
) override
;
127 virtual void SAL_CALL
setDouble( sal_Int32 parameterIndex
, double x
) override
;
128 virtual void SAL_CALL
setString( sal_Int32 parameterIndex
, const OUString
& x
) override
;
129 virtual void SAL_CALL
setBytes(
130 sal_Int32 parameterIndex
, const css::uno::Sequence
< sal_Int8
>& x
) override
;
131 virtual void SAL_CALL
setDate( sal_Int32 parameterIndex
, const css::util::Date
& x
) override
;
132 virtual void SAL_CALL
setTime( sal_Int32 parameterIndex
, const css::util::Time
& x
) override
;
133 virtual void SAL_CALL
setTimestamp(
134 sal_Int32 parameterIndex
, const css::util::DateTime
& x
) override
;
135 virtual void SAL_CALL
setBinaryStream(
136 sal_Int32 parameterIndex
,
137 const css::uno::Reference
< css::io::XInputStream
>& x
,
138 sal_Int32 length
) override
;
139 virtual void SAL_CALL
setCharacterStream(
140 sal_Int32 parameterIndex
,
141 const css::uno::Reference
< css::io::XInputStream
>& x
,
142 sal_Int32 length
) override
;
143 virtual void SAL_CALL
setObject( sal_Int32 parameterIndex
, const css::uno::Any
& x
) override
;
144 virtual void SAL_CALL
setObjectWithInfo(
145 sal_Int32 parameterIndex
,
146 const css::uno::Any
& x
,
147 sal_Int32 targetSqlType
,
148 sal_Int32 scale
) override
;
149 virtual void SAL_CALL
setRef(
150 sal_Int32 parameterIndex
,
151 const css::uno::Reference
< css::sdbc::XRef
>& x
) override
;
152 virtual void SAL_CALL
setBlob(
153 sal_Int32 parameterIndex
,
154 const css::uno::Reference
< css::sdbc::XBlob
>& x
) override
;
155 virtual void SAL_CALL
setClob(
156 sal_Int32 parameterIndex
,
157 const css::uno::Reference
< css::sdbc::XClob
>& x
) override
;
158 virtual void SAL_CALL
setArray(
159 sal_Int32 parameterIndex
,
160 const css::uno::Reference
< css::sdbc::XArray
>& x
) override
;
161 virtual void SAL_CALL
clearParameters( ) override
;
163 public: // XWarningsSupplier
164 virtual css::uno::Any SAL_CALL
getWarnings( ) override
;
165 virtual void SAL_CALL
clearWarnings( ) override
;
167 public: // XTypeProvider, first implemented by OPropertySetHelper
168 virtual css::uno::Sequence
< css::uno::Type
> SAL_CALL
getTypes() override
;
169 virtual css::uno::Sequence
< sal_Int8
> SAL_CALL
getImplementationId() override
;
171 public: // OPropertySetHelper
172 virtual cppu::IPropertyArrayHelper
& SAL_CALL
getInfoHelper() override
;
174 virtual sal_Bool SAL_CALL
convertFastPropertyValue(
175 css::uno::Any
& rConvertedValue
,
176 css::uno::Any
& rOldValue
,
178 const css::uno::Any
& rValue
) override
;
180 virtual void SAL_CALL
setFastPropertyValue_NoBroadcast(
182 const css::uno::Any
& rValue
) override
;
184 using ::cppu::OPropertySetHelper::getFastPropertyValue
;
186 void SAL_CALL
getFastPropertyValue(
187 css::uno::Any
& rValue
,
188 sal_Int32 nHandle
) const override
;
191 css::uno::Reference
< css::beans::XPropertySetInfo
> SAL_CALL
getPropertySetInfo() override
;
193 public: // XGeneratedResultSet
194 virtual css::uno::Reference
< css::sdbc::XResultSet
> SAL_CALL
195 getGeneratedValues( ) override
;
197 public: // XMultipleResults
198 virtual css::uno::Reference
< css::sdbc::XResultSet
> SAL_CALL
getResultSet( ) override
;
199 virtual sal_Int32 SAL_CALL
getUpdateCount( ) override
;
200 virtual sal_Bool SAL_CALL
getMoreResults( ) override
;
202 public: // XResultSetMetaDataSupplier (is required by framework (see
203 // dbaccess/source/core/api/preparedstatement.cxx::getMetaData() )
204 virtual css::uno::Reference
< css::sdbc::XResultSetMetaData
> SAL_CALL
getMetaData( ) override
;
206 public: // OComponentHelper
207 virtual void SAL_CALL
disposing() override
;
210 void checkColumnIndex( sal_Int32 parameterIndex
);
211 /// @throws css::sdbc::SQLException
212 /// @throws css::uno::RuntimeException
214 /// @throws css::sdbc::SQLException
215 void raiseSQLException( const char * errorMsg
);
216 // PGresult *pgExecute( OString *pQuery );
221 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */