Use correct object
[LibreOffice.git] / connectivity / source / drivers / postgresql / pq_statement.hxx
blob816d2a55afaac05ec09f728b8ec1ad34b16a38ca
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 * 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 #pragma once
39 #include <sal/config.h>
41 #include <string_view>
43 #include <cppuhelper/propshlp.hxx>
44 #include <cppuhelper/compbase.hxx>
45 #include <cppuhelper/component.hxx>
47 #include <libpq-fe.h>
49 #include "pq_connection.hxx"
50 #include <com/sun/star/sdbc/XMultipleResults.hpp>
51 #include <com/sun/star/sdbc/XGeneratedResultSet.hpp>
52 #include <com/sun/star/sdbc/XResultSetMetaDataSupplier.hpp>
54 namespace pq_sdbc_driver
57 const sal_Int32 STATEMENT_CURSOR_NAME = 0;
58 const sal_Int32 STATEMENT_ESCAPE_PROCESSING = 1;
59 const sal_Int32 STATEMENT_FETCH_DIRECTION = 2;
60 const sal_Int32 STATEMENT_FETCH_SIZE = 3;
61 const sal_Int32 STATEMENT_MAX_FIELD_SIZE = 4;
62 const sal_Int32 STATEMENT_MAX_ROWS = 5;
63 const sal_Int32 STATEMENT_QUERY_TIME_OUT = 6;
64 const sal_Int32 STATEMENT_RESULT_SET_CONCURRENCY = 7;
65 const sal_Int32 STATEMENT_RESULT_SET_TYPE = 8;
67 #define STATEMENT_SIZE 9
69 typedef ::cppu::WeakComponentImplHelper< css::sdbc::XStatement,
70 css::sdbc::XCloseable,
71 css::sdbc::XWarningsSupplier,
72 css::sdbc::XMultipleResults,
73 css::sdbc::XGeneratedResultSet,
74 css::sdbc::XResultSetMetaDataSupplier
75 > Statement_BASE;
77 class Statement : public Statement_BASE,
78 public cppu::OPropertySetHelper
80 private:
81 css::uno::Any m_props[STATEMENT_SIZE];
82 css::uno::Reference< css::sdbc::XConnection > m_connection;
83 ConnectionSettings *m_pSettings;
84 css::uno::Reference< css::sdbc::XCloseable > m_lastResultset;
85 ::rtl::Reference< comphelper::RefCountedMutex > m_xMutex;
86 bool m_multipleResultAvailable;
87 sal_Int32 m_multipleResultUpdateCount;
88 sal_Int32 m_lastOidInserted;
89 OUString m_lastTableInserted;
90 OString m_lastQuery;
92 public:
93 /**
94 * @param ppConnection The piece of memory, pConnection points to, is accessible
95 * as long as a reference to parameter con is held.
97 Statement( const rtl::Reference< comphelper::RefCountedMutex > & refMutex,
98 const css::uno::Reference< css::sdbc::XConnection> & con,
99 struct ConnectionSettings *pSettings );
101 virtual ~Statement() override;
102 public: // XInterface
103 virtual void SAL_CALL acquire() noexcept override { Statement_BASE::acquire(); }
104 virtual void SAL_CALL release() noexcept override { Statement_BASE::release(); }
105 virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & reqType ) override;
107 public: // XCloseable
108 virtual void SAL_CALL close( ) override;
110 public: // XStatement
111 virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL executeQuery(
112 const OUString& sql ) override;
113 virtual sal_Int32 SAL_CALL executeUpdate( const OUString& sql ) override;
114 virtual sal_Bool SAL_CALL execute( const OUString& sql ) override;
115 virtual css::uno::Reference< css::sdbc::XConnection > SAL_CALL getConnection( ) override;
117 public: // XWarningsSupplier
118 virtual css::uno::Any SAL_CALL getWarnings( ) override;
119 virtual void SAL_CALL clearWarnings( ) override;
121 public: // XTypeProvider, first implemented by OPropertySetHelper
122 virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes() override;
123 virtual css::uno::Sequence< sal_Int8> SAL_CALL getImplementationId() override;
125 public: // OPropertySetHelper
126 virtual cppu::IPropertyArrayHelper & SAL_CALL getInfoHelper() override;
128 virtual sal_Bool SAL_CALL convertFastPropertyValue(
129 css::uno::Any & rConvertedValue,
130 css::uno::Any & rOldValue,
131 sal_Int32 nHandle,
132 const css::uno::Any& rValue ) override;
134 virtual void SAL_CALL setFastPropertyValue_NoBroadcast(
135 sal_Int32 nHandle,
136 const css::uno::Any& rValue ) override;
138 using ::cppu::OPropertySetHelper::getFastPropertyValue;
140 void SAL_CALL getFastPropertyValue(
141 css::uno::Any& rValue,
142 sal_Int32 nHandle ) const override;
144 // XPropertySet
145 css::uno::Reference < css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo() override;
147 public: // XGeneratedResultSet
148 virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL
149 getGeneratedValues( ) override;
151 public: // XMultipleResults
152 virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL getResultSet( ) override;
153 virtual sal_Int32 SAL_CALL getUpdateCount( ) override;
154 virtual sal_Bool SAL_CALL getMoreResults( ) override;
156 public: // OComponentHelper
157 virtual void SAL_CALL disposing() override;
159 public: // XResultSetMetaDataSupplier (is required by framework (see
160 // dbaccess/source/core/api/preparedstatement.cxx::getMetaData() )
161 virtual css::uno::Reference< css::sdbc::XResultSetMetaData > SAL_CALL getMetaData( ) override;
163 private:
164 /// @throws css::sdbc::SQLException
165 /// @throws css::uno::RuntimeException
166 void checkClosed();
167 /// @throws css::sdbc::SQLException
168 void raiseSQLException( std::u16string_view sql, const char * errorMsg );
172 struct CommandData
174 ConnectionSettings **ppSettings;
175 sal_Int32 *pLastOidInserted;
176 sal_Int32 *pMultipleResultUpdateCount;
177 bool *pMultipleResultAvailable;
178 OUString *pLastTableInserted;
179 css::uno::Reference< css::sdbc::XCloseable > *pLastResultset;
180 OString *pLastQuery;
181 ::rtl::Reference< comphelper::RefCountedMutex > refMutex;
182 css::uno::Reference< css::uno::XInterface > owner;
183 css::uno::Reference< css::sdbcx::XTablesSupplier > tableSupplier;
184 sal_Int32 concurrency;
187 bool executePostgresCommand( const OString & cmd, struct CommandData *data );
188 css::uno::Reference< css::sdbc::XResultSet > getGeneratedValuesFromLastInsert(
189 ConnectionSettings *pConnectionSettings,
190 const css::uno::Reference< css::sdbc::XConnection > &connection,
191 sal_Int32 nLastOid,
192 std::u16string_view lastTableInserted,
193 const OString & lastQuery );
198 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */