LibreOffice Module connectivity (master) 1
OResultSet.hxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#pragma once
21
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>
36#include <odbc/OFunctions.hxx>
37#include <odbc/OStatement.hxx>
41#include <TSkipDeletedSet.hxx>
42#include <memory>
43
44namespace connectivity::odbc
45 {
46
47 /*
48 ** java_sql_ResultSet
49 */
50 typedef ::cppu::WeakComponentImplHelper< css::sdbc::XResultSet,
51 css::sdbc::XRow,
52 css::sdbc::XResultSetMetaDataSupplier,
53 css::util::XCancellable,
54 css::sdbc::XWarningsSupplier,
55 css::sdbc::XResultSetUpdate,
56 css::sdbc::XRowUpdate,
57 css::sdbcx::XRowLocate,
58 css::sdbcx::XDeleteRows,
59 css::sdbc::XCloseable,
60 css::sdbc::XColumnLocate,
61 css::lang::XServiceInfo> OResultSet_BASE;
62
63
64 typedef std::pair<sal_Int64,sal_Int32> TVoidPtr;
65 typedef std::allocator< TVoidPtr > TVoidAlloc;
66 typedef std::vector<TVoidPtr> TVoidVector;
69 {
70 bool operator()( const css::uno::Sequence<sal_Int8>& _rLH,
71 const css::uno::Sequence<sal_Int8>& _rRH) const
72 {
73 if(_rLH.getLength() == _rRH.getLength())
74 {
75 sal_Int32 nCount = _rLH.getLength();
76 if(nCount != 4)
77 {
78 const sal_Int8* pLHBack = _rLH.getConstArray() + nCount - 1;
79 const sal_Int8* pRHBack = _rRH.getConstArray() + nCount - 1;
80
81 sal_Int32 i;
82 for(i=0;i < nCount;++i,--pLHBack,--pRHBack)
83 {
84 if(!(*pLHBack) && *pRHBack)
85 return true;
86 else if(*pLHBack && !(*pRHBack))
87 return false;
88 }
89 for(i=0,++pLHBack,++pRHBack;i < nCount;++pLHBack,++pRHBack,++i)
90 if(*pLHBack < *pRHBack)
91 return true;
92 return false;
93 }
94 else
95 return *reinterpret_cast<const sal_Int32*>(_rLH.getConstArray()) < *reinterpret_cast<const sal_Int32*>(_rRH.getConstArray());
96
97 }
98 else
99 return _rLH.getLength() < _rRH.getLength();
100 }
101 };
102
103 typedef std::map< css::uno::Sequence<sal_Int8>, sal_Int32,TBookmarkPosMapCompare > TBookmarkPosMap;
104
106 public cppu::BaseMutex,
108 public OResultSet_BASE,
111 {
112 protected:
114 // used top hold the information about the value and the datatype to save calls to metadata
115 typedef std::vector<ORowSetValue> TDataRow;
116
118 std::vector<SQLLEN> m_aLengthVector;
119 std::map<sal_Int32,SWORD> m_aODBCColumnTypes;
120
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.
135 std::unique_ptr<OSkipDeletedSet> m_pSkipDeletedSet;
136 css::uno::Reference< css::uno::XInterface> m_xStatement;
137 css::uno::Reference< css::sdbc::XResultSetMetaData> 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;
144 bool m_bEOF; // after last record
148
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;
156
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;
160
161
162 void ensureCacheForColumn(sal_Int32 columnIndex);
163 void invalidateCache();
164 void fillColumn(sal_Int32 _nToColumn);
165 void allocBuffer();
166 void releaseBuffer();
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 TVoidPtr allocBindColumn(sal_Int32 _nType,sal_Int32 _nColumnIndex);
173 SQLRETURN unbind(bool _bUnbindHandle = true);
174 SWORD impl_getColumnType_nothrow(sal_Int32 columnIndex);
175
176 // helper to implement XRow::getXXX in simple cases
177 template < typename T > T getValue( sal_Int32 columnIndex );
178 // impl_getXXX are the functions that do the actual fetching from ODBC, ignoring the cache
179 // for simple cases
180 template < typename T > T impl_getValue( const sal_Int32 _nColumnIndex, SQLSMALLINT nType );
181 // these cases need some special treatment
184 bool impl_getBoolean( sal_Int32 columnIndex );
187 css::uno::Sequence< sal_Int8 > impl_getBytes( sal_Int32 columnIndex );
190 css::util::Date impl_getDate( sal_Int32 columnIndex );
193 css::util::Time impl_getTime( sal_Int32 columnIndex );
196 css::util::DateTime impl_getTimestamp( sal_Int32 columnIndex );
199 sal_Int64 impl_getLong( sal_Int32 columnIndex );
202 OUString impl_getString( sal_Int32 columnIndex );
205 css::uno::Sequence<sal_Int8> impl_getBookmark( );
206
207
208 // OPropertyArrayUsageHelper
209 virtual ::cppu::IPropertyArrayHelper* createArrayHelper( ) const override;
210 // OPropertySetHelper
211 virtual ::cppu::IPropertyArrayHelper & SAL_CALL getInfoHelper() override;
212
214 css::uno::Any & rConvertedValue,
215 css::uno::Any & rOldValue,
216 sal_Int32 nHandle,
217 const css::uno::Any& rValue ) override;
218 virtual void SAL_CALL setFastPropertyValue_NoBroadcast(
219 sal_Int32 nHandle,
220 const css::uno::Any& rValue
221 ) override;
222 virtual void SAL_CALL getFastPropertyValue(
223 css::uno::Any& rValue,
224 sal_Int32 nHandle
225 ) const override;
226 public:
228 // A ctor that is needed for returning the object
229 OResultSet( SQLHANDLE _pStatementHandle,OStatement_Base* pStmt);
230 virtual ~OResultSet() override;
231
232 void construct();
233
234 oslGenericFunction getOdbcFunction(ODBC3SQLFunctionId _nIndex) const
235 {
236 return m_pStatement->getOdbcFunction(_nIndex);
237 }
238
239 css::uno::Reference< css::uno::XInterface > operator *()
240 {
241 return css::uno::Reference< css::uno::XInterface >(*static_cast<OResultSet_BASE*>(this));
242 }
243
244 void setMetaData(const css::uno::Reference< css::sdbc::XResultSetMetaData>& _xMetaData) { m_xMetaData = _xMetaData;}
245
246 // ::cppu::OComponentHelper
247 virtual void SAL_CALL disposing() override;
248 // XInterface
249 virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & rType ) override;
250 virtual void SAL_CALL acquire() noexcept override;
251 virtual void SAL_CALL release() noexcept override;
252 //XTypeProvider
253 virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes( ) override;
254 // XPropertySet
255 virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo( ) override;
256 // XResultSet
257 virtual sal_Bool SAL_CALL next( ) override;
258 virtual sal_Bool SAL_CALL isBeforeFirst( ) override;
259 virtual sal_Bool SAL_CALL isAfterLast( ) override;
260 virtual sal_Bool SAL_CALL isFirst( ) override;
261 virtual sal_Bool SAL_CALL isLast( ) override;
262 virtual void SAL_CALL beforeFirst( ) override;
263 virtual void SAL_CALL afterLast( ) override;
264 virtual sal_Bool SAL_CALL first( ) override;
265 virtual sal_Bool SAL_CALL last( ) override;
266 virtual sal_Int32 SAL_CALL getRow( ) override;
267 virtual sal_Bool SAL_CALL absolute( sal_Int32 row ) override;
268 virtual sal_Bool SAL_CALL relative( sal_Int32 rows ) override;
269 virtual sal_Bool SAL_CALL previous( ) override;
270 virtual void SAL_CALL refreshRow( ) override;
271 virtual sal_Bool SAL_CALL rowUpdated( ) override;
272 virtual sal_Bool SAL_CALL rowInserted( ) override;
273 virtual sal_Bool SAL_CALL rowDeleted( ) override;
274 virtual css::uno::Reference< css::uno::XInterface > SAL_CALL getStatement( ) override;
275 // XRow
276 virtual sal_Bool SAL_CALL wasNull( ) override;
277 virtual OUString SAL_CALL getString( sal_Int32 columnIndex ) override;
278 virtual sal_Bool SAL_CALL getBoolean( sal_Int32 columnIndex ) override;
279 virtual sal_Int8 SAL_CALL getByte( sal_Int32 columnIndex ) override;
280 virtual sal_Int16 SAL_CALL getShort( sal_Int32 columnIndex ) override;
281 virtual sal_Int32 SAL_CALL getInt( sal_Int32 columnIndex ) override;
282 virtual sal_Int64 SAL_CALL getLong( sal_Int32 columnIndex ) override;
283 virtual float SAL_CALL getFloat( sal_Int32 columnIndex ) override;
284 virtual double SAL_CALL getDouble( sal_Int32 columnIndex ) override;
285 virtual css::uno::Sequence< sal_Int8 > SAL_CALL getBytes( sal_Int32 columnIndex ) override;
286 virtual css::util::Date SAL_CALL getDate( sal_Int32 columnIndex ) override;
287 virtual css::util::Time SAL_CALL getTime( sal_Int32 columnIndex ) override;
288 virtual css::util::DateTime SAL_CALL getTimestamp( sal_Int32 columnIndex ) override;
289 virtual css::uno::Reference< css::io::XInputStream > SAL_CALL getBinaryStream( sal_Int32 columnIndex ) override;
290 virtual css::uno::Reference< css::io::XInputStream > SAL_CALL getCharacterStream( sal_Int32 columnIndex ) override;
291 virtual css::uno::Any SAL_CALL getObject( sal_Int32 columnIndex, const css::uno::Reference< css::container::XNameAccess >& typeMap ) override;
292 virtual css::uno::Reference< css::sdbc::XRef > SAL_CALL getRef( sal_Int32 columnIndex ) override;
293 virtual css::uno::Reference< css::sdbc::XBlob > SAL_CALL getBlob( sal_Int32 columnIndex ) override;
294 virtual css::uno::Reference< css::sdbc::XClob > SAL_CALL getClob( sal_Int32 columnIndex ) override;
295 virtual css::uno::Reference< css::sdbc::XArray > SAL_CALL getArray( sal_Int32 columnIndex ) override;
296 // XResultSetMetaDataSupplier
297 virtual css::uno::Reference< css::sdbc::XResultSetMetaData > SAL_CALL getMetaData( ) override;
298 // XCancellable
299 virtual void SAL_CALL cancel( ) override;
300 // XCloseable
301 virtual void SAL_CALL close( ) override;
302 // XWarningsSupplier
303 virtual css::uno::Any SAL_CALL getWarnings( ) override;
304 virtual void SAL_CALL clearWarnings( ) override;
305 // XResultSetUpdate
306 virtual void SAL_CALL insertRow( ) override;
307 virtual void SAL_CALL updateRow( ) override;
308 virtual void SAL_CALL deleteRow( ) override;
309 virtual void SAL_CALL cancelRowUpdates( ) override;
310 virtual void SAL_CALL moveToInsertRow( ) override;
311 virtual void SAL_CALL moveToCurrentRow( ) override;
312 // XRowUpdate
313 virtual void SAL_CALL updateNull( sal_Int32 columnIndex ) override;
314 virtual void SAL_CALL updateBoolean( sal_Int32 columnIndex, sal_Bool x ) override;
315 virtual void SAL_CALL updateByte( sal_Int32 columnIndex, sal_Int8 x ) override;
316 virtual void SAL_CALL updateShort( sal_Int32 columnIndex, sal_Int16 x ) override;
317 virtual void SAL_CALL updateInt( sal_Int32 columnIndex, sal_Int32 x ) override;
318 virtual void SAL_CALL updateLong( sal_Int32 columnIndex, sal_Int64 x ) override;
319 virtual void SAL_CALL updateFloat( sal_Int32 columnIndex, float x ) override;
320 virtual void SAL_CALL updateDouble( sal_Int32 columnIndex, double x ) override;
321 virtual void SAL_CALL updateString( sal_Int32 columnIndex, const OUString& x ) override;
322 virtual void SAL_CALL updateBytes( sal_Int32 columnIndex, const css::uno::Sequence< sal_Int8 >& x ) override;
323 virtual void SAL_CALL updateDate( sal_Int32 columnIndex, const css::util::Date& x ) override;
324 virtual void SAL_CALL updateTime( sal_Int32 columnIndex, const css::util::Time& x ) override;
325 virtual void SAL_CALL updateTimestamp( sal_Int32 columnIndex, const css::util::DateTime& x ) override;
326 virtual void SAL_CALL updateBinaryStream( sal_Int32 columnIndex, const css::uno::Reference< css::io::XInputStream >& x, sal_Int32 length ) override;
327 virtual void SAL_CALL updateCharacterStream( sal_Int32 columnIndex, const css::uno::Reference< css::io::XInputStream >& x, sal_Int32 length ) override;
328 virtual void SAL_CALL updateObject( sal_Int32 columnIndex, const css::uno::Any& x ) override;
329 virtual void SAL_CALL updateNumericObject( sal_Int32 columnIndex, const css::uno::Any& x, sal_Int32 scale ) override;
330 // XColumnLocate
331 virtual sal_Int32 SAL_CALL findColumn( const OUString& columnName ) override;
332 // XRowLocate
333 virtual css::uno::Any SAL_CALL getBookmark( ) override;
334 virtual sal_Bool SAL_CALL moveToBookmark( const css::uno::Any& bookmark ) override;
335 virtual sal_Bool SAL_CALL moveRelativeToBookmark( const css::uno::Any& bookmark, sal_Int32 rows ) override;
336 virtual sal_Int32 SAL_CALL compareBookmarks( const css::uno::Any& first, const css::uno::Any& second ) override;
337 virtual sal_Bool SAL_CALL hasOrderedBookmarks( ) override;
338 virtual sal_Int32 SAL_CALL hashBookmark( const css::uno::Any& bookmark ) override;
339 // XDeleteRows
340 virtual css::uno::Sequence< sal_Int32 > SAL_CALL deleteRows( const css::uno::Sequence< css::uno::Any >& rows ) override;
341
342 // IResultSetHelper
343 virtual bool move(IResultSetHelper::Movement _eCursorPosition, sal_Int32 _nOffset, bool _bRetrieveData) override;
344 virtual sal_Int32 getDriverPos() const override;
345 virtual bool isRowDeleted() const override;
346
347 protected:
348 using OPropertySetHelper::getFastPropertyValue;
349 };
350
351}
352
353
354/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
ODBC3SQLFunctionId
Definition: OTools.hxx:33
css::uno::Reference< css::uno::XInterface > m_xStatement
Definition: OResultSet.hxx:136
virtual sal_Bool SAL_CALL convertFastPropertyValue(css::uno::Any &rConvertedValue, css::uno::Any &rOldValue, sal_Int32 nHandle, const css::uno::Any &rValue) override
virtual void SAL_CALL setFastPropertyValue_NoBroadcast(sal_Int32 nHandle, const css::uno::Any &rValue) override
std::unique_ptr< SQLUSMALLINT[]> m_pRowStatusArray
Definition: OResultSet.hxx:138
virtual void SAL_CALL getFastPropertyValue(css::uno::Any &rValue, sal_Int32 nHandle) const override
virtual css::uno::Any SAL_CALL queryInterface(const css::uno::Type &rType) override
css::uno::Reference< css::sdbc::XResultSetMetaData > m_xMetaData
Definition: OResultSet.hxx:137
OStatement_Base * m_pStatement
Definition: OResultSet.hxx:134
static sal_Int32 getFetchDirection()
Definition: OResultSet.hxx:152
std::vector< SQLLEN > m_aLengthVector
Definition: OResultSet.hxx:118
oslGenericFunction getOdbcFunction(ODBC3SQLFunctionId _nIndex) const
Definition: OResultSet.hxx:234
rtl_TextEncoding m_nTextEncoding
Definition: OResultSet.hxx:139
void setMetaData(const css::uno::Reference< css::sdbc::XResultSetMetaData > &_xMetaData)
Definition: OResultSet.hxx:244
std::map< sal_Int32, SWORD > m_aODBCColumnTypes
Definition: OResultSet.hxx:119
std::unique_ptr< OSkipDeletedSet > m_pSkipDeletedSet
Definition: OResultSet.hxx:135
TBookmarkPosMap m_aPosToBookmarks
Definition: OResultSet.hxx:113
std::vector< ORowSetValue > TDataRow
Definition: OResultSet.hxx:115
oslGenericFunction getOdbcFunction(ODBC3SQLFunctionId _nIndex) const
Definition: OStatement.hxx:161
int nCount
Type
std::map< css::uno::Sequence< sal_Int8 >, sal_Int32, TBookmarkPosMapCompare > TBookmarkPosMap
Definition: OResultSet.hxx:103
std::pair< sal_Int64, sal_Int32 > TVoidPtr
Definition: OResultSet.hxx:64
std::vector< TVoidPtr > TVoidVector
Definition: OResultSet.hxx:66
std::allocator< TVoidPtr > TVoidAlloc
Definition: OResultSet.hxx:65
void getValue(const OConnection *_pConnection, SQLHANDLE _aStatementHandle, sal_Int32 columnIndex, SQLSMALLINT _nType, bool &_bWasNull, const css::uno::Reference< css::uno::XInterface > &_xInterface, T &_rValue)
Definition: OTools.hxx:231
::cppu::WeakComponentImplHelper< css::sdbc::XResultSet, css::sdbc::XRow, css::sdbc::XResultSetMetaDataSupplier, css::util::XCancellable, css::sdbc::XWarningsSupplier, css::sdbc::XResultSetUpdate, css::sdbc::XRowUpdate, css::sdbcx::XRowLocate, css::sdbcx::XDeleteRows, css::sdbc::XCloseable, css::sdbc::XColumnLocate, css::lang::XServiceInfo > OResultSet_BASE
Definition: OResultSet.hxx:61
int i
#define OOO_DLLPUBLIC_ODBCBASE
sal_Int32 scale
Definition: pq_statics.cxx:62
const char * columnName
Definition: pq_statics.cxx:56
Functor object for class ZZ returntype is void.
Definition: OResultSet.hxx:69
bool operator()(const css::uno::Sequence< sal_Int8 > &_rLH, const css::uno::Sequence< sal_Int8 > &_rRH) const
Definition: OResultSet.hxx:70
unsigned char sal_Bool
signed char sal_Int8