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/util/XCancellable.hpp>
29 #include <cppuhelper/compbase.hxx>
30 #include <cppuhelper/basemutex.hxx>
31 #include <comphelper/proparrhlp.hxx>
32 #include <unotools/weakref.hxx>
33 #include <ado/AConnection.hxx>
34 #include <string_view>
36 #include <ado/Awrapado.hxx>
37 #include <com/sun/star/lang/XServiceInfo.hpp>
39 namespace connectivity::ado
41 typedef ::cppu::WeakComponentImplHelper
< css::sdbc::XStatement
,
42 css::sdbc::XWarningsSupplier
,
43 css::util::XCancellable
,
44 css::sdbc::XCloseable
,
45 css::sdbc::XMultipleResults
> OStatement_BASE
;
48 //************ Class: java.sql.Statement
50 class OStatement_Base
: public cppu::BaseMutex
,
51 public OStatement_BASE
,
52 public ::cppu::OPropertySetHelper
,
53 public ::comphelper::OPropertyArrayUsageHelper
<OStatement_Base
>
56 friend class OResultSet
;
58 css::sdbc::SQLWarning m_aLastWarning
;
61 std::vector
< OUString
> m_aBatchVector
;
63 unotools::WeakReference
<OResultSet
> m_xResultSet
; // The last ResultSet created
66 OConnection
* m_pConnection
;// The owning Connection object
67 WpADOCommand m_Command
;
68 WpADORecordset m_RecordSet
;
69 OLEVariant m_RecordsAffected
;
70 OLEVariant m_Parameters
;
71 std::vector
<connectivity::OTypeInfo
> m_aTypeInfo
; // Hashtable containing an entry
72 // for each row returned by
73 // DatabaseMetaData.getTypeInfo.
75 sal_Int32 m_nFetchSize
;
76 LockTypeEnum m_eLockType
;
77 CursorTypeEnum m_eCursorType
;
79 using OStatement_BASE::rBHelper
;
81 /// @throws css::sdbc::SQLException
82 /// @throws css::uno::RuntimeException
83 sal_Int32
getQueryTimeOut() const;
84 /// @throws css::sdbc::SQLException
85 /// @throws css::uno::RuntimeException
86 static sal_Int32
getMaxFieldSize();
87 /// @throws css::sdbc::SQLException
88 /// @throws css::uno::RuntimeException
89 sal_Int32
getMaxRows() const;
90 /// @throws css::sdbc::SQLException
91 /// @throws css::uno::RuntimeException
92 sal_Int32
getResultSetConcurrency() const;
93 /// @throws css::sdbc::SQLException
94 /// @throws css::uno::RuntimeException
95 sal_Int32
getResultSetType() const;
96 /// @throws css::sdbc::SQLException
97 /// @throws css::uno::RuntimeException
98 static sal_Int32
getFetchDirection();
99 /// @throws css::sdbc::SQLException
100 /// @throws css::uno::RuntimeException
101 sal_Int32
getFetchSize() const;
102 /// @throws css::sdbc::SQLException
103 /// @throws css::uno::RuntimeException
104 OUString
getCursorName() const;
106 /// @throws css::sdbc::SQLException
107 /// @throws css::uno::RuntimeException
108 void setQueryTimeOut(sal_Int32 _par0
);
109 /// @throws css::sdbc::SQLException
110 /// @throws css::uno::RuntimeException
111 void setMaxFieldSize(sal_Int32 _par0
);
112 /// @throws css::sdbc::SQLException
113 /// @throws css::uno::RuntimeException
114 void setMaxRows(sal_Int32 _par0
);
115 /// @throws css::sdbc::SQLException
116 /// @throws css::uno::RuntimeException
117 void setResultSetConcurrency(sal_Int32 _par0
);
118 /// @throws css::sdbc::SQLException
119 /// @throws css::uno::RuntimeException
120 void setResultSetType(sal_Int32 _par0
);
121 /// @throws css::sdbc::SQLException
122 /// @throws css::uno::RuntimeException
123 void setFetchDirection(sal_Int32 _par0
);
124 /// @throws css::sdbc::SQLException
125 /// @throws css::uno::RuntimeException
126 void setFetchSize(sal_Int32 _par0
);
127 /// @throws css::sdbc::SQLException
128 /// @throws css::uno::RuntimeException
129 void setCursorName(std::u16string_view _par0
);
133 void assignRecordSet( ADORecordset
* _pRS
);
135 /// @throws css::sdbc::SQLException
137 /// @throws css::sdbc::SQLException
138 void clearMyResultSet ();
139 /// @throws css::sdbc::SQLException
140 void setWarning (const css::sdbc::SQLWarning
&ex
);
141 /// @throws css::sdbc::SQLException
142 sal_Int32
getRowCount ();
143 sal_Int32
getPrecision ( sal_Int32 sqlType
);
145 void disposeResultSet();
147 // OPropertyArrayUsageHelper
148 virtual ::cppu::IPropertyArrayHelper
* createArrayHelper( ) const override
;
149 // OPropertySetHelper
150 virtual ::cppu::IPropertyArrayHelper
& SAL_CALL
getInfoHelper() override
;
151 virtual sal_Bool SAL_CALL
convertFastPropertyValue(
152 css::uno::Any
& rConvertedValue
,
153 css::uno::Any
& rOldValue
,
155 const css::uno::Any
& rValue
) override
;
156 virtual void SAL_CALL
setFastPropertyValue_NoBroadcast(
158 const css::uno::Any
& rValue
160 virtual void SAL_CALL
getFastPropertyValue(
161 css::uno::Any
& rValue
,
165 OStatement_Base(OConnection
* _pConnection
);
167 using OStatement_BASE::operator css::uno::Reference
< css::uno::XInterface
>;
169 virtual void SAL_CALL
disposing() override
;
171 virtual void SAL_CALL
acquire() noexcept override
;
172 virtual void SAL_CALL
release() noexcept override
;
173 virtual css::uno::Any SAL_CALL
queryInterface( const css::uno::Type
& rType
) override
;
175 virtual css::uno::Sequence
< css::uno::Type
> SAL_CALL
getTypes( ) override
;
178 virtual css::uno::Reference
< css::beans::XPropertySetInfo
> SAL_CALL
getPropertySetInfo( ) override
;
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
;
185 virtual css::uno::Any SAL_CALL
getWarnings( ) override
;
186 virtual void SAL_CALL
clearWarnings( ) override
;
188 virtual void SAL_CALL
cancel( ) override
;
190 virtual void SAL_CALL
close( ) override
;
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
;
197 class OStatement
: public OStatement_Base
,
198 public css::sdbc::XBatchExecution
,
199 public css::lang::XServiceInfo
202 // a Constructor, that is needed for when Returning the Object is needed:
203 OStatement( OConnection
* _pConnection
) : OStatement_Base( _pConnection
){};
204 ~OStatement() override
;
206 DECLARE_SERVICE_INFO();
208 virtual void SAL_CALL
acquire() noexcept override
;
209 virtual void SAL_CALL
release() noexcept override
;
210 virtual css::uno::Any SAL_CALL
queryInterface( const css::uno::Type
& rType
) override
;
212 virtual void SAL_CALL
addBatch( const OUString
& sql
) override
;
213 virtual void SAL_CALL
clearBatch( ) override
;
214 virtual css::uno::Sequence
< sal_Int32
> SAL_CALL
executeBatch( ) override
;
218 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */