cid#1607171 Data race condition
[LibreOffice.git] / connectivity / source / inc / file / FResultSet.hxx
blobb4c1786fd2d5310302d1334ade3576df71953729
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/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>
31 #include <cppuhelper/compbase.hxx>
32 #include <cppuhelper/basemutex.hxx>
33 #include <comphelper/proparrhlp.hxx>
34 #include <file/FStatement.hxx>
35 #include <connectivity/CommonTools.hxx>
36 #include <comphelper/propertycontainer.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 #include "FResultSetMetaData.hxx"
46 namespace connectivity::file
48 class OResultSetMetaData;
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::sdbc::XCloseable,
58 css::sdbc::XColumnLocate,
59 css::lang::XServiceInfo,
60 css::lang::XEventListener> OResultSet_BASE;
62 class UNLESS_MERGELIBS_MORE(OOO_DLLPUBLIC_FILE) OResultSet :
63 public cppu::BaseMutex,
64 public ::connectivity::IResultSetHelper,
65 public OResultSet_BASE,
66 public ::comphelper::OPropertyContainer,
67 public ::comphelper::OPropertyArrayUsageHelper<OResultSet>
70 protected:
71 std::vector<sal_Int32> m_aColMapping; // pos 0 is unused so we don't have to decrement 1 every time
73 std::vector<sal_Int32> m_aOrderbyColumnNumber;
74 std::vector<TAscendingOrder> m_aOrderbyAscending;
76 OValueRefRow m_aSelectRow;
77 OValueRefRow m_aRow;
78 OValueRefRow m_aEvaluateRow; // contains all values of a row
79 OValueRefRow m_aInsertRow; // needed for insert by cursor
80 ORefAssignValues m_aAssignValues; // needed for insert,update and parameters
81 // to compare with the restrictions
82 OSkipDeletedSet m_aSkipDeletedSet;
84 ::rtl::Reference<OKeySet> m_pFileSet;
85 OKeySet::iterator m_aFileSetIter;
88 std::unique_ptr<OSortIndex> m_pSortIndex;
89 ::rtl::Reference<connectivity::OSQLColumns> m_xColumns; // this are the select columns
90 rtl::Reference<OFileTable> m_pTable;
91 connectivity::OSQLParseNode* m_pParseTree;
93 OSQLAnalyzer* m_pSQLAnalyzer;
94 connectivity::OSQLParseTreeIterator& m_aSQLIterator;
96 sal_Int32 m_nFetchSize;
97 sal_Int32 m_nResultSetType;
98 sal_Int32 m_nFetchDirection;
99 sal_Int32 m_nResultSetConcurrency;
101 css::uno::Reference< css::uno::XInterface> m_xStatement;
102 rtl::Reference< OResultSetMetaData> m_xMetaData;
103 css::uno::Reference< css::container::XNameAccess> m_xColNames; // table columns
104 css::uno::Reference< css::container::XIndexAccess> m_xColsIdx; // table columns
107 sal_Int32 m_nRowPos;
108 sal_Int32 m_nFilePos;
109 sal_Int32 m_nLastVisitedPos;
110 sal_Int32 m_nRowCountResult;
111 sal_Int32 m_nColumnCount;
112 bool m_bWasNull;
113 bool m_bInserted; // true when moveToInsertRow was called
114 // set to false when cursor moved or cancel
115 bool m_bRowUpdated;
116 bool m_bRowInserted;
117 bool m_bRowDeleted;
118 bool m_bShowDeleted;
119 bool m_bIsCount;
121 static void initializeRow(OValueRefRow& _rRow,sal_Int32 _nColumnCount);
122 void construct();
123 //sal_Bool evaluate();
125 bool ExecuteRow(IResultSetHelper::Movement eFirstCursorPosition,
126 sal_Int32 nOffset = 1,
127 bool bEvaluate = true,
128 bool bRetrieveData = true);
130 std::unique_ptr<OKeyValue> GetOrderbyKeyValue(OValueRefRow const & _rRow);
131 bool IsSorted() const { return !m_aOrderbyColumnNumber.empty() && m_aOrderbyColumnNumber[0] >= 0;}
133 // return true when the select statement is "select count(*) from table"
134 bool isCount() const { return m_bIsCount; }
135 /// @throws css::sdbc::SQLException
136 void checkIndex(sal_Int32 columnIndex );
138 /// @throws css::sdbc::SQLException
139 /// @throws css::uno::RuntimeException
140 const ORowSetValue& getValue(sal_Int32 columnIndex);
141 /// @throws css::sdbc::SQLException
142 /// @throws css::uno::RuntimeException
143 void updateValue(sal_Int32 columnIndex,const ORowSetValue& x );
144 // clear insert row
145 void clearInsertRow();
146 void sortRows();
147 protected:
149 using OResultSet_BASE::rBHelper;
151 bool Move(IResultSetHelper::Movement eCursorPosition, sal_Int32 nOffset, bool bRetrieveData);
152 virtual bool fillIndexValues(const css::uno::Reference< css::sdbcx::XColumnsSupplier> &_xIndex);
154 // OPropertyArrayUsageHelper
155 virtual ::cppu::IPropertyArrayHelper* createArrayHelper( ) const override;
156 // OPropertySetHelper
157 virtual ::cppu::IPropertyArrayHelper & SAL_CALL getInfoHelper() override;
159 virtual ~OResultSet() override;
160 public:
161 DECLARE_SERVICE_INFO();
162 // a Constructor, that is needed for when Returning the Object is needed:
163 OResultSet( OStatement_Base* pStmt,connectivity::OSQLParseTreeIterator& _aSQLIterator);
165 // ::cppu::OComponentHelper
166 virtual void SAL_CALL disposing() override final;
167 // XInterface
168 virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & rType ) override;
169 virtual void SAL_CALL acquire() noexcept override;
170 virtual void SAL_CALL release() noexcept override;
171 //XTypeProvider
172 virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes( ) override;
173 // XPropertySet
174 virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo( ) override;
175 // XResultSet
176 virtual sal_Bool SAL_CALL next( ) override;
177 virtual sal_Bool SAL_CALL isBeforeFirst( ) override;
178 virtual sal_Bool SAL_CALL isAfterLast( ) override;
179 virtual sal_Bool SAL_CALL isFirst( ) override;
180 virtual sal_Bool SAL_CALL isLast( ) override;
181 virtual void SAL_CALL beforeFirst( ) override;
182 virtual void SAL_CALL afterLast( ) override;
183 virtual sal_Bool SAL_CALL first( ) override;
184 virtual sal_Bool SAL_CALL last( ) override;
185 virtual sal_Int32 SAL_CALL getRow( ) override;
186 virtual sal_Bool SAL_CALL absolute( sal_Int32 row ) override;
187 virtual sal_Bool SAL_CALL relative( sal_Int32 rows ) override;
188 virtual sal_Bool SAL_CALL previous( ) override;
189 virtual void SAL_CALL refreshRow( ) override;
190 virtual sal_Bool SAL_CALL rowUpdated( ) override;
191 virtual sal_Bool SAL_CALL rowInserted( ) override;
192 virtual sal_Bool SAL_CALL rowDeleted( ) override;
193 virtual css::uno::Reference< css::uno::XInterface > SAL_CALL getStatement( ) override;
194 // XRow
195 virtual sal_Bool SAL_CALL wasNull( ) override;
196 virtual OUString SAL_CALL getString( sal_Int32 columnIndex ) override;
197 virtual sal_Bool SAL_CALL getBoolean( sal_Int32 columnIndex ) override;
198 virtual sal_Int8 SAL_CALL getByte( sal_Int32 columnIndex ) override;
199 virtual sal_Int16 SAL_CALL getShort( sal_Int32 columnIndex ) override;
200 virtual sal_Int32 SAL_CALL getInt( sal_Int32 columnIndex ) override;
201 virtual sal_Int64 SAL_CALL getLong( sal_Int32 columnIndex ) override;
202 virtual float SAL_CALL getFloat( sal_Int32 columnIndex ) override;
203 virtual double SAL_CALL getDouble( sal_Int32 columnIndex ) override;
204 virtual css::uno::Sequence< sal_Int8 > SAL_CALL getBytes( sal_Int32 columnIndex ) override;
205 virtual css::util::Date SAL_CALL getDate( sal_Int32 columnIndex ) override;
206 virtual css::util::Time SAL_CALL getTime( sal_Int32 columnIndex ) override;
207 virtual css::util::DateTime SAL_CALL getTimestamp( sal_Int32 columnIndex ) override;
208 virtual css::uno::Reference< css::io::XInputStream > SAL_CALL getBinaryStream( sal_Int32 columnIndex ) override;
209 virtual css::uno::Reference< css::io::XInputStream > SAL_CALL getCharacterStream( sal_Int32 columnIndex ) override;
210 virtual css::uno::Any SAL_CALL getObject( sal_Int32 columnIndex, const css::uno::Reference< css::container::XNameAccess >& typeMap ) override;
211 virtual css::uno::Reference< css::sdbc::XRef > SAL_CALL getRef( sal_Int32 columnIndex ) override;
212 virtual css::uno::Reference< css::sdbc::XBlob > SAL_CALL getBlob( sal_Int32 columnIndex ) override;
213 virtual css::uno::Reference< css::sdbc::XClob > SAL_CALL getClob( sal_Int32 columnIndex ) override;
214 virtual css::uno::Reference< css::sdbc::XArray > SAL_CALL getArray( sal_Int32 columnIndex ) override;
215 // XResultSetMetaDataSupplier
216 virtual css::uno::Reference< css::sdbc::XResultSetMetaData > SAL_CALL getMetaData( ) override;
217 // XCancellable
218 virtual void SAL_CALL cancel( ) override;
219 // XCloseable
220 virtual void SAL_CALL close( ) override;
221 // XWarningsSupplier
222 virtual css::uno::Any SAL_CALL getWarnings( ) override;
223 virtual void SAL_CALL clearWarnings( ) override;
224 // XResultSetUpdate
225 virtual void SAL_CALL insertRow( ) override;
226 virtual void SAL_CALL updateRow( ) override;
227 virtual void SAL_CALL deleteRow( ) override;
228 virtual void SAL_CALL cancelRowUpdates( ) override;
229 virtual void SAL_CALL moveToInsertRow( ) override;
230 virtual void SAL_CALL moveToCurrentRow( ) override;
231 // XRowUpdate
232 virtual void SAL_CALL updateNull( sal_Int32 columnIndex ) override;
233 virtual void SAL_CALL updateBoolean( sal_Int32 columnIndex, sal_Bool x ) override;
234 virtual void SAL_CALL updateByte( sal_Int32 columnIndex, sal_Int8 x ) override;
235 virtual void SAL_CALL updateShort( sal_Int32 columnIndex, sal_Int16 x ) override;
236 virtual void SAL_CALL updateInt( sal_Int32 columnIndex, sal_Int32 x ) override;
237 virtual void SAL_CALL updateLong( sal_Int32 columnIndex, sal_Int64 x ) override;
238 virtual void SAL_CALL updateFloat( sal_Int32 columnIndex, float x ) override;
239 virtual void SAL_CALL updateDouble( sal_Int32 columnIndex, double x ) override;
240 virtual void SAL_CALL updateString( sal_Int32 columnIndex, const OUString& x ) override;
241 virtual void SAL_CALL updateBytes( sal_Int32 columnIndex, const css::uno::Sequence< sal_Int8 >& x ) override;
242 virtual void SAL_CALL updateDate( sal_Int32 columnIndex, const css::util::Date& x ) override;
243 virtual void SAL_CALL updateTime( sal_Int32 columnIndex, const css::util::Time& x ) override;
244 virtual void SAL_CALL updateTimestamp( sal_Int32 columnIndex, const css::util::DateTime& x ) override;
245 virtual void SAL_CALL updateBinaryStream( sal_Int32 columnIndex, const css::uno::Reference< css::io::XInputStream >& x, sal_Int32 length ) override;
246 virtual void SAL_CALL updateCharacterStream( sal_Int32 columnIndex, const css::uno::Reference< css::io::XInputStream >& x, sal_Int32 length ) override;
247 virtual void SAL_CALL updateObject( sal_Int32 columnIndex, const css::uno::Any& x ) override;
248 virtual void SAL_CALL updateNumericObject( sal_Int32 columnIndex, const css::uno::Any& x, sal_Int32 scale ) override;
249 // XColumnLocate
250 virtual sal_Int32 SAL_CALL findColumn( const OUString& columnName ) override;
251 //XEventlistener
252 virtual void SAL_CALL disposing( const css::lang::EventObject& Source ) override;
254 // special methods
255 inline sal_Int32 mapColumn(sal_Int32 column);
256 void OpenImpl();
257 void doTableSpecials(const OSQLTable& _xTable);
259 sal_Int32 getRowCountResult() const { return m_nRowCountResult; }
260 void setEvaluationRow(const OValueRefRow& _aRow) { m_aEvaluateRow = _aRow; }
261 void setAssignValues(const ORefAssignValues& _aAssignValues) { m_aAssignValues = _aAssignValues; }
262 void setBindingRow(const OValueRefRow& _aRow) { m_aRow = _aRow; }
263 void setSelectRow(const OValueRefRow& _rRow)
265 m_aSelectRow = _rRow;
266 m_nColumnCount = m_aSelectRow->size();
268 void setColumnMapping(std::vector<sal_Int32>&& _aColumnMapping) { m_aColMapping = std::move(_aColumnMapping); }
269 void setSqlAnalyzer(OSQLAnalyzer* _pSQLAnalyzer) { m_pSQLAnalyzer = _pSQLAnalyzer; }
271 void setOrderByColumns(std::vector<sal_Int32>&& _aColumnOrderBy) { m_aOrderbyColumnNumber = std::move(_aColumnOrderBy); }
272 void setOrderByAscending(std::vector<TAscendingOrder>&& _aOrderbyAsc) { m_aOrderbyAscending = std::move(_aOrderbyAsc); }
273 void setMetaData(const rtl::Reference< OResultSetMetaData>& _xMetaData) { m_xMetaData = _xMetaData;}
275 static void setBoundedColumns(const OValueRefRow& _rRow,
276 const OValueRefRow& _rSelectRow,
277 const ::rtl::Reference<connectivity::OSQLColumns>& _rxColumns,
278 const css::uno::Reference< css::container::XIndexAccess>& _xNames,
279 bool _bSetColumnMapping,
280 const css::uno::Reference< css::sdbc::XDatabaseMetaData>& _xMetaData,
281 std::vector<sal_Int32>& _rColMapping);
283 // IResultSetHelper
284 virtual bool move(IResultSetHelper::Movement _eCursorPosition, sal_Int32 _nOffset, bool _bRetrieveData) override;
285 virtual sal_Int32 getDriverPos() const override;
286 virtual bool isRowDeleted() const override;
289 inline sal_Int32 OResultSet::mapColumn(sal_Int32 column)
291 sal_Int32 map = column;
293 OSL_ENSURE(column > 0, "file::OResultSet::mapColumn: invalid column index!");
294 // the first column (index 0) is for convenience only. The first real select column is number 1.
295 if ((column > 0) && (o3tl::make_unsigned(column) < m_aColMapping.size()))
296 map = m_aColMapping[column];
298 return map;
304 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */