Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / connectivity / source / inc / odbc / OStatement.hxx
blob1e483108732d15982bc3144cdfbcfbfd37381643
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 #pragma once
22 #include <com/sun/star/sdbc/XStatement.hpp>
23 #include <com/sun/star/sdbc/XWarningsSupplier.hpp>
24 #include <com/sun/star/sdbc/XMultipleResults.hpp>
25 #include <com/sun/star/sdbc/XBatchExecution.hpp>
26 #include <com/sun/star/sdbc/XCloseable.hpp>
27 #include <com/sun/star/sdbc/SQLWarning.hpp>
28 #include <com/sun/star/sdbc/XGeneratedResultSet.hpp>
29 #include <com/sun/star/util/XCancellable.hpp>
30 #include <comphelper/proparrhlp.hxx>
31 #include <cppuhelper/compbase.hxx>
32 #include <cppuhelper/basemutex.hxx>
33 #include <connectivity/CommonTools.hxx>
34 #include <odbc/OFunctions.hxx>
35 #include <odbc/OConnection.hxx>
36 #include <odbc/odbcbasedllapi.hxx>
37 #include <string_view>
38 #include <vector>
39 #include <com/sun/star/lang/XServiceInfo.hpp>
41 namespace connectivity::odbc
44 typedef ::cppu::WeakComponentImplHelper< css::sdbc::XStatement,
45 css::sdbc::XWarningsSupplier,
46 css::util::XCancellable,
47 css::sdbc::XCloseable,
48 css::sdbc::XGeneratedResultSet,
49 css::sdbc::XMultipleResults> OStatement_BASE;
51 class OResultSet;
53 //************ Class: java.sql.Statement
55 class OOO_DLLPUBLIC_ODBCBASE OStatement_Base :
56 public cppu::BaseMutex,
57 public OStatement_BASE,
58 public ::cppu::OPropertySetHelper,
59 public ::comphelper::OPropertyArrayUsageHelper<OStatement_Base>
62 css::sdbc::SQLWarning m_aLastWarning;
63 protected:
64 css::uno::WeakReference< css::sdbc::XResultSet> m_xResultSet; // The last ResultSet created
65 css::uno::Reference< css::sdbc::XStatement> m_xGeneratedStatement;
66 // for this Statement
68 std::vector< OUString> m_aBatchVector;
69 OUString m_sSqlStatement;
71 rtl::Reference<OConnection> m_pConnection;// The owning Connection object
72 SQLHANDLE m_aStatementHandle;
73 SQLUSMALLINT* m_pRowStatusArray;
75 protected:
77 sal_Int64 getQueryTimeOut() const;
78 sal_Int64 getMaxFieldSize() const;
79 sal_Int64 getMaxRows() const;
80 sal_Int32 getResultSetConcurrency() const;
81 sal_Int32 getResultSetType() const;
82 sal_Int32 getFetchDirection() const;
83 sal_Int32 getFetchSize() const;
84 OUString getCursorName() const;
85 bool isUsingBookmarks() const;
86 bool getEscapeProcessing() const;
87 template < typename T, SQLINTEGER BufferLength > T getStmtOption (SQLINTEGER fOption) const;
89 void setQueryTimeOut(sal_Int64 _par0) ;
90 void setMaxFieldSize(sal_Int64 _par0) ;
91 void setMaxRows(sal_Int64 _par0) ;
92 void setFetchDirection(sal_Int32 _par0) ;
93 void setFetchSize(sal_Int32 _par0) ;
94 void setCursorName(std::u16string_view _par0);
95 void setEscapeProcessing( const bool _bEscapeProc );
96 template < typename T, SQLINTEGER BufferLength > SQLRETURN setStmtOption (SQLINTEGER fOption, T value) const;
98 void setResultSetConcurrency(sal_Int32 _par0) ;
99 void setResultSetType(sal_Int32 _par0) ;
100 void setUsingBookmarks(bool _bUseBookmark) ;
102 /// @throws css::sdbc::SQLException
103 /// @throws css::uno::RuntimeException
104 void reset();
105 /// @throws css::sdbc::SQLException
106 /// @throws css::uno::RuntimeException
107 void clearMyResultSet();
108 /// @throws css::sdbc::SQLException
109 /// @throws css::uno::RuntimeException
110 void setWarning (const css::sdbc::SQLWarning &ex);
111 /// @throws css::sdbc::SQLException
112 /// @throws css::uno::RuntimeException
113 bool lockIfNecessary (const OUString& sql);
114 /// @throws css::sdbc::SQLException
115 /// @throws css::uno::RuntimeException
116 sal_Int32 getColumnCount();
119 // getResultSet
120 // getResultSet returns the current result as a ResultSet. It
121 // returns NULL if the current result is not a ResultSet.
123 /// @throws css::sdbc::SQLException
124 /// @throws css::uno::RuntimeException
125 css::uno::Reference<css::sdbc::XResultSet> getResultSet(bool checkCount);
127 creates the driver specific resultset (factory)
129 virtual rtl::Reference<OResultSet> createResultSet();
131 /// @throws css::sdbc::SQLException
132 /// @throws css::uno::RuntimeException
133 SQLLEN getRowCount();
136 void disposeResultSet();
138 // OPropertyArrayUsageHelper
139 virtual ::cppu::IPropertyArrayHelper* createArrayHelper( ) const override;
140 // OPropertySetHelper
141 virtual ::cppu::IPropertyArrayHelper & SAL_CALL getInfoHelper() override;
142 virtual sal_Bool SAL_CALL convertFastPropertyValue(
143 css::uno::Any & rConvertedValue,
144 css::uno::Any & rOldValue,
145 sal_Int32 nHandle,
146 const css::uno::Any& rValue ) override;
147 virtual void SAL_CALL setFastPropertyValue_NoBroadcast(
148 sal_Int32 nHandle,
149 const css::uno::Any& rValue
150 ) override;
151 virtual void SAL_CALL getFastPropertyValue(
152 css::uno::Any& rValue,
153 sal_Int32 nHandle
154 ) const override;
155 virtual ~OStatement_Base() override;
157 public:
158 OStatement_Base(OConnection* _pConnection );
159 using OStatement_BASE::operator css::uno::Reference< css::uno::XInterface >;
161 oslGenericFunction getOdbcFunction(ODBC3SQLFunctionId _nIndex) const
163 return m_pConnection->getOdbcFunction(_nIndex);
165 // OComponentHelper
166 virtual void SAL_CALL disposing() override;
167 // XInterface
168 virtual void SAL_CALL release() noexcept override;
169 virtual void SAL_CALL acquire() noexcept override;
170 // XInterface
171 virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & rType ) override;
172 //XTypeProvider
173 virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes( ) override;
175 // XPropertySet
176 virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo( ) override;
177 // XStatement
178 virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL executeQuery( const OUString& sql ) override ;
179 virtual sal_Int32 SAL_CALL executeUpdate( const OUString& sql ) override ;
180 virtual sal_Bool SAL_CALL execute( const OUString& sql ) override ;
181 virtual css::uno::Reference< css::sdbc::XConnection > SAL_CALL getConnection( ) override ;
182 // XWarningsSupplier
183 virtual css::uno::Any SAL_CALL getWarnings( ) override;
184 virtual void SAL_CALL clearWarnings( ) override;
185 // XCancellable
186 virtual void SAL_CALL cancel( ) override;
187 // XCloseable
188 virtual void SAL_CALL close( ) override;
189 // XMultipleResults
190 virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL getResultSet( ) override;
191 virtual sal_Int32 SAL_CALL getUpdateCount( ) override;
192 virtual sal_Bool SAL_CALL getMoreResults( ) override;
193 //XGeneratedResultSet
194 virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL getGeneratedValues( ) override;
196 // other methods
197 SQLHANDLE getConnectionHandle() { return m_pConnection->getConnection(); }
198 OConnection* getOwnConnection() const { return m_pConnection.get();}
199 /** getCursorProperties return the properties for a specific cursor type
200 @param _nCursorType the CursorType
201 @param bFirst when true the first property set is returned
203 @return the cursor properties
205 SQLUINTEGER getCursorProperties(SQLINTEGER _nCursorType, bool bFirst);
207 protected:
208 using OPropertySetHelper::getFastPropertyValue;
211 class OOO_DLLPUBLIC_ODBCBASE OStatement_BASE2 : public OStatement_Base
213 public:
214 OStatement_BASE2(OConnection* _pConnection ) :
215 OStatement_Base(_pConnection )
217 // OComponentHelper
218 virtual void SAL_CALL disposing() override;
221 class OOO_DLLPUBLIC_ODBCBASE OStatement :
222 public OStatement_BASE2,
223 public css::sdbc::XBatchExecution,
224 public css::lang::XServiceInfo
226 protected:
227 virtual ~OStatement() override {}
228 public:
229 // A ctor that is needed for returning the object
230 OStatement( OConnection* _pConnection) : OStatement_BASE2( _pConnection){}
231 DECLARE_SERVICE_INFO();
233 virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & rType ) override;
234 virtual void SAL_CALL acquire() noexcept override;
235 virtual void SAL_CALL release() noexcept override;
236 // XBatchExecution
237 virtual void SAL_CALL addBatch( const OUString& sql ) override;
238 virtual void SAL_CALL clearBatch( ) override;
239 virtual css::uno::Sequence< sal_Int32 > SAL_CALL executeBatch( ) override;
244 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */