LibreOffice Module connectivity (master) 1
FResultSet.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/XResultSet.hpp>
23#include <com/sun/star/sdbc/XRow.hpp>
24#include <com/sun/star/sdbc/XResultSetMetaDataSupplier.hpp>
25#include <com/sun/star/sdbc/XCloseable.hpp>
26#include <com/sun/star/sdbc/XColumnLocate.hpp>
27#include <com/sun/star/util/XCancellable.hpp>
28#include <com/sun/star/sdbc/XWarningsSupplier.hpp>
29#include <com/sun/star/sdbc/XResultSetUpdate.hpp>
30#include <com/sun/star/sdbc/XRowUpdate.hpp>
34#include <file/FStatement.hxx>
37#include <file/fanalyzer.hxx>
38#include <file/FTable.hxx>
39#include <file/filedllapi.hxx>
40#include <TSortIndex.hxx>
41#include <TSkipDeletedSet.hxx>
42#include <com/sun/star/lang/XEventListener.hpp>
43#include <o3tl/safeint.hxx>
44
45namespace connectivity::file
46 {
47 typedef ::cppu::WeakComponentImplHelper< css::sdbc::XResultSet,
48 css::sdbc::XRow,
49 css::sdbc::XResultSetMetaDataSupplier,
50 css::util::XCancellable,
51 css::sdbc::XWarningsSupplier,
52 css::sdbc::XResultSetUpdate,
53 css::sdbc::XRowUpdate,
54 css::sdbc::XCloseable,
55 css::sdbc::XColumnLocate,
56 css::lang::XServiceInfo,
57 css::lang::XEventListener> OResultSet_BASE;
58
60 public cppu::BaseMutex,
62 public OResultSet_BASE,
65 {
66
67 protected:
68 std::vector<sal_Int32> m_aColMapping; // pos 0 is unused so we don't have to decrement 1 every time
69
70 std::vector<sal_Int32> m_aOrderbyColumnNumber;
71 std::vector<TAscendingOrder> m_aOrderbyAscending;
72
75 OValueRefRow m_aEvaluateRow; // contains all values of a row
76 OValueRefRow m_aInsertRow; // needed for insert by cursor
77 ORefAssignValues m_aAssignValues; // needed for insert,update and parameters
78 // to compare with the restrictions
80
82 OKeySet::iterator m_aFileSetIter;
83
84
85 std::unique_ptr<OSortIndex> m_pSortIndex;
89
92
93 sal_Int32 m_nFetchSize;
97
98 css::uno::Reference< css::uno::XInterface> m_xStatement;
99 css::uno::Reference< css::sdbc::XResultSetMetaData> m_xMetaData;
100 css::uno::Reference< css::container::XNameAccess> m_xColNames; // table columns
101 css::uno::Reference< css::container::XIndexAccess> m_xColsIdx; // table columns
102
103
104 sal_Int32 m_nRowPos;
105 sal_Int32 m_nFilePos;
108 sal_Int32 m_nColumnCount;
110 bool m_bInserted; // true when moveToInsertRow was called
111 // set to false when cursor moved or cancel
117
118 static void initializeRow(OValueRefRow& _rRow,sal_Int32 _nColumnCount);
119 void construct();
120 //sal_Bool evaluate();
121
122 bool ExecuteRow(IResultSetHelper::Movement eFirstCursorPosition,
123 sal_Int32 nOffset = 1,
124 bool bEvaluate = true,
125 bool bRetrieveData = true);
126
127 std::unique_ptr<OKeyValue> GetOrderbyKeyValue(OValueRefRow const & _rRow);
128 bool IsSorted() const { return !m_aOrderbyColumnNumber.empty() && m_aOrderbyColumnNumber[0] >= 0;}
129
130 // return true when the select statement is "select count(*) from table"
131 bool isCount() const { return m_bIsCount; }
133 void checkIndex(sal_Int32 columnIndex );
134
137 const ORowSetValue& getValue(sal_Int32 columnIndex);
140 void updateValue(sal_Int32 columnIndex,const ORowSetValue& x );
141 // clear insert row
142 void clearInsertRow();
143 void sortRows();
144 protected:
145
146 using OResultSet_BASE::rBHelper;
147
148 bool Move(IResultSetHelper::Movement eCursorPosition, sal_Int32 nOffset, bool bRetrieveData);
149 virtual bool fillIndexValues(const css::uno::Reference< css::sdbcx::XColumnsSupplier> &_xIndex);
150
151 // OPropertyArrayUsageHelper
152 virtual ::cppu::IPropertyArrayHelper* createArrayHelper( ) const override;
153 // OPropertySetHelper
154 virtual ::cppu::IPropertyArrayHelper & SAL_CALL getInfoHelper() override;
155
156 virtual ~OResultSet() override;
157 public:
159 // a Constructor, that is needed for when Returning the Object is needed:
161
162 // ::cppu::OComponentHelper
163 virtual void SAL_CALL disposing() override final;
164 // XInterface
165 virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & rType ) override;
166 virtual void SAL_CALL acquire() noexcept override;
167 virtual void SAL_CALL release() noexcept override;
168 //XTypeProvider
169 virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes( ) override;
170 // XPropertySet
171 virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo( ) override;
172 // XResultSet
173 virtual sal_Bool SAL_CALL next( ) override;
174 virtual sal_Bool SAL_CALL isBeforeFirst( ) override;
175 virtual sal_Bool SAL_CALL isAfterLast( ) override;
176 virtual sal_Bool SAL_CALL isFirst( ) override;
177 virtual sal_Bool SAL_CALL isLast( ) override;
178 virtual void SAL_CALL beforeFirst( ) override;
179 virtual void SAL_CALL afterLast( ) override;
180 virtual sal_Bool SAL_CALL first( ) override;
181 virtual sal_Bool SAL_CALL last( ) override;
182 virtual sal_Int32 SAL_CALL getRow( ) override;
183 virtual sal_Bool SAL_CALL absolute( sal_Int32 row ) override;
184 virtual sal_Bool SAL_CALL relative( sal_Int32 rows ) override;
185 virtual sal_Bool SAL_CALL previous( ) override;
186 virtual void SAL_CALL refreshRow( ) override;
187 virtual sal_Bool SAL_CALL rowUpdated( ) override;
188 virtual sal_Bool SAL_CALL rowInserted( ) override;
189 virtual sal_Bool SAL_CALL rowDeleted( ) override;
190 virtual css::uno::Reference< css::uno::XInterface > SAL_CALL getStatement( ) override;
191 // XRow
192 virtual sal_Bool SAL_CALL wasNull( ) override;
193 virtual OUString SAL_CALL getString( sal_Int32 columnIndex ) override;
194 virtual sal_Bool SAL_CALL getBoolean( sal_Int32 columnIndex ) override;
195 virtual sal_Int8 SAL_CALL getByte( sal_Int32 columnIndex ) override;
196 virtual sal_Int16 SAL_CALL getShort( sal_Int32 columnIndex ) override;
197 virtual sal_Int32 SAL_CALL getInt( sal_Int32 columnIndex ) override;
198 virtual sal_Int64 SAL_CALL getLong( sal_Int32 columnIndex ) override;
199 virtual float SAL_CALL getFloat( sal_Int32 columnIndex ) override;
200 virtual double SAL_CALL getDouble( sal_Int32 columnIndex ) override;
201 virtual css::uno::Sequence< sal_Int8 > SAL_CALL getBytes( sal_Int32 columnIndex ) override;
202 virtual css::util::Date SAL_CALL getDate( sal_Int32 columnIndex ) override;
203 virtual css::util::Time SAL_CALL getTime( sal_Int32 columnIndex ) override;
204 virtual css::util::DateTime SAL_CALL getTimestamp( sal_Int32 columnIndex ) override;
205 virtual css::uno::Reference< css::io::XInputStream > SAL_CALL getBinaryStream( sal_Int32 columnIndex ) override;
206 virtual css::uno::Reference< css::io::XInputStream > SAL_CALL getCharacterStream( sal_Int32 columnIndex ) override;
207 virtual css::uno::Any SAL_CALL getObject( sal_Int32 columnIndex, const css::uno::Reference< css::container::XNameAccess >& typeMap ) override;
208 virtual css::uno::Reference< css::sdbc::XRef > SAL_CALL getRef( sal_Int32 columnIndex ) override;
209 virtual css::uno::Reference< css::sdbc::XBlob > SAL_CALL getBlob( sal_Int32 columnIndex ) override;
210 virtual css::uno::Reference< css::sdbc::XClob > SAL_CALL getClob( sal_Int32 columnIndex ) override;
211 virtual css::uno::Reference< css::sdbc::XArray > SAL_CALL getArray( sal_Int32 columnIndex ) override;
212 // XResultSetMetaDataSupplier
213 virtual css::uno::Reference< css::sdbc::XResultSetMetaData > SAL_CALL getMetaData( ) override;
214 // XCancellable
215 virtual void SAL_CALL cancel( ) override;
216 // XCloseable
217 virtual void SAL_CALL close( ) override;
218 // XWarningsSupplier
219 virtual css::uno::Any SAL_CALL getWarnings( ) override;
220 virtual void SAL_CALL clearWarnings( ) override;
221 // XResultSetUpdate
222 virtual void SAL_CALL insertRow( ) override;
223 virtual void SAL_CALL updateRow( ) override;
224 virtual void SAL_CALL deleteRow( ) override;
225 virtual void SAL_CALL cancelRowUpdates( ) override;
226 virtual void SAL_CALL moveToInsertRow( ) override;
227 virtual void SAL_CALL moveToCurrentRow( ) override;
228 // XRowUpdate
229 virtual void SAL_CALL updateNull( sal_Int32 columnIndex ) override;
230 virtual void SAL_CALL updateBoolean( sal_Int32 columnIndex, sal_Bool x ) override;
231 virtual void SAL_CALL updateByte( sal_Int32 columnIndex, sal_Int8 x ) override;
232 virtual void SAL_CALL updateShort( sal_Int32 columnIndex, sal_Int16 x ) override;
233 virtual void SAL_CALL updateInt( sal_Int32 columnIndex, sal_Int32 x ) override;
234 virtual void SAL_CALL updateLong( sal_Int32 columnIndex, sal_Int64 x ) override;
235 virtual void SAL_CALL updateFloat( sal_Int32 columnIndex, float x ) override;
236 virtual void SAL_CALL updateDouble( sal_Int32 columnIndex, double x ) override;
237 virtual void SAL_CALL updateString( sal_Int32 columnIndex, const OUString& x ) override;
238 virtual void SAL_CALL updateBytes( sal_Int32 columnIndex, const css::uno::Sequence< sal_Int8 >& x ) override;
239 virtual void SAL_CALL updateDate( sal_Int32 columnIndex, const css::util::Date& x ) override;
240 virtual void SAL_CALL updateTime( sal_Int32 columnIndex, const css::util::Time& x ) override;
241 virtual void SAL_CALL updateTimestamp( sal_Int32 columnIndex, const css::util::DateTime& x ) override;
242 virtual void SAL_CALL updateBinaryStream( sal_Int32 columnIndex, const css::uno::Reference< css::io::XInputStream >& x, sal_Int32 length ) override;
243 virtual void SAL_CALL updateCharacterStream( sal_Int32 columnIndex, const css::uno::Reference< css::io::XInputStream >& x, sal_Int32 length ) override;
244 virtual void SAL_CALL updateObject( sal_Int32 columnIndex, const css::uno::Any& x ) override;
245 virtual void SAL_CALL updateNumericObject( sal_Int32 columnIndex, const css::uno::Any& x, sal_Int32 scale ) override;
246 // XColumnLocate
247 virtual sal_Int32 SAL_CALL findColumn( const OUString& columnName ) override;
248 //XEventlistener
249 virtual void SAL_CALL disposing( const css::lang::EventObject& Source ) override;
250
251 // special methods
252 inline sal_Int32 mapColumn(sal_Int32 column);
253 void OpenImpl();
254 void doTableSpecials(const OSQLTable& _xTable);
255
256 sal_Int32 getRowCountResult() const { return m_nRowCountResult; }
257 void setEvaluationRow(const OValueRefRow& _aRow) { m_aEvaluateRow = _aRow; }
258 void setAssignValues(const ORefAssignValues& _aAssignValues) { m_aAssignValues = _aAssignValues; }
259 void setBindingRow(const OValueRefRow& _aRow) { m_aRow = _aRow; }
260 void setSelectRow(const OValueRefRow& _rRow)
261 {
262 m_aSelectRow = _rRow;
263 m_nColumnCount = m_aSelectRow->size();
264 }
265 void setColumnMapping(std::vector<sal_Int32>&& _aColumnMapping) { m_aColMapping = std::move(_aColumnMapping); }
266 void setSqlAnalyzer(OSQLAnalyzer* _pSQLAnalyzer) { m_pSQLAnalyzer = _pSQLAnalyzer; }
267
268 void setOrderByColumns(std::vector<sal_Int32>&& _aColumnOrderBy) { m_aOrderbyColumnNumber = std::move(_aColumnOrderBy); }
269 void setOrderByAscending(std::vector<TAscendingOrder>&& _aOrderbyAsc) { m_aOrderbyAscending = std::move(_aOrderbyAsc); }
270 void setMetaData(const css::uno::Reference< css::sdbc::XResultSetMetaData>& _xMetaData) { m_xMetaData = _xMetaData;}
271
272 static void setBoundedColumns(const OValueRefRow& _rRow,
273 const OValueRefRow& _rSelectRow,
274 const ::rtl::Reference<connectivity::OSQLColumns>& _rxColumns,
275 const css::uno::Reference< css::container::XIndexAccess>& _xNames,
276 bool _bSetColumnMapping,
277 const css::uno::Reference< css::sdbc::XDatabaseMetaData>& _xMetaData,
278 std::vector<sal_Int32>& _rColMapping);
279
280 // IResultSetHelper
281 virtual bool move(IResultSetHelper::Movement _eCursorPosition, sal_Int32 _nOffset, bool _bRetrieveData) override;
282 virtual sal_Int32 getDriverPos() const override;
283 virtual bool isRowDeleted() const override;
284 };
285
286 inline sal_Int32 OResultSet::mapColumn(sal_Int32 column)
287 {
288 sal_Int32 map = column;
289
290 OSL_ENSURE(column > 0, "file::OResultSet::mapColumn: invalid column index!");
291 // the first column (index 0) is for convenience only. The first real select column is number 1.
292 if ((column > 0) && (o3tl::make_unsigned(column) < m_aColMapping.size()))
293 map = m_aColMapping[column];
294
295 return map;
296 }
297
298}
299
300
301/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
the class OSkipDeletedSet supports a general method to skip deleted rows
void setBindingRow(const OValueRefRow &_aRow)
Definition: FResultSet.hxx:259
void setSelectRow(const OValueRefRow &_rRow)
Definition: FResultSet.hxx:260
std::vector< sal_Int32 > m_aColMapping
Definition: FResultSet.hxx:68
::rtl::Reference< connectivity::OSQLColumns > m_xColumns
Definition: FResultSet.hxx:86
css::uno::Reference< css::sdbc::XResultSetMetaData > m_xMetaData
Definition: FResultSet.hxx:99
void setAssignValues(const ORefAssignValues &_aAssignValues)
Definition: FResultSet.hxx:258
void setSqlAnalyzer(OSQLAnalyzer *_pSQLAnalyzer)
Definition: FResultSet.hxx:266
css::uno::Reference< css::uno::XInterface > m_xStatement
Definition: FResultSet.hxx:98
rtl::Reference< OFileTable > m_pTable
Definition: FResultSet.hxx:87
std::vector< TAscendingOrder > m_aOrderbyAscending
Definition: FResultSet.hxx:71
connectivity::OSQLParseTreeIterator & m_aSQLIterator
Definition: FResultSet.hxx:91
void setColumnMapping(std::vector< sal_Int32 > &&_aColumnMapping)
Definition: FResultSet.hxx:265
void setEvaluationRow(const OValueRefRow &_aRow)
Definition: FResultSet.hxx:257
OKeySet::iterator m_aFileSetIter
Definition: FResultSet.hxx:82
connectivity::OSQLParseNode * m_pParseTree
Definition: FResultSet.hxx:88
::rtl::Reference< OKeySet > m_pFileSet
Definition: FResultSet.hxx:81
ORefAssignValues m_aAssignValues
Definition: FResultSet.hxx:77
sal_Int32 mapColumn(sal_Int32 column)
Definition: FResultSet.hxx:286
std::unique_ptr< OSortIndex > m_pSortIndex
Definition: FResultSet.hxx:85
void setOrderByAscending(std::vector< TAscendingOrder > &&_aOrderbyAsc)
Definition: FResultSet.hxx:269
css::uno::Reference< css::container::XNameAccess > m_xColNames
Definition: FResultSet.hxx:100
std::vector< sal_Int32 > m_aOrderbyColumnNumber
Definition: FResultSet.hxx:70
css::uno::Reference< css::container::XIndexAccess > m_xColsIdx
Definition: FResultSet.hxx:101
void setOrderByColumns(std::vector< sal_Int32 > &&_aColumnOrderBy)
Definition: FResultSet.hxx:268
OSkipDeletedSet m_aSkipDeletedSet
Definition: FResultSet.hxx:79
void setMetaData(const css::uno::Reference< css::sdbc::XResultSetMetaData > &_xMetaData)
Definition: FResultSet.hxx:270
#define OOO_DLLPUBLIC_FILE
Definition: filedllapi.hxx:29
Type
static bool getValue(EContact *pContact, sal_Int32 nColumnNum, GType nType, GValue *pStackValue, bool &_out_rWasNull)
Definition: NResultSet.cxx:243
::cppu::WeakComponentImplHelper< css::sdbc::XResultSet, css::sdbc::XRow, css::sdbc::XResultSetMetaDataSupplier, css::util::XCancellable, css::sdbc::XWarningsSupplier, css::sdbc::XResultSetUpdate, css::sdbc::XRowUpdate, css::sdbc::XCloseable, css::sdbc::XColumnLocate, css::lang::XServiceInfo, css::lang::XEventListener > OResultSet_BASE
Definition: FResultSet.hxx:57
css::uno::Reference< css::sdbcx::XColumnsSupplier > OSQLTable
Definition: CommonTools.hxx:54
constexpr std::enable_if_t< std::is_signed_v< T >, std::make_unsigned_t< T > > make_unsigned(T value)
sal_Int32 scale
Definition: pq_statics.cxx:62
const char * columnName
Definition: pq_statics.cxx:56
std::map< OUString, rtl::Reference< Entity > > map
unsigned char sal_Bool
signed char sal_Int8