tdf#130857 qt weld: Support mail merge "Server Auth" dialog
[LibreOffice.git] / connectivity / source / inc / odbc / OResultSet.hxx
blobc7638a18d8b9771824d56e95b7c9c5e7ea98711b
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/FetchDirection.hpp>
23 #include <com/sun/star/sdbc/XResultSet.hpp>
24 #include <com/sun/star/sdbc/XRow.hpp>
25 #include <com/sun/star/sdbc/XResultSetMetaDataSupplier.hpp>
26 #include <com/sun/star/sdbc/XCloseable.hpp>
27 #include <com/sun/star/sdbc/XColumnLocate.hpp>
28 #include <com/sun/star/util/XCancellable.hpp>
29 #include <com/sun/star/sdbc/XWarningsSupplier.hpp>
30 #include <com/sun/star/sdbc/XResultSetUpdate.hpp>
31 #include <com/sun/star/sdbc/XRowUpdate.hpp>
32 #include <com/sun/star/sdbcx/XRowLocate.hpp>
33 #include <com/sun/star/sdbcx/XDeleteRows.hpp>
34 #include <cppuhelper/compbase.hxx>
35 #include <comphelper/proparrhlp.hxx>
36 #include <odbc/OFunctions.hxx>
37 #include <odbc/OStatement.hxx>
38 #include <odbc/odbcbasedllapi.hxx>
39 #include <connectivity/CommonTools.hxx>
40 #include <connectivity/FValue.hxx>
41 #include <TSkipDeletedSet.hxx>
42 #include <memory>
43 #include "OResultSetMetaData.hxx"
45 namespace connectivity::odbc
47 class OResultSetMetaData;
50 ** java_sql_ResultSet
52 typedef ::cppu::WeakComponentImplHelper< css::sdbc::XResultSet,
53 css::sdbc::XRow,
54 css::sdbc::XResultSetMetaDataSupplier,
55 css::util::XCancellable,
56 css::sdbc::XWarningsSupplier,
57 css::sdbc::XResultSetUpdate,
58 css::sdbc::XRowUpdate,
59 css::sdbcx::XRowLocate,
60 css::sdbcx::XDeleteRows,
61 css::sdbc::XCloseable,
62 css::sdbc::XColumnLocate,
63 css::lang::XServiceInfo> OResultSet_BASE;
65 class BindData;
67 /// Functor object for class ZZ returntype is void
68 struct OOO_DLLPUBLIC_ODBCBASE TBookmarkPosMapCompare
70 bool operator()( const css::uno::Sequence<sal_Int8>& _rLH,
71 const css::uno::Sequence<sal_Int8>& _rRH) const
73 if(_rLH.getLength() == _rRH.getLength())
75 sal_Int32 nCount = _rLH.getLength();
76 if(nCount != 4)
78 const sal_Int8* pLHBack = _rLH.getConstArray() + nCount - 1;
79 const sal_Int8* pRHBack = _rRH.getConstArray() + nCount - 1;
81 sal_Int32 i;
82 for(i=0;i < nCount;++i,--pLHBack,--pRHBack)
84 if(!(*pLHBack) && *pRHBack)
85 return true;
86 else if(*pLHBack && !(*pRHBack))
87 return false;
89 for(i=0,++pLHBack,++pRHBack;i < nCount;++pLHBack,++pRHBack,++i)
90 if(*pLHBack < *pRHBack)
91 return true;
92 return false;
94 else
95 return *reinterpret_cast<const sal_Int32*>(_rLH.getConstArray()) < *reinterpret_cast<const sal_Int32*>(_rRH.getConstArray());
98 else
99 return _rLH.getLength() < _rRH.getLength();
103 typedef std::map< css::uno::Sequence<sal_Int8>, sal_Int32,TBookmarkPosMapCompare > TBookmarkPosMap;
105 class OResultSet :
106 public cppu::BaseMutex,
107 public ::connectivity::IResultSetHelper,
108 public OResultSet_BASE,
109 public ::cppu::OPropertySetHelper,
110 public ::comphelper::OPropertyArrayUsageHelper<OResultSet>
112 protected:
113 TBookmarkPosMap m_aPosToBookmarks;
114 // used top hold the information about the value and the datatype to save calls to metadata
115 typedef std::vector<ORowSetValue> TDataRow;
117 std::vector<std::unique_ptr<BindData>> m_aBindVector;
118 std::vector<SQLLEN> m_aLengthVector;
119 std::map<sal_Int32,SWORD> m_aODBCColumnTypes;
121 // In baseline ODBC, SQLGetData can only be called on monotonically increasing column numbers.
122 // additionally, any variable-length data can be fetched only once (possibly in parts);
123 // after that, SQLGetData returns SQL_NO_DATA.
124 // In order to insulate our callers from these restrictions,
125 // we cache the current row in m_aRow.
126 // If the driver claims to support the GD_ANY_ORDER extension,
127 // we read and cache only the columns requested by a caller.
128 // Else, we read and cache all columns whose number is <= a requested column.
129 // m_aRow[colNumber].getBound() says if it contains an up-to-date value or not.
130 TDataRow m_aRow;
131 bool m_bFetchDataInOrder;
132 SQLHANDLE m_aStatementHandle;
133 SQLHANDLE m_aConnectionHandle;
134 OStatement_Base* m_pStatement;
135 std::unique_ptr<OSkipDeletedSet> m_pSkipDeletedSet;
136 css::uno::Reference< css::uno::XInterface> m_xStatement;
137 rtl::Reference< OResultSetMetaData> m_xMetaData;
138 std::unique_ptr<SQLUSMALLINT[]> m_pRowStatusArray;
139 rtl_TextEncoding m_nTextEncoding;
140 sal_Int32 m_nRowPos;
141 mutable sal_uInt32 m_nUseBookmarks;
142 SQLRETURN m_nCurrentFetchState;
143 bool m_bWasNull;
144 bool m_bEOF; // after last record
145 bool m_bRowInserted;
146 bool m_bRowDeleted;
147 bool m_bUseFetchScroll;
149 bool isBookmarkable() const;
150 sal_Int32 getResultSetConcurrency() const;
151 sal_Int32 getResultSetType() const;
152 static sal_Int32 getFetchDirection() { return css::sdbc::FetchDirection::FORWARD; }
153 sal_Int32 getFetchSize() const;
154 OUString getCursorName() const;
155 template < typename T, SQLINTEGER BufferLength > T getStmtOption (SQLINTEGER fOption) const;
157 void setFetchDirection(sal_Int32 _par0);
158 void setFetchSize(sal_Int32 _par0);
159 template < typename T, SQLINTEGER BufferLength > SQLRETURN setStmtOption (SQLINTEGER fOption, T value) const;
162 void ensureCacheForColumn(sal_Int32 columnIndex);
163 void invalidateCache();
164 void fillColumn(sal_Int32 _nToColumn);
165 void allocBuffer();
166 void releaseBuffer();
167 /// @throws css::sdbc::SQLException
168 /// @throws css::uno::RuntimeException
169 void updateValue(sal_Int32 columnIndex, SQLSMALLINT _nType, void const * _pValue);
170 void fillNeededData(SQLRETURN _nRet);
171 bool moveImpl(IResultSetHelper::Movement _eCursorPosition, sal_Int32 _nOffset);
172 SQLRETURN unbind(bool _bUnbindHandle = true);
173 SWORD impl_getColumnType_nothrow(sal_Int32 columnIndex);
175 // helper to implement XRow::getXXX in simple cases
176 template < typename T > T getValue( sal_Int32 columnIndex );
177 // impl_getXXX are the functions that do the actual fetching from ODBC, ignoring the cache
178 // for simple cases
179 template < typename T > T impl_getValue( const sal_Int32 _nColumnIndex, SQLSMALLINT nType );
180 // these cases need some special treatment
181 /// @throws css::sdbc::SQLException
182 /// @throws css::uno::RuntimeException
183 bool impl_getBoolean( sal_Int32 columnIndex );
184 /// @throws css::sdbc::SQLException
185 /// @throws css::uno::RuntimeException
186 css::uno::Sequence< sal_Int8 > impl_getBytes( sal_Int32 columnIndex );
187 /// @throws css::sdbc::SQLException
188 /// @throws css::uno::RuntimeException
189 css::util::Date impl_getDate( sal_Int32 columnIndex );
190 /// @throws css::sdbc::SQLException
191 /// @throws css::uno::RuntimeException
192 css::util::Time impl_getTime( sal_Int32 columnIndex );
193 /// @throws css::sdbc::SQLException
194 /// @throws css::uno::RuntimeException
195 css::util::DateTime impl_getTimestamp( sal_Int32 columnIndex );
196 /// @throws css::sdbc::SQLException
197 /// @throws css::uno::RuntimeException
198 sal_Int64 impl_getLong( sal_Int32 columnIndex );
199 /// @throws css::sdbc::SQLException
200 /// @throws css::uno::RuntimeException
201 OUString impl_getString( sal_Int32 columnIndex );
202 /// @throws css::sdbc::SQLException
203 /// @throws css::uno::RuntimeException
204 css::uno::Sequence<sal_Int8> impl_getBookmark( );
207 // OPropertyArrayUsageHelper
208 virtual ::cppu::IPropertyArrayHelper* createArrayHelper( ) const override;
209 // OPropertySetHelper
210 virtual ::cppu::IPropertyArrayHelper & SAL_CALL getInfoHelper() override;
212 virtual sal_Bool SAL_CALL convertFastPropertyValue(
213 css::uno::Any & rConvertedValue,
214 css::uno::Any & rOldValue,
215 sal_Int32 nHandle,
216 const css::uno::Any& rValue ) override;
217 virtual void SAL_CALL setFastPropertyValue_NoBroadcast(
218 sal_Int32 nHandle,
219 const css::uno::Any& rValue
220 ) override;
221 virtual void SAL_CALL getFastPropertyValue(
222 css::uno::Any& rValue,
223 sal_Int32 nHandle
224 ) const override;
225 public:
226 DECLARE_SERVICE_INFO();
227 // A ctor that is needed for returning the object
228 OResultSet( SQLHANDLE _pStatementHandle,OStatement_Base* pStmt);
229 virtual ~OResultSet() override;
231 void construct();
233 const Functions& functions() const { return m_pStatement->functions(); }
235 css::uno::Reference< css::uno::XInterface > operator *()
237 return css::uno::Reference< css::uno::XInterface >(*static_cast<OResultSet_BASE*>(this));
240 void setMetaData(const rtl::Reference<OResultSetMetaData>& _xMetaData) { m_xMetaData = _xMetaData;}
242 // ::cppu::OComponentHelper
243 virtual void SAL_CALL disposing() override;
244 // XInterface
245 virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & rType ) override;
246 virtual void SAL_CALL acquire() noexcept override;
247 virtual void SAL_CALL release() noexcept override;
248 //XTypeProvider
249 virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes( ) override;
250 // XPropertySet
251 virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo( ) override;
252 // XResultSet
253 virtual sal_Bool SAL_CALL next( ) override;
254 virtual sal_Bool SAL_CALL isBeforeFirst( ) override;
255 virtual sal_Bool SAL_CALL isAfterLast( ) override;
256 virtual sal_Bool SAL_CALL isFirst( ) override;
257 virtual sal_Bool SAL_CALL isLast( ) override;
258 virtual void SAL_CALL beforeFirst( ) override;
259 virtual void SAL_CALL afterLast( ) override;
260 virtual sal_Bool SAL_CALL first( ) override;
261 virtual sal_Bool SAL_CALL last( ) override;
262 virtual sal_Int32 SAL_CALL getRow( ) override;
263 virtual sal_Bool SAL_CALL absolute( sal_Int32 row ) override;
264 virtual sal_Bool SAL_CALL relative( sal_Int32 rows ) override;
265 virtual sal_Bool SAL_CALL previous( ) override;
266 virtual void SAL_CALL refreshRow( ) override;
267 virtual sal_Bool SAL_CALL rowUpdated( ) override;
268 virtual sal_Bool SAL_CALL rowInserted( ) override;
269 virtual sal_Bool SAL_CALL rowDeleted( ) override;
270 virtual css::uno::Reference< css::uno::XInterface > SAL_CALL getStatement( ) override;
271 // XRow
272 virtual sal_Bool SAL_CALL wasNull( ) override;
273 virtual OUString SAL_CALL getString( sal_Int32 columnIndex ) override;
274 virtual sal_Bool SAL_CALL getBoolean( sal_Int32 columnIndex ) override;
275 virtual sal_Int8 SAL_CALL getByte( sal_Int32 columnIndex ) override;
276 virtual sal_Int16 SAL_CALL getShort( sal_Int32 columnIndex ) override;
277 virtual sal_Int32 SAL_CALL getInt( sal_Int32 columnIndex ) override;
278 virtual sal_Int64 SAL_CALL getLong( sal_Int32 columnIndex ) override;
279 virtual float SAL_CALL getFloat( sal_Int32 columnIndex ) override;
280 virtual double SAL_CALL getDouble( sal_Int32 columnIndex ) override;
281 virtual css::uno::Sequence< sal_Int8 > SAL_CALL getBytes( sal_Int32 columnIndex ) override;
282 virtual css::util::Date SAL_CALL getDate( sal_Int32 columnIndex ) override;
283 virtual css::util::Time SAL_CALL getTime( sal_Int32 columnIndex ) override;
284 virtual css::util::DateTime SAL_CALL getTimestamp( sal_Int32 columnIndex ) override;
285 virtual css::uno::Reference< css::io::XInputStream > SAL_CALL getBinaryStream( sal_Int32 columnIndex ) override;
286 virtual css::uno::Reference< css::io::XInputStream > SAL_CALL getCharacterStream( sal_Int32 columnIndex ) override;
287 virtual css::uno::Any SAL_CALL getObject( sal_Int32 columnIndex, const css::uno::Reference< css::container::XNameAccess >& typeMap ) override;
288 virtual css::uno::Reference< css::sdbc::XRef > SAL_CALL getRef( sal_Int32 columnIndex ) override;
289 virtual css::uno::Reference< css::sdbc::XBlob > SAL_CALL getBlob( sal_Int32 columnIndex ) override;
290 virtual css::uno::Reference< css::sdbc::XClob > SAL_CALL getClob( sal_Int32 columnIndex ) override;
291 virtual css::uno::Reference< css::sdbc::XArray > SAL_CALL getArray( sal_Int32 columnIndex ) override;
292 // XResultSetMetaDataSupplier
293 virtual css::uno::Reference< css::sdbc::XResultSetMetaData > SAL_CALL getMetaData( ) override;
294 // XCancellable
295 virtual void SAL_CALL cancel( ) override;
296 // XCloseable
297 virtual void SAL_CALL close( ) override;
298 // XWarningsSupplier
299 virtual css::uno::Any SAL_CALL getWarnings( ) override;
300 virtual void SAL_CALL clearWarnings( ) override;
301 // XResultSetUpdate
302 virtual void SAL_CALL insertRow( ) override;
303 virtual void SAL_CALL updateRow( ) override;
304 virtual void SAL_CALL deleteRow( ) override;
305 virtual void SAL_CALL cancelRowUpdates( ) override;
306 virtual void SAL_CALL moveToInsertRow( ) override;
307 virtual void SAL_CALL moveToCurrentRow( ) override;
308 // XRowUpdate
309 virtual void SAL_CALL updateNull( sal_Int32 columnIndex ) override;
310 virtual void SAL_CALL updateBoolean( sal_Int32 columnIndex, sal_Bool x ) override;
311 virtual void SAL_CALL updateByte( sal_Int32 columnIndex, sal_Int8 x ) override;
312 virtual void SAL_CALL updateShort( sal_Int32 columnIndex, sal_Int16 x ) override;
313 virtual void SAL_CALL updateInt( sal_Int32 columnIndex, sal_Int32 x ) override;
314 virtual void SAL_CALL updateLong( sal_Int32 columnIndex, sal_Int64 x ) override;
315 virtual void SAL_CALL updateFloat( sal_Int32 columnIndex, float x ) override;
316 virtual void SAL_CALL updateDouble( sal_Int32 columnIndex, double x ) override;
317 virtual void SAL_CALL updateString( sal_Int32 columnIndex, const OUString& x ) override;
318 virtual void SAL_CALL updateBytes( sal_Int32 columnIndex, const css::uno::Sequence< sal_Int8 >& x ) override;
319 virtual void SAL_CALL updateDate( sal_Int32 columnIndex, const css::util::Date& x ) override;
320 virtual void SAL_CALL updateTime( sal_Int32 columnIndex, const css::util::Time& x ) override;
321 virtual void SAL_CALL updateTimestamp( sal_Int32 columnIndex, const css::util::DateTime& x ) override;
322 virtual void SAL_CALL updateBinaryStream( sal_Int32 columnIndex, const css::uno::Reference< css::io::XInputStream >& x, sal_Int32 length ) override;
323 virtual void SAL_CALL updateCharacterStream( sal_Int32 columnIndex, const css::uno::Reference< css::io::XInputStream >& x, sal_Int32 length ) override;
324 virtual void SAL_CALL updateObject( sal_Int32 columnIndex, const css::uno::Any& x ) override;
325 virtual void SAL_CALL updateNumericObject( sal_Int32 columnIndex, const css::uno::Any& x, sal_Int32 scale ) override;
326 // XColumnLocate
327 virtual sal_Int32 SAL_CALL findColumn( const OUString& columnName ) override;
328 // XRowLocate
329 virtual css::uno::Any SAL_CALL getBookmark( ) override;
330 virtual sal_Bool SAL_CALL moveToBookmark( const css::uno::Any& bookmark ) override;
331 virtual sal_Bool SAL_CALL moveRelativeToBookmark( const css::uno::Any& bookmark, sal_Int32 rows ) override;
332 virtual sal_Int32 SAL_CALL compareBookmarks( const css::uno::Any& first, const css::uno::Any& second ) override;
333 virtual sal_Bool SAL_CALL hasOrderedBookmarks( ) override;
334 virtual sal_Int32 SAL_CALL hashBookmark( const css::uno::Any& bookmark ) override;
335 // XDeleteRows
336 virtual css::uno::Sequence< sal_Int32 > SAL_CALL deleteRows( const css::uno::Sequence< css::uno::Any >& rows ) override;
338 // IResultSetHelper
339 virtual bool move(IResultSetHelper::Movement _eCursorPosition, sal_Int32 _nOffset, bool _bRetrieveData) override;
340 virtual sal_Int32 getDriverPos() const override;
341 virtual bool isRowDeleted() const override;
343 protected:
344 using OPropertySetHelper::getFastPropertyValue;
350 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */