merge the formfield patch from ooo-build
[ooovba.git] / connectivity / source / drivers / file / FResultSet.cxx
blob2a373922d64c56f527aeb2e0b6f8a2ba06a22313
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: FResultSet.cxx,v $
10 * $Revision: 1.102.30.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_connectivity.hxx"
33 #include <limits> // included here to prevent problems if compiling with C52
35 #ifdef GCC
36 #include <iostream>
37 #endif
38 #include "connectivity/sdbcx/VColumn.hxx"
39 #include "file/FResultSet.hxx"
40 #include "file/FResultSetMetaData.hxx"
41 #include <com/sun/star/sdbc/DataType.hpp>
42 #include <com/sun/star/sdbc/ColumnValue.hpp>
43 #include <comphelper/property.hxx>
44 #include <com/sun/star/lang/DisposedException.hpp>
45 #include <com/sun/star/beans/PropertyAttribute.hpp>
46 #include <com/sun/star/container/XIndexAccess.hpp>
47 #include <comphelper/sequence.hxx>
48 #include <cppuhelper/typeprovider.hxx>
49 #include "connectivity/dbconversion.hxx"
50 #include "connectivity/dbtools.hxx"
51 #include <cppuhelper/propshlp.hxx>
52 #include <iterator>
53 #include <tools/debug.hxx>
54 #include <com/sun/star/sdbc/ResultSetType.hpp>
55 #include <com/sun/star/sdbc/FetchDirection.hpp>
56 #include <com/sun/star/sdbc/ResultSetConcurrency.hpp>
57 #include <com/sun/star/sdbcx/XIndexesSupplier.hpp>
59 #include <algorithm>
60 #include <comphelper/extract.hxx>
61 #include "connectivity/dbexception.hxx"
62 #include <comphelper/types.hxx>
63 #include "resource/file_res.hrc"
64 #include "resource/sharedresources.hxx"
65 #include <rtl/logfile.hxx>
68 using namespace ::comphelper;
69 using namespace connectivity;
70 using namespace connectivity::file;
71 using namespace ::cppu;
72 using namespace dbtools;
73 using namespace com::sun::star::uno;
74 using namespace com::sun::star::lang;
75 using namespace com::sun::star::beans;
76 using namespace com::sun::star::sdbc;
77 using namespace com::sun::star::sdbcx;
78 using namespace com::sun::star::container;
80 // Maximale Anzahl von Rows, die mit ORDER BY sortiert durchlaufen werden koennen:
81 #if defined (WIN)
82 #define MAX_KEYSET_SIZE 0x3ff0 // Etwas weniger als ein Segment, damit
83 // noch Platz fuer Memory Debug-Informationen
84 #else
85 #define MAX_KEYSET_SIZE 0x40000 // 256K
86 #endif
88 namespace
90 void lcl_throwError(sal_uInt16 _nErrorId,const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface>& _xContext)
92 ::connectivity::SharedResources aResources;
93 const ::rtl::OUString sMessage = aResources.getResourceString(_nErrorId);
94 ::dbtools::throwGenericSQLException(sMessage ,_xContext);
97 //------------------------------------------------------------------------------
98 IMPLEMENT_SERVICE_INFO(OResultSet,"com.sun.star.sdbcx.drivers.file.ResultSet","com.sun.star.sdbc.ResultSet");
99 DBG_NAME( file_OResultSet )
100 // -------------------------------------------------------------------------
101 OResultSet::OResultSet(OStatement_Base* pStmt,OSQLParseTreeIterator& _aSQLIterator) : OResultSet_BASE(m_aMutex)
102 ,::comphelper::OPropertyContainer(OResultSet_BASE::rBHelper)
103 ,m_aAssignValues(NULL)
104 ,m_pEvaluationKeySet(NULL)
105 ,m_aSkipDeletedSet(this)
106 ,m_pFileSet(NULL)
107 ,m_pSortIndex(NULL)
108 ,m_pTable(NULL)
109 ,m_pParseTree(pStmt->getParseTree())
110 ,m_pSQLAnalyzer(NULL)
111 ,m_aSQLIterator(_aSQLIterator)
112 ,m_nFetchSize(0)
113 ,m_nResultSetType(ResultSetType::SCROLL_INSENSITIVE)
114 ,m_nFetchDirection(FetchDirection::FORWARD)
115 ,m_nResultSetConcurrency(ResultSetConcurrency::UPDATABLE)
116 ,m_xStatement(*pStmt)
117 ,m_xMetaData(NULL)
118 ,m_xDBMetaData(pStmt->getOwnConnection()->getMetaData())
119 ,m_nTextEncoding(pStmt->getOwnConnection()->getTextEncoding())
120 ,m_nRowPos(-1)
121 ,m_nFilePos(0)
122 ,m_nLastVisitedPos(-1)
123 ,m_nRowCountResult(-1)
124 ,m_nCurrentPosition(0)
125 ,m_nColumnCount(0)
126 ,m_bWasNull(sal_False)
127 ,m_bEOF(sal_False)
128 ,m_bLastRecord(sal_False)
129 ,m_bInserted(sal_False)
130 ,m_bRowUpdated(sal_False)
131 ,m_bRowInserted(sal_False)
132 ,m_bRowDeleted(sal_False)
133 ,m_bShowDeleted(pStmt->getOwnConnection()->showDeleted())
134 ,m_bIsCount(sal_False)
136 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::OResultSet" );
137 DBG_CTOR( file_OResultSet, NULL );
138 osl_incrementInterlockedCount( &m_refCount );
139 m_bIsCount = (m_pParseTree &&
140 m_pParseTree->count() > 2 &&
141 SQL_ISRULE(m_pParseTree->getChild(2),scalar_exp_commalist) &&
142 SQL_ISRULE(m_pParseTree->getChild(2)->getChild(0),derived_column) &&
143 SQL_ISRULE(m_pParseTree->getChild(2)->getChild(0)->getChild(0),general_set_fct) &&
144 m_pParseTree->getChild(2)->getChild(0)->getChild(0)->count() == 4
147 m_nResultSetConcurrency = isCount() ? ResultSetConcurrency::READ_ONLY : ResultSetConcurrency::UPDATABLE;
148 construct();
149 m_aSkipDeletedSet.SetDeleted(m_bShowDeleted);
150 osl_decrementInterlockedCount( &m_refCount );
153 // -------------------------------------------------------------------------
154 OResultSet::~OResultSet()
156 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::~OResultSet" );
157 osl_incrementInterlockedCount( &m_refCount );
158 disposing();
159 DBG_DTOR( file_OResultSet, NULL );
161 // -------------------------------------------------------------------------
162 void OResultSet::construct()
164 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::construct" );
165 registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_FETCHSIZE), PROPERTY_ID_FETCHSIZE, 0,&m_nFetchSize, ::getCppuType(reinterpret_cast<sal_Int32*>(NULL)));
166 registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_RESULTSETTYPE), PROPERTY_ID_RESULTSETTYPE, PropertyAttribute::READONLY,&m_nResultSetType, ::getCppuType(reinterpret_cast<sal_Int32*>(NULL)));
167 registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_FETCHDIRECTION), PROPERTY_ID_FETCHDIRECTION, 0,&m_nFetchDirection, ::getCppuType(reinterpret_cast<sal_Int32*>(NULL)));
168 registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_RESULTSETCONCURRENCY), PROPERTY_ID_RESULTSETCONCURRENCY,PropertyAttribute::READONLY,&m_nResultSetConcurrency, ::getCppuType(reinterpret_cast<sal_Int32*>(NULL)));
170 // -------------------------------------------------------------------------
171 void OResultSet::disposing(void)
173 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::disposing" );
174 OPropertySetHelper::disposing();
176 ::osl::MutexGuard aGuard(m_aMutex);
177 m_xStatement.clear();
178 m_xMetaData.clear();
179 m_pParseTree = NULL;
180 m_xColNames.clear();
181 m_xColumns = NULL;
182 m_xParamColumns = NULL;
183 m_xColsIdx.clear();
185 Reference<XComponent> xComp = m_pTable;
186 if ( xComp.is() )
187 xComp->removeEventListener(this);
188 if(m_pTable)
190 m_pTable->release();
191 m_pTable = NULL;
193 clear();
195 // -----------------------------------------------------------------------------
196 void OResultSet::clear()
198 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::clear" );
199 m_pFileSet = NULL;
200 DELETEZ(m_pSortIndex);
202 if(m_aInsertRow.isValid())
203 m_aInsertRow->get().clear();
205 m_aSkipDeletedSet.clear();
207 // -------------------------------------------------------------------------
208 Any SAL_CALL OResultSet::queryInterface( const Type & rType ) throw(RuntimeException)
210 //RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::queryInterface" );
211 Any aRet = OPropertySetHelper::queryInterface(rType);
212 return aRet.hasValue() ? aRet : OResultSet_BASE::queryInterface(rType);
214 // -------------------------------------------------------------------------
215 Sequence< Type > SAL_CALL OResultSet::getTypes( ) throw(RuntimeException)
217 //RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::getTypes" );
218 ::osl::MutexGuard aGuard( m_aMutex );
220 OTypeCollection aTypes( ::getCppuType( (const Reference< ::com::sun::star::beans::XMultiPropertySet > *)0 ),
221 ::getCppuType( (const Reference< ::com::sun::star::beans::XPropertySet > *)0 ),
222 ::getCppuType( (const Reference< ::com::sun::star::beans::XPropertySet > *)0 ));
224 return ::comphelper::concatSequences(aTypes.getTypes(),OResultSet_BASE::getTypes());
226 // -------------------------------------------------------------------------
228 sal_Int32 SAL_CALL OResultSet::findColumn( const ::rtl::OUString& columnName ) throw(SQLException, RuntimeException)
230 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::findColumn" );
231 ::osl::MutexGuard aGuard( m_aMutex );
232 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
235 Reference< XResultSetMetaData > xMeta = getMetaData();
236 sal_Int32 nLen = xMeta->getColumnCount();
237 sal_Int32 i = 1;
238 for(;i<=nLen;++i)
239 if(xMeta->isCaseSensitive(i) ? columnName == xMeta->getColumnName(i) :
240 columnName.equalsIgnoreAsciiCase(xMeta->getColumnName(i)))
241 break;
242 return i;
244 // -----------------------------------------------------------------------------
245 const ORowSetValue& OResultSet::getValue(sal_Int32 columnIndex ) throw(::com::sun::star::sdbc::SQLException)
247 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::getValue" );
248 ::osl::MutexGuard aGuard( m_aMutex );
249 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
251 //columnIndex = mapColumn(columnIndex);
252 checkIndex(columnIndex );
255 m_bWasNull = (m_aSelectRow->get())[columnIndex]->getValue().isNull();
256 return *(m_aSelectRow->get())[columnIndex];
258 // -----------------------------------------------------------------------------
259 void OResultSet::checkIndex(sal_Int32 columnIndex ) throw(::com::sun::star::sdbc::SQLException)
261 //RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::checkIndex" );
262 if ( columnIndex <= 0
263 // || columnIndex > (sal_Int32)m_xColumns->size()
264 || columnIndex >= m_nColumnCount )
265 ::dbtools::throwInvalidIndexException(*this);
267 // -------------------------------------------------------------------------
268 Reference< ::com::sun::star::io::XInputStream > SAL_CALL OResultSet::getBinaryStream( sal_Int32 /*columnIndex*/ ) throw(SQLException, RuntimeException)
270 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::getBinaryStream" );
271 return NULL;
273 // -------------------------------------------------------------------------
274 Reference< ::com::sun::star::io::XInputStream > SAL_CALL OResultSet::getCharacterStream( sal_Int32 /*columnIndex*/ ) throw(SQLException, RuntimeException)
276 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::getCharacterStream" );
277 return NULL;
280 // -------------------------------------------------------------------------
281 sal_Bool SAL_CALL OResultSet::getBoolean( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
283 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::getBoolean" );
284 return getValue(columnIndex);
286 // -------------------------------------------------------------------------
288 sal_Int8 SAL_CALL OResultSet::getByte( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
290 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::getByte" );
291 return getValue(columnIndex);
293 // -------------------------------------------------------------------------
295 Sequence< sal_Int8 > SAL_CALL OResultSet::getBytes( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
297 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::getBytes" );
298 return getValue(columnIndex);
300 // -------------------------------------------------------------------------
302 ::com::sun::star::util::Date SAL_CALL OResultSet::getDate( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
304 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::getDate" );
305 return getValue(columnIndex);
307 // -------------------------------------------------------------------------
309 double SAL_CALL OResultSet::getDouble( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
311 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::getDouble" );
312 return getValue(columnIndex);
314 // -------------------------------------------------------------------------
316 float SAL_CALL OResultSet::getFloat( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
318 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::getFloat" );
319 return getValue(columnIndex);
321 // -------------------------------------------------------------------------
323 sal_Int32 SAL_CALL OResultSet::getInt( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
325 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::getInt" );
326 return getValue(columnIndex);
328 // -------------------------------------------------------------------------
330 sal_Int32 SAL_CALL OResultSet::getRow( ) throw(SQLException, RuntimeException)
332 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::getRow" );
333 ::osl::MutexGuard aGuard( m_aMutex );
334 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
336 OSL_ENSURE((m_bShowDeleted || !m_aRow->isDeleted()),"getRow called for deleted row");
338 return m_aSkipDeletedSet.getMappedPosition((m_aRow->get())[0]->getValue());
340 // -------------------------------------------------------------------------
342 sal_Int64 SAL_CALL OResultSet::getLong( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
344 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::getLong" );
345 return getValue(columnIndex);
347 // -------------------------------------------------------------------------
349 Reference< XResultSetMetaData > SAL_CALL OResultSet::getMetaData( ) throw(SQLException, RuntimeException)
351 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::getMetaData" );
352 ::osl::MutexGuard aGuard( m_aMutex );
353 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
356 if(!m_xMetaData.is())
357 m_xMetaData = new OResultSetMetaData(m_xColumns,m_aSQLIterator.getTables().begin()->first,m_pTable);
358 return m_xMetaData;
360 // -------------------------------------------------------------------------
361 Reference< XArray > SAL_CALL OResultSet::getArray( sal_Int32 /*columnIndex*/ ) throw(SQLException, RuntimeException)
363 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::getArray" );
364 return NULL;
367 // -------------------------------------------------------------------------
369 Reference< XClob > SAL_CALL OResultSet::getClob( sal_Int32 /*columnIndex*/ ) throw(SQLException, RuntimeException)
371 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::getClob" );
372 return NULL;
374 // -------------------------------------------------------------------------
375 Reference< XBlob > SAL_CALL OResultSet::getBlob( sal_Int32 /*columnIndex*/ ) throw(SQLException, RuntimeException)
377 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::getBlob" );
378 return NULL;
380 // -------------------------------------------------------------------------
382 Reference< XRef > SAL_CALL OResultSet::getRef( sal_Int32 /*columnIndex*/ ) throw(SQLException, RuntimeException)
384 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::getRef" );
385 return NULL;
387 // -------------------------------------------------------------------------
389 Any SAL_CALL OResultSet::getObject( sal_Int32 columnIndex, const Reference< ::com::sun::star::container::XNameAccess >& /*typeMap*/ ) throw(SQLException, RuntimeException)
391 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::getObject" );
392 return getValue(columnIndex).makeAny();
394 // -------------------------------------------------------------------------
396 sal_Int16 SAL_CALL OResultSet::getShort( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
398 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::getShort" );
399 return getValue(columnIndex);
401 // -------------------------------------------------------------------------
402 ::rtl::OUString SAL_CALL OResultSet::getString( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
404 //RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::getString" );
405 return getValue(columnIndex);
407 // -------------------------------------------------------------------------
408 ::com::sun::star::util::Time SAL_CALL OResultSet::getTime( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
410 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::getTime" );
411 return getValue(columnIndex);
413 // -------------------------------------------------------------------------
414 ::com::sun::star::util::DateTime SAL_CALL OResultSet::getTimestamp( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
416 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::getTimestamp" );
417 return getValue(columnIndex);
419 // -------------------------------------------------------------------------
421 sal_Bool SAL_CALL OResultSet::isAfterLast( ) throw(SQLException, RuntimeException)
423 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::isAfterLast" );
424 ::osl::MutexGuard aGuard( m_aMutex );
425 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
428 return m_nRowPos == sal_Int32(m_pFileSet->get().size());
430 // -------------------------------------------------------------------------
431 sal_Bool SAL_CALL OResultSet::isFirst( ) throw(SQLException, RuntimeException)
433 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::isFirst" );
434 ::osl::MutexGuard aGuard( m_aMutex );
435 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
438 return m_nRowPos == 0;
440 // -------------------------------------------------------------------------
441 sal_Bool SAL_CALL OResultSet::isLast( ) throw(SQLException, RuntimeException)
443 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::isLast" );
444 ::osl::MutexGuard aGuard( m_aMutex );
445 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
448 return m_nRowPos == sal_Int32(m_pFileSet->get().size() - 1);
450 // -------------------------------------------------------------------------
451 void SAL_CALL OResultSet::beforeFirst( ) throw(SQLException, RuntimeException)
453 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::beforeFirst" );
454 ::osl::MutexGuard aGuard( m_aMutex );
455 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
458 if(first())
459 previous();
461 // -------------------------------------------------------------------------
462 void SAL_CALL OResultSet::afterLast( ) throw(SQLException, RuntimeException)
464 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::afterLast" );
465 ::osl::MutexGuard aGuard( m_aMutex );
466 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
469 if(last())
470 next();
471 m_bEOF = sal_True;
473 // -------------------------------------------------------------------------
475 void SAL_CALL OResultSet::close( ) throw(SQLException, RuntimeException)
477 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::close" );
478 dispose();
480 // -------------------------------------------------------------------------
482 sal_Bool SAL_CALL OResultSet::first( ) throw(SQLException, RuntimeException)
484 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::first" );
485 ::osl::MutexGuard aGuard( m_aMutex );
486 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
487 return m_pTable ? m_aSkipDeletedSet.skipDeleted(IResultSetHelper::FIRST,1,sal_True) : sal_False;
489 // -------------------------------------------------------------------------
491 sal_Bool SAL_CALL OResultSet::last( ) throw(SQLException, RuntimeException)
493 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::last" );
494 // here I know definitely that I stand on the last record
495 ::osl::MutexGuard aGuard( m_aMutex );
496 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
497 return m_pTable ? m_aSkipDeletedSet.skipDeleted(IResultSetHelper::LAST,1,sal_True) : sal_False;
499 // -------------------------------------------------------------------------
500 sal_Bool SAL_CALL OResultSet::absolute( sal_Int32 row ) throw(SQLException, RuntimeException)
502 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::absolute" );
503 ::osl::MutexGuard aGuard( m_aMutex );
504 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
505 return m_pTable ? m_aSkipDeletedSet.skipDeleted(IResultSetHelper::ABSOLUTE,row,sal_True) : sal_False;
507 // -------------------------------------------------------------------------
508 sal_Bool SAL_CALL OResultSet::relative( sal_Int32 row ) throw(SQLException, RuntimeException)
510 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::relative" );
511 ::osl::MutexGuard aGuard( m_aMutex );
512 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
513 return m_pTable ? m_aSkipDeletedSet.skipDeleted(IResultSetHelper::RELATIVE,row,sal_True) : sal_False;
515 // -------------------------------------------------------------------------
516 sal_Bool SAL_CALL OResultSet::previous( ) throw(SQLException, RuntimeException)
518 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::previous" );
519 ::osl::MutexGuard aGuard( m_aMutex );
520 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
521 return m_pTable ? m_aSkipDeletedSet.skipDeleted(IResultSetHelper::PRIOR,0,sal_True) : sal_False;
523 // -------------------------------------------------------------------------
524 Reference< XInterface > SAL_CALL OResultSet::getStatement( ) throw(SQLException, RuntimeException)
526 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::getStatement" );
527 ::osl::MutexGuard aGuard( m_aMutex );
528 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
531 return m_xStatement;
533 // -------------------------------------------------------------------------
535 sal_Bool SAL_CALL OResultSet::rowDeleted( ) throw(SQLException, RuntimeException)
537 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::rowDeleted" );
538 ::osl::MutexGuard aGuard( m_aMutex );
539 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
542 return m_bRowDeleted;
544 // -------------------------------------------------------------------------
545 sal_Bool SAL_CALL OResultSet::rowInserted( ) throw(SQLException, RuntimeException)
546 { ::osl::MutexGuard aGuard( m_aMutex );
547 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
550 return m_bRowInserted;
552 // -------------------------------------------------------------------------
553 sal_Bool SAL_CALL OResultSet::rowUpdated( ) throw(SQLException, RuntimeException)
555 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::rowInserted" );
556 ::osl::MutexGuard aGuard( m_aMutex );
557 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
560 return m_bRowUpdated;
562 // -------------------------------------------------------------------------
564 sal_Bool SAL_CALL OResultSet::isBeforeFirst( ) throw(SQLException, RuntimeException)
566 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::isBeforeFirst" );
567 ::osl::MutexGuard aGuard( m_aMutex );
568 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
571 return m_nRowPos == -1;
573 // -------------------------------------------------------------------------
574 sal_Bool OResultSet::evaluate()
576 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::evaluate" );
577 OSL_ENSURE(m_pSQLAnalyzer,"OResultSet::evaluate: Analyzer isn't set!");
578 sal_Bool bRet = sal_True;
579 while(!m_pSQLAnalyzer->evaluateRestriction())
581 if(m_pEvaluationKeySet)
583 if(m_aEvaluateIter == m_pEvaluationKeySet->end())
584 return sal_False;
585 bRet = m_pTable->seekRow(IResultSetHelper::BOOKMARK,(*m_aEvaluateIter),m_nRowPos);
586 ++m_aEvaluateIter;
588 else
589 bRet = m_pTable->seekRow(IResultSetHelper::NEXT,1,m_nRowPos);
590 if(bRet)
592 if(m_pEvaluationKeySet)
594 bRet = m_pTable->fetchRow(m_aEvaluateRow,m_pTable->getTableColumns().getBody(),sal_True,sal_True);
595 evaluate();
598 else
599 bRet = m_pTable->fetchRow(m_aRow,m_xColumns.getBody(),sal_False,sal_True);
603 return bRet;
605 // -------------------------------------------------------------------------
607 sal_Bool SAL_CALL OResultSet::next( ) throw(SQLException, RuntimeException)
609 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::next" );
610 ::osl::MutexGuard aGuard( m_aMutex );
611 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
613 return m_pTable ? m_aSkipDeletedSet.skipDeleted(IResultSetHelper::NEXT,1,sal_True) : sal_False;
615 // -------------------------------------------------------------------------
617 sal_Bool SAL_CALL OResultSet::wasNull( ) throw(SQLException, RuntimeException)
619 //RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::wasNull" );
620 ::osl::MutexGuard aGuard( m_aMutex );
621 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
623 return m_bWasNull;
625 // -------------------------------------------------------------------------
627 void SAL_CALL OResultSet::cancel( ) throw(RuntimeException)
629 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::cancel" );
631 // -------------------------------------------------------------------------
632 void SAL_CALL OResultSet::clearWarnings( ) throw(SQLException, RuntimeException)
634 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::clearWarnings" );
636 // -------------------------------------------------------------------------
637 Any SAL_CALL OResultSet::getWarnings( ) throw(SQLException, RuntimeException)
639 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::getWarnings" );
640 return Any();
642 // -------------------------------------------------------------------------
643 void SAL_CALL OResultSet::insertRow( ) throw(SQLException, RuntimeException)
645 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::insertRow" );
646 ::osl::MutexGuard aGuard( m_aMutex );
647 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
650 if(!m_bInserted || !m_pTable)
651 throwFunctionSequenceException(*this);
653 // we know that we append new rows at the end
654 // so we have to know where the end is
655 m_aSkipDeletedSet.skipDeleted(IResultSetHelper::LAST,1,sal_False);
656 m_bRowInserted = m_pTable->InsertRow(m_aInsertRow.getBody(), TRUE,m_xColsIdx);
657 if(m_bRowInserted && m_pFileSet.isValid())
659 sal_Int32 nPos = (m_aInsertRow->get())[0]->getValue();
660 m_pFileSet->get().push_back(nPos);
661 *(m_aInsertRow->get())[0] = sal_Int32(m_pFileSet->get().size());
662 clearInsertRow();
664 m_aSkipDeletedSet.insertNewPosition((m_aRow->get())[0]->getValue());
667 // -------------------------------------------------------------------------
668 void SAL_CALL OResultSet::updateRow( ) throw(SQLException, RuntimeException)
670 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::updateRow" );
671 ::osl::MutexGuard aGuard( m_aMutex );
672 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
674 if(!m_pTable || m_pTable->isReadOnly())
675 lcl_throwError(STR_TABLE_READONLY,*this);
677 m_bRowUpdated = m_pTable->UpdateRow(m_aInsertRow.getBody(), m_aRow,m_xColsIdx);
678 *(m_aInsertRow->get())[0] = (sal_Int32)(m_aRow->get())[0]->getValue();
680 clearInsertRow();
682 // -------------------------------------------------------------------------
683 void SAL_CALL OResultSet::deleteRow() throw(SQLException, RuntimeException)
685 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::deleteRow" );
686 ::osl::MutexGuard aGuard( m_aMutex );
687 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
690 if(!m_pTable || m_pTable->isReadOnly())
691 lcl_throwError(STR_TABLE_READONLY,*this);
692 if (m_bShowDeleted)
693 lcl_throwError(STR_DELETE_ROW,*this);
694 if(m_aRow->isDeleted())
695 lcl_throwError(STR_ROW_ALREADY_DELETED,*this);
697 sal_Int32 nPos = (sal_Int32)(m_aRow->get())[0]->getValue();
698 m_bRowDeleted = m_pTable->DeleteRow(m_xColumns.getBody());
699 if(m_bRowDeleted && m_pFileSet.isValid())
701 m_aRow->setDeleted(sal_True);
702 // don't touch the m_pFileSet member here
703 m_aSkipDeletedSet.deletePosition(nPos);
706 // -------------------------------------------------------------------------
707 void SAL_CALL OResultSet::cancelRowUpdates( ) throw(SQLException, RuntimeException)
709 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::cancelRowUpdates" );
710 ::osl::MutexGuard aGuard( m_aMutex );
711 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
714 m_bInserted = sal_False;
715 m_bRowUpdated = sal_False;
716 m_bRowInserted = sal_False;
717 m_bRowDeleted = sal_False;
719 if(m_aInsertRow.isValid())
721 OValueRefVector::Vector::iterator aIter = m_aInsertRow->get().begin()+1;
722 for(;aIter != m_aInsertRow->get().end();++aIter)
724 (*aIter)->setBound(sal_False);
725 (*aIter)->setNull();
729 // -------------------------------------------------------------------------
731 void SAL_CALL OResultSet::moveToInsertRow( ) throw(SQLException, RuntimeException)
733 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::moveToInsertRow" );
734 ::osl::MutexGuard aGuard( m_aMutex );
735 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
737 if(!m_pTable || m_pTable->isReadOnly())
738 lcl_throwError(STR_TABLE_READONLY,*this);
740 m_bInserted = sal_True;
742 OValueRefVector::Vector::iterator aIter = m_aInsertRow->get().begin()+1;
743 for(;aIter != m_aInsertRow->get().end();++aIter)
745 (*aIter)->setBound(sal_False);
746 (*aIter)->setNull();
749 // -------------------------------------------------------------------------
751 void SAL_CALL OResultSet::moveToCurrentRow( ) throw(SQLException, RuntimeException)
753 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::moveToCurrentRow" );
755 // -------------------------------------------------------------------------
756 void OResultSet::updateValue(sal_Int32 columnIndex ,const ORowSetValue& x) throw(SQLException, RuntimeException)
758 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::updateValue" );
759 ::osl::MutexGuard aGuard( m_aMutex );
760 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
762 checkIndex(columnIndex );
763 columnIndex = mapColumn(columnIndex);
765 (m_aInsertRow->get())[columnIndex]->setBound(sal_True);
766 *(m_aInsertRow->get())[columnIndex] = x;
768 // -----------------------------------------------------------------------------
770 void SAL_CALL OResultSet::updateNull( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
772 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::updateNull" );
773 ORowSetValue aEmpty;
774 updateValue(columnIndex,aEmpty);
776 // -------------------------------------------------------------------------
778 void SAL_CALL OResultSet::updateBoolean( sal_Int32 columnIndex, sal_Bool x ) throw(SQLException, RuntimeException)
780 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::updateBoolean" );
781 updateValue(columnIndex,x);
783 // -------------------------------------------------------------------------
784 void SAL_CALL OResultSet::updateByte( sal_Int32 columnIndex, sal_Int8 x ) throw(SQLException, RuntimeException)
786 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::updateByte" );
787 updateValue(columnIndex,x);
789 // -------------------------------------------------------------------------
791 void SAL_CALL OResultSet::updateShort( sal_Int32 columnIndex, sal_Int16 x ) throw(SQLException, RuntimeException)
793 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::updateShort" );
794 updateValue(columnIndex,x);
796 // -------------------------------------------------------------------------
797 void SAL_CALL OResultSet::updateInt( sal_Int32 columnIndex, sal_Int32 x ) throw(SQLException, RuntimeException)
799 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::updateInt" );
800 updateValue(columnIndex,x);
802 // -------------------------------------------------------------------------
803 void SAL_CALL OResultSet::updateLong( sal_Int32 /*columnIndex*/, sal_Int64 /*x*/ ) throw(SQLException, RuntimeException)
805 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::updateLong" );
806 ::dbtools::throwFeatureNotImplementedException( "XRowUpdate::updateLong", *this );
808 // -----------------------------------------------------------------------
809 void SAL_CALL OResultSet::updateFloat( sal_Int32 columnIndex, float x ) throw(SQLException, RuntimeException)
811 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::updateFloat" );
812 updateValue(columnIndex,x);
814 // -------------------------------------------------------------------------
816 void SAL_CALL OResultSet::updateDouble( sal_Int32 columnIndex, double x ) throw(SQLException, RuntimeException)
818 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::updateDouble" );
819 updateValue(columnIndex,x);
821 // -------------------------------------------------------------------------
822 void SAL_CALL OResultSet::updateString( sal_Int32 columnIndex, const ::rtl::OUString& x ) throw(SQLException, RuntimeException)
824 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::updateString" );
825 updateValue(columnIndex,x);
827 // -------------------------------------------------------------------------
828 void SAL_CALL OResultSet::updateBytes( sal_Int32 columnIndex, const Sequence< sal_Int8 >& x ) throw(SQLException, RuntimeException)
830 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::updateBytes" );
831 updateValue(columnIndex,x);
833 // -------------------------------------------------------------------------
834 void SAL_CALL OResultSet::updateDate( sal_Int32 columnIndex, const ::com::sun::star::util::Date& x ) throw(SQLException, RuntimeException)
836 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::updateDate" );
837 updateValue(columnIndex,x);
839 // -------------------------------------------------------------------------
841 void SAL_CALL OResultSet::updateTime( sal_Int32 columnIndex, const ::com::sun::star::util::Time& x ) throw(SQLException, RuntimeException)
843 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::updateTime" );
844 updateValue(columnIndex,x);
846 // -------------------------------------------------------------------------
848 void SAL_CALL OResultSet::updateTimestamp( sal_Int32 columnIndex, const ::com::sun::star::util::DateTime& x ) throw(SQLException, RuntimeException)
850 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::updateTimestamp" );
851 updateValue(columnIndex,x);
853 // -------------------------------------------------------------------------
855 void SAL_CALL OResultSet::updateBinaryStream( sal_Int32 columnIndex, const Reference< ::com::sun::star::io::XInputStream >& x, sal_Int32 length ) throw(SQLException, RuntimeException)
857 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::updateBinaryStream" );
858 ::osl::MutexGuard aGuard( m_aMutex );
859 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
861 if(!x.is())
862 ::dbtools::throwFunctionSequenceException(*this);
864 Sequence<sal_Int8> aSeq;
865 x->readBytes(aSeq,length);
866 updateValue(columnIndex,aSeq);
868 // -------------------------------------------------------------------------
869 void SAL_CALL OResultSet::updateCharacterStream( sal_Int32 columnIndex, const Reference< ::com::sun::star::io::XInputStream >& x, sal_Int32 length ) throw(SQLException, RuntimeException)
871 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::updateCharacterStream" );
872 updateBinaryStream(columnIndex,x,length);
874 // -------------------------------------------------------------------------
875 void SAL_CALL OResultSet::refreshRow( ) throw(SQLException, RuntimeException)
877 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::refreshRow" );
878 ::osl::MutexGuard aGuard( m_aMutex );
879 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
881 // -------------------------------------------------------------------------
882 void SAL_CALL OResultSet::updateObject( sal_Int32 columnIndex, const Any& x ) throw(SQLException, RuntimeException)
884 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::updateObject" );
885 if (!::dbtools::implUpdateObject(this, columnIndex, x))
886 throw SQLException();
888 // -------------------------------------------------------------------------
890 void SAL_CALL OResultSet::updateNumericObject( sal_Int32 columnIndex, const Any& x, sal_Int32 /*scale*/ ) throw(SQLException, RuntimeException)
892 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::updateNumericObject" );
893 if (!::dbtools::implUpdateObject(this, columnIndex, x))
894 throw SQLException();
896 // -------------------------------------------------------------------------
897 IPropertyArrayHelper* OResultSet::createArrayHelper( ) const
899 //RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::createArrayHelper" );
900 Sequence< Property > aProps;
901 describeProperties(aProps);
902 return new ::cppu::OPropertyArrayHelper(aProps);
904 // -------------------------------------------------------------------------
905 IPropertyArrayHelper & OResultSet::getInfoHelper()
907 //RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::getInfoHelper" );
908 return *const_cast<OResultSet*>(this)->getArrayHelper();
911 //------------------------------------------------------------------
912 BOOL OResultSet::ExecuteRow(IResultSetHelper::Movement eFirstCursorPosition,
913 INT32 nFirstOffset,
914 BOOL bEvaluate,
915 BOOL bRetrieveData)
917 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::ExecuteRow" );
918 OSL_ENSURE(m_pSQLAnalyzer,"OResultSet::ExecuteRow: Analyzer isn't set!");
920 // Fuer weitere Fetch-Operationen werden diese Angaben ggf. veraendert ...
921 IResultSetHelper::Movement eCursorPosition = eFirstCursorPosition;
922 INT32 nOffset = nFirstOffset;
924 const OSQLColumns & rTableCols = m_pTable->getTableColumns().getBody();
925 BOOL bHasRestriction = m_pSQLAnalyzer->hasRestriction();
926 again:
928 // protect from reading over the end when someboby is inserting while we are reading
929 // this method works only for dBase at the moment !!!!
930 if (eCursorPosition == IResultSetHelper::NEXT && m_nFilePos == m_nLastVisitedPos)
932 return sal_False;
935 if (!m_pTable || !m_pTable->seekRow(eCursorPosition, nOffset, m_nFilePos))
937 return sal_False;
940 if (!bEvaluate) // Laeuft keine Auswertung, dann nur Ergebniszeile fuellen
942 m_pTable->fetchRow(m_aRow,rTableCols, sal_True,bRetrieveData);
944 else
946 m_pTable->fetchRow(m_aEvaluateRow, rTableCols, sal_True,bRetrieveData || bHasRestriction);
948 if ( (!m_bShowDeleted && m_aEvaluateRow->isDeleted())
949 || (bHasRestriction && //!bShowDeleted && m_aEvaluateRow->isDeleted() ||// keine Anzeige von geloeschten Saetzen
950 !m_pSQLAnalyzer->evaluateRestriction())) // Auswerten der Bedingungen
951 { // naechsten Satz auswerten
952 // aktuelle Zeile loeschen im Keyset
953 if (m_pEvaluationKeySet)
955 ++m_aEvaluateIter;
956 if (m_pEvaluationKeySet->end() != m_aEvaluateIter)
957 nOffset = (*m_aEvaluateIter);
958 else
960 return sal_False;
963 else if (m_pFileSet.isValid())
965 OSL_ENSURE(//!m_pFileSet->IsFrozen() &&
966 eCursorPosition == IResultSetHelper::NEXT, "Falsche CursorPosition!");
967 eCursorPosition = IResultSetHelper::NEXT;
968 nOffset = 1;
970 else if (eCursorPosition == IResultSetHelper::FIRST ||
971 eCursorPosition == IResultSetHelper::NEXT ||
972 eCursorPosition == IResultSetHelper::ABSOLUTE)
974 eCursorPosition = IResultSetHelper::NEXT;
975 nOffset = 1;
977 else if (eCursorPosition == IResultSetHelper::LAST ||
978 eCursorPosition == IResultSetHelper::PRIOR)
980 eCursorPosition = IResultSetHelper::PRIOR;
981 nOffset = 1;
983 else if (eCursorPosition == IResultSetHelper::RELATIVE)
985 eCursorPosition = (nOffset >= 0) ? IResultSetHelper::NEXT : IResultSetHelper::PRIOR;
987 else
989 // aStatus.Set(SQL_STAT_NO_DATA_FOUND);
990 return sal_False;
992 // Nochmal probieren ...
993 goto again;
997 // Evaluate darf nur gesetzt sein,
998 // wenn der Keyset weiter aufgebaut werden soll
999 if (m_aSQLIterator.getStatementType() == SQL_STATEMENT_SELECT && !isCount() &&
1000 (m_pFileSet.isValid() || m_pSortIndex) && bEvaluate)
1002 if (m_pSortIndex)
1004 OKeyValue* pKeyValue = GetOrderbyKeyValue(m_aEvaluateRow);
1005 m_pSortIndex->AddKeyValue(pKeyValue);
1007 else if (m_pFileSet.isValid())
1009 // OSL_ENSURE(!m_pFileSet->IsFrozen() , "Falsche CursorPosition!");
1010 sal_uInt32 nBookmarkValue = Abs((sal_Int32)(m_aEvaluateRow->get())[0]->getValue());
1011 m_pFileSet->get().push_back(nBookmarkValue);
1014 else if (m_aSQLIterator.getStatementType() == SQL_STATEMENT_UPDATE)
1016 sal_Bool bOK = sal_True;
1017 if (bEvaluate)
1019 // jetzt die eigentliche Ergebniszeile Lesen
1020 bOK = m_pTable->fetchRow(m_aEvaluateRow, m_pTable->getTableColumns().getBody(), sal_True,TRUE);
1023 if (bOK)
1025 // Nur die zu aendernden Werte uebergeben:
1026 if(!m_pTable->UpdateRow(m_aAssignValues.getBody(),m_aEvaluateRow,m_xColsIdx))
1027 return sal_False;
1030 else if (m_aSQLIterator.getStatementType() == SQL_STATEMENT_DELETE)
1032 sal_Bool bOK = sal_True;
1033 if (bEvaluate)
1035 bOK = m_pTable->fetchRow(m_aEvaluateRow, m_pTable->getTableColumns().getBody(), sal_True,TRUE);
1037 if (bOK)
1039 if(!m_pTable->DeleteRow(m_xColumns.getBody()))
1040 return sal_False;
1043 return sal_True;
1046 //-------------------------------------------------------------------
1047 BOOL OResultSet::Move(IResultSetHelper::Movement eCursorPosition, INT32 nOffset, BOOL bRetrieveData)
1049 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::Move" );
1051 //IgnoreDeletedRows:
1053 INT32 nTempPos = m_nRowPos;
1054 // exclusiver zugriff auf die Tabelle
1055 // NAMESPACE_VOS(OGuard)* pGuard = m_pTable->Lock();
1057 if (m_aSQLIterator.getStatementType() == SQL_STATEMENT_SELECT &&
1058 !isCount())
1060 if (!m_pFileSet.isValid()) // kein Index verfuegbar
1062 // Normales FETCH
1063 ExecuteRow(eCursorPosition,nOffset,FALSE,bRetrieveData);
1065 // now set the bookmark for outside this is the logical pos and not the file pos
1066 *(*m_aRow->get().begin()) = sal_Int32(m_nRowPos + 1);
1068 else
1070 switch(eCursorPosition)
1072 case IResultSetHelper::NEXT:
1073 ++m_nRowPos;
1074 break;
1075 case IResultSetHelper::PRIOR:
1076 if (m_nRowPos >= 0)
1077 --m_nRowPos;
1078 break;
1079 case IResultSetHelper::FIRST:
1080 m_nRowPos = 0;
1081 break;
1082 case IResultSetHelper::LAST:
1083 // OSL_ENSURE(IsRowCountFinal(), "Fehler im Keyset!"); // muss eingefroren sein, sonst Fehler beim SQLCursor
1084 m_nRowPos = m_pFileSet->get().size() - 1;
1085 break;
1086 case IResultSetHelper::RELATIVE:
1087 m_nRowPos += nOffset;
1088 break;
1089 case IResultSetHelper::ABSOLUTE:
1090 case IResultSetHelper::BOOKMARK:
1091 if ( m_nRowPos == (nOffset -1) )
1092 return sal_True;
1093 m_nRowPos = nOffset -1;
1094 break;
1097 // OffRange?
1098 // Der FileCursor ist ausserhalb des gueltigen Bereichs, wenn
1099 // a.) m_nRowPos < 1
1100 // b.) Ein KeySet besteht und m_nRowPos > m_pFileSet->size()
1101 if (m_nRowPos < 0 || (m_pFileSet->isFrozen() && eCursorPosition != IResultSetHelper::BOOKMARK && m_nRowPos >= (INT32)m_pFileSet->get().size() )) // && m_pFileSet->IsFrozen()
1103 // aStatus.Set(SQL_STAT_NO_DATA_FOUND);
1104 goto Error;
1106 else
1108 if (m_nRowPos < (INT32)m_pFileSet->get().size())
1110 // Fetch ueber Index
1111 ExecuteRow(IResultSetHelper::BOOKMARK,(m_pFileSet->get())[m_nRowPos],FALSE,bRetrieveData);
1113 // now set the bookmark for outside
1114 *(*m_aRow->get().begin()) = sal_Int32(m_nRowPos + 1);
1115 if ( (bRetrieveData || m_pSQLAnalyzer->hasRestriction()) && m_pSQLAnalyzer->hasFunctions() )
1117 m_pSQLAnalyzer->setSelectionEvaluationResult(m_aSelectRow,m_aColMapping);
1120 else // Index muss weiter aufgebaut werden
1122 // Zunaechst auf die letzte bekannte Zeile setzen
1123 if (!m_pFileSet->get().empty())
1125 m_aFileSetIter = m_pFileSet->get().end()-1;
1126 // m_pFileSet->SeekPos(m_pFileSet->size()-1);
1127 m_pTable->seekRow(IResultSetHelper::BOOKMARK, *m_aFileSetIter, m_nFilePos);
1129 sal_Bool bOK = sal_True;
1130 // Ermitteln der Anzahl weiterer Fetches
1131 while (bOK && m_nRowPos >= (INT32)m_pFileSet->get().size())
1133 if (m_pEvaluationKeySet)
1135 if (m_nRowPos >= (INT32)m_pEvaluationKeySet->size())
1136 return sal_False;
1137 // aStatus.Set(SQL_STAT_NO_DATA_FOUND);
1138 else if (m_nRowPos == 0)
1140 m_aEvaluateIter = m_pEvaluationKeySet->begin();
1141 bOK = ExecuteRow(IResultSetHelper::BOOKMARK,*m_aEvaluateIter,TRUE, bRetrieveData);
1143 else
1145 ++m_aEvaluateIter;
1146 bOK = ExecuteRow(IResultSetHelper::BOOKMARK,*m_aEvaluateIter,TRUE, bRetrieveData);
1149 else
1150 bOK = ExecuteRow(IResultSetHelper::NEXT,1,TRUE, FALSE);//bRetrieveData);
1153 if (bOK)
1155 // jetzt nochmal die Ergebnisse lesen
1156 m_pTable->fetchRow(m_aRow, m_pTable->getTableColumns().getBody(), sal_True,bRetrieveData);
1158 // now set the bookmark for outside
1159 *(*m_aRow->get().begin()) = sal_Int32(m_nRowPos + 1);
1161 if ( (bRetrieveData || m_pSQLAnalyzer->hasRestriction()) && m_pSQLAnalyzer->hasFunctions() )
1163 m_pSQLAnalyzer->setSelectionEvaluationResult(m_aSelectRow,m_aColMapping);
1166 else if (!m_pFileSet->isFrozen()) // keinen gueltigen Satz gefunden
1168 //m_pFileSet->Freeze();
1169 m_pFileSet->setFrozen();
1171 // DELETEZ(m_pEvaluationKeySet);
1172 m_pEvaluationKeySet = NULL;
1173 // aStatus.Set(SQL_STAT_NO_DATA_FOUND);
1174 goto Error;
1180 else if (m_aSQLIterator.getStatementType() == SQL_STATEMENT_SELECT && isCount())
1182 // Fetch des COUNT(*)
1183 switch (eCursorPosition)
1185 case IResultSetHelper::NEXT:
1186 ++m_nRowPos;
1187 break;
1188 case IResultSetHelper::PRIOR:
1189 --m_nRowPos;
1190 break;
1191 case IResultSetHelper::FIRST:
1192 m_nRowPos = 0;
1193 break;
1194 case IResultSetHelper::LAST:
1195 m_nRowPos = 0;
1196 break;
1197 case IResultSetHelper::RELATIVE:
1198 m_nRowPos += nOffset;
1199 break;
1200 case IResultSetHelper::ABSOLUTE:
1201 case IResultSetHelper::BOOKMARK:
1202 m_nRowPos = nOffset - 1;
1203 break;
1206 if (m_nRowPos == 0)
1208 // COUNT(*) in Ergebnisrow packen
1209 // (muss die erste und einzige Variable in der Row sein)
1210 if (m_aRow->get().size() >= 2)
1212 *(m_aRow->get())[1] = m_nRowCountResult;
1213 *(m_aRow->get())[0] = sal_Int32(1);
1214 (m_aRow->get())[1]->setBound(sal_True);
1215 (m_aSelectRow->get())[1] = (m_aRow->get())[1];
1218 else
1220 m_bEOF = sal_True;
1221 m_nRowPos = 1;
1222 return sal_False;
1225 else
1226 // Fetch nur bei SELECT moeglich!
1227 return sal_False;
1229 return sal_True;
1231 Error:
1232 // steht der Cursor vor dem ersten Satz
1233 // dann wird die position beibehalten
1234 if (nTempPos == -1)
1235 m_nRowPos = nTempPos;
1236 else
1238 switch(eCursorPosition)
1240 case IResultSetHelper::PRIOR:
1241 case IResultSetHelper::FIRST:
1242 m_nRowPos = -1;
1243 break;
1244 case IResultSetHelper::LAST:
1245 case IResultSetHelper::NEXT:
1246 case IResultSetHelper::ABSOLUTE:
1247 case IResultSetHelper::RELATIVE:
1248 if (nOffset > 0)
1249 m_nRowPos = m_pFileSet.isValid() ? (sal_Int32)m_pFileSet->get().size() : -1;
1250 else if (nOffset < 0)
1251 m_nRowPos = -1;
1252 break;
1253 case IResultSetHelper::BOOKMARK:
1254 m_nRowPos = nTempPos; // vorherige Position
1257 // delete pGuard;
1258 // rMode = (!bShowDeleted && aStatus.IsSuccessful() && m_aRow->isDeleted()) ? // keine Anzeige von geloeschten Saetzen
1259 // OCursor::SQL_MOD_INVALID : OCursor::SQL_MOD_NONE;
1260 return sal_False;
1262 // -------------------------------------------------------------------------
1263 void OResultSet::sortRows()
1265 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::sortRows" );
1266 if (!m_pSQLAnalyzer->hasRestriction() && m_aOrderbyColumnNumber.size() == 1)
1268 // Ist nur ein Feld fuer die Sortierung angegeben
1269 // Und diese Feld ist indiziert, dann den Index ausnutzen
1270 Reference<XIndexesSupplier> xIndexSup;
1271 m_pTable->queryInterface(::getCppuType((const Reference<XIndexesSupplier>*)0)) >>= xIndexSup;
1272 // Reference<XIndexesSupplier> xIndexSup(m_pTable,UNO_QUERY);
1273 Reference<XIndexAccess> xIndexes;
1274 if(xIndexSup.is())
1276 xIndexes.set(xIndexSup->getIndexes(),UNO_QUERY);
1277 Reference<XPropertySet> xColProp;
1278 if(m_aOrderbyColumnNumber[0] < xIndexes->getCount())
1280 xColProp.set(xIndexes->getByIndex(m_aOrderbyColumnNumber[0]),UNO_QUERY);
1281 // iterate through the indexes to find the matching column
1282 const sal_Int32 nCount = xIndexes->getCount();
1283 for(sal_Int32 i=0; i < nCount;++i)
1285 Reference<XColumnsSupplier> xIndex(xIndexes->getByIndex(i),UNO_QUERY);
1286 Reference<XNameAccess> xIndexCols = xIndex->getColumns();
1287 if(xIndexCols->hasByName(comphelper::getString(xColProp->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME)))))
1289 m_pFileSet = new OKeySet();
1291 if(fillIndexValues(xIndex))
1292 return;
1299 OSortIndex::TKeyTypeVector eKeyType(m_aOrderbyColumnNumber.size());
1300 ::std::vector<sal_Int32>::iterator aOrderByIter = m_aOrderbyColumnNumber.begin();
1301 for (::std::vector<sal_Int16>::size_type i=0;aOrderByIter != m_aOrderbyColumnNumber.end(); ++aOrderByIter,++i)
1303 OSL_ENSURE((sal_Int32)m_aRow->get().size() > *aOrderByIter,"Invalid Index");
1304 switch ((*(m_aRow->get().begin()+*aOrderByIter))->getValue().getTypeKind())
1306 case DataType::CHAR:
1307 case DataType::VARCHAR:
1308 case DataType::LONGVARCHAR:
1309 eKeyType[i] = SQL_ORDERBYKEY_STRING;
1310 break;
1312 case DataType::OTHER:
1313 case DataType::TINYINT:
1314 case DataType::SMALLINT:
1315 case DataType::INTEGER:
1316 case DataType::DECIMAL:
1317 case DataType::NUMERIC:
1318 case DataType::REAL:
1319 case DataType::DOUBLE:
1320 case DataType::DATE:
1321 case DataType::TIME:
1322 case DataType::TIMESTAMP:
1323 case DataType::BIT:
1324 eKeyType[i] = SQL_ORDERBYKEY_DOUBLE;
1325 break;
1327 // Andere Typen sind nicht implementiert (und damit immer FALSE)
1328 default:
1329 eKeyType[i] = SQL_ORDERBYKEY_NONE;
1330 OSL_ASSERT("OFILECursor::Execute: Datentyp nicht implementiert");
1331 break;
1333 (m_aEvaluateRow->get())[*aOrderByIter]->setBound(sal_True);
1336 m_pSortIndex = new OSortIndex(eKeyType,m_aOrderbyAscending);
1338 if (m_pEvaluationKeySet)
1340 m_aEvaluateIter = m_pEvaluationKeySet->begin();
1342 while (m_aEvaluateIter != m_pEvaluationKeySet->end())
1344 ExecuteRow(IResultSetHelper::BOOKMARK,(*m_aEvaluateIter),TRUE);
1345 ++m_aEvaluateIter;
1348 else
1350 while (ExecuteRow(IResultSetHelper::NEXT,1,TRUE))
1355 // Sortiertes Keyset erzeugen
1356 // DELETEZ(m_pEvaluationKeySet);
1357 m_pEvaluationKeySet = NULL;
1358 m_pFileSet = NULL;
1359 m_pFileSet = m_pSortIndex->CreateKeySet();
1360 // if(!bDistinct)
1361 // SetRowCount(pFileSet->count());
1362 DELETEZ(m_pSortIndex);
1363 // Nun kann ueber den Index sortiert zugegriffen werden.
1367 // -------------------------------------------------------------------------
1368 BOOL OResultSet::OpenImpl()
1370 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::OpenImpl" );
1371 OSL_ENSURE(m_pSQLAnalyzer,"No analyzer set with setSqlAnalyzer!");
1372 if(!m_pTable)
1374 const OSQLTables& xTabs = m_aSQLIterator.getTables();
1375 if ((xTabs.begin() == xTabs.end()) || !xTabs.begin()->second.is())
1376 lcl_throwError(STR_QUERY_TOO_COMPLEX,*this);
1378 if ( xTabs.size() > 1 || m_aSQLIterator.hasErrors() )
1379 lcl_throwError(STR_QUERY_MORE_TABLES,*this);
1381 OSQLTable xTable = xTabs.begin()->second;
1382 m_xColumns = m_aSQLIterator.getSelectColumns();
1384 m_xColNames = xTable->getColumns();
1385 m_xColsIdx.set(m_xColNames,UNO_QUERY);
1386 doTableSpecials(xTable);
1387 Reference<XComponent> xComp(xTable,UNO_QUERY);
1388 if(xComp.is())
1389 xComp->addEventListener(this);
1392 m_pTable->refreshHeader();
1394 sal_Int32 nColumnCount = m_xColsIdx->getCount();
1396 initializeRow(m_aRow,nColumnCount);
1397 initializeRow(m_aEvaluateRow,nColumnCount);
1398 initializeRow(m_aInsertRow,nColumnCount);
1401 m_nResultSetConcurrency = (m_pTable->isReadOnly() || isCount()) ? ResultSetConcurrency::READ_ONLY : ResultSetConcurrency::UPDATABLE;
1403 // Neuen Index aufbauen:
1404 m_pFileSet = NULL;
1405 // DELETEZ(m_pEvaluationKeySet);
1407 // An den Anfang positionieren
1408 m_nRowPos = -1;
1409 m_nFilePos = 0;
1410 m_nRowCountResult = -1;
1412 // exclusiver zugriff auf die Tabelle
1413 // NAMESPACE_VOS(OGuard)* pGuard = pTable->Lock();
1414 m_nLastVisitedPos = m_pTable->getCurrentLastPos();
1416 switch(m_aSQLIterator.getStatementType())
1418 case SQL_STATEMENT_SELECT:
1420 if(isCount())
1422 if(m_xColumns->get().size() > 1)
1423 lcl_throwError(STR_QUERY_COMPLEX_COUNT,*this);
1425 m_nRowCountResult = 0;
1426 // Vorlaeufig einfach ueber alle Datensaetze iterieren und
1427 // dabei die Aktionen bearbeiten (bzw. einfach nur zaehlen):
1429 sal_Bool bOK = sal_True;
1430 if (m_pEvaluationKeySet)
1432 m_aEvaluateIter = m_pEvaluationKeySet->begin();
1433 bOK = m_aEvaluateIter == m_pEvaluationKeySet->end();
1436 while (bOK)
1438 if (m_pEvaluationKeySet)
1439 ExecuteRow(IResultSetHelper::BOOKMARK,(*m_aEvaluateIter),TRUE);
1440 else
1441 bOK = ExecuteRow(IResultSetHelper::NEXT,1,TRUE);
1443 if (bOK)
1445 m_nRowCountResult++;
1446 if(m_pEvaluationKeySet)
1448 ++m_aEvaluateIter;
1449 bOK = m_aEvaluateIter == m_pEvaluationKeySet->end();
1454 // Ergebnis von COUNT(*) in m_nRowCountResult merken.
1455 // nRowCount, also die Anzahl der Rows in der Ergebnismenge, ist bei dieser
1456 // Anfrage = 1!
1457 m_pEvaluationKeySet = NULL;
1458 // DELETEZ(m_pEvaluationKeySet);
1461 else
1463 BOOL bDistinct = FALSE;
1464 BOOL bWasSorted = FALSE;
1465 OSQLParseNode *pDistinct = m_pParseTree->getChild(1);
1466 ::std::vector<sal_Int32> aOrderbyColumnNumberSave;
1467 ::std::vector<TAscendingOrder> aOrderbyAscendingSave;
1469 if (pDistinct && pDistinct->getTokenID() == SQL_TOKEN_DISTINCT )
1471 // Sort on all columns, saving original order for later
1472 if(IsSorted())
1474 aOrderbyColumnNumberSave = m_aOrderbyColumnNumber;// .assign(m_aOrderbyColumnNumber.begin(), m_aOrderbyColumnNumber.end());
1475 m_aOrderbyColumnNumber.clear();
1476 aOrderbyAscendingSave.assign(m_aOrderbyAscending.begin(), m_aOrderbyAscending.end());
1477 bWasSorted = TRUE;
1480 // the first column is the bookmark column
1481 ::std::vector<sal_Int32>::iterator aColStart = (m_aColMapping.begin()+1);
1482 ::std::copy(aColStart, m_aColMapping.end(),::std::back_inserter(m_aOrderbyColumnNumber));
1483 // m_aOrderbyColumnNumber.assign(aColStart, m_aColMapping.end());
1484 m_aOrderbyAscending.assign(m_aColMapping.size()-1, SQL_ASC);
1485 bDistinct = TRUE;
1488 if (IsSorted())
1489 sortRows();
1491 if (!m_pFileSet.isValid())
1493 m_pFileSet = new OKeySet();
1495 if (!m_pSQLAnalyzer->hasRestriction())
1496 // jetzt kann das Keyset schon gefuellt werden!
1497 // Aber Achtung: es wird davon ausgegangen, das die FilePositionen als Folge 1..n
1498 // abgelegt werden!
1500 if ( m_nLastVisitedPos > 0)
1501 m_pFileSet->get().reserve( m_nLastVisitedPos );
1502 for (sal_Int32 i = 0; i < m_nLastVisitedPos; i++)
1503 m_pFileSet->get().push_back(i + 1);
1506 OSL_ENSURE(m_pFileSet.isValid(),"Kein KeySet vorhanden! :-(");
1508 if(bDistinct && m_pFileSet.isValid()) // sicher ist sicher
1510 OValueRow aSearchRow = new OValueVector(m_aRow->get().size());
1511 OValueRefVector::Vector::iterator aRowIter = m_aRow->get().begin();
1512 OValueVector::Vector::iterator aSearchIter = aSearchRow->get().begin();
1513 for ( ++aRowIter,++aSearchIter; // the first column is the bookmark column
1514 aRowIter != m_aRow->get().end();
1515 ++aRowIter,++aSearchIter)
1516 aSearchIter->setBound((*aRowIter)->isBound());
1518 size_t nMaxRow = m_pFileSet->get().size();
1520 if (nMaxRow)
1522 #if OSL_DEBUG_LEVEL > 1
1523 INT32 nFound=0;
1524 #endif
1525 INT32 nPos;
1526 INT32 nKey;
1528 for( size_t j = nMaxRow-1; j > 0; --j)
1530 nPos = (m_pFileSet->get())[j];
1531 ExecuteRow(IResultSetHelper::BOOKMARK,nPos,FALSE);
1532 m_pSQLAnalyzer->setSelectionEvaluationResult(m_aSelectRow,m_aColMapping);
1533 { // copy row values
1534 OValueRefVector::Vector::iterator copyFrom = m_aSelectRow->get().begin();
1535 OValueVector::Vector::iterator copyTo = aSearchRow->get().begin();
1536 for ( ++copyFrom,++copyTo; // the first column is the bookmark column
1537 copyFrom != m_aSelectRow->get().end();
1538 ++copyFrom,++copyTo)
1539 *copyTo = *(*copyFrom);
1540 // *aSearchRow = *m_aRow;
1543 // compare with next row
1544 nKey = (m_pFileSet->get())[j-1];
1545 ExecuteRow(IResultSetHelper::BOOKMARK,nKey,FALSE);
1546 m_pSQLAnalyzer->setSelectionEvaluationResult(m_aSelectRow,m_aColMapping);
1547 OValueRefVector::Vector::iterator loopInRow = m_aSelectRow->get().begin();
1548 OValueVector::Vector::iterator existentInSearchRow = aSearchRow->get().begin();
1549 for ( ++loopInRow,++existentInSearchRow; // the first column is the bookmark column
1550 loopInRow != m_aSelectRow->get().end();
1551 ++loopInRow,++existentInSearchRow)
1553 if ( (*loopInRow)->isBound() && !( *(*loopInRow) == *existentInSearchRow) )
1554 break;
1557 if(loopInRow == m_aSelectRow->get().end())
1558 (m_pFileSet->get())[j] = 0; // Rows match -- Mark for deletion by setting key to 0
1559 #if OSL_DEBUG_LEVEL > 1
1560 else
1561 nFound++;
1562 #endif
1565 m_pFileSet->get().erase(::std::remove_if(m_pFileSet->get().begin(),m_pFileSet->get().end(),
1566 ::std::bind2nd(::std::equal_to<sal_Int32>(),0))
1567 ,m_pFileSet->get().end());
1569 if (bWasSorted)
1571 // Re-sort on original requested order
1572 m_aOrderbyColumnNumber = aOrderbyColumnNumberSave;
1573 m_aOrderbyAscending.assign(aOrderbyAscendingSave.begin(), aOrderbyAscendingSave.end());
1575 TIntVector aEvaluationKeySet(m_pFileSet->get());
1576 m_pEvaluationKeySet = &aEvaluationKeySet;
1577 sortRows();
1579 else
1581 m_aOrderbyColumnNumber.clear();
1582 m_aOrderbyAscending.clear();
1583 ::std::sort(m_pFileSet->get().begin(),m_pFileSet->get().end());
1586 // SetRowCount(m_pFileSet->count());
1589 } break;
1591 case SQL_STATEMENT_UPDATE:
1592 case SQL_STATEMENT_DELETE:
1593 // waehrend der Bearbeitung die Anzahl der bearbeiteten Rows zaehlen:
1594 m_nRowCountResult = 0;
1595 // Vorlaeufig einfach ueber alle Datensaetze iterieren und
1596 // dabei die Aktionen bearbeiten (bzw. einfach nur zaehlen):
1599 sal_Bool bOK = sal_True;
1600 if (m_pEvaluationKeySet)
1602 m_aEvaluateIter = m_pEvaluationKeySet->begin();
1603 bOK = m_aEvaluateIter == m_pEvaluationKeySet->end();
1606 while (bOK)
1608 if (m_pEvaluationKeySet)
1609 ExecuteRow(IResultSetHelper::BOOKMARK,(*m_aEvaluateIter),TRUE);
1610 else
1611 bOK = ExecuteRow(IResultSetHelper::NEXT,1,TRUE);
1613 if (bOK)
1615 m_nRowCountResult++;
1616 if(m_pEvaluationKeySet)
1618 ++m_aEvaluateIter;
1619 bOK = m_aEvaluateIter == m_pEvaluationKeySet->end();
1624 // Ergebnis von COUNT(*) in nRowCountResult merken.
1625 // nRowCount, also die Anzahl der Rows in der Ergebnismenge, ist bei dieser
1626 // Anfrage = 1!
1627 // DELETEZ(m_pEvaluationKeySet);
1628 m_pEvaluationKeySet = NULL;
1630 // SetRowCount(1);
1631 break;
1632 case SQL_STATEMENT_INSERT:
1633 m_nRowCountResult = 0;
1635 OSL_ENSURE(m_aAssignValues.isValid(),"No assign values set!");
1636 if(!m_pTable->InsertRow(m_aAssignValues.getBody(), TRUE,m_xColsIdx))
1638 m_nFilePos = 0;
1639 return sal_False;
1642 m_nRowCountResult = 1;
1643 break;
1644 default:
1645 OSL_ENSURE( false, "OResultSet::OpenImpl: unsupported statement type!" );
1646 break;
1649 // FilePos zuruecksetzen
1650 m_nFilePos = 0;
1652 return sal_True;
1654 //--------------------------------------------------------------------------
1655 Sequence< sal_Int8 > OResultSet::getUnoTunnelImplementationId()
1657 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::getUnoTunnelImplementationId" );
1658 static ::cppu::OImplementationId * pId = 0;
1659 if (! pId)
1661 ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
1662 if (! pId)
1664 static ::cppu::OImplementationId aId;
1665 pId = &aId;
1668 return pId->getImplementationId();
1671 // com::sun::star::lang::XUnoTunnel
1672 //------------------------------------------------------------------
1673 sal_Int64 OResultSet::getSomething( const Sequence< sal_Int8 > & rId ) throw (RuntimeException)
1675 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::getSomething" );
1676 return (rId.getLength() == 16 && 0 == rtl_compareMemory(getUnoTunnelImplementationId().getConstArray(), rId.getConstArray(), 16 ) )
1677 ? reinterpret_cast< sal_Int64 >( this )
1678 : 0;
1680 // -----------------------------------------------------------------------------
1681 void OResultSet::setBoundedColumns(const OValueRefRow& _rRow,
1682 const OValueRefRow& _rSelectRow,
1683 const ::vos::ORef<connectivity::OSQLColumns>& _rxColumns,
1684 const Reference<XIndexAccess>& _xNames,
1685 sal_Bool _bSetColumnMapping,
1686 const Reference<XDatabaseMetaData>& _xMetaData,
1687 ::std::vector<sal_Int32>& _rColMapping)
1689 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::setBoundedColumns" );
1690 ::comphelper::UStringMixEqual aCase(_xMetaData->storesMixedCaseQuotedIdentifiers());
1692 Reference<XPropertySet> xTableColumn;
1693 ::rtl::OUString sTableColumnName, sSelectColumnRealName;
1695 const ::rtl::OUString sName = OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME);
1696 const ::rtl::OUString sRealName = OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_REALNAME);
1697 const ::rtl::OUString sType = OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPE);
1699 typedef ::std::map<OSQLColumns::Vector::iterator,sal_Bool> IterMap;
1700 IterMap aSelectIters;
1701 OValueRefVector::Vector::iterator aRowIter = _rRow->get().begin()+1;
1702 for (sal_Int32 i=0; // the first column is the bookmark column
1703 aRowIter != _rRow->get().end();
1704 ++i, ++aRowIter
1707 (*aRowIter)->setBound(sal_False);
1710 // get the table column and it's name
1711 _xNames->getByIndex(i) >>= xTableColumn;
1712 OSL_ENSURE(xTableColumn.is(), "OResultSet::setBoundedColumns: invalid table column!");
1713 if (xTableColumn.is())
1714 xTableColumn->getPropertyValue(sName) >>= sTableColumnName;
1715 else
1716 sTableColumnName = ::rtl::OUString();
1718 // look if we have such a select column
1719 // TODO: would like to have a O(log n) search here ...
1720 for ( OSQLColumns::Vector::iterator aIter = _rxColumns->get().begin();
1721 aIter != _rxColumns->get().end();
1722 ++aIter
1725 if((*aIter)->getPropertySetInfo()->hasPropertyByName(sRealName))
1726 (*aIter)->getPropertyValue(sRealName) >>= sSelectColumnRealName;
1727 else
1728 (*aIter)->getPropertyValue(sName) >>= sSelectColumnRealName;
1730 if ( aCase(sTableColumnName, sSelectColumnRealName) && !(*aRowIter)->isBound() && aSelectIters.end() == aSelectIters.find(aIter) )
1732 aSelectIters.insert(IterMap::value_type(aIter,sal_True));
1733 if(_bSetColumnMapping)
1735 sal_Int32 nSelectColumnPos = aIter - _rxColumns->get().begin() + 1;
1736 // the getXXX methods are 1-based ...
1737 sal_Int32 nTableColumnPos = i + 1;
1738 // get first table column is the bookmark column ...
1739 _rColMapping[nSelectColumnPos] = nTableColumnPos;
1740 (_rSelectRow->get())[nSelectColumnPos] = *aRowIter;
1743 (*aRowIter)->setBound(sal_True);
1744 sal_Int32 nType = DataType::OTHER;
1745 if (xTableColumn.is())
1746 xTableColumn->getPropertyValue(sType) >>= nType;
1747 (*aRowIter)->setTypeKind(nType);
1749 break;
1753 catch (Exception&)
1755 OSL_ENSURE(sal_False, "OResultSet::setBoundedColumns: caught an Exception!");
1758 // in this case we got more select columns as columns exist in the table
1759 if ( _bSetColumnMapping && aSelectIters.size() != _rColMapping.size() )
1761 Reference<XNameAccess> xNameAccess(_xNames,UNO_QUERY);
1762 Sequence< ::rtl::OUString > aSelectColumns = xNameAccess->getElementNames();
1764 for ( OSQLColumns::Vector::iterator aIter = _rxColumns->get().begin();
1765 aIter != _rxColumns->get().end();
1766 ++aIter
1769 if ( aSelectIters.end() == aSelectIters.find(aIter) )
1771 if ( (*aIter)->getPropertySetInfo()->hasPropertyByName(sRealName) )
1772 (*aIter)->getPropertyValue(sRealName) >>= sSelectColumnRealName;
1773 else
1774 (*aIter)->getPropertyValue(sName) >>= sSelectColumnRealName;
1776 if ( xNameAccess->hasByName( sSelectColumnRealName ) )
1778 aSelectIters.insert(IterMap::value_type(aIter,sal_True));
1779 sal_Int32 nSelectColumnPos = aIter - _rxColumns->get().begin() + 1;
1780 const ::rtl::OUString* pBegin = aSelectColumns.getConstArray();
1781 const ::rtl::OUString* pEnd = pBegin + aSelectColumns.getLength();
1782 for(sal_Int32 i=0;pBegin != pEnd;++pBegin,++i)
1784 if ( aCase(*pBegin, sSelectColumnRealName) )
1786 // the getXXX methods are 1-based ...
1787 sal_Int32 nTableColumnPos = i + 1;
1788 // get first table column is the bookmark column ...
1789 _rColMapping[nSelectColumnPos] = nTableColumnPos;
1790 (_rSelectRow->get())[nSelectColumnPos] = (_rRow->get())[nTableColumnPos];
1791 break;
1799 // -----------------------------------------------------------------------------
1800 void SAL_CALL OResultSet::acquire() throw()
1802 OResultSet_BASE::acquire();
1804 // -----------------------------------------------------------------------------
1805 void SAL_CALL OResultSet::release() throw()
1807 OResultSet_BASE::release();
1809 // -----------------------------------------------------------------------------
1810 Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL OResultSet::getPropertySetInfo( ) throw(RuntimeException)
1812 //RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::getPropertySetInfo" );
1813 return ::cppu::OPropertySetHelper::createPropertySetInfo(getInfoHelper());
1815 // -----------------------------------------------------------------------------
1816 void OResultSet::doTableSpecials(const OSQLTable& _xTable)
1818 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::doTableSpecials" );
1819 Reference< ::com::sun::star::lang::XUnoTunnel> xTunnel(_xTable,UNO_QUERY);
1820 if(xTunnel.is())
1822 m_pTable = reinterpret_cast< OFileTable* >( xTunnel->getSomething(OFileTable::getUnoTunnelImplementationId()) );
1823 if(m_pTable)
1824 m_pTable->acquire();
1827 // -----------------------------------------------------------------------------
1828 void OResultSet::clearInsertRow()
1830 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::clearInsertRow" );
1831 m_aRow->setDeleted(sal_False); // set to false here because this is the new row
1832 OValueRefVector::Vector::iterator aIter = m_aInsertRow->get().begin();
1833 const OValueRefVector::Vector::iterator aEnd = m_aInsertRow->get().end();
1834 for(sal_Int32 nPos = 0;aIter != aEnd;++aIter,++nPos)
1836 ORowSetValueDecoratorRef& rValue = (*aIter);
1837 if ( rValue->isBound() )
1839 (m_aRow->get())[nPos]->setValue( (*aIter)->getValue() );
1841 rValue->setBound(nPos == 0);
1842 rValue->setModified(sal_False);
1843 rValue->setNull();
1846 // -----------------------------------------------------------------------------
1847 void OResultSet::initializeRow(OValueRefRow& _rRow,sal_Int32 _nColumnCount)
1849 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::initializeRow" );
1850 if(!_rRow.isValid())
1852 _rRow = new OValueRefVector(_nColumnCount);
1853 (_rRow->get())[0]->setBound(sal_True);
1854 ::std::for_each(_rRow->get().begin()+1,_rRow->get().end(),TSetRefBound(sal_False));
1857 // -----------------------------------------------------------------------------
1858 sal_Bool OResultSet::fillIndexValues(const Reference< XColumnsSupplier> &/*_xIndex*/)
1860 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::fillIndexValues" );
1861 return sal_False;
1863 // -----------------------------------------------------------------------------
1864 sal_Bool OResultSet::move(IResultSetHelper::Movement _eCursorPosition, sal_Int32 _nOffset, sal_Bool _bRetrieveData)
1866 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::move" );
1867 return Move(_eCursorPosition,_nOffset,_bRetrieveData);
1869 // -----------------------------------------------------------------------------
1870 sal_Int32 OResultSet::getDriverPos() const
1872 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::getDriverPos" );
1873 return (m_aRow->get())[0]->getValue();
1875 // -----------------------------------------------------------------------------
1876 sal_Bool OResultSet::deletedVisible() const
1878 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::deletedVisible" );
1879 return m_bShowDeleted;
1881 // -----------------------------------------------------------------------------
1882 sal_Bool OResultSet::isRowDeleted() const
1884 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::isRowDeleted" );
1885 return m_aRow->isDeleted();
1887 // -----------------------------------------------------------------------------
1888 void SAL_CALL OResultSet::disposing( const EventObject& Source ) throw (RuntimeException)
1890 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::disposing" );
1891 // Reference<XInterface> xInt = m_pTable;
1892 Reference<XPropertySet> xProp = m_pTable;
1893 if(m_pTable && Source.Source == xProp)
1895 m_pTable->release();
1896 m_pTable = NULL;
1899 // -----------------------------------------------------------------------------