Version 4.3.0.0.beta1, tag libreoffice-4.3.0.0.beta1
[LibreOffice.git] / connectivity / source / drivers / postgresql / pq_statement.hxx
blobf2e20c33659b730d113c51933afcb9597fa1667e
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 #ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_POSTGRESQL_PQ_STATEMENT_HXX
38 #define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_POSTGRESQL_PQ_STATEMENT_HXX
39 #include <cppuhelper/propshlp.hxx>
40 #include <cppuhelper/component.hxx>
42 #include <libpq-fe.h>
44 #include "pq_connection.hxx"
45 #include <com/sun/star/sdbc/XMultipleResults.hpp>
46 #include <com/sun/star/sdbc/XGeneratedResultSet.hpp>
47 #include <com/sun/star/sdbc/XResultSetMetaDataSupplier.hpp>
49 namespace pq_sdbc_driver
52 static const sal_Int32 STATEMENT_CURSOR_NAME = 0;
53 static const sal_Int32 STATEMENT_ESCAPE_PROCESSING = 1;
54 static const sal_Int32 STATEMENT_FETCH_DIRECTION = 2;
55 static const sal_Int32 STATEMENT_FETCH_SIZE = 3;
56 static const sal_Int32 STATEMENT_MAX_FIELD_SIZE = 4;
57 static const sal_Int32 STATEMENT_MAX_ROWS = 5;
58 static const sal_Int32 STATEMENT_QUERY_TIME_OUT = 6;
59 static const sal_Int32 STATEMENT_RESULT_SET_CONCURRENCY = 7;
60 static const sal_Int32 STATEMENT_RESULT_SET_TYPE = 8;
62 #define STATEMENT_SIZE 9
64 class Statement : public cppu::OComponentHelper,
65 public cppu::OPropertySetHelper,
66 public com::sun::star::sdbc::XStatement,
67 public com::sun::star::sdbc::XCloseable,
68 public com::sun::star::sdbc::XWarningsSupplier,
69 public com::sun::star::sdbc::XMultipleResults,
70 public com::sun::star::sdbc::XGeneratedResultSet,
71 public com::sun::star::sdbc::XResultSetMetaDataSupplier
73 private:
74 com::sun::star::uno::Any m_props[STATEMENT_SIZE];
75 com::sun::star::uno::Reference< com::sun::star::sdbc::XConnection > m_connection;
76 ConnectionSettings *m_pSettings;
77 com::sun::star::uno::Reference< com::sun::star::sdbc::XCloseable > m_lastResultset;
78 ::rtl::Reference< RefCountedMutex > m_refMutex;
79 bool m_multipleResultAvailable;
80 sal_Int32 m_multipleResultUpdateCount;
81 sal_Int32 m_lastOidInserted;
82 OUString m_lastTableInserted;
83 OString m_lastQuery;
85 public:
86 /**
87 * @param ppConnection The piece of memory, pConnection points to, is accessisble
88 * as long as a reference to paramenter con is held.
90 Statement( const rtl::Reference< RefCountedMutex > & refMutex,
91 const com::sun::star::uno::Reference< com::sun::star::sdbc::XConnection> & con,
92 struct ConnectionSettings *pSettings );
94 virtual ~Statement();
95 public: // XInterface
96 virtual void SAL_CALL acquire() throw() SAL_OVERRIDE { OComponentHelper::acquire(); }
97 virtual void SAL_CALL release() throw() SAL_OVERRIDE { OComponentHelper::release(); }
98 virtual com::sun::star::uno::Any SAL_CALL queryInterface( const com::sun::star::uno::Type & reqType )
99 throw (com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
101 public: // XCloseable
102 virtual void SAL_CALL close( )
103 throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
105 public: // XStatement
106 virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet > SAL_CALL executeQuery(
107 const OUString& sql )
108 throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
109 virtual sal_Int32 SAL_CALL executeUpdate( const OUString& sql )
110 throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
111 virtual sal_Bool SAL_CALL execute( const OUString& sql )
112 throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
113 virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection > SAL_CALL getConnection( )
114 throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
116 public: // XWarningsSupplier
117 virtual ::com::sun::star::uno::Any SAL_CALL getWarnings( )
118 throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
119 virtual void SAL_CALL clearWarnings( )
120 throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
122 public: // XTypeProvider, first implemented by OPropertySetHelper
123 virtual com::sun::star::uno::Sequence< com::sun::star::uno::Type > SAL_CALL getTypes()
124 throw( com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
125 virtual com::sun::star::uno::Sequence< sal_Int8> SAL_CALL getImplementationId()
126 throw( com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
128 public: // OPropertySetHelper
129 virtual cppu::IPropertyArrayHelper & SAL_CALL getInfoHelper() SAL_OVERRIDE;
131 virtual sal_Bool SAL_CALL convertFastPropertyValue(
132 ::com::sun::star::uno::Any & rConvertedValue,
133 ::com::sun::star::uno::Any & rOldValue,
134 sal_Int32 nHandle,
135 const ::com::sun::star::uno::Any& rValue )
136 throw (::com::sun::star::lang::IllegalArgumentException) SAL_OVERRIDE;
138 virtual void SAL_CALL setFastPropertyValue_NoBroadcast(
139 sal_Int32 nHandle,
140 const ::com::sun::star::uno::Any& rValue )
141 throw (::com::sun::star::uno::Exception, std::exception) SAL_OVERRIDE;
143 using ::cppu::OPropertySetHelper::getFastPropertyValue;
145 void SAL_CALL getFastPropertyValue(
146 ::com::sun::star::uno::Any& rValue,
147 sal_Int32 nHandle ) const SAL_OVERRIDE;
149 // XPropertySet
150 ::com::sun::star::uno::Reference < ::com::sun::star::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo()
151 throw(com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
153 public: // XGeneratedResultSet
154 virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet > SAL_CALL
155 getGeneratedValues( )
156 throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
158 public: // XMultipleResults
159 virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet > SAL_CALL getResultSet( )
160 throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
161 virtual sal_Int32 SAL_CALL getUpdateCount( )
162 throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
163 virtual sal_Bool SAL_CALL getMoreResults( )
164 throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
166 public: // OComponentHelper
167 virtual void SAL_CALL disposing() SAL_OVERRIDE;
169 public: // XResultSetMetaDataSupplier (is required by framework (see
170 // dbaccess/source/core/api/preparedstatement.cxx::getMetaData() )
171 virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSetMetaData > SAL_CALL getMetaData( )
172 throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
174 private:
175 void checkClosed() throw (com::sun::star::sdbc::SQLException, com::sun::star::uno::RuntimeException);
176 void raiseSQLException( const OUString & sql, const char * errorMsg, const char *errorType = 0 )
177 throw ( com::sun::star::sdbc::SQLException );
181 struct CommandData
183 ConnectionSettings **ppSettings;
184 sal_Int32 *pLastOidInserted;
185 sal_Int32 *pMultipleResultUpdateCount;
186 bool *pMultipleResultAvailable;
187 OUString *pLastTableInserted;
188 ::com::sun::star::uno::Reference< com::sun::star::sdbc::XCloseable > *pLastResultset;
189 OString *pLastQuery;
190 ::rtl::Reference< RefCountedMutex > refMutex;
191 ::com::sun::star::uno::Reference< com::sun::star::uno::XInterface > owner;
192 ::com::sun::star::uno::Reference< com::sun::star::sdbcx::XTablesSupplier > tableSupplier;
193 sal_Int32 concurrency;
196 bool executePostgresCommand( const OString & cmd, struct CommandData *data );
197 com::sun::star::uno::Reference< com::sun::star::sdbc::XResultSet > getGeneratedValuesFromLastInsert(
198 ConnectionSettings *pConnectionSettings,
199 const com::sun::star::uno::Reference< com::sun::star::sdbc::XConnection > &connection,
200 sal_Int32 nLastOid,
201 const OUString & lastTableInserted,
202 const OString & lastQuery );
206 #endif
208 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */