/src/libreoffice/connectivity/source/drivers/file/FResultSet.cxx
Line | Count | Source |
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 | | |
21 | | #include <file/FResultSet.hxx> |
22 | | #include <sqlbison.hxx> |
23 | | #include <file/FResultSetMetaData.hxx> |
24 | | #include <com/sun/star/sdbc/DataType.hpp> |
25 | | #include <com/sun/star/beans/PropertyAttribute.hpp> |
26 | | #include <com/sun/star/container/XIndexAccess.hpp> |
27 | | #include <comphelper/sequence.hxx> |
28 | | #include <cppuhelper/typeprovider.hxx> |
29 | | #include <connectivity/dbtools.hxx> |
30 | | #include <cppuhelper/propshlp.hxx> |
31 | | #include <o3tl/safeint.hxx> |
32 | | #include <sal/log.hxx> |
33 | | #include <iterator> |
34 | | #include <com/sun/star/sdbc/ResultSetType.hpp> |
35 | | #include <com/sun/star/sdbc/FetchDirection.hpp> |
36 | | #include <com/sun/star/sdbc/ResultSetConcurrency.hpp> |
37 | | #include <com/sun/star/sdbcx/XIndexesSupplier.hpp> |
38 | | |
39 | | #include <algorithm> |
40 | | #include <connectivity/dbexception.hxx> |
41 | | #include <comphelper/types.hxx> |
42 | | #include <resource/sharedresources.hxx> |
43 | | #include <strings.hrc> |
44 | | #include <comphelper/diagnose_ex.hxx> |
45 | | |
46 | | using namespace ::comphelper; |
47 | | using namespace connectivity; |
48 | | using namespace connectivity::file; |
49 | | using namespace ::cppu; |
50 | | using namespace dbtools; |
51 | | using namespace com::sun::star::uno; |
52 | | using namespace com::sun::star::lang; |
53 | | using namespace com::sun::star::beans; |
54 | | using namespace com::sun::star::sdbc; |
55 | | using namespace com::sun::star::sdbcx; |
56 | | using namespace com::sun::star::container; |
57 | | |
58 | | namespace |
59 | | { |
60 | | void lcl_throwError(TranslateId pErrorId, const css::uno::Reference< css::uno::XInterface>& _xContext) |
61 | 0 | { |
62 | 0 | ::connectivity::SharedResources aResources; |
63 | 0 | const OUString sMessage = aResources.getResourceString(pErrorId); |
64 | 0 | ::dbtools::throwGenericSQLException(sMessage ,_xContext); |
65 | 0 | } |
66 | | } |
67 | | |
68 | | IMPLEMENT_SERVICE_INFO(OResultSet,u"com.sun.star.sdbcx.drivers.file.ResultSet"_ustr,u"com.sun.star.sdbc.ResultSet"_ustr); |
69 | | |
70 | 19.1k | OResultSet::OResultSet(OStatement_Base* pStmt,OSQLParseTreeIterator& _aSQLIterator) : OResultSet_BASE(m_aMutex) |
71 | 19.1k | ,::comphelper::OPropertyContainer(OResultSet_BASE::rBHelper) |
72 | 19.1k | ,m_aSkipDeletedSet(this) |
73 | 19.1k | ,m_pParseTree(pStmt->getParseTree()) |
74 | 19.1k | ,m_pSQLAnalyzer(nullptr) |
75 | 19.1k | ,m_aSQLIterator(_aSQLIterator) |
76 | 19.1k | ,m_nFetchSize(0) |
77 | 19.1k | ,m_nResultSetType(ResultSetType::SCROLL_INSENSITIVE) |
78 | 19.1k | ,m_nFetchDirection(FetchDirection::FORWARD) |
79 | 19.1k | ,m_nResultSetConcurrency(ResultSetConcurrency::UPDATABLE) |
80 | 19.1k | ,m_xStatement(*pStmt) |
81 | 19.1k | ,m_nRowPos(-1) |
82 | 19.1k | ,m_nFilePos(0) |
83 | 19.1k | ,m_nLastVisitedPos(-1) |
84 | 19.1k | ,m_nRowCountResult(-1) |
85 | 19.1k | ,m_nColumnCount(0) |
86 | 19.1k | ,m_bWasNull(false) |
87 | 19.1k | ,m_bInserted(false) |
88 | 19.1k | ,m_bRowUpdated(false) |
89 | 19.1k | ,m_bRowInserted(false) |
90 | 19.1k | ,m_bRowDeleted(false) |
91 | 19.1k | ,m_bShowDeleted(pStmt->getOwnConnection()->showDeleted()) |
92 | 19.1k | ,m_bIsCount(false) |
93 | 19.1k | { |
94 | 19.1k | osl_atomic_increment( &m_refCount ); |
95 | 19.1k | m_bIsCount = (m_pParseTree && |
96 | 19.1k | m_pParseTree->count() > 2 && |
97 | 19.1k | SQL_ISRULE(m_pParseTree->getChild(2),scalar_exp_commalist) && |
98 | 0 | SQL_ISRULE(m_pParseTree->getChild(2)->getChild(0),derived_column) && |
99 | 0 | SQL_ISRULE(m_pParseTree->getChild(2)->getChild(0)->getChild(0),general_set_fct) && |
100 | 0 | m_pParseTree->getChild(2)->getChild(0)->getChild(0)->count() == 4 |
101 | 19.1k | ); |
102 | | |
103 | 19.1k | m_nResultSetConcurrency = isCount() ? ResultSetConcurrency::READ_ONLY : ResultSetConcurrency::UPDATABLE; |
104 | 19.1k | construct(); |
105 | 19.1k | m_aSkipDeletedSet.SetDeletedVisible(m_bShowDeleted); |
106 | 19.1k | osl_atomic_decrement( &m_refCount ); |
107 | 19.1k | } |
108 | | |
109 | | |
110 | | OResultSet::~OResultSet() |
111 | 19.1k | { |
112 | 19.1k | osl_atomic_increment( &m_refCount ); |
113 | 19.1k | disposing(); |
114 | 19.1k | } |
115 | | |
116 | | void OResultSet::construct() |
117 | 19.1k | { |
118 | 19.1k | registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_FETCHSIZE), PROPERTY_ID_FETCHSIZE, 0,&m_nFetchSize, ::cppu::UnoType<sal_Int32>::get()); |
119 | 19.1k | registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_RESULTSETTYPE), PROPERTY_ID_RESULTSETTYPE, PropertyAttribute::READONLY,&m_nResultSetType, ::cppu::UnoType<sal_Int32>::get()); |
120 | 19.1k | registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_FETCHDIRECTION), PROPERTY_ID_FETCHDIRECTION, 0,&m_nFetchDirection, ::cppu::UnoType<sal_Int32>::get()); |
121 | 19.1k | registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_RESULTSETCONCURRENCY), PROPERTY_ID_RESULTSETCONCURRENCY,PropertyAttribute::READONLY,&m_nResultSetConcurrency, ::cppu::UnoType<sal_Int32>::get()); |
122 | 19.1k | } |
123 | | |
124 | | void OResultSet::disposing() |
125 | 38.2k | { |
126 | 38.2k | OPropertySetHelper::disposing(); |
127 | | |
128 | 38.2k | ::osl::MutexGuard aGuard(m_aMutex); |
129 | 38.2k | m_xStatement.clear(); |
130 | 38.2k | m_xMetaData.clear(); |
131 | 38.2k | m_pParseTree = nullptr; |
132 | 38.2k | m_xColNames.clear(); |
133 | 38.2k | m_xColumns = nullptr; |
134 | 38.2k | m_xColsIdx.clear(); |
135 | | |
136 | 38.2k | if ( m_pTable.is() ) |
137 | 19.1k | m_pTable->removeEventListener(this); |
138 | 38.2k | m_pTable.clear(); |
139 | | |
140 | 38.2k | m_pFileSet = nullptr; |
141 | 38.2k | m_pSortIndex.reset(); |
142 | | |
143 | 38.2k | if(m_aInsertRow.is()) |
144 | 38.2k | m_aInsertRow->clear(); |
145 | | |
146 | 38.2k | m_aSkipDeletedSet.clear(); |
147 | 38.2k | } |
148 | | |
149 | | Any SAL_CALL OResultSet::queryInterface( const Type & rType ) |
150 | 95.5k | { |
151 | 95.5k | Any aRet = OPropertySetHelper::queryInterface(rType); |
152 | 95.5k | return aRet.hasValue() ? aRet : OResultSet_BASE::queryInterface(rType); |
153 | 95.5k | } |
154 | | |
155 | | Sequence< Type > SAL_CALL OResultSet::getTypes( ) |
156 | 0 | { |
157 | 0 | ::osl::MutexGuard aGuard( m_aMutex ); |
158 | |
|
159 | 0 | OTypeCollection aTypes( cppu::UnoType<css::beans::XMultiPropertySet>::get(), |
160 | 0 | cppu::UnoType<css::beans::XPropertySet>::get(), |
161 | 0 | cppu::UnoType<css::beans::XPropertySet>::get()); |
162 | |
|
163 | 0 | return ::comphelper::concatSequences(aTypes.getTypes(),OResultSet_BASE::getTypes()); |
164 | 0 | } |
165 | | |
166 | | |
167 | | sal_Int32 SAL_CALL OResultSet::findColumn( const OUString& columnName ) |
168 | 0 | { |
169 | 0 | ::osl::MutexGuard aGuard( m_aMutex ); |
170 | 0 | checkDisposed(OResultSet_BASE::rBHelper.bDisposed); |
171 | | |
172 | |
|
173 | 0 | Reference< XResultSetMetaData > xMeta = getMetaData(); |
174 | 0 | sal_Int32 nLen = xMeta->getColumnCount(); |
175 | 0 | sal_Int32 i = 1; |
176 | 0 | for(;i<=nLen;++i) |
177 | 0 | { |
178 | 0 | if(xMeta->isCaseSensitive(i) ? columnName == xMeta->getColumnName(i) : |
179 | 0 | columnName.equalsIgnoreAsciiCase(xMeta->getColumnName(i))) |
180 | 0 | return i; |
181 | 0 | } |
182 | | |
183 | 0 | ::dbtools::throwInvalidColumnException( columnName, *this ); |
184 | 0 | } |
185 | | |
186 | | const ORowSetValue& OResultSet::getValue(sal_Int32 columnIndex) |
187 | 9.46M | { |
188 | 9.46M | ::osl::MutexGuard aGuard( m_aMutex ); |
189 | 9.46M | checkDisposed(OResultSet_BASE::rBHelper.bDisposed); |
190 | | |
191 | 9.46M | checkIndex(columnIndex ); |
192 | | |
193 | | |
194 | 9.46M | m_bWasNull = (*m_aSelectRow)[columnIndex]->getValue().isNull(); |
195 | 9.46M | return *(*m_aSelectRow)[columnIndex]; |
196 | 9.46M | } |
197 | | |
198 | | void OResultSet::checkIndex(sal_Int32 columnIndex ) |
199 | 9.46M | { |
200 | 9.46M | if ( columnIndex <= 0 |
201 | 9.46M | || columnIndex >= m_nColumnCount ) |
202 | 0 | ::dbtools::throwInvalidIndexException(*this); |
203 | 9.46M | } |
204 | | |
205 | | Reference< css::io::XInputStream > SAL_CALL OResultSet::getBinaryStream( sal_Int32 /*columnIndex*/ ) |
206 | 0 | { |
207 | 0 | return nullptr; |
208 | 0 | } |
209 | | |
210 | | Reference< css::io::XInputStream > SAL_CALL OResultSet::getCharacterStream( sal_Int32 /*columnIndex*/ ) |
211 | 0 | { |
212 | 0 | return nullptr; |
213 | 0 | } |
214 | | |
215 | | |
216 | | sal_Bool SAL_CALL OResultSet::getBoolean( sal_Int32 columnIndex ) |
217 | 293k | { |
218 | 293k | return getValue(columnIndex).getBool(); |
219 | 293k | } |
220 | | |
221 | | |
222 | | sal_Int8 SAL_CALL OResultSet::getByte( sal_Int32 columnIndex ) |
223 | 0 | { |
224 | 0 | return getValue(columnIndex).getInt8(); |
225 | 0 | } |
226 | | |
227 | | |
228 | | Sequence< sal_Int8 > SAL_CALL OResultSet::getBytes( sal_Int32 columnIndex ) |
229 | 275k | { |
230 | 275k | return getValue(columnIndex).getSequence(); |
231 | 275k | } |
232 | | |
233 | | |
234 | | css::util::Date SAL_CALL OResultSet::getDate( sal_Int32 columnIndex ) |
235 | 207k | { |
236 | 207k | return getValue(columnIndex).getDate(); |
237 | 207k | } |
238 | | |
239 | | |
240 | | double SAL_CALL OResultSet::getDouble( sal_Int32 columnIndex ) |
241 | 562k | { |
242 | 562k | return getValue(columnIndex).getDouble(); |
243 | 562k | } |
244 | | |
245 | | |
246 | | float SAL_CALL OResultSet::getFloat( sal_Int32 columnIndex ) |
247 | 0 | { |
248 | 0 | return getValue(columnIndex).getFloat(); |
249 | 0 | } |
250 | | |
251 | | |
252 | | sal_Int32 SAL_CALL OResultSet::getInt( sal_Int32 columnIndex ) |
253 | 85.7k | { |
254 | 85.7k | return getValue(columnIndex).getInt32(); |
255 | 85.7k | } |
256 | | |
257 | | |
258 | | sal_Int32 SAL_CALL OResultSet::getRow( ) |
259 | 4.66k | { |
260 | 4.66k | ::osl::MutexGuard aGuard( m_aMutex ); |
261 | 4.66k | checkDisposed(OResultSet_BASE::rBHelper.bDisposed); |
262 | | |
263 | 4.66k | OSL_ENSURE((m_bShowDeleted || !m_aRow->isDeleted()),"getRow called for deleted row"); |
264 | | |
265 | 4.66k | return m_aSkipDeletedSet.getMappedPosition((*m_aRow)[0]->getValue().getInt32()); |
266 | 4.66k | } |
267 | | |
268 | | |
269 | | sal_Int64 SAL_CALL OResultSet::getLong( sal_Int32 columnIndex ) |
270 | 0 | { |
271 | 0 | return getValue(columnIndex).getLong(); |
272 | 0 | } |
273 | | |
274 | | |
275 | | Reference< XResultSetMetaData > SAL_CALL OResultSet::getMetaData( ) |
276 | 28.6k | { |
277 | 28.6k | ::osl::MutexGuard aGuard( m_aMutex ); |
278 | 28.6k | checkDisposed(OResultSet_BASE::rBHelper.bDisposed); |
279 | | |
280 | | |
281 | 28.6k | if(!m_xMetaData.is()) |
282 | 9.55k | m_xMetaData = new OResultSetMetaData(m_xColumns,m_aSQLIterator.getTables().begin()->first,m_pTable.get()); |
283 | 28.6k | return m_xMetaData; |
284 | 28.6k | } |
285 | | |
286 | | Reference< XArray > SAL_CALL OResultSet::getArray( sal_Int32 /*columnIndex*/ ) |
287 | 0 | { |
288 | 0 | return nullptr; |
289 | 0 | } |
290 | | |
291 | | |
292 | | Reference< XClob > SAL_CALL OResultSet::getClob( sal_Int32 /*columnIndex*/ ) |
293 | 0 | { |
294 | 0 | return nullptr; |
295 | 0 | } |
296 | | |
297 | | Reference< XBlob > SAL_CALL OResultSet::getBlob( sal_Int32 /*columnIndex*/ ) |
298 | 0 | { |
299 | 0 | return nullptr; |
300 | 0 | } |
301 | | |
302 | | |
303 | | Reference< XRef > SAL_CALL OResultSet::getRef( sal_Int32 /*columnIndex*/ ) |
304 | 0 | { |
305 | 0 | return nullptr; |
306 | 0 | } |
307 | | |
308 | | |
309 | | Any SAL_CALL OResultSet::getObject( sal_Int32 columnIndex, const Reference< css::container::XNameAccess >& /*typeMap*/ ) |
310 | 6.44M | { |
311 | 6.44M | return getValue(columnIndex).makeAny(); |
312 | 6.44M | } |
313 | | |
314 | | |
315 | | sal_Int16 SAL_CALL OResultSet::getShort( sal_Int32 columnIndex ) |
316 | 0 | { |
317 | 0 | return getValue(columnIndex).getInt16(); |
318 | 0 | } |
319 | | |
320 | | OUString SAL_CALL OResultSet::getString( sal_Int32 columnIndex ) |
321 | 1.42M | { |
322 | 1.42M | return getValue(columnIndex).getString(); |
323 | 1.42M | } |
324 | | |
325 | | css::util::Time SAL_CALL OResultSet::getTime( sal_Int32 columnIndex ) |
326 | 0 | { |
327 | 0 | return getValue(columnIndex).getTime(); |
328 | 0 | } |
329 | | |
330 | | css::util::DateTime SAL_CALL OResultSet::getTimestamp( sal_Int32 columnIndex ) |
331 | 179k | { |
332 | 179k | return getValue(columnIndex).getDateTime(); |
333 | 179k | } |
334 | | |
335 | | |
336 | | sal_Bool SAL_CALL OResultSet::isAfterLast( ) |
337 | 0 | { |
338 | 0 | ::osl::MutexGuard aGuard( m_aMutex ); |
339 | 0 | checkDisposed(OResultSet_BASE::rBHelper.bDisposed); |
340 | | |
341 | |
|
342 | 0 | return m_nRowPos == sal_Int32(m_pFileSet->size()); |
343 | 0 | } |
344 | | |
345 | | sal_Bool SAL_CALL OResultSet::isFirst( ) |
346 | 0 | { |
347 | 0 | ::osl::MutexGuard aGuard( m_aMutex ); |
348 | 0 | checkDisposed(OResultSet_BASE::rBHelper.bDisposed); |
349 | | |
350 | |
|
351 | 0 | return m_nRowPos == 0; |
352 | 0 | } |
353 | | |
354 | | sal_Bool SAL_CALL OResultSet::isLast( ) |
355 | 0 | { |
356 | 0 | ::osl::MutexGuard aGuard( m_aMutex ); |
357 | 0 | checkDisposed(OResultSet_BASE::rBHelper.bDisposed); |
358 | | |
359 | |
|
360 | 0 | return m_nRowPos == sal_Int32(m_pFileSet->size() - 1); |
361 | 0 | } |
362 | | |
363 | | void SAL_CALL OResultSet::beforeFirst( ) |
364 | 9.55k | { |
365 | 9.55k | ::osl::MutexGuard aGuard( m_aMutex ); |
366 | 9.55k | checkDisposed(OResultSet_BASE::rBHelper.bDisposed); |
367 | | |
368 | | |
369 | 9.55k | if(first()) |
370 | 7.21k | previous(); |
371 | 9.55k | } |
372 | | |
373 | | void SAL_CALL OResultSet::afterLast( ) |
374 | 0 | { |
375 | 0 | ::osl::MutexGuard aGuard( m_aMutex ); |
376 | 0 | checkDisposed(OResultSet_BASE::rBHelper.bDisposed); |
377 | | |
378 | |
|
379 | 0 | if(last()) |
380 | 0 | next(); |
381 | 0 | } |
382 | | |
383 | | |
384 | | void SAL_CALL OResultSet::close( ) |
385 | 0 | { |
386 | 0 | dispose(); |
387 | 0 | } |
388 | | |
389 | | |
390 | | sal_Bool SAL_CALL OResultSet::first( ) |
391 | 9.55k | { |
392 | 9.55k | ::osl::MutexGuard aGuard( m_aMutex ); |
393 | 9.55k | checkDisposed(OResultSet_BASE::rBHelper.bDisposed); |
394 | 9.55k | return m_pTable.is() && m_aSkipDeletedSet.skipDeleted(IResultSetHelper::FIRST,1,true); |
395 | 9.55k | } |
396 | | |
397 | | |
398 | | sal_Bool SAL_CALL OResultSet::last( ) |
399 | 0 | { |
400 | | // here I know definitely that I stand on the last record |
401 | 0 | ::osl::MutexGuard aGuard( m_aMutex ); |
402 | 0 | checkDisposed(OResultSet_BASE::rBHelper.bDisposed); |
403 | 0 | return m_pTable.is() && m_aSkipDeletedSet.skipDeleted(IResultSetHelper::LAST,1,true); |
404 | 0 | } |
405 | | |
406 | | sal_Bool SAL_CALL OResultSet::absolute( sal_Int32 row ) |
407 | 73.1k | { |
408 | 73.1k | ::osl::MutexGuard aGuard( m_aMutex ); |
409 | 73.1k | checkDisposed(OResultSet_BASE::rBHelper.bDisposed); |
410 | 73.1k | return m_pTable.is() && m_aSkipDeletedSet.skipDeleted(IResultSetHelper::ABSOLUTE1,row,true); |
411 | 73.1k | } |
412 | | |
413 | | sal_Bool SAL_CALL OResultSet::relative( sal_Int32 row ) |
414 | 0 | { |
415 | 0 | ::osl::MutexGuard aGuard( m_aMutex ); |
416 | 0 | checkDisposed(OResultSet_BASE::rBHelper.bDisposed); |
417 | 0 | return m_pTable.is() && m_aSkipDeletedSet.skipDeleted(IResultSetHelper::RELATIVE1,row,true); |
418 | 0 | } |
419 | | |
420 | | sal_Bool SAL_CALL OResultSet::previous( ) |
421 | 16.7k | { |
422 | 16.7k | ::osl::MutexGuard aGuard( m_aMutex ); |
423 | 16.7k | checkDisposed(OResultSet_BASE::rBHelper.bDisposed); |
424 | 16.7k | return m_pTable.is() && m_aSkipDeletedSet.skipDeleted(IResultSetHelper::PRIOR,0,true); |
425 | 16.7k | } |
426 | | |
427 | | Reference< XInterface > SAL_CALL OResultSet::getStatement( ) |
428 | 19.1k | { |
429 | 19.1k | ::osl::MutexGuard aGuard( m_aMutex ); |
430 | 19.1k | checkDisposed(OResultSet_BASE::rBHelper.bDisposed); |
431 | | |
432 | | |
433 | 19.1k | return m_xStatement; |
434 | 19.1k | } |
435 | | |
436 | | |
437 | | sal_Bool SAL_CALL OResultSet::rowDeleted( ) |
438 | 0 | { |
439 | 0 | ::osl::MutexGuard aGuard( m_aMutex ); |
440 | 0 | checkDisposed(OResultSet_BASE::rBHelper.bDisposed); |
441 | | |
442 | |
|
443 | 0 | return m_bRowDeleted; |
444 | 0 | } |
445 | | |
446 | | sal_Bool SAL_CALL OResultSet::rowInserted( ) |
447 | 0 | { ::osl::MutexGuard aGuard( m_aMutex ); |
448 | 0 | checkDisposed(OResultSet_BASE::rBHelper.bDisposed); |
449 | | |
450 | |
|
451 | 0 | return m_bRowInserted; |
452 | 0 | } |
453 | | |
454 | | sal_Bool SAL_CALL OResultSet::rowUpdated( ) |
455 | 0 | { |
456 | 0 | ::osl::MutexGuard aGuard( m_aMutex ); |
457 | 0 | checkDisposed(OResultSet_BASE::rBHelper.bDisposed); |
458 | | |
459 | |
|
460 | 0 | return m_bRowUpdated; |
461 | 0 | } |
462 | | |
463 | | |
464 | | sal_Bool SAL_CALL OResultSet::isBeforeFirst( ) |
465 | 0 | { |
466 | 0 | ::osl::MutexGuard aGuard( m_aMutex ); |
467 | 0 | checkDisposed(OResultSet_BASE::rBHelper.bDisposed); |
468 | | |
469 | |
|
470 | 0 | return m_nRowPos == -1; |
471 | 0 | } |
472 | | |
473 | | sal_Bool SAL_CALL OResultSet::next( ) |
474 | 1.67M | { |
475 | 1.67M | ::osl::MutexGuard aGuard( m_aMutex ); |
476 | 1.67M | checkDisposed(OResultSet_BASE::rBHelper.bDisposed); |
477 | | |
478 | 1.67M | return m_pTable.is() && m_aSkipDeletedSet.skipDeleted(IResultSetHelper::NEXT,1,true); |
479 | 1.67M | } |
480 | | |
481 | | |
482 | | sal_Bool SAL_CALL OResultSet::wasNull( ) |
483 | 9.46M | { |
484 | 9.46M | ::osl::MutexGuard aGuard( m_aMutex ); |
485 | 9.46M | checkDisposed(OResultSet_BASE::rBHelper.bDisposed); |
486 | | |
487 | 9.46M | return m_bWasNull; |
488 | 9.46M | } |
489 | | |
490 | | |
491 | | void SAL_CALL OResultSet::cancel( ) |
492 | 0 | { |
493 | 0 | } |
494 | | |
495 | | void SAL_CALL OResultSet::clearWarnings( ) |
496 | 0 | { |
497 | 0 | } |
498 | | |
499 | | Any SAL_CALL OResultSet::getWarnings( ) |
500 | 0 | { |
501 | 0 | return Any(); |
502 | 0 | } |
503 | | |
504 | | void SAL_CALL OResultSet::insertRow( ) |
505 | 0 | { |
506 | 0 | ::osl::MutexGuard aGuard( m_aMutex ); |
507 | 0 | checkDisposed(OResultSet_BASE::rBHelper.bDisposed); |
508 | | |
509 | |
|
510 | 0 | if(!m_bInserted || !m_pTable.is()) |
511 | 0 | throwFunctionSequenceException(*this); |
512 | | |
513 | | // we know that we append new rows at the end |
514 | | // so we have to know where the end is |
515 | 0 | (void)m_aSkipDeletedSet.skipDeleted(IResultSetHelper::LAST,1,false); |
516 | 0 | m_bRowInserted = m_pTable->InsertRow(*m_aInsertRow, m_xColsIdx); |
517 | 0 | if(m_bRowInserted && m_pFileSet.is()) |
518 | 0 | { |
519 | 0 | sal_Int32 nPos = (*m_aInsertRow)[0]->getValue().getInt32(); |
520 | 0 | m_pFileSet->push_back(nPos); |
521 | 0 | *(*m_aInsertRow)[0] = sal_Int32(m_pFileSet->size()); |
522 | 0 | clearInsertRow(); |
523 | |
|
524 | 0 | m_aSkipDeletedSet.insertNewPosition((*m_aRow)[0]->getValue().getInt32()); |
525 | 0 | } |
526 | 0 | } |
527 | | |
528 | | void SAL_CALL OResultSet::updateRow( ) |
529 | 0 | { |
530 | 0 | ::osl::MutexGuard aGuard( m_aMutex ); |
531 | 0 | checkDisposed(OResultSet_BASE::rBHelper.bDisposed); |
532 | |
|
533 | 0 | if(!m_pTable.is() || m_pTable->isReadOnly()) |
534 | 0 | lcl_throwError(STR_TABLE_READONLY,*this); |
535 | |
|
536 | 0 | m_bRowUpdated = m_pTable->UpdateRow(*m_aInsertRow, m_aRow,m_xColsIdx); |
537 | 0 | *(*m_aInsertRow)[0] = (*m_aRow)[0]->getValue().getInt32(); |
538 | |
|
539 | 0 | clearInsertRow(); |
540 | 0 | } |
541 | | |
542 | | void SAL_CALL OResultSet::deleteRow() |
543 | 0 | { |
544 | 0 | ::osl::MutexGuard aGuard( m_aMutex ); |
545 | 0 | checkDisposed(OResultSet_BASE::rBHelper.bDisposed); |
546 | |
|
547 | 0 | if(!m_pTable.is() || m_pTable->isReadOnly()) |
548 | 0 | lcl_throwError(STR_TABLE_READONLY,*this); |
549 | 0 | if (m_bShowDeleted) |
550 | 0 | lcl_throwError(STR_DELETE_ROW,*this); |
551 | 0 | if(m_aRow->isDeleted()) |
552 | 0 | lcl_throwError(STR_ROW_ALREADY_DELETED,*this); |
553 | |
|
554 | 0 | sal_Int32 nPos = (*m_aRow)[0]->getValue().getInt32(); |
555 | 0 | m_bRowDeleted = m_pTable->DeleteRow(*m_xColumns); |
556 | 0 | if(m_bRowDeleted && m_pFileSet.is()) |
557 | 0 | { |
558 | 0 | m_aRow->setDeleted(true); |
559 | | // don't touch the m_pFileSet member here |
560 | 0 | m_aSkipDeletedSet.deletePosition(nPos); |
561 | 0 | } |
562 | 0 | } |
563 | | |
564 | | void SAL_CALL OResultSet::cancelRowUpdates( ) |
565 | 0 | { |
566 | 0 | ::osl::MutexGuard aGuard( m_aMutex ); |
567 | 0 | checkDisposed(OResultSet_BASE::rBHelper.bDisposed); |
568 | | |
569 | |
|
570 | 0 | m_bInserted = false; |
571 | 0 | m_bRowUpdated = false; |
572 | 0 | m_bRowInserted = false; |
573 | 0 | m_bRowDeleted = false; |
574 | |
|
575 | 0 | if(m_aInsertRow.is()) |
576 | 0 | { |
577 | 0 | OValueRefVector::iterator aIter = m_aInsertRow->begin()+1; |
578 | 0 | for(;aIter != m_aInsertRow->end();++aIter) |
579 | 0 | { |
580 | 0 | (*aIter)->setBound(false); |
581 | 0 | (*aIter)->setNull(); |
582 | 0 | } |
583 | 0 | } |
584 | 0 | } |
585 | | |
586 | | |
587 | | void SAL_CALL OResultSet::moveToInsertRow( ) |
588 | 9.55k | { |
589 | 9.55k | ::osl::MutexGuard aGuard( m_aMutex ); |
590 | 9.55k | checkDisposed(OResultSet_BASE::rBHelper.bDisposed); |
591 | | |
592 | 9.55k | if(!m_pTable.is() || m_pTable->isReadOnly()) |
593 | 0 | lcl_throwError(STR_TABLE_READONLY,*this); |
594 | | |
595 | 9.55k | m_bInserted = true; |
596 | | |
597 | 9.55k | OValueRefVector::iterator aIter = m_aInsertRow->begin()+1; |
598 | 290k | for(;aIter != m_aInsertRow->end();++aIter) |
599 | 281k | { |
600 | 281k | (*aIter)->setBound(false); |
601 | 281k | (*aIter)->setNull(); |
602 | 281k | } |
603 | 9.55k | } |
604 | | |
605 | | |
606 | | void SAL_CALL OResultSet::moveToCurrentRow( ) |
607 | 9.55k | { |
608 | 9.55k | } |
609 | | |
610 | | void OResultSet::updateValue(sal_Int32 columnIndex ,const ORowSetValue& x) |
611 | 0 | { |
612 | 0 | ::osl::MutexGuard aGuard( m_aMutex ); |
613 | 0 | checkDisposed(OResultSet_BASE::rBHelper.bDisposed); |
614 | |
|
615 | 0 | checkIndex(columnIndex ); |
616 | 0 | columnIndex = mapColumn(columnIndex); |
617 | |
|
618 | 0 | (*m_aInsertRow)[columnIndex]->setBound(true); |
619 | 0 | *(*m_aInsertRow)[columnIndex] = x; |
620 | 0 | } |
621 | | |
622 | | |
623 | | void SAL_CALL OResultSet::updateNull( sal_Int32 columnIndex ) |
624 | 0 | { |
625 | 0 | ORowSetValue aEmpty; |
626 | 0 | updateValue(columnIndex,aEmpty); |
627 | 0 | } |
628 | | |
629 | | |
630 | | void SAL_CALL OResultSet::updateBoolean( sal_Int32 columnIndex, sal_Bool x ) |
631 | 0 | { |
632 | 0 | updateValue(columnIndex, static_cast<bool>(x)); |
633 | 0 | } |
634 | | |
635 | | void SAL_CALL OResultSet::updateByte( sal_Int32 columnIndex, sal_Int8 x ) |
636 | 0 | { |
637 | 0 | updateValue(columnIndex,x); |
638 | 0 | } |
639 | | |
640 | | |
641 | | void SAL_CALL OResultSet::updateShort( sal_Int32 columnIndex, sal_Int16 x ) |
642 | 0 | { |
643 | 0 | updateValue(columnIndex,x); |
644 | 0 | } |
645 | | |
646 | | void SAL_CALL OResultSet::updateInt( sal_Int32 columnIndex, sal_Int32 x ) |
647 | 0 | { |
648 | 0 | updateValue(columnIndex,x); |
649 | 0 | } |
650 | | |
651 | | void SAL_CALL OResultSet::updateLong( sal_Int32 /*columnIndex*/, sal_Int64 /*x*/ ) |
652 | 0 | { |
653 | 0 | ::dbtools::throwFeatureNotImplementedSQLException( u"XRowUpdate::updateLong"_ustr, *this ); |
654 | 0 | } |
655 | | |
656 | | void SAL_CALL OResultSet::updateFloat( sal_Int32 columnIndex, float x ) |
657 | 0 | { |
658 | 0 | updateValue(columnIndex,x); |
659 | 0 | } |
660 | | |
661 | | |
662 | | void SAL_CALL OResultSet::updateDouble( sal_Int32 columnIndex, double x ) |
663 | 0 | { |
664 | 0 | updateValue(columnIndex,x); |
665 | 0 | } |
666 | | |
667 | | void SAL_CALL OResultSet::updateString( sal_Int32 columnIndex, const OUString& x ) |
668 | 0 | { |
669 | 0 | updateValue(columnIndex,x); |
670 | 0 | } |
671 | | |
672 | | void SAL_CALL OResultSet::updateBytes( sal_Int32 columnIndex, const Sequence< sal_Int8 >& x ) |
673 | 0 | { |
674 | 0 | updateValue(columnIndex,x); |
675 | 0 | } |
676 | | |
677 | | void SAL_CALL OResultSet::updateDate( sal_Int32 columnIndex, const css::util::Date& x ) |
678 | 0 | { |
679 | 0 | updateValue(columnIndex,x); |
680 | 0 | } |
681 | | |
682 | | |
683 | | void SAL_CALL OResultSet::updateTime( sal_Int32 columnIndex, const css::util::Time& x ) |
684 | 0 | { |
685 | 0 | updateValue(columnIndex,x); |
686 | 0 | } |
687 | | |
688 | | |
689 | | void SAL_CALL OResultSet::updateTimestamp( sal_Int32 columnIndex, const css::util::DateTime& x ) |
690 | 0 | { |
691 | 0 | updateValue(columnIndex,x); |
692 | 0 | } |
693 | | |
694 | | |
695 | | void SAL_CALL OResultSet::updateBinaryStream( sal_Int32 columnIndex, const Reference< css::io::XInputStream >& x, sal_Int32 length ) |
696 | 0 | { |
697 | 0 | ::osl::MutexGuard aGuard( m_aMutex ); |
698 | 0 | checkDisposed(OResultSet_BASE::rBHelper.bDisposed); |
699 | |
|
700 | 0 | if(!x.is()) |
701 | 0 | ::dbtools::throwFunctionSequenceException(*this); |
702 | |
|
703 | 0 | Sequence<sal_Int8> aSeq; |
704 | 0 | x->readBytes(aSeq,length); |
705 | 0 | updateValue(columnIndex,aSeq); |
706 | 0 | } |
707 | | |
708 | | void SAL_CALL OResultSet::updateCharacterStream( sal_Int32 columnIndex, const Reference< css::io::XInputStream >& x, sal_Int32 length ) |
709 | 0 | { |
710 | 0 | updateBinaryStream(columnIndex,x,length); |
711 | 0 | } |
712 | | |
713 | | void SAL_CALL OResultSet::refreshRow( ) |
714 | 0 | { |
715 | 0 | ::osl::MutexGuard aGuard( m_aMutex ); |
716 | 0 | checkDisposed(OResultSet_BASE::rBHelper.bDisposed); |
717 | 0 | } |
718 | | |
719 | | void SAL_CALL OResultSet::updateObject( sal_Int32 columnIndex, const Any& x ) |
720 | 0 | { |
721 | 0 | if (!::dbtools::implUpdateObject(this, columnIndex, x)) |
722 | 0 | throw SQLException(); |
723 | 0 | } |
724 | | |
725 | | |
726 | | void SAL_CALL OResultSet::updateNumericObject( sal_Int32 columnIndex, const Any& x, sal_Int32 /*scale*/ ) |
727 | 0 | { |
728 | 0 | if (!::dbtools::implUpdateObject(this, columnIndex, x)) |
729 | 0 | throw SQLException(); |
730 | 0 | } |
731 | | |
732 | | IPropertyArrayHelper* OResultSet::createArrayHelper( ) const |
733 | 0 | { |
734 | 0 | Sequence< Property > aProps; |
735 | 0 | describeProperties(aProps); |
736 | 0 | return new ::cppu::OPropertyArrayHelper(aProps); |
737 | 0 | } |
738 | | |
739 | | IPropertyArrayHelper & OResultSet::getInfoHelper() |
740 | 0 | { |
741 | 0 | return *getArrayHelper(); |
742 | 0 | } |
743 | | |
744 | | |
745 | | bool OResultSet::ExecuteRow(IResultSetHelper::Movement eFirstCursorPosition, |
746 | | sal_Int32 nFirstOffset, |
747 | | bool bEvaluate, |
748 | | bool bRetrieveData) |
749 | 1.95M | { |
750 | 1.95M | OSL_ENSURE(m_pSQLAnalyzer,"OResultSet::ExecuteRow: Analyzer isn't set!"); |
751 | | |
752 | | // For further Fetch-Operations this information may possibly be changed ... |
753 | 1.95M | IResultSetHelper::Movement eCursorPosition = eFirstCursorPosition; |
754 | 1.95M | sal_Int32 nOffset = nFirstOffset; |
755 | | |
756 | 1.95M | if (!m_pTable.is()) |
757 | 0 | return false; |
758 | | |
759 | 1.95M | const OSQLColumns & rTableCols = *(m_pTable->getTableColumns()); |
760 | 1.95M | bool bHasRestriction = m_pSQLAnalyzer->hasRestriction(); |
761 | 1.95M | again: |
762 | | |
763 | | // protect from reading over the end when somebody is inserting while we are reading |
764 | | // this method works only for dBase at the moment!!! |
765 | 1.95M | if (eCursorPosition == IResultSetHelper::NEXT && m_nFilePos == m_nLastVisitedPos) |
766 | 7.38k | { |
767 | 7.38k | return false; |
768 | 7.38k | } |
769 | | |
770 | 1.95M | if (!m_pTable.is() || !m_pTable->seekRow(eCursorPosition, nOffset, m_nFilePos)) |
771 | 6.46k | { |
772 | 6.46k | return false; |
773 | 6.46k | } |
774 | | |
775 | 1.94M | if (!bEvaluate) // If no evaluation runs, then just fill the results-row |
776 | 1.94M | { |
777 | 1.94M | m_pTable->fetchRow(m_aRow,rTableCols, bRetrieveData); |
778 | 1.94M | } |
779 | 0 | else |
780 | 0 | { |
781 | 0 | m_pTable->fetchRow(m_aEvaluateRow, rTableCols, bRetrieveData || bHasRestriction); |
782 | |
|
783 | 0 | if ( ( !m_bShowDeleted |
784 | 0 | && m_aEvaluateRow->isDeleted() |
785 | 0 | ) |
786 | 0 | || ( bHasRestriction |
787 | 0 | && !m_pSQLAnalyzer->evaluateRestriction() |
788 | 0 | ) |
789 | 0 | ) |
790 | 0 | { // Evaluate the next record |
791 | | // delete current row in Keyset |
792 | 0 | if (m_pFileSet.is()) |
793 | 0 | { |
794 | 0 | OSL_ENSURE(eCursorPosition == IResultSetHelper::NEXT, "Wrong CursorPosition!"); |
795 | 0 | eCursorPosition = IResultSetHelper::NEXT; |
796 | 0 | nOffset = 1; |
797 | 0 | } |
798 | 0 | else if (eCursorPosition == IResultSetHelper::FIRST || |
799 | 0 | eCursorPosition == IResultSetHelper::NEXT || |
800 | 0 | eCursorPosition == IResultSetHelper::ABSOLUTE1) |
801 | 0 | { |
802 | 0 | eCursorPosition = IResultSetHelper::NEXT; |
803 | 0 | nOffset = 1; |
804 | 0 | } |
805 | 0 | else if (eCursorPosition == IResultSetHelper::LAST || |
806 | 0 | eCursorPosition == IResultSetHelper::PRIOR) |
807 | 0 | { |
808 | 0 | eCursorPosition = IResultSetHelper::PRIOR; |
809 | 0 | nOffset = 1; |
810 | 0 | } |
811 | 0 | else if (eCursorPosition == IResultSetHelper::RELATIVE1) |
812 | 0 | { |
813 | 0 | eCursorPosition = (nOffset >= 0) ? IResultSetHelper::NEXT : IResultSetHelper::PRIOR; |
814 | 0 | } |
815 | 0 | else |
816 | 0 | { |
817 | 0 | return false; |
818 | 0 | } |
819 | | // Try again ... |
820 | 0 | goto again; |
821 | 0 | } |
822 | 0 | } |
823 | | |
824 | | // Evaluate may only be set, |
825 | | // if the Keyset will be constructed further |
826 | 1.94M | if ( ( m_aSQLIterator.getStatementType() == OSQLStatementType::Select ) |
827 | 1.94M | && !isCount() |
828 | 1.94M | && bEvaluate |
829 | 1.94M | ) |
830 | 0 | { |
831 | 0 | if (m_pSortIndex) |
832 | 0 | { |
833 | 0 | std::unique_ptr<OKeyValue> pKeyValue = GetOrderbyKeyValue( m_aSelectRow ); |
834 | 0 | m_pSortIndex->AddKeyValue(std::move(pKeyValue)); |
835 | 0 | } |
836 | 0 | else if (m_pFileSet.is()) |
837 | 0 | { |
838 | 0 | sal_uInt32 nBookmarkValue = std::abs((*m_aEvaluateRow)[0]->getValue().getInt32()); |
839 | 0 | m_pFileSet->push_back(nBookmarkValue); |
840 | 0 | } |
841 | 0 | } |
842 | 1.94M | else if (m_aSQLIterator.getStatementType() == OSQLStatementType::Update) |
843 | 0 | { |
844 | 0 | bool bOK = true; |
845 | 0 | if (bEvaluate) |
846 | 0 | { |
847 | | // read the actual result-row |
848 | 0 | bOK = m_pTable->fetchRow(m_aEvaluateRow, *(m_pTable->getTableColumns()), true); |
849 | 0 | } |
850 | |
|
851 | 0 | if (bOK) |
852 | 0 | { |
853 | | // just give the values to be changed: |
854 | 0 | if(!m_pTable->UpdateRow(*m_aAssignValues,m_aEvaluateRow, m_xColsIdx)) |
855 | 0 | return false; |
856 | 0 | } |
857 | 0 | } |
858 | 1.94M | else if (m_aSQLIterator.getStatementType() == OSQLStatementType::Delete) |
859 | 0 | { |
860 | 0 | bool bOK = true; |
861 | 0 | if (bEvaluate) |
862 | 0 | { |
863 | 0 | bOK = m_pTable->fetchRow(m_aEvaluateRow, *(m_pTable->getTableColumns()), true); |
864 | 0 | } |
865 | 0 | if (bOK) |
866 | 0 | { |
867 | 0 | if(!m_pTable->DeleteRow(*m_xColumns)) |
868 | 0 | return false; |
869 | 0 | } |
870 | 0 | } |
871 | 1.94M | return true; |
872 | 1.94M | } |
873 | | |
874 | | |
875 | | bool OResultSet::Move(IResultSetHelper::Movement eCursorPosition, sal_Int32 nOffset, bool bRetrieveData) |
876 | 1.97M | { |
877 | 1.97M | sal_Int32 nTempPos = m_nRowPos; |
878 | | |
879 | 1.97M | if (m_aSQLIterator.getStatementType() == OSQLStatementType::Select && |
880 | 1.97M | !isCount()) |
881 | 1.97M | { |
882 | 1.97M | if (!m_pFileSet.is()) //no Index available |
883 | 0 | { |
884 | | // Normal FETCH |
885 | 0 | ExecuteRow(eCursorPosition,nOffset,false,bRetrieveData); |
886 | | |
887 | | // now set the bookmark for outside this is the logical pos and not the file pos |
888 | 0 | *(*m_aRow->begin()) = sal_Int32(m_nRowPos + 1); |
889 | 0 | } |
890 | 1.97M | else |
891 | 1.97M | { |
892 | 1.97M | switch(eCursorPosition) |
893 | 1.97M | { |
894 | 1.80M | case IResultSetHelper::NEXT: |
895 | 1.80M | ++m_nRowPos; |
896 | 1.80M | break; |
897 | 79.8k | case IResultSetHelper::PRIOR: |
898 | 79.8k | if (m_nRowPos >= 0) |
899 | 77.5k | --m_nRowPos; |
900 | 79.8k | break; |
901 | 14.2k | case IResultSetHelper::FIRST: |
902 | 14.2k | m_nRowPos = 0; |
903 | 14.2k | break; |
904 | 0 | case IResultSetHelper::LAST: |
905 | 0 | m_nRowPos = m_pFileSet->size() - 1; |
906 | 0 | break; |
907 | 0 | case IResultSetHelper::RELATIVE1: |
908 | 0 | m_nRowPos += nOffset; |
909 | 0 | break; |
910 | 0 | case IResultSetHelper::ABSOLUTE1: |
911 | 68.4k | case IResultSetHelper::BOOKMARK: |
912 | 68.4k | if ( m_nRowPos == (nOffset -1) ) |
913 | 848 | return true; |
914 | 67.6k | m_nRowPos = nOffset -1; |
915 | 67.6k | break; |
916 | 1.97M | } |
917 | | |
918 | | // OffRange? |
919 | | // The FileCursor is outside of the valid range, if: |
920 | | // a.) m_nRowPos < 1 |
921 | | // b.) a KeySet exists and m_nRowPos > m_pFileSet->size() |
922 | 1.96M | if (m_nRowPos < 0 || (m_pFileSet->isFrozen() && eCursorPosition != IResultSetHelper::BOOKMARK && o3tl::make_unsigned(m_nRowPos) >= m_pFileSet->size() )) // && m_pFileSet->IsFrozen() |
923 | 10.0k | { |
924 | 10.0k | goto Error; |
925 | 10.0k | } |
926 | 1.95M | else |
927 | 1.95M | { |
928 | 1.95M | if (m_nRowPos < static_cast<sal_Int32>(m_pFileSet->size())) |
929 | 1.95M | { |
930 | | // Fetch via Index |
931 | 1.95M | bool bOK = ExecuteRow(IResultSetHelper::BOOKMARK,(*m_pFileSet)[m_nRowPos],false,bRetrieveData); |
932 | 1.95M | if (!bOK) |
933 | 6.46k | goto Error; |
934 | | |
935 | | // now set the bookmark for outside |
936 | 1.94M | *(*m_aRow->begin()) = sal_Int32(m_nRowPos + 1); |
937 | 1.94M | if ( (bRetrieveData || m_pSQLAnalyzer->hasRestriction()) && m_pSQLAnalyzer->hasFunctions() ) |
938 | 0 | { |
939 | 0 | m_pSQLAnalyzer->setSelectionEvaluationResult(m_aSelectRow,m_aColMapping); |
940 | 0 | } |
941 | 1.94M | } |
942 | 7.38k | else // Index must be further constructed |
943 | 7.38k | { |
944 | | // set first on the last known row |
945 | 7.38k | if (m_pFileSet->empty()) |
946 | 168 | { |
947 | 168 | m_pTable->seekRow(IResultSetHelper::ABSOLUTE1, 0, m_nFilePos); |
948 | 168 | } |
949 | 7.22k | else |
950 | 7.22k | { |
951 | 7.22k | m_aFileSetIter = m_pFileSet->end()-1; |
952 | 7.22k | m_pTable->seekRow(IResultSetHelper::BOOKMARK, *m_aFileSetIter, m_nFilePos); |
953 | 7.22k | } |
954 | 7.38k | bool bOK = true; |
955 | | // Determine the number of further Fetches |
956 | 14.7k | while (bOK && m_nRowPos >= static_cast<sal_Int32>(m_pFileSet->size())) |
957 | 7.38k | { |
958 | 7.38k | bOK = ExecuteRow(IResultSetHelper::NEXT,1,true, false);//bRetrieveData); |
959 | 7.38k | } |
960 | | |
961 | 7.38k | if (bOK) |
962 | 0 | { |
963 | | // read the results again |
964 | 0 | m_pTable->fetchRow(m_aRow, *(m_pTable->getTableColumns()), bRetrieveData); |
965 | | |
966 | | // now set the bookmark for outside |
967 | 0 | *(*m_aRow->begin()) = sal_Int32(m_nRowPos + 1); |
968 | |
|
969 | 0 | if ( (bRetrieveData || m_pSQLAnalyzer->hasRestriction()) && m_pSQLAnalyzer->hasFunctions() ) |
970 | 0 | { |
971 | 0 | m_pSQLAnalyzer->setSelectionEvaluationResult(m_aSelectRow,m_aColMapping); |
972 | 0 | } |
973 | 0 | } |
974 | 7.38k | else if (!m_pFileSet->isFrozen()) // no valid record found |
975 | 7.38k | { |
976 | 7.38k | m_pFileSet->setFrozen(); |
977 | 7.38k | goto Error; |
978 | 7.38k | } |
979 | 7.38k | } |
980 | 1.95M | } |
981 | 1.96M | } |
982 | 1.97M | } |
983 | 0 | else if (m_aSQLIterator.getStatementType() == OSQLStatementType::Select && isCount()) |
984 | 0 | { |
985 | | // Fetch the COUNT(*) |
986 | 0 | switch (eCursorPosition) |
987 | 0 | { |
988 | 0 | case IResultSetHelper::NEXT: |
989 | 0 | ++m_nRowPos; |
990 | 0 | break; |
991 | 0 | case IResultSetHelper::PRIOR: |
992 | 0 | --m_nRowPos; |
993 | 0 | break; |
994 | 0 | case IResultSetHelper::FIRST: |
995 | 0 | case IResultSetHelper::LAST: |
996 | 0 | m_nRowPos = 0; |
997 | 0 | break; |
998 | 0 | case IResultSetHelper::RELATIVE1: |
999 | 0 | m_nRowPos += nOffset; |
1000 | 0 | break; |
1001 | 0 | case IResultSetHelper::ABSOLUTE1: |
1002 | 0 | case IResultSetHelper::BOOKMARK: |
1003 | 0 | m_nRowPos = nOffset - 1; |
1004 | 0 | break; |
1005 | 0 | } |
1006 | | |
1007 | 0 | if ( m_nRowPos < 0 ) |
1008 | 0 | goto Error; |
1009 | 0 | else if (m_nRowPos == 0) |
1010 | 0 | { |
1011 | | // put COUNT(*) in result-row |
1012 | | // (must be the first and only variable in the row) |
1013 | 0 | if (m_aRow->size() >= 2) |
1014 | 0 | { |
1015 | 0 | *(*m_aRow)[1] = m_nRowCountResult; |
1016 | 0 | *(*m_aRow)[0] = sal_Int32(1); |
1017 | 0 | (*m_aRow)[1]->setBound(true); |
1018 | 0 | (*m_aSelectRow)[1] = (*m_aRow)[1]; |
1019 | 0 | } |
1020 | 0 | } |
1021 | 0 | else |
1022 | 0 | { |
1023 | 0 | m_nRowPos = 1; |
1024 | 0 | return false; |
1025 | 0 | } |
1026 | 0 | } |
1027 | 0 | else |
1028 | | // Fetch only possible at SELECT! |
1029 | 0 | return false; |
1030 | | |
1031 | 1.94M | return true; |
1032 | | |
1033 | 23.9k | Error: |
1034 | | // is the Cursor positioned before the first row |
1035 | | // then the position will be maintained |
1036 | 23.9k | if (nTempPos == -1) |
1037 | 9.28k | m_nRowPos = nTempPos; |
1038 | 14.6k | else |
1039 | 14.6k | { |
1040 | 14.6k | switch(eCursorPosition) |
1041 | 14.6k | { |
1042 | 7.23k | case IResultSetHelper::PRIOR: |
1043 | 7.23k | case IResultSetHelper::FIRST: |
1044 | 7.23k | m_nRowPos = -1; |
1045 | 7.23k | break; |
1046 | 0 | case IResultSetHelper::LAST: |
1047 | 7.40k | case IResultSetHelper::NEXT: |
1048 | 7.40k | case IResultSetHelper::ABSOLUTE1: |
1049 | 7.40k | case IResultSetHelper::RELATIVE1: |
1050 | 7.40k | if (nOffset > 0) |
1051 | 7.40k | m_nRowPos = m_pFileSet.is() ? static_cast<sal_Int32>(m_pFileSet->size()) : -1; |
1052 | 0 | else if (nOffset < 0) |
1053 | 0 | m_nRowPos = -1; |
1054 | 7.40k | break; |
1055 | 0 | case IResultSetHelper::BOOKMARK: |
1056 | 0 | m_nRowPos = nTempPos; // last Position |
1057 | 14.6k | } |
1058 | 14.6k | } |
1059 | 23.9k | return false; |
1060 | 23.9k | } |
1061 | | |
1062 | | void OResultSet::sortRows() |
1063 | 0 | { |
1064 | 0 | if (!m_pSQLAnalyzer->hasRestriction() && m_aOrderbyColumnNumber.size() == 1) |
1065 | 0 | { |
1066 | | // is just one field given for sorting |
1067 | | // and this field is indexed, then the Index will be used |
1068 | 0 | Reference<XIndexesSupplier> xIndexSup; |
1069 | 0 | m_pTable->queryInterface(cppu::UnoType<XIndexesSupplier>::get()) >>= xIndexSup; |
1070 | |
|
1071 | 0 | Reference<XIndexAccess> xIndexes; |
1072 | 0 | if(xIndexSup.is()) |
1073 | 0 | { |
1074 | 0 | xIndexes.set(xIndexSup->getIndexes(),UNO_QUERY); |
1075 | 0 | Reference<XPropertySet> xColProp; |
1076 | 0 | if(m_aOrderbyColumnNumber[0] < xIndexes->getCount()) |
1077 | 0 | { |
1078 | 0 | xColProp.set(xIndexes->getByIndex(m_aOrderbyColumnNumber[0]),UNO_QUERY); |
1079 | | // iterate through the indexes to find the matching column |
1080 | 0 | const sal_Int32 nCount = xIndexes->getCount(); |
1081 | 0 | for(sal_Int32 i=0; i < nCount;++i) |
1082 | 0 | { |
1083 | 0 | Reference<XColumnsSupplier> xIndex(xIndexes->getByIndex(i),UNO_QUERY); |
1084 | 0 | Reference<XNameAccess> xIndexCols = xIndex->getColumns(); |
1085 | 0 | if(xIndexCols->hasByName(comphelper::getString(xColProp->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME))))) |
1086 | 0 | { |
1087 | 0 | m_pFileSet = new OKeySet(); |
1088 | |
|
1089 | 0 | if(fillIndexValues(xIndex)) |
1090 | 0 | return; |
1091 | 0 | } |
1092 | 0 | } |
1093 | 0 | } |
1094 | 0 | } |
1095 | 0 | } |
1096 | | |
1097 | 0 | OSortIndex::TKeyTypeVector eKeyType(m_aOrderbyColumnNumber.size()); |
1098 | 0 | size_t i = 0; |
1099 | 0 | for (auto const& elem : m_aOrderbyColumnNumber) |
1100 | 0 | { |
1101 | 0 | OSL_ENSURE(static_cast<sal_Int32>(m_aSelectRow->size()) > elem,"Invalid Index"); |
1102 | 0 | switch ((*(m_aSelectRow->begin()+elem))->getValue().getTypeKind()) |
1103 | 0 | { |
1104 | 0 | case DataType::CHAR: |
1105 | 0 | case DataType::VARCHAR: |
1106 | 0 | case DataType::LONGVARCHAR: |
1107 | 0 | eKeyType[i] = OKeyType::String; |
1108 | 0 | break; |
1109 | | |
1110 | 0 | case DataType::OTHER: |
1111 | 0 | case DataType::TINYINT: |
1112 | 0 | case DataType::SMALLINT: |
1113 | 0 | case DataType::INTEGER: |
1114 | 0 | case DataType::DECIMAL: |
1115 | 0 | case DataType::NUMERIC: |
1116 | 0 | case DataType::REAL: |
1117 | 0 | case DataType::DOUBLE: |
1118 | 0 | case DataType::DATE: |
1119 | 0 | case DataType::TIME: |
1120 | 0 | case DataType::TIMESTAMP: |
1121 | 0 | case DataType::BIT: |
1122 | 0 | eKeyType[i] = OKeyType::Double; |
1123 | 0 | break; |
1124 | | |
1125 | | // Other types aren't implemented (so they are always FALSE) |
1126 | 0 | default: |
1127 | 0 | eKeyType[i] = OKeyType::NONE; |
1128 | 0 | SAL_WARN( "connectivity.drivers","OFILECursor::Execute: Data type not implemented"); |
1129 | 0 | break; |
1130 | 0 | } |
1131 | 0 | (*m_aSelectRow)[elem]->setBound(true); |
1132 | 0 | ++i; |
1133 | 0 | } |
1134 | | |
1135 | 0 | m_pSortIndex.reset(new OSortIndex(std::move(eKeyType), std::vector(m_aOrderbyAscending))); |
1136 | |
|
1137 | 0 | while ( ExecuteRow( IResultSetHelper::NEXT, 1, false ) ) |
1138 | 0 | { |
1139 | 0 | (*m_aSelectRow)[0]->setValue( (*m_aRow)[0]->getValue() ); |
1140 | 0 | if ( m_pSQLAnalyzer->hasFunctions() ) |
1141 | 0 | m_pSQLAnalyzer->setSelectionEvaluationResult( m_aSelectRow, m_aColMapping ); |
1142 | 0 | const sal_Int32 nBookmark = (*m_aRow->begin())->getValue().getInt32(); |
1143 | 0 | ExecuteRow( IResultSetHelper::BOOKMARK, nBookmark, true, false ); |
1144 | 0 | } |
1145 | | |
1146 | | // create sorted Keyset |
1147 | 0 | m_pFileSet = nullptr; |
1148 | 0 | m_pFileSet = m_pSortIndex->CreateKeySet(); |
1149 | 0 | m_pSortIndex.reset(); |
1150 | | // now access to a sorted set is possible via Index |
1151 | 0 | } |
1152 | | |
1153 | | |
1154 | | void OResultSet::OpenImpl() |
1155 | 19.1k | { |
1156 | 19.1k | OSL_ENSURE(m_pSQLAnalyzer,"No analyzer set with setSqlAnalyzer!"); |
1157 | 19.1k | if(!m_pTable.is()) |
1158 | 19.1k | { |
1159 | 19.1k | const OSQLTables& rTabs = m_aSQLIterator.getTables(); |
1160 | 19.1k | if (rTabs.empty() || !rTabs.begin()->second.is()) |
1161 | 0 | lcl_throwError(STR_QUERY_TOO_COMPLEX,*this); |
1162 | | |
1163 | 19.1k | if ( rTabs.size() > 1 || m_aSQLIterator.hasErrors() ) |
1164 | 0 | lcl_throwError(STR_QUERY_MORE_TABLES,*this); |
1165 | | |
1166 | 19.1k | OSQLTable xTable = rTabs.begin()->second; |
1167 | 19.1k | m_xColumns = m_aSQLIterator.getSelectColumns(); |
1168 | | |
1169 | 19.1k | m_xColNames = xTable->getColumns(); |
1170 | 19.1k | m_xColsIdx.set(m_xColNames,UNO_QUERY); |
1171 | 19.1k | doTableSpecials(xTable); |
1172 | 19.1k | Reference<XComponent> xComp(xTable,UNO_QUERY); |
1173 | 19.1k | if(xComp.is()) |
1174 | 19.1k | xComp->addEventListener(this); |
1175 | 19.1k | } |
1176 | | |
1177 | 19.1k | m_pTable->refreshHeader(); |
1178 | | |
1179 | 19.1k | sal_Int32 nColumnCount = m_xColsIdx->getCount(); |
1180 | | |
1181 | 19.1k | initializeRow(m_aRow,nColumnCount); |
1182 | 19.1k | initializeRow(m_aEvaluateRow,nColumnCount); |
1183 | 19.1k | initializeRow(m_aInsertRow,nColumnCount); |
1184 | | |
1185 | | |
1186 | 19.1k | m_nResultSetConcurrency = (m_pTable->isReadOnly() || isCount()) ? ResultSetConcurrency::READ_ONLY : ResultSetConcurrency::UPDATABLE; |
1187 | | |
1188 | | // create new Index: |
1189 | 19.1k | m_pFileSet = nullptr; |
1190 | | |
1191 | | // position at the beginning |
1192 | 19.1k | m_nRowPos = -1; |
1193 | 19.1k | m_nFilePos = 0; |
1194 | 19.1k | m_nRowCountResult = -1; |
1195 | 19.1k | m_pTable->seekRow(IResultSetHelper::ABSOLUTE1, 0, m_nFilePos); |
1196 | | |
1197 | 19.1k | m_nLastVisitedPos = m_pTable->getCurrentLastPos(); |
1198 | | |
1199 | 19.1k | switch(m_aSQLIterator.getStatementType()) |
1200 | 19.1k | { |
1201 | 19.1k | case OSQLStatementType::Select: |
1202 | 19.1k | { |
1203 | 19.1k | if(isCount()) |
1204 | 0 | { |
1205 | 0 | if(m_xColumns->size() > 1) |
1206 | 0 | lcl_throwError(STR_QUERY_COMPLEX_COUNT,*this); |
1207 | |
|
1208 | 0 | m_nRowCountResult = 0; |
1209 | | // for now simply iterate over all rows and |
1210 | | // do all actions (or just count) |
1211 | 0 | { |
1212 | 0 | bool bOK = true; |
1213 | 0 | while (bOK) |
1214 | 0 | { |
1215 | 0 | bOK = ExecuteRow(IResultSetHelper::NEXT); |
1216 | |
|
1217 | 0 | if (bOK) |
1218 | 0 | { |
1219 | 0 | m_nRowCountResult++; |
1220 | 0 | } |
1221 | 0 | } |
1222 | | |
1223 | | // save result of COUNT(*) in m_nRowCountResult. |
1224 | | // nRowCount (number of Rows in the result) = 1 for this request! |
1225 | 0 | } |
1226 | 0 | } |
1227 | 19.1k | else |
1228 | 19.1k | { |
1229 | 19.1k | bool bDistinct = false; |
1230 | 19.1k | assert(m_pParseTree != nullptr); |
1231 | 19.1k | OSQLParseNode *pDistinct = m_pParseTree->getChild(1); |
1232 | | |
1233 | 19.1k | assert(m_aOrderbyColumnNumber.size() == |
1234 | 19.1k | m_aOrderbyAscending.size()); |
1235 | 19.1k | if (pDistinct && pDistinct->getTokenID() == SQL_TOKEN_DISTINCT ) |
1236 | 0 | { |
1237 | | // To eliminate duplicates we need to sort on all columns. |
1238 | | // This is not a problem because the SQL spec says that the |
1239 | | // order of columns that are not specified in ORDER BY |
1240 | | // clause is undefined, so it doesn't hurt to sort on |
1241 | | // these; pad the vectors to include them. |
1242 | 0 | for (size_t i = 1; // 0: bookmark (see setBoundedColumns) |
1243 | 0 | i < m_aColMapping.size(); ++i) |
1244 | 0 | { |
1245 | 0 | if (std::find(m_aOrderbyColumnNumber.begin(), |
1246 | 0 | m_aOrderbyColumnNumber.end(), |
1247 | 0 | sal::static_int_cast<sal_Int32>(i)) |
1248 | 0 | == m_aOrderbyColumnNumber.end()) |
1249 | 0 | { |
1250 | 0 | m_aOrderbyColumnNumber.push_back(i); |
1251 | | // ASC or DESC doesn't matter |
1252 | 0 | m_aOrderbyAscending.push_back(TAscendingOrder::ASC); |
1253 | 0 | } |
1254 | 0 | } |
1255 | 0 | bDistinct = true; |
1256 | 0 | } |
1257 | | |
1258 | 19.1k | if (IsSorted()) |
1259 | 0 | sortRows(); |
1260 | | |
1261 | 19.1k | if (!m_pFileSet.is()) |
1262 | 19.1k | { |
1263 | 19.1k | m_pFileSet = new OKeySet(); |
1264 | | |
1265 | 19.1k | if (!m_pSQLAnalyzer->hasRestriction()) |
1266 | | // now the Keyset can be filled! |
1267 | | // But be careful: It is assumed, that the FilePositions will be stored as sequence 1..n |
1268 | 9.55k | { |
1269 | 9.55k | if ( m_nLastVisitedPos > 0) |
1270 | 9.38k | m_pFileSet->reserve( m_nLastVisitedPos ); |
1271 | 1.78M | for (sal_Int32 i = 0; i < m_nLastVisitedPos; i++) |
1272 | 1.77M | m_pFileSet->push_back(i + 1); |
1273 | 9.55k | } |
1274 | 19.1k | } |
1275 | 19.1k | OSL_ENSURE(m_pFileSet.is(),"No KeySet existing! :-("); |
1276 | | |
1277 | 19.1k | if(bDistinct && m_pFileSet.is()) |
1278 | 0 | { |
1279 | 0 | OValueRow aSearchRow = new OValueVector(m_aRow->size()); |
1280 | 0 | OValueRefVector::iterator aRowIter = m_aRow->begin(); |
1281 | 0 | OValueVector::iterator aSearchIter = aSearchRow->begin(); |
1282 | 0 | for ( ++aRowIter,++aSearchIter; // the first column is the bookmark column |
1283 | 0 | aRowIter != m_aRow->end(); |
1284 | 0 | ++aRowIter,++aSearchIter) |
1285 | 0 | aSearchIter->setBound((*aRowIter)->isBound()); |
1286 | |
|
1287 | 0 | size_t nMaxRow = m_pFileSet->size(); |
1288 | |
|
1289 | 0 | if (nMaxRow) |
1290 | 0 | { |
1291 | | #if OSL_DEBUG_LEVEL > 1 |
1292 | | sal_Int32 nFound=0; |
1293 | | #endif |
1294 | 0 | sal_Int32 nPos; |
1295 | 0 | sal_Int32 nKey; |
1296 | |
|
1297 | 0 | for( size_t j = nMaxRow-1; j > 0; --j) |
1298 | 0 | { |
1299 | 0 | nPos = (*m_pFileSet)[j]; |
1300 | 0 | ExecuteRow(IResultSetHelper::BOOKMARK,nPos,false); |
1301 | 0 | m_pSQLAnalyzer->setSelectionEvaluationResult(m_aSelectRow,m_aColMapping); |
1302 | 0 | { // cop*y row values |
1303 | 0 | OValueRefVector::iterator copyFrom = m_aSelectRow->begin(); |
1304 | 0 | OValueVector::iterator copyTo = aSearchRow->begin(); |
1305 | 0 | for ( ++copyFrom,++copyTo; // the first column is the bookmark column |
1306 | 0 | copyFrom != m_aSelectRow->end(); |
1307 | 0 | ++copyFrom,++copyTo) |
1308 | 0 | *copyTo = *(*copyFrom); |
1309 | 0 | } |
1310 | | |
1311 | | // compare with next row |
1312 | 0 | nKey = (*m_pFileSet)[j-1]; |
1313 | 0 | ExecuteRow(IResultSetHelper::BOOKMARK,nKey,false); |
1314 | 0 | m_pSQLAnalyzer->setSelectionEvaluationResult(m_aSelectRow,m_aColMapping); |
1315 | 0 | auto rowsMismatchIters = std::mismatch(std::next(m_aSelectRow->begin()), m_aSelectRow->end(), |
1316 | 0 | std::next(aSearchRow->begin()), // the first column is the bookmark column |
1317 | 0 | [](const OValueRefVector::value_type& a, const OValueVector::value_type& b) { |
1318 | 0 | return !a->isBound() || (*a == b); }); |
1319 | |
|
1320 | 0 | if(rowsMismatchIters.first == m_aSelectRow->end()) |
1321 | 0 | (*m_pFileSet)[j] = 0; // Rows match -- Mark for deletion by setting key to 0 |
1322 | | #if OSL_DEBUG_LEVEL > 1 |
1323 | | else |
1324 | | nFound++; |
1325 | | #endif |
1326 | 0 | } |
1327 | |
|
1328 | 0 | std::erase(*m_pFileSet, 0); |
1329 | 0 | } |
1330 | 0 | } |
1331 | 19.1k | } |
1332 | 19.1k | } break; |
1333 | | |
1334 | 0 | case OSQLStatementType::Update: |
1335 | 0 | case OSQLStatementType::Delete: |
1336 | | // during processing count the number of processed Rows |
1337 | 0 | m_nRowCountResult = 0; |
1338 | | // for now simply iterate over all rows and |
1339 | | // run the actions (or simply count): |
1340 | 0 | { |
1341 | |
|
1342 | 0 | bool bOK = true; |
1343 | 0 | while (bOK) |
1344 | 0 | { |
1345 | 0 | bOK = ExecuteRow(IResultSetHelper::NEXT); |
1346 | |
|
1347 | 0 | if (bOK) |
1348 | 0 | { |
1349 | 0 | m_nRowCountResult++; |
1350 | 0 | } |
1351 | 0 | } |
1352 | | |
1353 | | // save result of COUNT(*) in nRowCountResult. |
1354 | | // nRowCount (number of rows in the result-set) = 1 for this request! |
1355 | 0 | } |
1356 | 0 | break; |
1357 | 0 | case OSQLStatementType::Insert: |
1358 | 0 | m_nRowCountResult = 0; |
1359 | |
|
1360 | 0 | OSL_ENSURE(m_aAssignValues.is(),"No assign values set!"); |
1361 | 0 | if(!m_pTable->InsertRow(*m_aAssignValues, m_xColsIdx)) |
1362 | 0 | { |
1363 | 0 | m_nFilePos = 0; |
1364 | 0 | return; |
1365 | 0 | } |
1366 | | |
1367 | 0 | m_nRowCountResult = 1; |
1368 | 0 | break; |
1369 | 0 | default: |
1370 | 0 | SAL_WARN( "connectivity.drivers", "OResultSet::OpenImpl: unsupported statement type!" ); |
1371 | 0 | break; |
1372 | 19.1k | } |
1373 | | |
1374 | | // reset FilePos |
1375 | 19.1k | m_nFilePos = 0; |
1376 | 19.1k | } |
1377 | | |
1378 | | void OResultSet::setBoundedColumns(const OValueRefRow& _rRow, |
1379 | | const OValueRefRow& _rSelectRow, |
1380 | | const ::rtl::Reference<connectivity::OSQLColumns>& _rxColumns, |
1381 | | const Reference<XIndexAccess>& _xNames, |
1382 | | bool _bSetColumnMapping, |
1383 | | const Reference<XDatabaseMetaData>& _xMetaData, |
1384 | | std::vector<sal_Int32>& _rColMapping) |
1385 | 47.7k | { |
1386 | 47.7k | ::comphelper::UStringMixEqual aCase(_xMetaData->supportsMixedCaseQuotedIdentifiers()); |
1387 | | |
1388 | 47.7k | Reference<XPropertySet> xTableColumn; |
1389 | 47.7k | OUString sTableColumnName, sSelectColumnRealName; |
1390 | | |
1391 | 47.7k | const OUString sName = OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME); |
1392 | 47.7k | const OUString sRealName = OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_REALNAME); |
1393 | 47.7k | const OUString sType = OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPE); |
1394 | | |
1395 | 47.7k | std::map<OSQLColumns::iterator,bool> aSelectIters; |
1396 | 47.7k | OValueRefVector::const_iterator aRowIter = _rRow->begin()+1; |
1397 | 47.7k | for (sal_Int32 i=0; // the first column is the bookmark column |
1398 | 1.45M | aRowIter != _rRow->end(); |
1399 | 1.40M | ++i, ++aRowIter |
1400 | 47.7k | ) |
1401 | 1.40M | { |
1402 | 1.40M | (*aRowIter)->setBound(false); |
1403 | 1.40M | try |
1404 | 1.40M | { |
1405 | | // get the table column and its name |
1406 | 1.40M | _xNames->getByIndex(i) >>= xTableColumn; |
1407 | 1.40M | OSL_ENSURE(xTableColumn.is(), "OResultSet::setBoundedColumns: invalid table column!"); |
1408 | 1.40M | if (xTableColumn.is()) |
1409 | 1.40M | xTableColumn->getPropertyValue(sName) >>= sTableColumnName; |
1410 | 0 | else |
1411 | 0 | sTableColumnName.clear(); |
1412 | | |
1413 | | // look if we have such a select column |
1414 | | // TODO: would like to have a O(log n) search here ... |
1415 | 1.40M | for ( OSQLColumns::iterator aIter = _rxColumns->begin(); |
1416 | 111M | aIter != _rxColumns->end(); |
1417 | 109M | ++aIter |
1418 | 1.40M | ) |
1419 | 110M | { |
1420 | 110M | if((*aIter)->getPropertySetInfo()->hasPropertyByName(sRealName)) |
1421 | 110M | (*aIter)->getPropertyValue(sRealName) >>= sSelectColumnRealName; |
1422 | 0 | else |
1423 | 0 | (*aIter)->getPropertyValue(sName) >>= sSelectColumnRealName; |
1424 | | |
1425 | 110M | if ( aCase(sTableColumnName, sSelectColumnRealName) && !(*aRowIter)->isBound() && aSelectIters.end() == aSelectIters.find(aIter) ) |
1426 | 843k | { |
1427 | 843k | aSelectIters.emplace(aIter,true); |
1428 | 843k | if(_bSetColumnMapping) |
1429 | 843k | { |
1430 | 843k | sal_Int32 nSelectColumnPos = aIter - _rxColumns->begin() + 1; |
1431 | | // the getXXX methods are 1-based ... |
1432 | 843k | sal_Int32 nTableColumnPos = i + 1; |
1433 | | // get first table column is the bookmark column ... |
1434 | 843k | _rColMapping[nSelectColumnPos] = nTableColumnPos; |
1435 | 843k | (*_rSelectRow)[nSelectColumnPos] = *aRowIter; |
1436 | 843k | } |
1437 | | |
1438 | 843k | (*aRowIter)->setBound(true); |
1439 | 843k | sal_Int32 nType = DataType::OTHER; |
1440 | 843k | if (xTableColumn.is()) |
1441 | 843k | xTableColumn->getPropertyValue(sType) >>= nType; |
1442 | 843k | (*aRowIter)->setTypeKind(nType); |
1443 | | |
1444 | 843k | break; |
1445 | 843k | } |
1446 | 110M | } |
1447 | 1.40M | } |
1448 | 1.40M | catch (Exception&) |
1449 | 1.40M | { |
1450 | 0 | TOOLS_WARN_EXCEPTION( "connectivity.drivers",""); |
1451 | 0 | } |
1452 | 1.40M | } |
1453 | | // in this case we got more select columns as columns exist in the table |
1454 | 47.7k | if ( !(_bSetColumnMapping && aSelectIters.size() != _rColMapping.size()) ) |
1455 | 19.1k | return; |
1456 | | |
1457 | 28.6k | Reference<XNameAccess> xNameAccess(_xNames,UNO_QUERY); |
1458 | 28.6k | Sequence< OUString > aSelectColumns = xNameAccess->getElementNames(); |
1459 | | |
1460 | 28.6k | for ( OSQLColumns::iterator aIter = _rxColumns->begin(); |
1461 | 871k | aIter != _rxColumns->end(); |
1462 | 843k | ++aIter |
1463 | 28.6k | ) |
1464 | 843k | { |
1465 | 843k | if ( aSelectIters.end() == aSelectIters.find(aIter) ) |
1466 | 0 | { |
1467 | 0 | if ( (*aIter)->getPropertySetInfo()->hasPropertyByName(sRealName) ) |
1468 | 0 | (*aIter)->getPropertyValue(sRealName) >>= sSelectColumnRealName; |
1469 | 0 | else |
1470 | 0 | (*aIter)->getPropertyValue(sName) >>= sSelectColumnRealName; |
1471 | |
|
1472 | 0 | if ( xNameAccess->hasByName( sSelectColumnRealName ) ) |
1473 | 0 | { |
1474 | 0 | aSelectIters.emplace(aIter,true); |
1475 | 0 | sal_Int32 nSelectColumnPos = aIter - _rxColumns->begin() + 1; |
1476 | 0 | for (sal_Int32 i = 0; i < aSelectColumns.getLength(); ++i) |
1477 | 0 | { |
1478 | 0 | if (aCase(aSelectColumns[i], sSelectColumnRealName)) |
1479 | 0 | { |
1480 | | // the getXXX methods are 1-based ... |
1481 | 0 | sal_Int32 nTableColumnPos = i + 1; |
1482 | | // get first table column is the bookmark column ... |
1483 | 0 | _rColMapping[nSelectColumnPos] = nTableColumnPos; |
1484 | 0 | (*_rSelectRow)[nSelectColumnPos] = (*_rRow)[nTableColumnPos]; |
1485 | 0 | break; |
1486 | 0 | } |
1487 | 0 | } |
1488 | 0 | } |
1489 | 0 | } |
1490 | 843k | } |
1491 | 28.6k | } |
1492 | | |
1493 | | void SAL_CALL OResultSet::acquire() noexcept |
1494 | 458k | { |
1495 | 458k | OResultSet_BASE::acquire(); |
1496 | 458k | } |
1497 | | |
1498 | | void SAL_CALL OResultSet::release() noexcept |
1499 | 458k | { |
1500 | 458k | OResultSet_BASE::release(); |
1501 | 458k | } |
1502 | | |
1503 | | Reference< css::beans::XPropertySetInfo > SAL_CALL OResultSet::getPropertySetInfo( ) |
1504 | 0 | { |
1505 | 0 | return ::cppu::OPropertySetHelper::createPropertySetInfo(getInfoHelper()); |
1506 | 0 | } |
1507 | | |
1508 | | void OResultSet::doTableSpecials(const OSQLTable& _xTable) |
1509 | 19.1k | { |
1510 | 19.1k | m_pTable = dynamic_cast<OFileTable*>(_xTable.get()); |
1511 | 19.1k | assert(m_pTable.is()); |
1512 | 19.1k | } |
1513 | | |
1514 | | void OResultSet::clearInsertRow() |
1515 | 0 | { |
1516 | 0 | m_aRow->setDeleted(false); // set to false here because this is the new row |
1517 | 0 | sal_Int32 nPos = 0; |
1518 | 0 | for(ORowSetValueDecoratorRef& rValue : *m_aInsertRow) |
1519 | 0 | { |
1520 | 0 | if ( rValue->isBound() ) |
1521 | 0 | { |
1522 | 0 | (*m_aRow)[nPos]->setValue( rValue->getValue() ); |
1523 | 0 | } |
1524 | 0 | rValue->setBound(nPos == 0); |
1525 | 0 | rValue->setModified(false); |
1526 | 0 | rValue->setNull(); |
1527 | 0 | ++nPos; |
1528 | 0 | } |
1529 | 0 | } |
1530 | | |
1531 | | void OResultSet::initializeRow(OValueRefRow& _rRow,sal_Int32 _nColumnCount) |
1532 | 57.3k | { |
1533 | 57.3k | if(!_rRow.is()) |
1534 | 19.1k | { |
1535 | 19.1k | _rRow = new OValueRefVector(_nColumnCount); |
1536 | 19.1k | (*_rRow)[0]->setBound(true); |
1537 | 19.1k | std::for_each(_rRow->begin()+1,_rRow->end(),TSetRefBound(false)); |
1538 | 19.1k | } |
1539 | 57.3k | } |
1540 | | |
1541 | | bool OResultSet::fillIndexValues(const Reference< XColumnsSupplier> &/*_xIndex*/) |
1542 | 0 | { |
1543 | 0 | return false; |
1544 | 0 | } |
1545 | | |
1546 | | bool OResultSet::move(IResultSetHelper::Movement _eCursorPosition, sal_Int32 _nOffset, bool _bRetrieveData) |
1547 | 1.97M | { |
1548 | 1.97M | return Move(_eCursorPosition,_nOffset,_bRetrieveData); |
1549 | 1.97M | } |
1550 | | |
1551 | | sal_Int32 OResultSet::getDriverPos() const |
1552 | 1.68M | { |
1553 | 1.68M | return (*m_aRow)[0]->getValue().getInt32(); |
1554 | 1.68M | } |
1555 | | |
1556 | | bool OResultSet::isRowDeleted() const |
1557 | 1.87M | { |
1558 | 1.87M | return m_aRow->isDeleted(); |
1559 | 1.87M | } |
1560 | | |
1561 | | void SAL_CALL OResultSet::disposing( const EventObject& Source ) |
1562 | 0 | { |
1563 | 0 | if(m_pTable.is() && Source.Source == Reference<XPropertySet>(m_pTable)) |
1564 | 0 | { |
1565 | 0 | m_pTable.clear(); |
1566 | 0 | } |
1567 | 0 | } |
1568 | | |
1569 | | |
1570 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |