Version 6.4.0.3, tag libreoffice-6.4.0.3
[LibreOffice.git] / connectivity / source / inc / odbc / OStatement.hxx
blob5beaf9bb6fb36824d891a50ddaadacc43519bec9
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_ODBC_OSTATEMENT_HXX
21 #define INCLUDED_CONNECTIVITY_SOURCE_INC_ODBC_OSTATEMENT_HXX
23 #include <com/sun/star/sdbc/XStatement.hpp>
24 #include <com/sun/star/sdbc/XWarningsSupplier.hpp>
25 #include <com/sun/star/sdbc/XMultipleResults.hpp>
26 #include <com/sun/star/sdbc/XBatchExecution.hpp>
27 #include <com/sun/star/sdbc/XCloseable.hpp>
28 #include <com/sun/star/sdbc/SQLWarning.hpp>
29 #include <com/sun/star/sdbc/XGeneratedResultSet.hpp>
30 #include <com/sun/star/util/XCancellable.hpp>
31 #include <comphelper/proparrhlp.hxx>
32 #include <cppuhelper/compbase.hxx>
33 #include <cppuhelper/basemutex.hxx>
34 #include <connectivity/CommonTools.hxx>
35 #include <odbc/OFunctions.hxx>
36 #include <odbc/OConnection.hxx>
37 #include <odbc/odbcbasedllapi.hxx>
38 #include <vector>
39 #include <com/sun/star/lang/XServiceInfo.hpp>
41 namespace connectivity
43 namespace odbc
46 typedef ::cppu::WeakComponentImplHelper< css::sdbc::XStatement,
47 css::sdbc::XWarningsSupplier,
48 css::util::XCancellable,
49 css::sdbc::XCloseable,
50 css::sdbc::XGeneratedResultSet,
51 css::sdbc::XMultipleResults> OStatement_BASE;
53 class OResultSet;
55 //************ Class: java.sql.Statement
57 class OOO_DLLPUBLIC_ODBCBASE OStatement_Base :
58 public cppu::BaseMutex,
59 public OStatement_BASE,
60 public ::cppu::OPropertySetHelper,
61 public ::comphelper::OPropertyArrayUsageHelper<OStatement_Base>
64 css::sdbc::SQLWarning m_aLastWarning;
65 protected:
66 css::uno::WeakReference< css::sdbc::XResultSet> m_xResultSet; // The last ResultSet created
67 css::uno::Reference< css::sdbc::XStatement> m_xGeneratedStatement;
68 // for this Statement
70 std::vector< OUString> m_aBatchVector;
71 OUString m_sSqlStatement;
73 rtl::Reference<OConnection> m_pConnection;// The owning Connection object
74 SQLHANDLE m_aStatementHandle;
75 SQLUSMALLINT* m_pRowStatusArray;
77 protected:
79 sal_Int64 getQueryTimeOut() const;
80 sal_Int64 getMaxFieldSize() const;
81 sal_Int64 getMaxRows() const;
82 sal_Int32 getResultSetConcurrency() const;
83 sal_Int32 getResultSetType() const;
84 sal_Int32 getFetchDirection() const;
85 sal_Int32 getFetchSize() const;
86 OUString getCursorName() const;
87 bool isUsingBookmarks() const;
88 bool getEscapeProcessing() const;
89 template < typename T, SQLINTEGER BufferLength > T getStmtOption (SQLINTEGER fOption) const;
91 void setQueryTimeOut(sal_Int64 _par0) ;
92 void setMaxFieldSize(sal_Int64 _par0) ;
93 void setMaxRows(sal_Int64 _par0) ;
94 void setFetchDirection(sal_Int32 _par0) ;
95 void setFetchSize(sal_Int32 _par0) ;
96 void setCursorName(const OUString &_par0);
97 void setEscapeProcessing( const bool _bEscapeProc );
98 template < typename T, SQLINTEGER BufferLength > SQLRETURN setStmtOption (SQLINTEGER fOption, T value) const;
100 void setResultSetConcurrency(sal_Int32 _par0) ;
101 void setResultSetType(sal_Int32 _par0) ;
102 void setUsingBookmarks(bool _bUseBookmark) ;
104 /// @throws css::sdbc::SQLException
105 /// @throws css::uno::RuntimeException
106 void reset();
107 /// @throws css::sdbc::SQLException
108 /// @throws css::uno::RuntimeException
109 void clearMyResultSet();
110 /// @throws css::sdbc::SQLException
111 /// @throws css::uno::RuntimeException
112 void setWarning (const css::sdbc::SQLWarning &ex);
113 /// @throws css::sdbc::SQLException
114 /// @throws css::uno::RuntimeException
115 bool lockIfNecessary (const OUString& sql);
116 /// @throws css::sdbc::SQLException
117 /// @throws css::uno::RuntimeException
118 sal_Int32 getColumnCount();
121 // getResultSet
122 // getResultSet returns the current result as a ResultSet. It
123 // returns NULL if the current result is not a ResultSet.
125 /// @throws css::sdbc::SQLException
126 /// @throws css::uno::RuntimeException
127 css::uno::Reference<css::sdbc::XResultSet> getResultSet(bool checkCount);
129 creates the driver specific resultset (factory)
131 virtual OResultSet* createResulSet();
133 /// @throws css::sdbc::SQLException
134 /// @throws css::uno::RuntimeException
135 SQLLEN getRowCount();
138 void disposeResultSet();
140 // OPropertyArrayUsageHelper
141 virtual ::cppu::IPropertyArrayHelper* createArrayHelper( ) const override;
142 // OPropertySetHelper
143 virtual ::cppu::IPropertyArrayHelper & SAL_CALL getInfoHelper() override;
144 virtual sal_Bool SAL_CALL convertFastPropertyValue(
145 css::uno::Any & rConvertedValue,
146 css::uno::Any & rOldValue,
147 sal_Int32 nHandle,
148 const css::uno::Any& rValue ) override;
149 virtual void SAL_CALL setFastPropertyValue_NoBroadcast(
150 sal_Int32 nHandle,
151 const css::uno::Any& rValue
152 ) override;
153 virtual void SAL_CALL getFastPropertyValue(
154 css::uno::Any& rValue,
155 sal_Int32 nHandle
156 ) const override;
157 virtual ~OStatement_Base() override;
159 public:
160 OStatement_Base(OConnection* _pConnection );
161 using OStatement_BASE::operator css::uno::Reference< css::uno::XInterface >;
163 oslGenericFunction getOdbcFunction(ODBC3SQLFunctionId _nIndex) const
165 return m_pConnection->getOdbcFunction(_nIndex);
167 // OComponentHelper
168 virtual void SAL_CALL disposing() override;
169 // XInterface
170 virtual void SAL_CALL release() throw() override;
171 virtual void SAL_CALL acquire() throw() override;
172 // XInterface
173 virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & rType ) override;
174 //XTypeProvider
175 virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes( ) override;
177 // XPropertySet
178 virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo( ) override;
179 // XStatement
180 virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL executeQuery( const OUString& sql ) override ;
181 virtual sal_Int32 SAL_CALL executeUpdate( const OUString& sql ) override ;
182 virtual sal_Bool SAL_CALL execute( const OUString& sql ) override ;
183 virtual css::uno::Reference< css::sdbc::XConnection > SAL_CALL getConnection( ) override ;
184 // XWarningsSupplier
185 virtual css::uno::Any SAL_CALL getWarnings( ) override;
186 virtual void SAL_CALL clearWarnings( ) override;
187 // XCancellable
188 virtual void SAL_CALL cancel( ) override;
189 // XCloseable
190 virtual void SAL_CALL close( ) override;
191 // XMultipleResults
192 virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL getResultSet( ) override;
193 virtual sal_Int32 SAL_CALL getUpdateCount( ) override;
194 virtual sal_Bool SAL_CALL getMoreResults( ) override;
195 //XGeneratedResultSet
196 virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL getGeneratedValues( ) override;
198 // other methods
199 SQLHANDLE getConnectionHandle() { return m_pConnection->getConnection(); }
200 OConnection* getOwnConnection() const { return m_pConnection.get();}
201 /** getCursorProperties return the properties for a specific cursor type
202 @param _nCursorType the CursorType
203 @param bFirst when true the first property set is returned
205 @return the cursor properties
207 SQLUINTEGER getCursorProperties(SQLINTEGER _nCursorType, bool bFirst);
209 protected:
210 using OPropertySetHelper::getFastPropertyValue;
213 class OOO_DLLPUBLIC_ODBCBASE OStatement_BASE2 : public OStatement_Base
215 public:
216 OStatement_BASE2(OConnection* _pConnection ) :
217 OStatement_Base(_pConnection )
219 // OComponentHelper
220 virtual void SAL_CALL disposing() override;
223 class OOO_DLLPUBLIC_ODBCBASE OStatement :
224 public OStatement_BASE2,
225 public css::sdbc::XBatchExecution,
226 public css::lang::XServiceInfo
228 protected:
229 virtual ~OStatement() override {}
230 public:
231 // A ctor that is needed for returning the object
232 OStatement( OConnection* _pConnection) : OStatement_BASE2( _pConnection){}
233 DECLARE_SERVICE_INFO();
235 virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & rType ) override;
236 virtual void SAL_CALL acquire() throw() override;
237 virtual void SAL_CALL release() throw() override;
238 // XBatchExecution
239 virtual void SAL_CALL addBatch( const OUString& sql ) override;
240 virtual void SAL_CALL clearBatch( ) override;
241 virtual css::uno::Sequence< sal_Int32 > SAL_CALL executeBatch( ) override;
245 #endif // INCLUDED_CONNECTIVITY_SOURCE_INC_ODBC_OSTATEMENT_HXX
247 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */