nss: upgrade to release 3.73
[LibreOffice.git] / connectivity / source / drivers / file / FResultSet.cxx
blob5cf5d1ae862d9fe086a4c978e14a8d487b036ea5
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 .
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 <comphelper/servicehelper.hxx>
29 #include <cppuhelper/typeprovider.hxx>
30 #include <connectivity/dbtools.hxx>
31 #include <cppuhelper/propshlp.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>
39 #include <algorithm>
40 #include <connectivity/dbexception.hxx>
41 #include <comphelper/types.hxx>
42 #include <resource/sharedresources.hxx>
43 #include <strings.hrc>
44 #include <tools/diagnose_ex.h>
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;
58 namespace
60 void lcl_throwError(const char* pErrorId, const css::uno::Reference< css::uno::XInterface>& _xContext)
62 ::connectivity::SharedResources aResources;
63 const OUString sMessage = aResources.getResourceString(pErrorId);
64 ::dbtools::throwGenericSQLException(sMessage ,_xContext);
68 IMPLEMENT_SERVICE_INFO(OResultSet,"com.sun.star.sdbcx.drivers.file.ResultSet","com.sun.star.sdbc.ResultSet");
70 OResultSet::OResultSet(OStatement_Base* pStmt,OSQLParseTreeIterator& _aSQLIterator) : OResultSet_BASE(m_aMutex)
71 ,::comphelper::OPropertyContainer(OResultSet_BASE::rBHelper)
72 ,m_aSkipDeletedSet(this)
73 ,m_pParseTree(pStmt->getParseTree())
74 ,m_pSQLAnalyzer(nullptr)
75 ,m_aSQLIterator(_aSQLIterator)
76 ,m_nFetchSize(0)
77 ,m_nResultSetType(ResultSetType::SCROLL_INSENSITIVE)
78 ,m_nFetchDirection(FetchDirection::FORWARD)
79 ,m_nResultSetConcurrency(ResultSetConcurrency::UPDATABLE)
80 ,m_xStatement(*pStmt)
81 ,m_nRowPos(-1)
82 ,m_nFilePos(0)
83 ,m_nLastVisitedPos(-1)
84 ,m_nRowCountResult(-1)
85 ,m_nColumnCount(0)
86 ,m_bWasNull(false)
87 ,m_bInserted(false)
88 ,m_bRowUpdated(false)
89 ,m_bRowInserted(false)
90 ,m_bRowDeleted(false)
91 ,m_bShowDeleted(pStmt->getOwnConnection()->showDeleted())
92 ,m_bIsCount(false)
94 osl_atomic_increment( &m_refCount );
95 m_bIsCount = (m_pParseTree &&
96 m_pParseTree->count() > 2 &&
97 SQL_ISRULE(m_pParseTree->getChild(2),scalar_exp_commalist) &&
98 SQL_ISRULE(m_pParseTree->getChild(2)->getChild(0),derived_column) &&
99 SQL_ISRULE(m_pParseTree->getChild(2)->getChild(0)->getChild(0),general_set_fct) &&
100 m_pParseTree->getChild(2)->getChild(0)->getChild(0)->count() == 4
103 m_nResultSetConcurrency = isCount() ? ResultSetConcurrency::READ_ONLY : ResultSetConcurrency::UPDATABLE;
104 construct();
105 m_aSkipDeletedSet.SetDeletedVisible(m_bShowDeleted);
106 osl_atomic_decrement( &m_refCount );
110 OResultSet::~OResultSet()
112 osl_atomic_increment( &m_refCount );
113 disposing();
116 void OResultSet::construct()
118 registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_FETCHSIZE), PROPERTY_ID_FETCHSIZE, 0,&m_nFetchSize, ::cppu::UnoType<sal_Int32>::get());
119 registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_RESULTSETTYPE), PROPERTY_ID_RESULTSETTYPE, PropertyAttribute::READONLY,&m_nResultSetType, ::cppu::UnoType<sal_Int32>::get());
120 registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_FETCHDIRECTION), PROPERTY_ID_FETCHDIRECTION, 0,&m_nFetchDirection, ::cppu::UnoType<sal_Int32>::get());
121 registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_RESULTSETCONCURRENCY), PROPERTY_ID_RESULTSETCONCURRENCY,PropertyAttribute::READONLY,&m_nResultSetConcurrency, ::cppu::UnoType<sal_Int32>::get());
124 void OResultSet::disposing()
126 OPropertySetHelper::disposing();
128 ::osl::MutexGuard aGuard(m_aMutex);
129 m_xStatement.clear();
130 m_xMetaData.clear();
131 m_pParseTree = nullptr;
132 m_xColNames.clear();
133 m_xColumns = nullptr;
134 m_xColsIdx.clear();
136 Reference<XComponent> xComp = m_pTable.get();
137 if ( xComp.is() )
138 xComp->removeEventListener(this);
139 m_pTable.clear();
141 m_pFileSet = nullptr;
142 m_pSortIndex.reset();
144 if(m_aInsertRow.is())
145 m_aInsertRow->clear();
147 m_aSkipDeletedSet.clear();
150 Any SAL_CALL OResultSet::queryInterface( const Type & rType )
152 Any aRet = OPropertySetHelper::queryInterface(rType);
153 return aRet.hasValue() ? aRet : OResultSet_BASE::queryInterface(rType);
156 Sequence< Type > SAL_CALL OResultSet::getTypes( )
158 ::osl::MutexGuard aGuard( m_aMutex );
160 OTypeCollection aTypes( cppu::UnoType<css::beans::XMultiPropertySet>::get(),
161 cppu::UnoType<css::beans::XPropertySet>::get(),
162 cppu::UnoType<css::beans::XPropertySet>::get());
164 return ::comphelper::concatSequences(aTypes.getTypes(),OResultSet_BASE::getTypes());
168 sal_Int32 SAL_CALL OResultSet::findColumn( const OUString& columnName )
170 ::osl::MutexGuard aGuard( m_aMutex );
171 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
174 Reference< XResultSetMetaData > xMeta = getMetaData();
175 sal_Int32 nLen = xMeta->getColumnCount();
176 sal_Int32 i = 1;
177 for(;i<=nLen;++i)
179 if(xMeta->isCaseSensitive(i) ? columnName == xMeta->getColumnName(i) :
180 columnName.equalsIgnoreAsciiCase(xMeta->getColumnName(i)))
181 return i;
184 ::dbtools::throwInvalidColumnException( columnName, *this );
185 assert(false);
186 return 0; // Never reached
189 const ORowSetValue& OResultSet::getValue(sal_Int32 columnIndex)
191 ::osl::MutexGuard aGuard( m_aMutex );
192 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
194 checkIndex(columnIndex );
197 m_bWasNull = (*m_aSelectRow)[columnIndex]->getValue().isNull();
198 return *(*m_aSelectRow)[columnIndex];
201 void OResultSet::checkIndex(sal_Int32 columnIndex )
203 if ( columnIndex <= 0
204 || columnIndex >= m_nColumnCount )
205 ::dbtools::throwInvalidIndexException(*this);
208 Reference< css::io::XInputStream > SAL_CALL OResultSet::getBinaryStream( sal_Int32 /*columnIndex*/ )
210 return nullptr;
213 Reference< css::io::XInputStream > SAL_CALL OResultSet::getCharacterStream( sal_Int32 /*columnIndex*/ )
215 return nullptr;
219 sal_Bool SAL_CALL OResultSet::getBoolean( sal_Int32 columnIndex )
221 return bool(getValue(columnIndex));
225 sal_Int8 SAL_CALL OResultSet::getByte( sal_Int32 columnIndex )
227 return getValue(columnIndex);
231 Sequence< sal_Int8 > SAL_CALL OResultSet::getBytes( sal_Int32 columnIndex )
233 return getValue(columnIndex);
237 css::util::Date SAL_CALL OResultSet::getDate( sal_Int32 columnIndex )
239 return getValue(columnIndex);
243 double SAL_CALL OResultSet::getDouble( sal_Int32 columnIndex )
245 return getValue(columnIndex);
249 float SAL_CALL OResultSet::getFloat( sal_Int32 columnIndex )
251 return getValue(columnIndex);
255 sal_Int32 SAL_CALL OResultSet::getInt( sal_Int32 columnIndex )
257 return getValue(columnIndex);
261 sal_Int32 SAL_CALL OResultSet::getRow( )
263 ::osl::MutexGuard aGuard( m_aMutex );
264 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
266 OSL_ENSURE((m_bShowDeleted || !m_aRow->isDeleted()),"getRow called for deleted row");
268 return m_aSkipDeletedSet.getMappedPosition((*m_aRow)[0]->getValue());
272 sal_Int64 SAL_CALL OResultSet::getLong( sal_Int32 columnIndex )
274 return getValue(columnIndex);
278 Reference< XResultSetMetaData > SAL_CALL OResultSet::getMetaData( )
280 ::osl::MutexGuard aGuard( m_aMutex );
281 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
284 if(!m_xMetaData.is())
285 m_xMetaData = new OResultSetMetaData(m_xColumns,m_aSQLIterator.getTables().begin()->first,m_pTable.get());
286 return m_xMetaData;
289 Reference< XArray > SAL_CALL OResultSet::getArray( sal_Int32 /*columnIndex*/ )
291 return nullptr;
295 Reference< XClob > SAL_CALL OResultSet::getClob( sal_Int32 /*columnIndex*/ )
297 return nullptr;
300 Reference< XBlob > SAL_CALL OResultSet::getBlob( sal_Int32 /*columnIndex*/ )
302 return nullptr;
306 Reference< XRef > SAL_CALL OResultSet::getRef( sal_Int32 /*columnIndex*/ )
308 return nullptr;
312 Any SAL_CALL OResultSet::getObject( sal_Int32 columnIndex, const Reference< css::container::XNameAccess >& /*typeMap*/ )
314 return getValue(columnIndex).makeAny();
318 sal_Int16 SAL_CALL OResultSet::getShort( sal_Int32 columnIndex )
320 return getValue(columnIndex);
323 OUString SAL_CALL OResultSet::getString( sal_Int32 columnIndex )
325 return getValue(columnIndex);
328 css::util::Time SAL_CALL OResultSet::getTime( sal_Int32 columnIndex )
330 return getValue(columnIndex);
333 css::util::DateTime SAL_CALL OResultSet::getTimestamp( sal_Int32 columnIndex )
335 return getValue(columnIndex);
339 sal_Bool SAL_CALL OResultSet::isAfterLast( )
341 ::osl::MutexGuard aGuard( m_aMutex );
342 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
345 return m_nRowPos == sal_Int32(m_pFileSet->size());
348 sal_Bool SAL_CALL OResultSet::isFirst( )
350 ::osl::MutexGuard aGuard( m_aMutex );
351 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
354 return m_nRowPos == 0;
357 sal_Bool SAL_CALL OResultSet::isLast( )
359 ::osl::MutexGuard aGuard( m_aMutex );
360 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
363 return m_nRowPos == sal_Int32(m_pFileSet->size() - 1);
366 void SAL_CALL OResultSet::beforeFirst( )
368 ::osl::MutexGuard aGuard( m_aMutex );
369 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
372 if(first())
373 previous();
376 void SAL_CALL OResultSet::afterLast( )
378 ::osl::MutexGuard aGuard( m_aMutex );
379 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
382 if(last())
383 next();
387 void SAL_CALL OResultSet::close( )
389 dispose();
393 sal_Bool SAL_CALL OResultSet::first( )
395 ::osl::MutexGuard aGuard( m_aMutex );
396 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
397 return m_pTable.is() && m_aSkipDeletedSet.skipDeleted(IResultSetHelper::FIRST,1,true);
401 sal_Bool SAL_CALL OResultSet::last( )
403 // here I know definitely that I stand on the last record
404 ::osl::MutexGuard aGuard( m_aMutex );
405 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
406 return m_pTable.is() && m_aSkipDeletedSet.skipDeleted(IResultSetHelper::LAST,1,true);
409 sal_Bool SAL_CALL OResultSet::absolute( sal_Int32 row )
411 ::osl::MutexGuard aGuard( m_aMutex );
412 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
413 return m_pTable.is() && m_aSkipDeletedSet.skipDeleted(IResultSetHelper::ABSOLUTE1,row,true);
416 sal_Bool SAL_CALL OResultSet::relative( sal_Int32 row )
418 ::osl::MutexGuard aGuard( m_aMutex );
419 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
420 return m_pTable.is() && m_aSkipDeletedSet.skipDeleted(IResultSetHelper::RELATIVE1,row,true);
423 sal_Bool SAL_CALL OResultSet::previous( )
425 ::osl::MutexGuard aGuard( m_aMutex );
426 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
427 return m_pTable.is() && m_aSkipDeletedSet.skipDeleted(IResultSetHelper::PRIOR,0,true);
430 Reference< XInterface > SAL_CALL OResultSet::getStatement( )
432 ::osl::MutexGuard aGuard( m_aMutex );
433 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
436 return m_xStatement;
440 sal_Bool SAL_CALL OResultSet::rowDeleted( )
442 ::osl::MutexGuard aGuard( m_aMutex );
443 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
446 return m_bRowDeleted;
449 sal_Bool SAL_CALL OResultSet::rowInserted( )
450 { ::osl::MutexGuard aGuard( m_aMutex );
451 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
454 return m_bRowInserted;
457 sal_Bool SAL_CALL OResultSet::rowUpdated( )
459 ::osl::MutexGuard aGuard( m_aMutex );
460 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
463 return m_bRowUpdated;
467 sal_Bool SAL_CALL OResultSet::isBeforeFirst( )
469 ::osl::MutexGuard aGuard( m_aMutex );
470 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
473 return m_nRowPos == -1;
476 sal_Bool SAL_CALL OResultSet::next( )
478 ::osl::MutexGuard aGuard( m_aMutex );
479 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
481 return m_pTable.is() && m_aSkipDeletedSet.skipDeleted(IResultSetHelper::NEXT,1,true);
485 sal_Bool SAL_CALL OResultSet::wasNull( )
487 ::osl::MutexGuard aGuard( m_aMutex );
488 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
490 return m_bWasNull;
494 void SAL_CALL OResultSet::cancel( )
498 void SAL_CALL OResultSet::clearWarnings( )
502 Any SAL_CALL OResultSet::getWarnings( )
504 return Any();
507 void SAL_CALL OResultSet::insertRow( )
509 ::osl::MutexGuard aGuard( m_aMutex );
510 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
513 if(!m_bInserted || !m_pTable.is())
514 throwFunctionSequenceException(*this);
516 // we know that we append new rows at the end
517 // so we have to know where the end is
518 (void)m_aSkipDeletedSet.skipDeleted(IResultSetHelper::LAST,1,false);
519 m_bRowInserted = m_pTable->InsertRow(*m_aInsertRow, m_xColsIdx);
520 if(m_bRowInserted && m_pFileSet.is())
522 sal_Int32 nPos = (*m_aInsertRow)[0]->getValue();
523 m_pFileSet->push_back(nPos);
524 *(*m_aInsertRow)[0] = sal_Int32(m_pFileSet->size());
525 clearInsertRow();
527 m_aSkipDeletedSet.insertNewPosition((*m_aRow)[0]->getValue());
531 void SAL_CALL OResultSet::updateRow( )
533 ::osl::MutexGuard aGuard( m_aMutex );
534 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
536 if(!m_pTable.is() || m_pTable->isReadOnly())
537 lcl_throwError(STR_TABLE_READONLY,*this);
539 m_bRowUpdated = m_pTable->UpdateRow(*m_aInsertRow, m_aRow,m_xColsIdx);
540 *(*m_aInsertRow)[0] = static_cast<sal_Int32>((*m_aRow)[0]->getValue());
542 clearInsertRow();
545 void SAL_CALL OResultSet::deleteRow()
547 ::osl::MutexGuard aGuard( m_aMutex );
548 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
550 if(!m_pTable.is() || m_pTable->isReadOnly())
551 lcl_throwError(STR_TABLE_READONLY,*this);
552 if (m_bShowDeleted)
553 lcl_throwError(STR_DELETE_ROW,*this);
554 if(m_aRow->isDeleted())
555 lcl_throwError(STR_ROW_ALREADY_DELETED,*this);
557 sal_Int32 nPos = static_cast<sal_Int32>((*m_aRow)[0]->getValue());
558 m_bRowDeleted = m_pTable->DeleteRow(*m_xColumns);
559 if(m_bRowDeleted && m_pFileSet.is())
561 m_aRow->setDeleted(true);
562 // don't touch the m_pFileSet member here
563 m_aSkipDeletedSet.deletePosition(nPos);
567 void SAL_CALL OResultSet::cancelRowUpdates( )
569 ::osl::MutexGuard aGuard( m_aMutex );
570 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
573 m_bInserted = false;
574 m_bRowUpdated = false;
575 m_bRowInserted = false;
576 m_bRowDeleted = false;
578 if(m_aInsertRow.is())
580 OValueRefVector::iterator aIter = m_aInsertRow->begin()+1;
581 for(;aIter != m_aInsertRow->end();++aIter)
583 (*aIter)->setBound(false);
584 (*aIter)->setNull();
590 void SAL_CALL OResultSet::moveToInsertRow( )
592 ::osl::MutexGuard aGuard( m_aMutex );
593 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
595 if(!m_pTable.is() || m_pTable->isReadOnly())
596 lcl_throwError(STR_TABLE_READONLY,*this);
598 m_bInserted = true;
600 OValueRefVector::iterator aIter = m_aInsertRow->begin()+1;
601 for(;aIter != m_aInsertRow->end();++aIter)
603 (*aIter)->setBound(false);
604 (*aIter)->setNull();
609 void SAL_CALL OResultSet::moveToCurrentRow( )
613 void OResultSet::updateValue(sal_Int32 columnIndex ,const ORowSetValue& x)
615 ::osl::MutexGuard aGuard( m_aMutex );
616 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
618 checkIndex(columnIndex );
619 columnIndex = mapColumn(columnIndex);
621 (*m_aInsertRow)[columnIndex]->setBound(true);
622 *(*m_aInsertRow)[columnIndex] = x;
626 void SAL_CALL OResultSet::updateNull( sal_Int32 columnIndex )
628 ORowSetValue aEmpty;
629 updateValue(columnIndex,aEmpty);
633 void SAL_CALL OResultSet::updateBoolean( sal_Int32 columnIndex, sal_Bool x )
635 updateValue(columnIndex, static_cast<bool>(x));
638 void SAL_CALL OResultSet::updateByte( sal_Int32 columnIndex, sal_Int8 x )
640 updateValue(columnIndex,x);
644 void SAL_CALL OResultSet::updateShort( sal_Int32 columnIndex, sal_Int16 x )
646 updateValue(columnIndex,x);
649 void SAL_CALL OResultSet::updateInt( sal_Int32 columnIndex, sal_Int32 x )
651 updateValue(columnIndex,x);
654 void SAL_CALL OResultSet::updateLong( sal_Int32 /*columnIndex*/, sal_Int64 /*x*/ )
656 ::dbtools::throwFeatureNotImplementedSQLException( "XRowUpdate::updateLong", *this );
659 void SAL_CALL OResultSet::updateFloat( sal_Int32 columnIndex, float x )
661 updateValue(columnIndex,x);
665 void SAL_CALL OResultSet::updateDouble( sal_Int32 columnIndex, double x )
667 updateValue(columnIndex,x);
670 void SAL_CALL OResultSet::updateString( sal_Int32 columnIndex, const OUString& x )
672 updateValue(columnIndex,x);
675 void SAL_CALL OResultSet::updateBytes( sal_Int32 columnIndex, const Sequence< sal_Int8 >& x )
677 updateValue(columnIndex,x);
680 void SAL_CALL OResultSet::updateDate( sal_Int32 columnIndex, const css::util::Date& x )
682 updateValue(columnIndex,x);
686 void SAL_CALL OResultSet::updateTime( sal_Int32 columnIndex, const css::util::Time& x )
688 updateValue(columnIndex,x);
692 void SAL_CALL OResultSet::updateTimestamp( sal_Int32 columnIndex, const css::util::DateTime& x )
694 updateValue(columnIndex,x);
698 void SAL_CALL OResultSet::updateBinaryStream( sal_Int32 columnIndex, const Reference< css::io::XInputStream >& x, sal_Int32 length )
700 ::osl::MutexGuard aGuard( m_aMutex );
701 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
703 if(!x.is())
704 ::dbtools::throwFunctionSequenceException(*this);
706 Sequence<sal_Int8> aSeq;
707 x->readBytes(aSeq,length);
708 updateValue(columnIndex,aSeq);
711 void SAL_CALL OResultSet::updateCharacterStream( sal_Int32 columnIndex, const Reference< css::io::XInputStream >& x, sal_Int32 length )
713 updateBinaryStream(columnIndex,x,length);
716 void SAL_CALL OResultSet::refreshRow( )
718 ::osl::MutexGuard aGuard( m_aMutex );
719 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
722 void SAL_CALL OResultSet::updateObject( sal_Int32 columnIndex, const Any& x )
724 if (!::dbtools::implUpdateObject(this, columnIndex, x))
725 throw SQLException();
729 void SAL_CALL OResultSet::updateNumericObject( sal_Int32 columnIndex, const Any& x, sal_Int32 /*scale*/ )
731 if (!::dbtools::implUpdateObject(this, columnIndex, x))
732 throw SQLException();
735 IPropertyArrayHelper* OResultSet::createArrayHelper( ) const
737 Sequence< Property > aProps;
738 describeProperties(aProps);
739 return new ::cppu::OPropertyArrayHelper(aProps);
742 IPropertyArrayHelper & OResultSet::getInfoHelper()
744 return *getArrayHelper();
748 bool OResultSet::ExecuteRow(IResultSetHelper::Movement eFirstCursorPosition,
749 sal_Int32 nFirstOffset,
750 bool bEvaluate,
751 bool bRetrieveData)
753 OSL_ENSURE(m_pSQLAnalyzer,"OResultSet::ExecuteRow: Analyzer isn't set!");
755 // For further Fetch-Operations this information may possibly be changed ...
756 IResultSetHelper::Movement eCursorPosition = eFirstCursorPosition;
757 sal_Int32 nOffset = nFirstOffset;
759 if (!m_pTable.is())
760 return false;
762 const OSQLColumns & rTableCols = *(m_pTable->getTableColumns());
763 bool bHasRestriction = m_pSQLAnalyzer->hasRestriction();
764 again:
766 // protect from reading over the end when somebody is inserting while we are reading
767 // this method works only for dBase at the moment!!!
768 if (eCursorPosition == IResultSetHelper::NEXT && m_nFilePos == m_nLastVisitedPos)
770 return false;
773 if (!m_pTable.is() || !m_pTable->seekRow(eCursorPosition, nOffset, m_nFilePos))
775 return false;
778 if (!bEvaluate) // If no evaluation runs, then just fill the results-row
780 m_pTable->fetchRow(m_aRow,rTableCols, bRetrieveData);
782 else
784 m_pTable->fetchRow(m_aEvaluateRow, rTableCols, bRetrieveData || bHasRestriction);
786 if ( ( !m_bShowDeleted
787 && m_aEvaluateRow->isDeleted()
789 || ( bHasRestriction
790 && !m_pSQLAnalyzer->evaluateRestriction()
793 { // Evaluate the next record
794 // delete current row in Keyset
795 if (m_pFileSet.is())
797 OSL_ENSURE(eCursorPosition == IResultSetHelper::NEXT, "Wrong CursorPosition!");
798 eCursorPosition = IResultSetHelper::NEXT;
799 nOffset = 1;
801 else if (eCursorPosition == IResultSetHelper::FIRST ||
802 eCursorPosition == IResultSetHelper::NEXT ||
803 eCursorPosition == IResultSetHelper::ABSOLUTE1)
805 eCursorPosition = IResultSetHelper::NEXT;
806 nOffset = 1;
808 else if (eCursorPosition == IResultSetHelper::LAST ||
809 eCursorPosition == IResultSetHelper::PRIOR)
811 eCursorPosition = IResultSetHelper::PRIOR;
812 nOffset = 1;
814 else if (eCursorPosition == IResultSetHelper::RELATIVE1)
816 eCursorPosition = (nOffset >= 0) ? IResultSetHelper::NEXT : IResultSetHelper::PRIOR;
818 else
820 return false;
822 // Try again ...
823 goto again;
827 // Evaluate may only be set,
828 // if the Keyset will be constructed further
829 if ( ( m_aSQLIterator.getStatementType() == OSQLStatementType::Select )
830 && !isCount()
831 && bEvaluate
834 if (m_pSortIndex)
836 std::unique_ptr<OKeyValue> pKeyValue = GetOrderbyKeyValue( m_aSelectRow );
837 m_pSortIndex->AddKeyValue(std::move(pKeyValue));
839 else if (m_pFileSet.is())
841 sal_uInt32 nBookmarkValue = std::abs(static_cast<sal_Int32>((*m_aEvaluateRow)[0]->getValue()));
842 m_pFileSet->push_back(nBookmarkValue);
845 else if (m_aSQLIterator.getStatementType() == OSQLStatementType::Update)
847 bool bOK = true;
848 if (bEvaluate)
850 // read the actual result-row
851 bOK = m_pTable->fetchRow(m_aEvaluateRow, *(m_pTable->getTableColumns()), true);
854 if (bOK)
856 // just give the values to be changed:
857 if(!m_pTable->UpdateRow(*m_aAssignValues,m_aEvaluateRow, m_xColsIdx))
858 return false;
861 else if (m_aSQLIterator.getStatementType() == OSQLStatementType::Delete)
863 bool bOK = true;
864 if (bEvaluate)
866 bOK = m_pTable->fetchRow(m_aEvaluateRow, *(m_pTable->getTableColumns()), true);
868 if (bOK)
870 if(!m_pTable->DeleteRow(*m_xColumns))
871 return false;
874 return true;
878 bool OResultSet::Move(IResultSetHelper::Movement eCursorPosition, sal_Int32 nOffset, bool bRetrieveData)
880 sal_Int32 nTempPos = m_nRowPos;
882 if (m_aSQLIterator.getStatementType() == OSQLStatementType::Select &&
883 !isCount())
885 if (!m_pFileSet.is()) //no Index available
887 // Normal FETCH
888 ExecuteRow(eCursorPosition,nOffset,false,bRetrieveData);
890 // now set the bookmark for outside this is the logical pos and not the file pos
891 *(*m_aRow->begin()) = sal_Int32(m_nRowPos + 1);
893 else
895 switch(eCursorPosition)
897 case IResultSetHelper::NEXT:
898 ++m_nRowPos;
899 break;
900 case IResultSetHelper::PRIOR:
901 if (m_nRowPos >= 0)
902 --m_nRowPos;
903 break;
904 case IResultSetHelper::FIRST:
905 m_nRowPos = 0;
906 break;
907 case IResultSetHelper::LAST:
908 m_nRowPos = m_pFileSet->size() - 1;
909 break;
910 case IResultSetHelper::RELATIVE1:
911 m_nRowPos += nOffset;
912 break;
913 case IResultSetHelper::ABSOLUTE1:
914 case IResultSetHelper::BOOKMARK:
915 if ( m_nRowPos == (nOffset -1) )
916 return true;
917 m_nRowPos = nOffset -1;
918 break;
921 // OffRange?
922 // The FileCursor is outside of the valid range, if:
923 // a.) m_nRowPos < 1
924 // b.) a KeySet exists and m_nRowPos > m_pFileSet->size()
925 if (m_nRowPos < 0 || (m_pFileSet->isFrozen() && eCursorPosition != IResultSetHelper::BOOKMARK && m_nRowPos >= static_cast<sal_Int32>(m_pFileSet->size()) )) // && m_pFileSet->IsFrozen()
927 goto Error;
929 else
931 if (m_nRowPos < static_cast<sal_Int32>(m_pFileSet->size()))
933 // Fetch via Index
934 bool bOK = ExecuteRow(IResultSetHelper::BOOKMARK,(*m_pFileSet)[m_nRowPos],false,bRetrieveData);
935 if (!bOK)
936 goto Error;
938 // now set the bookmark for outside
939 *(*m_aRow->begin()) = sal_Int32(m_nRowPos + 1);
940 if ( (bRetrieveData || m_pSQLAnalyzer->hasRestriction()) && m_pSQLAnalyzer->hasFunctions() )
942 m_pSQLAnalyzer->setSelectionEvaluationResult(m_aSelectRow,m_aColMapping);
945 else // Index must be further constructed
947 // set first on the last known row
948 if (m_pFileSet->empty())
950 m_pTable->seekRow(IResultSetHelper::ABSOLUTE1, 0, m_nFilePos);
952 else
954 m_aFileSetIter = m_pFileSet->end()-1;
955 m_pTable->seekRow(IResultSetHelper::BOOKMARK, *m_aFileSetIter, m_nFilePos);
957 bool bOK = true;
958 // Determine the number of further Fetches
959 while (bOK && m_nRowPos >= static_cast<sal_Int32>(m_pFileSet->size()))
961 bOK = ExecuteRow(IResultSetHelper::NEXT,1,true, false);//bRetrieveData);
964 if (bOK)
966 // read the results again
967 m_pTable->fetchRow(m_aRow, *(m_pTable->getTableColumns()), bRetrieveData);
969 // now set the bookmark for outside
970 *(*m_aRow->begin()) = sal_Int32(m_nRowPos + 1);
972 if ( (bRetrieveData || m_pSQLAnalyzer->hasRestriction()) && m_pSQLAnalyzer->hasFunctions() )
974 m_pSQLAnalyzer->setSelectionEvaluationResult(m_aSelectRow,m_aColMapping);
977 else if (!m_pFileSet->isFrozen()) // no valid record found
979 m_pFileSet->setFrozen();
980 goto Error;
986 else if (m_aSQLIterator.getStatementType() == OSQLStatementType::Select && isCount())
988 // Fetch the COUNT(*)
989 switch (eCursorPosition)
991 case IResultSetHelper::NEXT:
992 ++m_nRowPos;
993 break;
994 case IResultSetHelper::PRIOR:
995 --m_nRowPos;
996 break;
997 case IResultSetHelper::FIRST:
998 m_nRowPos = 0;
999 break;
1000 case IResultSetHelper::LAST:
1001 m_nRowPos = 0;
1002 break;
1003 case IResultSetHelper::RELATIVE1:
1004 m_nRowPos += nOffset;
1005 break;
1006 case IResultSetHelper::ABSOLUTE1:
1007 case IResultSetHelper::BOOKMARK:
1008 m_nRowPos = nOffset - 1;
1009 break;
1012 if ( m_nRowPos < 0 )
1013 goto Error;
1014 else if (m_nRowPos == 0)
1016 // put COUNT(*) in result-row
1017 // (must be the first and only variable in the row)
1018 if (m_aRow->size() >= 2)
1020 *(*m_aRow)[1] = m_nRowCountResult;
1021 *(*m_aRow)[0] = sal_Int32(1);
1022 (*m_aRow)[1]->setBound(true);
1023 (*m_aSelectRow)[1] = (*m_aRow)[1];
1026 else
1028 m_nRowPos = 1;
1029 return false;
1032 else
1033 // Fetch only possible at SELECT!
1034 return false;
1036 return true;
1038 Error:
1039 // is the Cursor positioned before the first row
1040 // then the position will be maintained
1041 if (nTempPos == -1)
1042 m_nRowPos = nTempPos;
1043 else
1045 switch(eCursorPosition)
1047 case IResultSetHelper::PRIOR:
1048 case IResultSetHelper::FIRST:
1049 m_nRowPos = -1;
1050 break;
1051 case IResultSetHelper::LAST:
1052 case IResultSetHelper::NEXT:
1053 case IResultSetHelper::ABSOLUTE1:
1054 case IResultSetHelper::RELATIVE1:
1055 if (nOffset > 0)
1056 m_nRowPos = m_pFileSet.is() ? static_cast<sal_Int32>(m_pFileSet->size()) : -1;
1057 else if (nOffset < 0)
1058 m_nRowPos = -1;
1059 break;
1060 case IResultSetHelper::BOOKMARK:
1061 m_nRowPos = nTempPos; // last Position
1064 return false;
1067 void OResultSet::sortRows()
1069 if (!m_pSQLAnalyzer->hasRestriction() && m_aOrderbyColumnNumber.size() == 1)
1071 // is just one field given for sorting
1072 // and this field is indexed, then the Index will be used
1073 Reference<XIndexesSupplier> xIndexSup;
1074 m_pTable->queryInterface(cppu::UnoType<XIndexesSupplier>::get()) >>= xIndexSup;
1076 Reference<XIndexAccess> xIndexes;
1077 if(xIndexSup.is())
1079 xIndexes.set(xIndexSup->getIndexes(),UNO_QUERY);
1080 Reference<XPropertySet> xColProp;
1081 if(m_aOrderbyColumnNumber[0] < xIndexes->getCount())
1083 xColProp.set(xIndexes->getByIndex(m_aOrderbyColumnNumber[0]),UNO_QUERY);
1084 // iterate through the indexes to find the matching column
1085 const sal_Int32 nCount = xIndexes->getCount();
1086 for(sal_Int32 i=0; i < nCount;++i)
1088 Reference<XColumnsSupplier> xIndex(xIndexes->getByIndex(i),UNO_QUERY);
1089 Reference<XNameAccess> xIndexCols = xIndex->getColumns();
1090 if(xIndexCols->hasByName(comphelper::getString(xColProp->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME)))))
1092 m_pFileSet = new OKeySet();
1094 if(fillIndexValues(xIndex))
1095 return;
1102 OSortIndex::TKeyTypeVector eKeyType(m_aOrderbyColumnNumber.size());
1103 size_t i = 0;
1104 for (auto const& elem : m_aOrderbyColumnNumber)
1106 OSL_ENSURE(static_cast<sal_Int32>(m_aSelectRow->size()) > elem,"Invalid Index");
1107 switch ((*(m_aSelectRow->begin()+elem))->getValue().getTypeKind())
1109 case DataType::CHAR:
1110 case DataType::VARCHAR:
1111 case DataType::LONGVARCHAR:
1112 eKeyType[i] = OKeyType::String;
1113 break;
1115 case DataType::OTHER:
1116 case DataType::TINYINT:
1117 case DataType::SMALLINT:
1118 case DataType::INTEGER:
1119 case DataType::DECIMAL:
1120 case DataType::NUMERIC:
1121 case DataType::REAL:
1122 case DataType::DOUBLE:
1123 case DataType::DATE:
1124 case DataType::TIME:
1125 case DataType::TIMESTAMP:
1126 case DataType::BIT:
1127 eKeyType[i] = OKeyType::Double;
1128 break;
1130 // Other types aren't implemented (so they are always FALSE)
1131 default:
1132 eKeyType[i] = OKeyType::NONE;
1133 SAL_WARN( "connectivity.drivers","OFILECursor::Execute: Data type not implemented");
1134 break;
1136 (*m_aSelectRow)[elem]->setBound(true);
1137 ++i;
1140 m_pSortIndex.reset(new OSortIndex(eKeyType,m_aOrderbyAscending));
1142 while ( ExecuteRow( IResultSetHelper::NEXT, 1, false ) )
1144 (*m_aSelectRow)[0]->setValue( (*m_aRow)[0]->getValue() );
1145 if ( m_pSQLAnalyzer->hasFunctions() )
1146 m_pSQLAnalyzer->setSelectionEvaluationResult( m_aSelectRow, m_aColMapping );
1147 const sal_Int32 nBookmark = (*m_aRow->begin())->getValue();
1148 ExecuteRow( IResultSetHelper::BOOKMARK, nBookmark, true, false );
1151 // create sorted Keyset
1152 m_pFileSet = nullptr;
1153 m_pFileSet = m_pSortIndex->CreateKeySet();
1154 m_pSortIndex.reset();
1155 // now access to a sorted set is possible via Index
1159 void OResultSet::OpenImpl()
1161 OSL_ENSURE(m_pSQLAnalyzer,"No analyzer set with setSqlAnalyzer!");
1162 if(!m_pTable.is())
1164 const OSQLTables& rTabs = m_aSQLIterator.getTables();
1165 if (rTabs.empty() || !rTabs.begin()->second.is())
1166 lcl_throwError(STR_QUERY_TOO_COMPLEX,*this);
1168 if ( rTabs.size() > 1 || m_aSQLIterator.hasErrors() )
1169 lcl_throwError(STR_QUERY_MORE_TABLES,*this);
1171 OSQLTable xTable = rTabs.begin()->second;
1172 m_xColumns = m_aSQLIterator.getSelectColumns();
1174 m_xColNames = xTable->getColumns();
1175 m_xColsIdx.set(m_xColNames,UNO_QUERY);
1176 doTableSpecials(xTable);
1177 Reference<XComponent> xComp(xTable,UNO_QUERY);
1178 if(xComp.is())
1179 xComp->addEventListener(this);
1182 m_pTable->refreshHeader();
1184 sal_Int32 nColumnCount = m_xColsIdx->getCount();
1186 initializeRow(m_aRow,nColumnCount);
1187 initializeRow(m_aEvaluateRow,nColumnCount);
1188 initializeRow(m_aInsertRow,nColumnCount);
1191 m_nResultSetConcurrency = (m_pTable->isReadOnly() || isCount()) ? ResultSetConcurrency::READ_ONLY : ResultSetConcurrency::UPDATABLE;
1193 // create new Index:
1194 m_pFileSet = nullptr;
1196 // position at the beginning
1197 m_nRowPos = -1;
1198 m_nFilePos = 0;
1199 m_nRowCountResult = -1;
1200 m_pTable->seekRow(IResultSetHelper::ABSOLUTE1, 0, m_nFilePos);
1202 m_nLastVisitedPos = m_pTable->getCurrentLastPos();
1204 switch(m_aSQLIterator.getStatementType())
1206 case OSQLStatementType::Select:
1208 if(isCount())
1210 if(m_xColumns->size() > 1)
1211 lcl_throwError(STR_QUERY_COMPLEX_COUNT,*this);
1213 m_nRowCountResult = 0;
1214 // for now simply iterate over all rows and
1215 // do all actions (or just count)
1217 bool bOK = true;
1218 while (bOK)
1220 bOK = ExecuteRow(IResultSetHelper::NEXT);
1222 if (bOK)
1224 m_nRowCountResult++;
1228 // save result of COUNT(*) in m_nRowCountResult.
1229 // nRowCount (number of Rows in the result) = 1 for this request!
1232 else
1234 bool bDistinct = false;
1235 assert(m_pParseTree != nullptr);
1236 OSQLParseNode *pDistinct = m_pParseTree->getChild(1);
1238 assert(m_aOrderbyColumnNumber.size() ==
1239 m_aOrderbyAscending.size());
1240 if (pDistinct && pDistinct->getTokenID() == SQL_TOKEN_DISTINCT )
1242 // To eliminate duplicates we need to sort on all columns.
1243 // This is not a problem because the SQL spec says that the
1244 // order of columns that are not specified in ORDER BY
1245 // clause is undefined, so it doesn't hurt to sort on
1246 // these; pad the vectors to include them.
1247 for (size_t i = 1; // 0: bookmark (see setBoundedColumns)
1248 i < m_aColMapping.size(); ++i)
1250 if (std::find(m_aOrderbyColumnNumber.begin(),
1251 m_aOrderbyColumnNumber.end(),
1252 sal::static_int_cast<sal_Int32>(i))
1253 == m_aOrderbyColumnNumber.end())
1255 m_aOrderbyColumnNumber.push_back(i);
1256 // ASC or DESC doesn't matter
1257 m_aOrderbyAscending.push_back(TAscendingOrder::ASC);
1260 bDistinct = true;
1263 if (IsSorted())
1264 sortRows();
1266 if (!m_pFileSet.is())
1268 m_pFileSet = new OKeySet();
1270 if (!m_pSQLAnalyzer->hasRestriction())
1271 // now the Keyset can be filled!
1272 // But be careful: It is assumed, that the FilePositions will be stored as sequence 1..n
1274 if ( m_nLastVisitedPos > 0)
1275 m_pFileSet->reserve( m_nLastVisitedPos );
1276 for (sal_Int32 i = 0; i < m_nLastVisitedPos; i++)
1277 m_pFileSet->push_back(i + 1);
1280 OSL_ENSURE(m_pFileSet.is(),"No KeySet existing! :-(");
1282 if(bDistinct && m_pFileSet.is())
1284 OValueRow aSearchRow = new OValueVector(m_aRow->size());
1285 OValueRefVector::iterator aRowIter = m_aRow->begin();
1286 OValueVector::iterator aSearchIter = aSearchRow->begin();
1287 for ( ++aRowIter,++aSearchIter; // the first column is the bookmark column
1288 aRowIter != m_aRow->end();
1289 ++aRowIter,++aSearchIter)
1290 aSearchIter->setBound((*aRowIter)->isBound());
1292 size_t nMaxRow = m_pFileSet->size();
1294 if (nMaxRow)
1296 #if OSL_DEBUG_LEVEL > 1
1297 sal_Int32 nFound=0;
1298 #endif
1299 sal_Int32 nPos;
1300 sal_Int32 nKey;
1302 for( size_t j = nMaxRow-1; j > 0; --j)
1304 nPos = (*m_pFileSet)[j];
1305 ExecuteRow(IResultSetHelper::BOOKMARK,nPos,false);
1306 m_pSQLAnalyzer->setSelectionEvaluationResult(m_aSelectRow,m_aColMapping);
1307 { // cop*y row values
1308 OValueRefVector::iterator copyFrom = m_aSelectRow->begin();
1309 OValueVector::iterator copyTo = aSearchRow->begin();
1310 for ( ++copyFrom,++copyTo; // the first column is the bookmark column
1311 copyFrom != m_aSelectRow->end();
1312 ++copyFrom,++copyTo)
1313 *copyTo = *(*copyFrom);
1316 // compare with next row
1317 nKey = (*m_pFileSet)[j-1];
1318 ExecuteRow(IResultSetHelper::BOOKMARK,nKey,false);
1319 m_pSQLAnalyzer->setSelectionEvaluationResult(m_aSelectRow,m_aColMapping);
1320 auto rowsMismatchIters = std::mismatch(std::next(m_aSelectRow->begin()), m_aSelectRow->end(),
1321 std::next(aSearchRow->begin()), // the first column is the bookmark column
1322 [](const OValueRefVector::value_type& a, const OValueVector::value_type& b) {
1323 return !a->isBound() || (*a == b); });
1325 if(rowsMismatchIters.first == m_aSelectRow->end())
1326 (*m_pFileSet)[j] = 0; // Rows match -- Mark for deletion by setting key to 0
1327 #if OSL_DEBUG_LEVEL > 1
1328 else
1329 nFound++;
1330 #endif
1333 m_pFileSet->erase(std::remove(m_pFileSet->begin(),m_pFileSet->end(),0)
1334 ,m_pFileSet->end());
1338 } break;
1340 case OSQLStatementType::Update:
1341 case OSQLStatementType::Delete:
1342 // during processing count the number of processed Rows
1343 m_nRowCountResult = 0;
1344 // for now simply iterate over all rows and
1345 // run the actions (or simply count):
1348 bool bOK = true;
1349 while (bOK)
1351 bOK = ExecuteRow(IResultSetHelper::NEXT);
1353 if (bOK)
1355 m_nRowCountResult++;
1359 // save result of COUNT(*) in nRowCountResult.
1360 // nRowCount (number of rows in the result-set) = 1 for this request!
1362 break;
1363 case OSQLStatementType::Insert:
1364 m_nRowCountResult = 0;
1366 OSL_ENSURE(m_aAssignValues.is(),"No assign values set!");
1367 if(!m_pTable->InsertRow(*m_aAssignValues, m_xColsIdx))
1369 m_nFilePos = 0;
1370 return;
1373 m_nRowCountResult = 1;
1374 break;
1375 default:
1376 SAL_WARN( "connectivity.drivers", "OResultSet::OpenImpl: unsupported statement type!" );
1377 break;
1380 // reset FilePos
1381 m_nFilePos = 0;
1384 Sequence< sal_Int8 > OResultSet::getUnoTunnelId()
1386 static ::cppu::OImplementationId implId;
1388 return implId.getImplementationId();
1391 // css::lang::XUnoTunnel
1393 sal_Int64 OResultSet::getSomething( const Sequence< sal_Int8 > & rId )
1395 return isUnoTunnelId<OResultSet>(rId)
1396 ? reinterpret_cast< sal_Int64 >( this )
1397 : 0;
1400 void OResultSet::setBoundedColumns(const OValueRefRow& _rRow,
1401 const OValueRefRow& _rSelectRow,
1402 const ::rtl::Reference<connectivity::OSQLColumns>& _rxColumns,
1403 const Reference<XIndexAccess>& _xNames,
1404 bool _bSetColumnMapping,
1405 const Reference<XDatabaseMetaData>& _xMetaData,
1406 std::vector<sal_Int32>& _rColMapping)
1408 ::comphelper::UStringMixEqual aCase(_xMetaData->supportsMixedCaseQuotedIdentifiers());
1410 Reference<XPropertySet> xTableColumn;
1411 OUString sTableColumnName, sSelectColumnRealName;
1413 const OUString sName = OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME);
1414 const OUString sRealName = OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_REALNAME);
1415 const OUString sType = OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPE);
1417 std::map<OSQLColumns::iterator,bool> aSelectIters;
1418 OValueRefVector::const_iterator aRowIter = _rRow->begin()+1;
1419 for (sal_Int32 i=0; // the first column is the bookmark column
1420 aRowIter != _rRow->end();
1421 ++i, ++aRowIter
1424 (*aRowIter)->setBound(false);
1427 // get the table column and its name
1428 _xNames->getByIndex(i) >>= xTableColumn;
1429 OSL_ENSURE(xTableColumn.is(), "OResultSet::setBoundedColumns: invalid table column!");
1430 if (xTableColumn.is())
1431 xTableColumn->getPropertyValue(sName) >>= sTableColumnName;
1432 else
1433 sTableColumnName.clear();
1435 // look if we have such a select column
1436 // TODO: would like to have a O(log n) search here ...
1437 for ( OSQLColumns::iterator aIter = _rxColumns->begin();
1438 aIter != _rxColumns->end();
1439 ++aIter
1442 if((*aIter)->getPropertySetInfo()->hasPropertyByName(sRealName))
1443 (*aIter)->getPropertyValue(sRealName) >>= sSelectColumnRealName;
1444 else
1445 (*aIter)->getPropertyValue(sName) >>= sSelectColumnRealName;
1447 if ( aCase(sTableColumnName, sSelectColumnRealName) && !(*aRowIter)->isBound() && aSelectIters.end() == aSelectIters.find(aIter) )
1449 aSelectIters.emplace(aIter,true);
1450 if(_bSetColumnMapping)
1452 sal_Int32 nSelectColumnPos = aIter - _rxColumns->begin() + 1;
1453 // the getXXX methods are 1-based ...
1454 sal_Int32 nTableColumnPos = i + 1;
1455 // get first table column is the bookmark column ...
1456 _rColMapping[nSelectColumnPos] = nTableColumnPos;
1457 (*_rSelectRow)[nSelectColumnPos] = *aRowIter;
1460 (*aRowIter)->setBound(true);
1461 sal_Int32 nType = DataType::OTHER;
1462 if (xTableColumn.is())
1463 xTableColumn->getPropertyValue(sType) >>= nType;
1464 (*aRowIter)->setTypeKind(nType);
1466 break;
1470 catch (Exception&)
1472 TOOLS_WARN_EXCEPTION( "connectivity.drivers","");
1475 // in this case we got more select columns as columns exist in the table
1476 if ( !(_bSetColumnMapping && aSelectIters.size() != _rColMapping.size()) )
1477 return;
1479 Reference<XNameAccess> xNameAccess(_xNames,UNO_QUERY);
1480 Sequence< OUString > aSelectColumns = xNameAccess->getElementNames();
1482 for ( OSQLColumns::iterator aIter = _rxColumns->begin();
1483 aIter != _rxColumns->end();
1484 ++aIter
1487 if ( aSelectIters.end() == aSelectIters.find(aIter) )
1489 if ( (*aIter)->getPropertySetInfo()->hasPropertyByName(sRealName) )
1490 (*aIter)->getPropertyValue(sRealName) >>= sSelectColumnRealName;
1491 else
1492 (*aIter)->getPropertyValue(sName) >>= sSelectColumnRealName;
1494 if ( xNameAccess->hasByName( sSelectColumnRealName ) )
1496 aSelectIters.emplace(aIter,true);
1497 sal_Int32 nSelectColumnPos = aIter - _rxColumns->begin() + 1;
1498 const OUString* pBegin = aSelectColumns.getConstArray();
1499 const OUString* pEnd = pBegin + aSelectColumns.getLength();
1500 for(sal_Int32 i=0;pBegin != pEnd;++pBegin,++i)
1502 if ( aCase(*pBegin, sSelectColumnRealName) )
1504 // the getXXX methods are 1-based ...
1505 sal_Int32 nTableColumnPos = i + 1;
1506 // get first table column is the bookmark column ...
1507 _rColMapping[nSelectColumnPos] = nTableColumnPos;
1508 (*_rSelectRow)[nSelectColumnPos] = (*_rRow)[nTableColumnPos];
1509 break;
1517 void SAL_CALL OResultSet::acquire() throw()
1519 OResultSet_BASE::acquire();
1522 void SAL_CALL OResultSet::release() throw()
1524 OResultSet_BASE::release();
1527 Reference< css::beans::XPropertySetInfo > SAL_CALL OResultSet::getPropertySetInfo( )
1529 return ::cppu::OPropertySetHelper::createPropertySetInfo(getInfoHelper());
1532 void OResultSet::doTableSpecials(const OSQLTable& _xTable)
1534 Reference<css::lang::XUnoTunnel> xTunnel(_xTable, UNO_QUERY_THROW);
1535 m_pTable = reinterpret_cast< OFileTable* >(xTunnel->getSomething(OFileTable::getUnoTunnelId()));
1536 assert(m_pTable.is());
1539 void OResultSet::clearInsertRow()
1541 m_aRow->setDeleted(false); // set to false here because this is the new row
1542 sal_Int32 nPos = 0;
1543 for(ORowSetValueDecoratorRef& rValue : *m_aInsertRow)
1545 if ( rValue->isBound() )
1547 (*m_aRow)[nPos]->setValue( rValue->getValue() );
1549 rValue->setBound(nPos == 0);
1550 rValue->setModified(false);
1551 rValue->setNull();
1552 ++nPos;
1556 void OResultSet::initializeRow(OValueRefRow& _rRow,sal_Int32 _nColumnCount)
1558 if(!_rRow.is())
1560 _rRow = new OValueRefVector(_nColumnCount);
1561 (*_rRow)[0]->setBound(true);
1562 std::for_each(_rRow->begin()+1,_rRow->end(),TSetRefBound(false));
1566 bool OResultSet::fillIndexValues(const Reference< XColumnsSupplier> &/*_xIndex*/)
1568 return false;
1571 bool OResultSet::move(IResultSetHelper::Movement _eCursorPosition, sal_Int32 _nOffset, bool _bRetrieveData)
1573 return Move(_eCursorPosition,_nOffset,_bRetrieveData);
1576 sal_Int32 OResultSet::getDriverPos() const
1578 return (*m_aRow)[0]->getValue();
1581 bool OResultSet::isRowDeleted() const
1583 return m_aRow->isDeleted();
1586 void SAL_CALL OResultSet::disposing( const EventObject& Source )
1588 Reference<XPropertySet> xProp = m_pTable.get();
1589 if(m_pTable.is() && Source.Source == xProp)
1591 m_pTable.clear();
1596 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */