1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
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>
39 #include <com/sun/star/lang/XServiceInfo.hpp>
40 #include <unotools/weakref.hxx>
42 namespace connectivity::odbc
45 typedef ::cppu::WeakComponentImplHelper
< css::sdbc::XStatement
,
46 css::sdbc::XWarningsSupplier
,
47 css::util::XCancellable
,
48 css::sdbc::XCloseable
,
49 css::sdbc::XGeneratedResultSet
,
50 css::sdbc::XMultipleResults
> OStatement_BASE
;
54 //************ Class: java.sql.Statement
56 class OStatement_Base
:
57 public cppu::BaseMutex
,
58 public OStatement_BASE
,
59 public ::cppu::OPropertySetHelper
,
60 public ::comphelper::OPropertyArrayUsageHelper
<OStatement_Base
>
63 css::sdbc::SQLWarning m_aLastWarning
;
65 unotools::WeakReference
< OResultSet
> m_xResultSet
; // The last ResultSet created
66 css::uno::Reference
< css::sdbc::XStatement
> m_xGeneratedStatement
;
69 std::vector
< OUString
> m_aBatchVector
;
70 OUString m_sSqlStatement
;
72 rtl::Reference
<OConnection
> m_pConnection
;// The owning Connection object
73 SQLHANDLE m_aStatementHandle
;
74 SQLUSMALLINT
* m_pRowStatusArray
;
78 sal_Int64
getQueryTimeOut() const;
79 sal_Int64
getMaxFieldSize() const;
80 sal_Int64
getMaxRows() const;
81 sal_Int32
getResultSetConcurrency() const;
82 sal_Int32
getResultSetType() const;
83 sal_Int32
getFetchDirection() const;
84 sal_Int32
getFetchSize() const;
85 OUString
getCursorName() const;
86 bool isUsingBookmarks() const;
87 bool getEscapeProcessing() const;
88 template < typename T
, SQLINTEGER BufferLength
> T
getStmtOption (SQLINTEGER fOption
) const;
90 void setQueryTimeOut(sal_Int64 _par0
) ;
91 void setMaxFieldSize(sal_Int64 _par0
) ;
92 void setMaxRows(sal_Int64 _par0
) ;
93 void setFetchDirection(sal_Int32 _par0
) ;
94 void setFetchSize(sal_Int32 _par0
) ;
95 void setCursorName(const OUString
& _par0
);
96 void setEscapeProcessing( const bool _bEscapeProc
);
97 template < typename T
, SQLINTEGER BufferLength
> SQLRETURN
setStmtOption (SQLINTEGER fOption
, T value
) const;
99 void setResultSetConcurrency(sal_Int32 _par0
) ;
100 void setResultSetType(sal_Int32 _par0
) ;
101 void setUsingBookmarks(bool _bUseBookmark
) ;
103 /// @throws css::sdbc::SQLException
104 /// @throws css::uno::RuntimeException
106 /// @throws css::sdbc::SQLException
107 /// @throws css::uno::RuntimeException
108 void clearMyResultSet();
109 /// @throws css::sdbc::SQLException
110 /// @throws css::uno::RuntimeException
111 void setWarning (const css::sdbc::SQLWarning
&ex
);
112 /// @throws css::sdbc::SQLException
113 /// @throws css::uno::RuntimeException
114 bool lockIfNecessary (const OUString
& sql
);
115 /// @throws css::sdbc::SQLException
116 /// @throws css::uno::RuntimeException
117 sal_Int32
getColumnCount();
121 // getResultSet returns the current result as a ResultSet. It
122 // returns NULL if the current result is not a ResultSet.
124 /// @throws css::sdbc::SQLException
125 /// @throws css::uno::RuntimeException
126 rtl::Reference
<OResultSet
> getResultSet(bool checkCount
);
128 creates the driver specific resultset (factory)
130 virtual rtl::Reference
<OResultSet
> createResultSet();
132 /// @throws css::sdbc::SQLException
133 /// @throws css::uno::RuntimeException
134 SQLLEN
getRowCount();
137 void disposeResultSet();
139 // OPropertyArrayUsageHelper
140 virtual ::cppu::IPropertyArrayHelper
* createArrayHelper( ) const override
;
141 // OPropertySetHelper
142 virtual ::cppu::IPropertyArrayHelper
& SAL_CALL
getInfoHelper() override
;
143 virtual sal_Bool SAL_CALL
convertFastPropertyValue(
144 css::uno::Any
& rConvertedValue
,
145 css::uno::Any
& rOldValue
,
147 const css::uno::Any
& rValue
) override
;
148 virtual void SAL_CALL
setFastPropertyValue_NoBroadcast(
150 const css::uno::Any
& rValue
152 virtual void SAL_CALL
getFastPropertyValue(
153 css::uno::Any
& rValue
,
156 virtual ~OStatement_Base() override
;
159 OStatement_Base(OConnection
* _pConnection
);
160 using OStatement_BASE::operator css::uno::Reference
< css::uno::XInterface
>;
162 const Functions
& functions() const { return m_pConnection
->functions(); }
164 virtual void SAL_CALL
disposing() override
;
166 virtual void SAL_CALL
release() noexcept override
;
167 virtual void SAL_CALL
acquire() noexcept override
;
169 virtual css::uno::Any SAL_CALL
queryInterface( const css::uno::Type
& rType
) override
;
171 virtual css::uno::Sequence
< css::uno::Type
> SAL_CALL
getTypes( ) override
;
174 virtual css::uno::Reference
< css::beans::XPropertySetInfo
> SAL_CALL
getPropertySetInfo( ) override
;
176 virtual css::uno::Reference
< css::sdbc::XResultSet
> SAL_CALL
executeQuery( const OUString
& sql
) override
;
177 virtual sal_Int32 SAL_CALL
executeUpdate( const OUString
& sql
) override
;
178 virtual sal_Bool SAL_CALL
execute( const OUString
& sql
) override
;
179 virtual css::uno::Reference
< css::sdbc::XConnection
> SAL_CALL
getConnection( ) override
;
181 virtual css::uno::Any SAL_CALL
getWarnings( ) override
;
182 virtual void SAL_CALL
clearWarnings( ) override
;
184 virtual void SAL_CALL
cancel( ) override
;
186 virtual void SAL_CALL
close( ) override
;
188 virtual css::uno::Reference
< css::sdbc::XResultSet
> SAL_CALL
getResultSet( ) override
;
189 virtual sal_Int32 SAL_CALL
getUpdateCount( ) override
;
190 virtual sal_Bool SAL_CALL
getMoreResults( ) override
;
191 //XGeneratedResultSet
192 virtual css::uno::Reference
< css::sdbc::XResultSet
> SAL_CALL
getGeneratedValues( ) override
;
195 SQLHANDLE
getConnectionHandle() { return m_pConnection
->getConnection(); }
196 OConnection
* getOwnConnection() const { return m_pConnection
.get();}
197 /** getCursorProperties return the properties for a specific cursor type
198 @param _nCursorType the CursorType
199 @param bFirst when true the first property set is returned
201 @return the cursor properties
203 SQLUINTEGER
getCursorProperties(SQLINTEGER _nCursorType
, bool bFirst
);
206 using OPropertySetHelper::getFastPropertyValue
;
209 class OOO_DLLPUBLIC_ODBCBASE OStatement_BASE2
: public OStatement_Base
212 OStatement_BASE2(OConnection
* _pConnection
) :
213 OStatement_Base(_pConnection
)
216 virtual void SAL_CALL
disposing() override
;
220 public OStatement_BASE2
,
221 public css::sdbc::XBatchExecution
,
222 public css::lang::XServiceInfo
225 virtual ~OStatement() override
{}
227 // A ctor that is needed for returning the object
228 OStatement( OConnection
* _pConnection
) : OStatement_BASE2( _pConnection
){}
229 DECLARE_SERVICE_INFO();
231 virtual css::uno::Any SAL_CALL
queryInterface( const css::uno::Type
& rType
) override
;
232 virtual void SAL_CALL
acquire() noexcept override
;
233 virtual void SAL_CALL
release() noexcept override
;
235 virtual void SAL_CALL
addBatch( const OUString
& sql
) override
;
236 virtual void SAL_CALL
clearBatch( ) override
;
237 virtual css::uno::Sequence
< sal_Int32
> SAL_CALL
executeBatch( ) override
;
242 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */