1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_connectivity.hxx"
26 #include <limits>  // included here to prevent problems if compiling with C52
27 
28 #ifdef GCC
29 #include <iostream>
30 #endif
31 #include "connectivity/sdbcx/VColumn.hxx"
32 #include "file/FResultSet.hxx"
33 #include "file/FResultSetMetaData.hxx"
34 #include <com/sun/star/sdbc/DataType.hpp>
35 #include <com/sun/star/sdbc/ColumnValue.hpp>
36 #include <comphelper/property.hxx>
37 #include <com/sun/star/lang/DisposedException.hpp>
38 #include <com/sun/star/beans/PropertyAttribute.hpp>
39 #include <com/sun/star/container/XIndexAccess.hpp>
40 #include <comphelper/sequence.hxx>
41 #include <cppuhelper/typeprovider.hxx>
42 #include "connectivity/dbconversion.hxx"
43 #include "connectivity/dbtools.hxx"
44 #include <cppuhelper/propshlp.hxx>
45 #include <iterator>
46 #include <tools/debug.hxx>
47 #include <com/sun/star/sdbc/ResultSetType.hpp>
48 #include <com/sun/star/sdbc/FetchDirection.hpp>
49 #include <com/sun/star/sdbc/ResultSetConcurrency.hpp>
50 #include <com/sun/star/sdbcx/XIndexesSupplier.hpp>
51 
52 #include <algorithm>
53 #include <comphelper/extract.hxx>
54 #include "connectivity/dbexception.hxx"
55 #include <comphelper/types.hxx>
56 #include "resource/file_res.hrc"
57 #include "resource/sharedresources.hxx"
58 #include <rtl/logfile.hxx>
59 
60 
61 using namespace ::comphelper;
62 using namespace connectivity;
63 using namespace connectivity::file;
64 using namespace ::cppu;
65 using namespace dbtools;
66 using namespace com::sun::star::uno;
67 using namespace com::sun::star::lang;
68 using namespace com::sun::star::beans;
69 using namespace com::sun::star::sdbc;
70 using namespace com::sun::star::sdbcx;
71 using namespace com::sun::star::container;
72 
73 // Maximale Anzahl von Rows, die mit ORDER BY sortiert durchlaufen werden koennen:
74 #define MAX_KEYSET_SIZE 0x40000 // 256K
75 
76 namespace
77 {
lcl_throwError(sal_uInt16 _nErrorId,const::com::sun::star::uno::Reference<::com::sun::star::uno::XInterface> & _xContext)78     void lcl_throwError(sal_uInt16 _nErrorId,const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface>& _xContext)
79     {
80         ::connectivity::SharedResources aResources;
81         const ::rtl::OUString sMessage = aResources.getResourceString(_nErrorId);
82 		::dbtools::throwGenericSQLException(sMessage ,_xContext);
83     }
84 }
85 //------------------------------------------------------------------------------
86 IMPLEMENT_SERVICE_INFO(OResultSet,"com.sun.star.sdbcx.drivers.file.ResultSet","com.sun.star.sdbc.ResultSet");
DBG_NAME(file_OResultSet)87 DBG_NAME( file_OResultSet )
88 // -------------------------------------------------------------------------
89 OResultSet::OResultSet(OStatement_Base* pStmt,OSQLParseTreeIterator&	_aSQLIterator) :	OResultSet_BASE(m_aMutex)
90 						,::comphelper::OPropertyContainer(OResultSet_BASE::rBHelper)
91                         ,m_aAssignValues(NULL)
92                         ,m_pEvaluationKeySet(NULL)
93                         ,m_aSkipDeletedSet(this)
94                         ,m_pFileSet(NULL)
95                         ,m_pSortIndex(NULL)
96                         ,m_pTable(NULL)
97                         ,m_pParseTree(pStmt->getParseTree())
98                         ,m_pSQLAnalyzer(NULL)
99                         ,m_aSQLIterator(_aSQLIterator)
100                         ,m_nFetchSize(0)
101                         ,m_nResultSetType(ResultSetType::SCROLL_INSENSITIVE)
102                         ,m_nFetchDirection(FetchDirection::FORWARD)
103                         ,m_nResultSetConcurrency(ResultSetConcurrency::UPDATABLE)
104 						,m_xStatement(*pStmt)
105                         ,m_xMetaData(NULL)
106                         ,m_xDBMetaData(pStmt->getOwnConnection()->getMetaData())
107                         ,m_nTextEncoding(pStmt->getOwnConnection()->getTextEncoding())
108 						,m_nRowPos(-1)
109                         ,m_nFilePos(0)
110                         ,m_nLastVisitedPos(-1)
111                         ,m_nRowCountResult(-1)
112                         ,m_nCurrentPosition(0)
113                         ,m_nColumnCount(0)
114                         ,m_bWasNull(sal_False)
115                         ,m_bEOF(sal_False)
116 						,m_bLastRecord(sal_False)
117                         ,m_bInserted(sal_False)
118                         ,m_bRowUpdated(sal_False)
119                         ,m_bRowInserted(sal_False)
120                         ,m_bRowDeleted(sal_False)
121                         ,m_bShowDeleted(pStmt->getOwnConnection()->showDeleted())
122                         ,m_bIsCount(sal_False)
123 {
124     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::OResultSet" );
125 	DBG_CTOR( file_OResultSet, NULL );
126 	osl_incrementInterlockedCount( &m_refCount );
127     m_bIsCount = (m_pParseTree &&
128 			m_pParseTree->count() > 2														&&
129 			SQL_ISRULE(m_pParseTree->getChild(2),scalar_exp_commalist)						&&
130 			SQL_ISRULE(m_pParseTree->getChild(2)->getChild(0),derived_column)				&&
131 			SQL_ISRULE(m_pParseTree->getChild(2)->getChild(0)->getChild(0),general_set_fct)	&&
132 			m_pParseTree->getChild(2)->getChild(0)->getChild(0)->count() == 4
133 			);
134 
135 	m_nResultSetConcurrency = isCount() ? ResultSetConcurrency::READ_ONLY : ResultSetConcurrency::UPDATABLE;
136 	construct();
137     m_aSkipDeletedSet.SetDeletedVisible(m_bShowDeleted);
138 	osl_decrementInterlockedCount( &m_refCount );
139 }
140 
141 // -------------------------------------------------------------------------
~OResultSet()142 OResultSet::~OResultSet()
143 {
144     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::~OResultSet" );
145 	osl_incrementInterlockedCount( &m_refCount );
146 	disposing();
147 	DBG_DTOR( file_OResultSet, NULL );
148 }
149 // -------------------------------------------------------------------------
construct()150 void OResultSet::construct()
151 {
152     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::construct" );
153 	registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_FETCHSIZE),			PROPERTY_ID_FETCHSIZE,			0,&m_nFetchSize,		::getCppuType(reinterpret_cast<sal_Int32*>(NULL)));
154     registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_RESULTSETTYPE),        PROPERTY_ID_RESULTSETTYPE,      PropertyAttribute::READONLY,&m_nResultSetType,       ::getCppuType(reinterpret_cast<sal_Int32*>(NULL)));
155 	registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_FETCHDIRECTION),		PROPERTY_ID_FETCHDIRECTION,		0,&m_nFetchDirection,	::getCppuType(reinterpret_cast<sal_Int32*>(NULL)));
156     registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_RESULTSETCONCURRENCY), PROPERTY_ID_RESULTSETCONCURRENCY,PropertyAttribute::READONLY,&m_nResultSetConcurrency,                ::getCppuType(reinterpret_cast<sal_Int32*>(NULL)));
157 }
158 // -------------------------------------------------------------------------
disposing(void)159 void OResultSet::disposing(void)
160 {
161     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::disposing" );
162 	OPropertySetHelper::disposing();
163 
164 	::osl::MutexGuard aGuard(m_aMutex);
165     m_xStatement.clear();
166     m_xMetaData.clear();
167 	m_pParseTree	= NULL;
168     m_xColNames.clear();
169     m_xColumns = NULL;
170     m_xParamColumns = NULL;
171     m_xColsIdx.clear();
172 
173     Reference<XComponent> xComp = m_pTable;
174 	if ( xComp.is() )
175 		xComp->removeEventListener(this);
176 	if(m_pTable)
177 	{
178 		m_pTable->release();
179 		m_pTable = NULL;
180 	}
181 	clear();
182 }
183 // -----------------------------------------------------------------------------
clear()184 void OResultSet::clear()
185 {
186     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::clear" );
187 	m_pFileSet = NULL;
188 	DELETEZ(m_pSortIndex);
189 
190 	if(m_aInsertRow.isValid())
191 		m_aInsertRow->get().clear();
192 
193 	m_aSkipDeletedSet.clear();
194 }
195 // -------------------------------------------------------------------------
queryInterface(const Type & rType)196 Any SAL_CALL OResultSet::queryInterface( const Type & rType ) throw(RuntimeException)
197 {
198     //RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::queryInterface" );
199 	Any aRet = OPropertySetHelper::queryInterface(rType);
200 	return aRet.hasValue() ? aRet : OResultSet_BASE::queryInterface(rType);
201 }
202 // -------------------------------------------------------------------------
getTypes()203 Sequence< Type > SAL_CALL OResultSet::getTypes(  ) throw(RuntimeException)
204 {
205     //RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::getTypes" );
206 	::osl::MutexGuard aGuard( m_aMutex );
207 
208 	OTypeCollection aTypes(	::getCppuType( (const Reference< ::com::sun::star::beans::XMultiPropertySet > *)0 ),
209 							::getCppuType( (const Reference< ::com::sun::star::beans::XPropertySet > *)0 ),
210 							::getCppuType( (const Reference< ::com::sun::star::beans::XPropertySet > *)0 ));
211 
212 	return ::comphelper::concatSequences(aTypes.getTypes(),OResultSet_BASE::getTypes());
213 }
214 // -------------------------------------------------------------------------
215 
findColumn(const::rtl::OUString & columnName)216 sal_Int32 SAL_CALL OResultSet::findColumn( const ::rtl::OUString& columnName ) throw(SQLException, RuntimeException)
217 {
218     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::findColumn" );
219 	::osl::MutexGuard aGuard( m_aMutex );
220 	checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
221 
222 
223 	Reference< XResultSetMetaData > xMeta = getMetaData();
224 	sal_Int32 nLen = xMeta->getColumnCount();
225 	sal_Int32 i = 1;
226 	for(;i<=nLen;++i)
227 		if(xMeta->isCaseSensitive(i) ? columnName == xMeta->getColumnName(i) :
228 				columnName.equalsIgnoreAsciiCase(xMeta->getColumnName(i)))
229 			break;
230 	return i;
231 }
232 // -----------------------------------------------------------------------------
getValue(sal_Int32 columnIndex)233 const ORowSetValue& OResultSet::getValue(sal_Int32 columnIndex ) throw(::com::sun::star::sdbc::SQLException)
234 {
235     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::getValue" );
236 	::osl::MutexGuard aGuard( m_aMutex );
237 	checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
238 
239 	//columnIndex = mapColumn(columnIndex);
240 	checkIndex(columnIndex );
241 
242 
243 	m_bWasNull = (m_aSelectRow->get())[columnIndex]->getValue().isNull();
244 	return *(m_aSelectRow->get())[columnIndex];
245 }
246 // -----------------------------------------------------------------------------
checkIndex(sal_Int32 columnIndex)247 void OResultSet::checkIndex(sal_Int32 columnIndex ) throw(::com::sun::star::sdbc::SQLException)
248 {
249     //RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::checkIndex" );
250 	if (   columnIndex <= 0
251 		//	|| columnIndex > (sal_Int32)m_xColumns->size()
252            || columnIndex >= m_nColumnCount )
253         ::dbtools::throwInvalidIndexException(*this);
254 }
255 // -------------------------------------------------------------------------
getBinaryStream(sal_Int32)256 Reference< ::com::sun::star::io::XInputStream > SAL_CALL OResultSet::getBinaryStream( sal_Int32 /*columnIndex*/ ) throw(SQLException, RuntimeException)
257 {
258     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::getBinaryStream" );
259 	return NULL;
260 }
261 // -------------------------------------------------------------------------
getCharacterStream(sal_Int32)262 Reference< ::com::sun::star::io::XInputStream > SAL_CALL OResultSet::getCharacterStream( sal_Int32 /*columnIndex*/ ) throw(SQLException, RuntimeException)
263 {
264     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::getCharacterStream" );
265 	return NULL;
266 }
267 
268 // -------------------------------------------------------------------------
getBoolean(sal_Int32 columnIndex)269 sal_Bool SAL_CALL OResultSet::getBoolean( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
270 {
271     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::getBoolean" );
272 	return getValue(columnIndex);
273 }
274 // -------------------------------------------------------------------------
275 
getByte(sal_Int32 columnIndex)276 sal_Int8 SAL_CALL OResultSet::getByte( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
277 {
278     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::getByte" );
279 	return getValue(columnIndex);
280 }
281 // -------------------------------------------------------------------------
282 
getBytes(sal_Int32 columnIndex)283 Sequence< sal_Int8 > SAL_CALL OResultSet::getBytes( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
284 {
285     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::getBytes" );
286 	return getValue(columnIndex);
287 }
288 // -------------------------------------------------------------------------
289 
getDate(sal_Int32 columnIndex)290 ::com::sun::star::util::Date SAL_CALL OResultSet::getDate( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
291 {
292     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::getDate" );
293 	return getValue(columnIndex);
294 }
295 // -------------------------------------------------------------------------
296 
getDouble(sal_Int32 columnIndex)297 double SAL_CALL OResultSet::getDouble( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
298 {
299     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::getDouble" );
300 	return getValue(columnIndex);
301 }
302 // -------------------------------------------------------------------------
303 
getFloat(sal_Int32 columnIndex)304 float SAL_CALL OResultSet::getFloat( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
305 {
306     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::getFloat" );
307 	return getValue(columnIndex);
308 }
309 // -------------------------------------------------------------------------
310 
getInt(sal_Int32 columnIndex)311 sal_Int32 SAL_CALL OResultSet::getInt( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
312 {
313     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::getInt" );
314 	return getValue(columnIndex);
315 }
316 // -------------------------------------------------------------------------
317 
getRow()318 sal_Int32 SAL_CALL OResultSet::getRow(  ) throw(SQLException, RuntimeException)
319 {
320     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::getRow" );
321 	::osl::MutexGuard aGuard( m_aMutex );
322 	checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
323 
324 	OSL_ENSURE((m_bShowDeleted || !m_aRow->isDeleted()),"getRow called for deleted row");
325 
326 	return m_aSkipDeletedSet.getMappedPosition((m_aRow->get())[0]->getValue());
327 }
328 // -------------------------------------------------------------------------
329 
getLong(sal_Int32 columnIndex)330 sal_Int64 SAL_CALL OResultSet::getLong( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
331 {
332     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::getLong" );
333 	return getValue(columnIndex);
334 }
335 // -------------------------------------------------------------------------
336 
getMetaData()337 Reference< XResultSetMetaData > SAL_CALL OResultSet::getMetaData(  ) throw(SQLException, RuntimeException)
338 {
339     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::getMetaData" );
340 	::osl::MutexGuard aGuard( m_aMutex );
341 	checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
342 
343 
344 	if(!m_xMetaData.is())
345 		m_xMetaData = new OResultSetMetaData(m_xColumns,m_aSQLIterator.getTables().begin()->first,m_pTable);
346 	return m_xMetaData;
347 }
348 // -------------------------------------------------------------------------
getArray(sal_Int32)349 Reference< XArray > SAL_CALL OResultSet::getArray( sal_Int32 /*columnIndex*/ ) throw(SQLException, RuntimeException)
350 {
351     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::getArray" );
352 	return NULL;
353 }
354 
355 // -------------------------------------------------------------------------
356 
getClob(sal_Int32)357 Reference< XClob > SAL_CALL OResultSet::getClob( sal_Int32 /*columnIndex*/ ) throw(SQLException, RuntimeException)
358 {
359     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::getClob" );
360 	return NULL;
361 }
362 // -------------------------------------------------------------------------
getBlob(sal_Int32)363 Reference< XBlob > SAL_CALL OResultSet::getBlob( sal_Int32 /*columnIndex*/ ) throw(SQLException, RuntimeException)
364 {
365     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::getBlob" );
366 	return NULL;
367 }
368 // -------------------------------------------------------------------------
369 
getRef(sal_Int32)370 Reference< XRef > SAL_CALL OResultSet::getRef( sal_Int32 /*columnIndex*/ ) throw(SQLException, RuntimeException)
371 {
372     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::getRef" );
373 	return NULL;
374 }
375 // -------------------------------------------------------------------------
376 
getObject(sal_Int32 columnIndex,const Reference<::com::sun::star::container::XNameAccess> &)377 Any SAL_CALL OResultSet::getObject( sal_Int32 columnIndex, const Reference< ::com::sun::star::container::XNameAccess >& /*typeMap*/ ) throw(SQLException, RuntimeException)
378 {
379     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::getObject" );
380 	return getValue(columnIndex).makeAny();
381 }
382 // -------------------------------------------------------------------------
383 
getShort(sal_Int32 columnIndex)384 sal_Int16 SAL_CALL OResultSet::getShort( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
385 {
386     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::getShort" );
387 	return getValue(columnIndex);
388 }
389 // -------------------------------------------------------------------------
getString(sal_Int32 columnIndex)390 ::rtl::OUString SAL_CALL OResultSet::getString( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
391 {
392     //RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::getString" );
393 	return getValue(columnIndex);
394 }
395 // -------------------------------------------------------------------------
getTime(sal_Int32 columnIndex)396 ::com::sun::star::util::Time SAL_CALL OResultSet::getTime( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
397 {
398     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::getTime" );
399 	return getValue(columnIndex);
400 }
401 // -------------------------------------------------------------------------
getTimestamp(sal_Int32 columnIndex)402 ::com::sun::star::util::DateTime SAL_CALL OResultSet::getTimestamp( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
403 {
404     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::getTimestamp" );
405 	return getValue(columnIndex);
406 }
407 // -------------------------------------------------------------------------
408 
isAfterLast()409 sal_Bool SAL_CALL OResultSet::isAfterLast(  ) throw(SQLException, RuntimeException)
410 {
411     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::isAfterLast" );
412 	::osl::MutexGuard aGuard( m_aMutex );
413 	checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
414 
415 
416 	return m_nRowPos == sal_Int32(m_pFileSet->get().size());
417 }
418 // -------------------------------------------------------------------------
isFirst()419 sal_Bool SAL_CALL OResultSet::isFirst(  ) throw(SQLException, RuntimeException)
420 {
421     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::isFirst" );
422 	::osl::MutexGuard aGuard( m_aMutex );
423 	checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
424 
425 
426 	return m_nRowPos == 0;
427 }
428 // -------------------------------------------------------------------------
isLast()429 sal_Bool SAL_CALL OResultSet::isLast(  ) throw(SQLException, RuntimeException)
430 {
431     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::isLast" );
432 	::osl::MutexGuard aGuard( m_aMutex );
433 	checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
434 
435 
436 	return m_nRowPos == sal_Int32(m_pFileSet->get().size() - 1);
437 }
438 // -------------------------------------------------------------------------
beforeFirst()439 void SAL_CALL OResultSet::beforeFirst(  ) throw(SQLException, RuntimeException)
440 {
441     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::beforeFirst" );
442 	::osl::MutexGuard aGuard( m_aMutex );
443 	checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
444 
445 
446 	if(first())
447 		previous();
448 }
449 // -------------------------------------------------------------------------
afterLast()450 void SAL_CALL OResultSet::afterLast(  ) throw(SQLException, RuntimeException)
451 {
452     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::afterLast" );
453 	::osl::MutexGuard aGuard( m_aMutex );
454 	checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
455 
456 
457 	if(last())
458 		next();
459 	m_bEOF = sal_True;
460 }
461 // -------------------------------------------------------------------------
462 
close()463 void SAL_CALL OResultSet::close(  ) throw(SQLException, RuntimeException)
464 {
465     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::close" );
466 	dispose();
467 }
468 // -------------------------------------------------------------------------
469 
first()470 sal_Bool SAL_CALL OResultSet::first(  ) throw(SQLException, RuntimeException)
471 {
472     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::first" );
473 	::osl::MutexGuard aGuard( m_aMutex );
474 	checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
475 	return m_pTable ? m_aSkipDeletedSet.skipDeleted(IResultSetHelper::FIRST,1,sal_True) : sal_False;
476 }
477 // -------------------------------------------------------------------------
478 
last()479 sal_Bool SAL_CALL OResultSet::last(  ) throw(SQLException, RuntimeException)
480 {
481     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::last" );
482 	// here I know definitely that I stand on the last record
483 	::osl::MutexGuard aGuard( m_aMutex );
484 	checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
485 	return m_pTable ? m_aSkipDeletedSet.skipDeleted(IResultSetHelper::LAST,1,sal_True) : sal_False;
486 }
487 // -------------------------------------------------------------------------
absolute(sal_Int32 row)488 sal_Bool SAL_CALL OResultSet::absolute( sal_Int32 row ) throw(SQLException, RuntimeException)
489 {
490     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::absolute" );
491 	::osl::MutexGuard aGuard( m_aMutex );
492 	checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
493 	return m_pTable ? m_aSkipDeletedSet.skipDeleted(IResultSetHelper::ABSOLUTE,row,sal_True) : sal_False;
494 }
495 // -------------------------------------------------------------------------
relative(sal_Int32 row)496 sal_Bool SAL_CALL OResultSet::relative( sal_Int32 row ) throw(SQLException, RuntimeException)
497 {
498     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::relative" );
499 	::osl::MutexGuard aGuard( m_aMutex );
500 	checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
501 	return m_pTable ? m_aSkipDeletedSet.skipDeleted(IResultSetHelper::RELATIVE,row,sal_True) : sal_False;
502 }
503 // -------------------------------------------------------------------------
previous()504 sal_Bool SAL_CALL OResultSet::previous(  ) throw(SQLException, RuntimeException)
505 {
506     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::previous" );
507 	::osl::MutexGuard aGuard( m_aMutex );
508 	checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
509 	return m_pTable ? m_aSkipDeletedSet.skipDeleted(IResultSetHelper::PRIOR,0,sal_True) : sal_False;
510 }
511 // -------------------------------------------------------------------------
getStatement()512 Reference< XInterface > SAL_CALL OResultSet::getStatement(  ) throw(SQLException, RuntimeException)
513 {
514     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::getStatement" );
515 	::osl::MutexGuard aGuard( m_aMutex );
516 	checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
517 
518 
519 	return m_xStatement;
520 }
521 // -------------------------------------------------------------------------
522 
rowDeleted()523 sal_Bool SAL_CALL OResultSet::rowDeleted(  ) throw(SQLException, RuntimeException)
524 {
525     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::rowDeleted" );
526 	::osl::MutexGuard aGuard( m_aMutex );
527 	checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
528 
529 
530 	return m_bRowDeleted;
531 }
532 // -------------------------------------------------------------------------
rowInserted()533 sal_Bool SAL_CALL OResultSet::rowInserted(  ) throw(SQLException, RuntimeException)
534 {	::osl::MutexGuard aGuard( m_aMutex );
535 	checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
536 
537 
538 	return m_bRowInserted;
539 }
540 // -------------------------------------------------------------------------
rowUpdated()541 sal_Bool SAL_CALL OResultSet::rowUpdated(  ) throw(SQLException, RuntimeException)
542 {
543     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::rowInserted" );
544 	::osl::MutexGuard aGuard( m_aMutex );
545 	checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
546 
547 
548 	return m_bRowUpdated;
549 }
550 // -------------------------------------------------------------------------
551 
isBeforeFirst()552 sal_Bool SAL_CALL OResultSet::isBeforeFirst(  ) throw(SQLException, RuntimeException)
553 {
554     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::isBeforeFirst" );
555 	::osl::MutexGuard aGuard( m_aMutex );
556 	checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
557 
558 
559 	return m_nRowPos == -1;
560 }
561 // -------------------------------------------------------------------------
evaluate()562 sal_Bool OResultSet::evaluate()
563 {
564     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::evaluate" );
565 	OSL_ENSURE(m_pSQLAnalyzer,"OResultSet::evaluate: Analyzer isn't set!");
566 	sal_Bool bRet = sal_True;
567 	while(!m_pSQLAnalyzer->evaluateRestriction())
568 	{
569 		if(m_pEvaluationKeySet)
570 		{
571 			if(m_aEvaluateIter == m_pEvaluationKeySet->end())
572 				return sal_False;
573 			bRet = m_pTable->seekRow(IResultSetHelper::BOOKMARK,(*m_aEvaluateIter),m_nRowPos);
574 			++m_aEvaluateIter;
575 		}
576 		else
577 			bRet = m_pTable->seekRow(IResultSetHelper::NEXT,1,m_nRowPos);
578 		if(bRet)
579 		{
580 			if(m_pEvaluationKeySet)
581 			{
582 				bRet = m_pTable->fetchRow(m_aEvaluateRow,m_pTable->getTableColumns().getBody(),sal_True,sal_True);
583 				evaluate();
584 
585 			}
586 			else
587 				bRet = m_pTable->fetchRow(m_aRow,m_xColumns.getBody(),sal_False,sal_True);
588 		}
589 	}
590 
591 	return bRet;
592 }
593 // -------------------------------------------------------------------------
594 
next()595 sal_Bool SAL_CALL OResultSet::next(  ) throw(SQLException, RuntimeException)
596 {
597     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::next" );
598 	::osl::MutexGuard aGuard( m_aMutex );
599 	checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
600 
601 	return m_pTable ? m_aSkipDeletedSet.skipDeleted(IResultSetHelper::NEXT,1,sal_True) : sal_False;
602 }
603 // -------------------------------------------------------------------------
604 
wasNull()605 sal_Bool SAL_CALL OResultSet::wasNull(  ) throw(SQLException, RuntimeException)
606 {
607     //RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::wasNull" );
608 	::osl::MutexGuard aGuard( m_aMutex );
609 	checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
610 
611 	return m_bWasNull;
612 }
613 // -------------------------------------------------------------------------
614 
cancel()615 void SAL_CALL OResultSet::cancel(  ) throw(RuntimeException)
616 {
617     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::cancel" );
618 }
619 // -------------------------------------------------------------------------
clearWarnings()620 void SAL_CALL OResultSet::clearWarnings(  ) throw(SQLException, RuntimeException)
621 {
622     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::clearWarnings" );
623 }
624 // -------------------------------------------------------------------------
getWarnings()625 Any SAL_CALL OResultSet::getWarnings(  ) throw(SQLException, RuntimeException)
626 {
627     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::getWarnings" );
628 	return Any();
629 }
630 // -------------------------------------------------------------------------
insertRow()631 void SAL_CALL OResultSet::insertRow(  ) throw(SQLException, RuntimeException)
632 {
633     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::insertRow" );
634 	::osl::MutexGuard aGuard( m_aMutex );
635 	checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
636 
637 
638 	if(!m_bInserted || !m_pTable)
639 		throwFunctionSequenceException(*this);
640 
641 	// we know that we append new rows at the end
642 	// so we have to know where the end is
643 	m_aSkipDeletedSet.skipDeleted(IResultSetHelper::LAST,1,sal_False);
644 	m_bRowInserted = m_pTable->InsertRow(m_aInsertRow.getBody(), sal_True,m_xColsIdx);
645 	if(m_bRowInserted && m_pFileSet.isValid())
646 	{
647 		sal_Int32 nPos = (m_aInsertRow->get())[0]->getValue();
648 		m_pFileSet->get().push_back(nPos);
649 		*(m_aInsertRow->get())[0] = sal_Int32(m_pFileSet->get().size());
650 		clearInsertRow();
651 
652 		m_aSkipDeletedSet.insertNewPosition((m_aRow->get())[0]->getValue());
653 	}
654 }
655 // -------------------------------------------------------------------------
updateRow()656 void SAL_CALL OResultSet::updateRow(  ) throw(SQLException, RuntimeException)
657 {
658     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::updateRow" );
659 	::osl::MutexGuard aGuard( m_aMutex );
660 	checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
661 
662 	if(!m_pTable || m_pTable->isReadOnly())
663         lcl_throwError(STR_TABLE_READONLY,*this);
664 
665 	m_bRowUpdated = m_pTable->UpdateRow(m_aInsertRow.getBody(), m_aRow,m_xColsIdx);
666 	*(m_aInsertRow->get())[0] = (sal_Int32)(m_aRow->get())[0]->getValue();
667 
668 	clearInsertRow();
669 }
670 // -------------------------------------------------------------------------
deleteRow()671 void SAL_CALL OResultSet::deleteRow() throw(SQLException, RuntimeException)
672 {
673     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::deleteRow" );
674 	::osl::MutexGuard aGuard( m_aMutex );
675 	checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
676 
677 
678 	if(!m_pTable || m_pTable->isReadOnly())
679         lcl_throwError(STR_TABLE_READONLY,*this);
680 	if (m_bShowDeleted)
681         lcl_throwError(STR_DELETE_ROW,*this);
682 	if(m_aRow->isDeleted())
683         lcl_throwError(STR_ROW_ALREADY_DELETED,*this);
684 
685 	sal_Int32 nPos = (sal_Int32)(m_aRow->get())[0]->getValue();
686 	m_bRowDeleted = m_pTable->DeleteRow(m_xColumns.getBody());
687 	if(m_bRowDeleted && m_pFileSet.isValid())
688 	{
689 		m_aRow->setDeleted(sal_True);
690 		// don't touch the m_pFileSet member here
691 		m_aSkipDeletedSet.deletePosition(nPos);
692 	}
693 }
694 // -------------------------------------------------------------------------
cancelRowUpdates()695 void SAL_CALL OResultSet::cancelRowUpdates(  ) throw(SQLException, RuntimeException)
696 {
697     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::cancelRowUpdates" );
698 	::osl::MutexGuard aGuard( m_aMutex );
699 	checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
700 
701 
702 	m_bInserted		= sal_False;
703 	m_bRowUpdated	= sal_False;
704 	m_bRowInserted	= sal_False;
705 	m_bRowDeleted	= sal_False;
706 
707 	if(m_aInsertRow.isValid())
708 	{
709 		OValueRefVector::Vector::iterator aIter = m_aInsertRow->get().begin()+1;
710 		for(;aIter != m_aInsertRow->get().end();++aIter)
711 		{
712 			(*aIter)->setBound(sal_False);
713 			(*aIter)->setNull();
714 		}
715 	}
716 }
717 // -------------------------------------------------------------------------
718 
moveToInsertRow()719 void SAL_CALL OResultSet::moveToInsertRow(  ) throw(SQLException, RuntimeException)
720 {
721     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::moveToInsertRow" );
722 	::osl::MutexGuard aGuard( m_aMutex );
723 	checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
724 
725 	if(!m_pTable || m_pTable->isReadOnly())
726         lcl_throwError(STR_TABLE_READONLY,*this);
727 
728 	m_bInserted		= sal_True;
729 
730 	OValueRefVector::Vector::iterator aIter = m_aInsertRow->get().begin()+1;
731 	for(;aIter != m_aInsertRow->get().end();++aIter)
732 	{
733 		(*aIter)->setBound(sal_False);
734 		(*aIter)->setNull();
735 	}
736 }
737 // -------------------------------------------------------------------------
738 
moveToCurrentRow()739 void SAL_CALL OResultSet::moveToCurrentRow(  ) throw(SQLException, RuntimeException)
740 {
741     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::moveToCurrentRow" );
742 }
743 // -------------------------------------------------------------------------
updateValue(sal_Int32 columnIndex,const ORowSetValue & x)744 void OResultSet::updateValue(sal_Int32 columnIndex ,const ORowSetValue& x) throw(SQLException, RuntimeException)
745 {
746     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::updateValue" );
747 	::osl::MutexGuard aGuard( m_aMutex );
748 	checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
749 
750 	checkIndex(columnIndex );
751     columnIndex = mapColumn(columnIndex);
752 
753 	(m_aInsertRow->get())[columnIndex]->setBound(sal_True);
754 	*(m_aInsertRow->get())[columnIndex] = x;
755 }
756 // -----------------------------------------------------------------------------
757 
updateNull(sal_Int32 columnIndex)758 void SAL_CALL OResultSet::updateNull( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
759 {
760     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::updateNull" );
761     ORowSetValue aEmpty;
762     updateValue(columnIndex,aEmpty);
763 }
764 // -------------------------------------------------------------------------
765 
updateBoolean(sal_Int32 columnIndex,sal_Bool x)766 void SAL_CALL OResultSet::updateBoolean( sal_Int32 columnIndex, sal_Bool x ) throw(SQLException, RuntimeException)
767 {
768     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::updateBoolean" );
769 	updateValue(columnIndex,x);
770 }
771 // -------------------------------------------------------------------------
updateByte(sal_Int32 columnIndex,sal_Int8 x)772 void SAL_CALL OResultSet::updateByte( sal_Int32 columnIndex, sal_Int8 x ) throw(SQLException, RuntimeException)
773 {
774     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::updateByte" );
775 	updateValue(columnIndex,x);
776 }
777 // -------------------------------------------------------------------------
778 
updateShort(sal_Int32 columnIndex,sal_Int16 x)779 void SAL_CALL OResultSet::updateShort( sal_Int32 columnIndex, sal_Int16 x ) throw(SQLException, RuntimeException)
780 {
781     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::updateShort" );
782 	updateValue(columnIndex,x);
783 }
784 // -------------------------------------------------------------------------
updateInt(sal_Int32 columnIndex,sal_Int32 x)785 void SAL_CALL OResultSet::updateInt( sal_Int32 columnIndex, sal_Int32 x ) throw(SQLException, RuntimeException)
786 {
787     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::updateInt" );
788 	updateValue(columnIndex,x);
789 }
790 // -------------------------------------------------------------------------
updateLong(sal_Int32,sal_Int64)791 void SAL_CALL OResultSet::updateLong( sal_Int32 /*columnIndex*/, sal_Int64 /*x*/ ) throw(SQLException, RuntimeException)
792 {
793     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::updateLong" );
794     ::dbtools::throwFeatureNotImplementedException( "XRowUpdate::updateLong", *this );
795 }
796 // -----------------------------------------------------------------------
updateFloat(sal_Int32 columnIndex,float x)797 void SAL_CALL OResultSet::updateFloat( sal_Int32 columnIndex, float x ) throw(SQLException, RuntimeException)
798 {
799     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::updateFloat" );
800 	updateValue(columnIndex,x);
801 }
802 // -------------------------------------------------------------------------
803 
updateDouble(sal_Int32 columnIndex,double x)804 void SAL_CALL OResultSet::updateDouble( sal_Int32 columnIndex, double x ) throw(SQLException, RuntimeException)
805 {
806     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::updateDouble" );
807 	updateValue(columnIndex,x);
808 }
809 // -------------------------------------------------------------------------
updateString(sal_Int32 columnIndex,const::rtl::OUString & x)810 void SAL_CALL OResultSet::updateString( sal_Int32 columnIndex, const ::rtl::OUString& x ) throw(SQLException, RuntimeException)
811 {
812     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::updateString" );
813 	updateValue(columnIndex,x);
814 }
815 // -------------------------------------------------------------------------
updateBytes(sal_Int32 columnIndex,const Sequence<sal_Int8> & x)816 void SAL_CALL OResultSet::updateBytes( sal_Int32 columnIndex, const Sequence< sal_Int8 >& x ) throw(SQLException, RuntimeException)
817 {
818     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::updateBytes" );
819 	updateValue(columnIndex,x);
820 }
821 // -------------------------------------------------------------------------
updateDate(sal_Int32 columnIndex,const::com::sun::star::util::Date & x)822 void SAL_CALL OResultSet::updateDate( sal_Int32 columnIndex, const ::com::sun::star::util::Date& x ) throw(SQLException, RuntimeException)
823 {
824     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::updateDate" );
825 	updateValue(columnIndex,x);
826 }
827 // -------------------------------------------------------------------------
828 
updateTime(sal_Int32 columnIndex,const::com::sun::star::util::Time & x)829 void SAL_CALL OResultSet::updateTime( sal_Int32 columnIndex, const ::com::sun::star::util::Time& x ) throw(SQLException, RuntimeException)
830 {
831     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::updateTime" );
832 	updateValue(columnIndex,x);
833 }
834 // -------------------------------------------------------------------------
835 
updateTimestamp(sal_Int32 columnIndex,const::com::sun::star::util::DateTime & x)836 void SAL_CALL OResultSet::updateTimestamp( sal_Int32 columnIndex, const ::com::sun::star::util::DateTime& x ) throw(SQLException, RuntimeException)
837 {
838     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::updateTimestamp" );
839 	updateValue(columnIndex,x);
840 }
841 // -------------------------------------------------------------------------
842 
updateBinaryStream(sal_Int32 columnIndex,const Reference<::com::sun::star::io::XInputStream> & x,sal_Int32 length)843 void SAL_CALL OResultSet::updateBinaryStream( sal_Int32 columnIndex, const Reference< ::com::sun::star::io::XInputStream >& x, sal_Int32 length ) throw(SQLException, RuntimeException)
844 {
845     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::updateBinaryStream" );
846 	::osl::MutexGuard aGuard( m_aMutex );
847 	checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
848 
849 	if(!x.is())
850 		::dbtools::throwFunctionSequenceException(*this);
851 
852 	Sequence<sal_Int8> aSeq;
853 	x->readBytes(aSeq,length);
854 	updateValue(columnIndex,aSeq);
855 }
856 // -------------------------------------------------------------------------
updateCharacterStream(sal_Int32 columnIndex,const Reference<::com::sun::star::io::XInputStream> & x,sal_Int32 length)857 void SAL_CALL OResultSet::updateCharacterStream( sal_Int32 columnIndex, const Reference< ::com::sun::star::io::XInputStream >& x, sal_Int32 length ) throw(SQLException, RuntimeException)
858 {
859     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::updateCharacterStream" );
860 	updateBinaryStream(columnIndex,x,length);
861 }
862 // -------------------------------------------------------------------------
refreshRow()863 void SAL_CALL OResultSet::refreshRow(  ) throw(SQLException, RuntimeException)
864 {
865     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::refreshRow" );
866 	::osl::MutexGuard aGuard( m_aMutex );
867 	checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
868 }
869 // -------------------------------------------------------------------------
updateObject(sal_Int32 columnIndex,const Any & x)870 void SAL_CALL OResultSet::updateObject( sal_Int32 columnIndex, const Any& x ) throw(SQLException, RuntimeException)
871 {
872     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::updateObject" );
873 	if (!::dbtools::implUpdateObject(this, columnIndex, x))
874 		throw SQLException();
875 }
876 // -------------------------------------------------------------------------
877 
updateNumericObject(sal_Int32 columnIndex,const Any & x,sal_Int32)878 void SAL_CALL OResultSet::updateNumericObject( sal_Int32 columnIndex, const Any& x, sal_Int32 /*scale*/ ) throw(SQLException, RuntimeException)
879 {
880     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::updateNumericObject" );
881 	if (!::dbtools::implUpdateObject(this, columnIndex, x))
882 		throw SQLException();
883 }
884 // -------------------------------------------------------------------------
createArrayHelper() const885 IPropertyArrayHelper* OResultSet::createArrayHelper( ) const
886 {
887     //RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::createArrayHelper" );
888 	Sequence< Property > aProps;
889 	describeProperties(aProps);
890 	return new ::cppu::OPropertyArrayHelper(aProps);
891 }
892 // -------------------------------------------------------------------------
getInfoHelper()893 IPropertyArrayHelper & OResultSet::getInfoHelper()
894 {
895     //RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::getInfoHelper" );
896 	return *const_cast<OResultSet*>(this)->getArrayHelper();
897 }
898 
899 //------------------------------------------------------------------
ExecuteRow(IResultSetHelper::Movement eFirstCursorPosition,sal_Int32 nFirstOffset,sal_Bool bEvaluate,sal_Bool bRetrieveData)900 sal_Bool OResultSet::ExecuteRow(IResultSetHelper::Movement eFirstCursorPosition,
901 							   sal_Int32 nFirstOffset,
902 							   sal_Bool bEvaluate,
903 							   sal_Bool bRetrieveData)
904 {
905     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::ExecuteRow" );
906 	OSL_ENSURE(m_pSQLAnalyzer,"OResultSet::ExecuteRow: Analyzer isn't set!");
907 
908 	// Fuer weitere Fetch-Operationen werden diese Angaben ggf. veraendert ...
909 	IResultSetHelper::Movement eCursorPosition = eFirstCursorPosition;
910 	sal_Int32  nOffset = nFirstOffset;
911 
912     const OSQLColumns & rTableCols = m_pTable->getTableColumns().getBody();
913     sal_Bool bHasRestriction = m_pSQLAnalyzer->hasRestriction();
914 again:
915 
916 	// protect from reading over the end when someboby is inserting while we are reading
917 	// this method works only for dBase at the moment !!!!
918 	if (eCursorPosition == IResultSetHelper::NEXT && m_nFilePos == m_nLastVisitedPos)
919 	{
920 		return sal_False;
921 	}
922 
923 	if (!m_pTable || !m_pTable->seekRow(eCursorPosition, nOffset, m_nFilePos))
924 	{
925 		return sal_False;
926 	}
927 
928 	if (!bEvaluate)	// Laeuft keine Auswertung, dann nur Ergebniszeile fuellen
929 	{
930 		m_pTable->fetchRow(m_aRow,rTableCols, sal_True,bRetrieveData);
931 	}
932 	else
933 	{
934 		m_pTable->fetchRow(m_aEvaluateRow, rTableCols, sal_True,bRetrieveData || bHasRestriction);
935 
936 		if  (   (   !m_bShowDeleted
937                 &&  m_aEvaluateRow->isDeleted()
938                 )
939             ||  (   bHasRestriction
940                 &&  !m_pSQLAnalyzer->evaluateRestriction()
941                 )
942             )
943 		{												 // naechsten Satz auswerten
944 			// aktuelle Zeile loeschen im Keyset
945 			if (m_pEvaluationKeySet)
946 			{
947 				++m_aEvaluateIter;
948 				if (m_pEvaluationKeySet->end() != m_aEvaluateIter)
949 					nOffset = (*m_aEvaluateIter);
950 				else
951 				{
952 					return sal_False;
953 				}
954 			}
955 			else if (m_pFileSet.isValid())
956 			{
957 				OSL_ENSURE(//!m_pFileSet->IsFrozen() &&
958 							eCursorPosition == IResultSetHelper::NEXT, "Falsche CursorPosition!");
959 				eCursorPosition = IResultSetHelper::NEXT;
960 				nOffset = 1;
961 			}
962 			else if (eCursorPosition == IResultSetHelper::FIRST ||
963 					 eCursorPosition == IResultSetHelper::NEXT ||
964 					 eCursorPosition == IResultSetHelper::ABSOLUTE)
965 			{
966 				eCursorPosition = IResultSetHelper::NEXT;
967 				nOffset = 1;
968 			}
969 			else if (eCursorPosition == IResultSetHelper::LAST ||
970 					 eCursorPosition == IResultSetHelper::PRIOR)
971 			{
972 				eCursorPosition = IResultSetHelper::PRIOR;
973 				nOffset = 1;
974 			}
975 			else if (eCursorPosition == IResultSetHelper::RELATIVE)
976 			{
977 				eCursorPosition = (nOffset >= 0) ? IResultSetHelper::NEXT : IResultSetHelper::PRIOR;
978 			}
979 			else
980 			{
981 				//	aStatus.Set(SQL_STAT_NO_DATA_FOUND);
982 				return sal_False;
983 			}
984 			// Nochmal probieren ...
985 			goto again;
986 		}
987 	}
988 
989 	// Evaluate darf nur gesetzt sein,
990 	// wenn der Keyset weiter aufgebaut	werden soll
991 	if  (   ( m_aSQLIterator.getStatementType() == SQL_STATEMENT_SELECT )
992         &&  !isCount()
993         &&  bEvaluate
994         )
995 	{
996 		if (m_pSortIndex)
997 		{
998 			OKeyValue* pKeyValue = GetOrderbyKeyValue( m_aSelectRow );
999 			m_pSortIndex->AddKeyValue(pKeyValue);
1000 		}
1001 		else if (m_pFileSet.isValid())
1002 		{
1003 			//	OSL_ENSURE(!m_pFileSet->IsFrozen() , "Falsche CursorPosition!");
1004 			sal_uInt32 nBookmarkValue = Abs((sal_Int32)(m_aEvaluateRow->get())[0]->getValue());
1005 			m_pFileSet->get().push_back(nBookmarkValue);
1006 		}
1007 	}
1008 	else if (m_aSQLIterator.getStatementType() == SQL_STATEMENT_UPDATE)
1009 	{
1010 		sal_Bool bOK = sal_True;
1011 		if (bEvaluate)
1012 		{
1013 			// jetzt die eigentliche Ergebniszeile Lesen
1014 			bOK = m_pTable->fetchRow(m_aEvaluateRow, m_pTable->getTableColumns().getBody(), sal_True,sal_True);
1015 		}
1016 
1017 		if (bOK)
1018 		{
1019 			// Nur die zu aendernden Werte uebergeben:
1020 			if(!m_pTable->UpdateRow(m_aAssignValues.getBody(),m_aEvaluateRow,m_xColsIdx))
1021 				return sal_False;
1022 		}
1023 	}
1024 	else if (m_aSQLIterator.getStatementType() == SQL_STATEMENT_DELETE)
1025 	{
1026 		sal_Bool bOK = sal_True;
1027 		if (bEvaluate)
1028 		{
1029 			bOK = m_pTable->fetchRow(m_aEvaluateRow, m_pTable->getTableColumns().getBody(), sal_True,sal_True);
1030 		}
1031 		if (bOK)
1032 		{
1033 			if(!m_pTable->DeleteRow(m_xColumns.getBody()))
1034 				return sal_False;
1035 		}
1036 	}
1037 	return sal_True;
1038 }
1039 
1040 //-------------------------------------------------------------------
Move(IResultSetHelper::Movement eCursorPosition,sal_Int32 nOffset,sal_Bool bRetrieveData)1041 sal_Bool OResultSet::Move(IResultSetHelper::Movement eCursorPosition, sal_Int32 nOffset, sal_Bool bRetrieveData)
1042 {
1043     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::Move" );
1044 
1045 //IgnoreDeletedRows:
1046 //
1047 	sal_Int32 nTempPos = m_nRowPos;
1048 	// exclusiver zugriff auf die Tabelle
1049 	//	vos::OGuard* pGuard = m_pTable->Lock();
1050 
1051 	if (m_aSQLIterator.getStatementType() == SQL_STATEMENT_SELECT &&
1052 		!isCount())
1053 	{
1054 		if (!m_pFileSet.isValid()) // kein Index verfuegbar
1055 		{
1056 			// Normales FETCH
1057 			ExecuteRow(eCursorPosition,nOffset,sal_False,bRetrieveData);
1058 
1059 			// now set the bookmark for outside this is the logical pos  and not the file pos
1060 			*(*m_aRow->get().begin()) = sal_Int32(m_nRowPos + 1);
1061 		}
1062 		else
1063 		{
1064 			switch(eCursorPosition)
1065 			{
1066 				case IResultSetHelper::NEXT:
1067 					++m_nRowPos;
1068 					break;
1069 				case IResultSetHelper::PRIOR:
1070 					if (m_nRowPos >= 0)
1071 						--m_nRowPos;
1072 					break;
1073 				case IResultSetHelper::FIRST:
1074 					m_nRowPos = 0;
1075 					break;
1076 				case IResultSetHelper::LAST:
1077                     //  OSL_ENSURE(IsRowCountFinal(), "Fehler im Keyset!"); // muss eingefroren sein, sonst Fehler beim SQLCursor
1078 					m_nRowPos = m_pFileSet->get().size() - 1;
1079 					break;
1080 				case IResultSetHelper::RELATIVE:
1081 					m_nRowPos += nOffset;
1082 					break;
1083 				case IResultSetHelper::ABSOLUTE:
1084 				case IResultSetHelper::BOOKMARK:
1085                     if ( m_nRowPos == (nOffset -1) )
1086                         return sal_True;
1087 					m_nRowPos = nOffset -1;
1088 					break;
1089 			}
1090 
1091 			// OffRange?
1092             // Der FileCursor ist ausserhalb des gueltigen Bereichs, wenn
1093 			// a.) m_nRowPos < 1
1094 			// b.) Ein KeySet besteht und m_nRowPos > m_pFileSet->size()
1095 			if (m_nRowPos < 0 || (m_pFileSet->isFrozen() && eCursorPosition != IResultSetHelper::BOOKMARK && m_nRowPos >= (sal_Int32)m_pFileSet->get().size() )) // && m_pFileSet->IsFrozen()
1096 			{
1097 				//	aStatus.Set(SQL_STAT_NO_DATA_FOUND);
1098 				goto Error;
1099 			}
1100 			else
1101 			{
1102 				if (m_nRowPos < (sal_Int32)m_pFileSet->get().size())
1103 				{
1104 					// Fetch ueber Index
1105 					ExecuteRow(IResultSetHelper::BOOKMARK,(m_pFileSet->get())[m_nRowPos],sal_False,bRetrieveData);
1106 
1107 					// now set the bookmark for outside
1108 					*(*m_aRow->get().begin()) = sal_Int32(m_nRowPos + 1);
1109                     if ( (bRetrieveData || m_pSQLAnalyzer->hasRestriction()) && m_pSQLAnalyzer->hasFunctions() )
1110 	                {
1111 		                m_pSQLAnalyzer->setSelectionEvaluationResult(m_aSelectRow,m_aColMapping);
1112 	                }
1113 				}
1114                 else // Index muss weiter aufgebaut werden
1115 				{
1116 					// Zunaechst auf die letzte bekannte Zeile setzen
1117 					if (!m_pFileSet->get().empty())
1118 					{
1119 						m_aFileSetIter = m_pFileSet->get().end()-1;
1120 						//	m_pFileSet->SeekPos(m_pFileSet->size()-1);
1121 						m_pTable->seekRow(IResultSetHelper::BOOKMARK, *m_aFileSetIter, m_nFilePos);
1122 					}
1123 					sal_Bool bOK = sal_True;
1124 					// Ermitteln der Anzahl weiterer Fetches
1125 					while (bOK && m_nRowPos >= (sal_Int32)m_pFileSet->get().size())
1126 					{
1127 						if (m_pEvaluationKeySet)
1128 						{
1129 							if (m_nRowPos >= (sal_Int32)m_pEvaluationKeySet->size())
1130 								return sal_False;
1131 								//	aStatus.Set(SQL_STAT_NO_DATA_FOUND);
1132 							else if (m_nRowPos == 0)
1133 							{
1134 								m_aEvaluateIter = m_pEvaluationKeySet->begin();
1135 								bOK = ExecuteRow(IResultSetHelper::BOOKMARK,*m_aEvaluateIter,sal_True, bRetrieveData);
1136 							}
1137 							else
1138 							{
1139 								++m_aEvaluateIter;
1140 								bOK = ExecuteRow(IResultSetHelper::BOOKMARK,*m_aEvaluateIter,sal_True, bRetrieveData);
1141 							}
1142 						}
1143 						else
1144 							bOK = ExecuteRow(IResultSetHelper::NEXT,1,sal_True, sal_False);//bRetrieveData);
1145 					}
1146 
1147 					if (bOK)
1148 					{
1149 						// jetzt nochmal die Ergebnisse lesen
1150 						m_pTable->fetchRow(m_aRow, m_pTable->getTableColumns().getBody(), sal_True,bRetrieveData);
1151 
1152 						// now set the bookmark for outside
1153 						*(*m_aRow->get().begin()) = sal_Int32(m_nRowPos + 1);
1154 
1155                         if ( (bRetrieveData || m_pSQLAnalyzer->hasRestriction()) && m_pSQLAnalyzer->hasFunctions() )
1156 	                    {
1157 		                    m_pSQLAnalyzer->setSelectionEvaluationResult(m_aSelectRow,m_aColMapping);
1158 	                    }
1159 					}
1160 					else if (!m_pFileSet->isFrozen())					// keinen gueltigen Satz gefunden
1161 					{
1162 						//m_pFileSet->Freeze();
1163 						m_pFileSet->setFrozen();
1164 
1165 						//	DELETEZ(m_pEvaluationKeySet);
1166 						m_pEvaluationKeySet = NULL;
1167 						//	aStatus.Set(SQL_STAT_NO_DATA_FOUND);
1168 						goto Error;
1169 					}
1170 				}
1171 			}
1172 		}
1173 	}
1174 	else if (m_aSQLIterator.getStatementType() == SQL_STATEMENT_SELECT && isCount())
1175 	{
1176 		// Fetch des COUNT(*)
1177 		switch (eCursorPosition)
1178 		{
1179 			case IResultSetHelper::NEXT:
1180 				++m_nRowPos;
1181 				break;
1182 			case IResultSetHelper::PRIOR:
1183 				--m_nRowPos;
1184 				break;
1185 			case IResultSetHelper::FIRST:
1186 				m_nRowPos = 0;
1187 				break;
1188 			case IResultSetHelper::LAST:
1189 				m_nRowPos = 0;
1190 				break;
1191 			case IResultSetHelper::RELATIVE:
1192 				m_nRowPos += nOffset;
1193 				break;
1194 			case IResultSetHelper::ABSOLUTE:
1195 			case IResultSetHelper::BOOKMARK:
1196 				m_nRowPos = nOffset - 1;
1197 				break;
1198 		}
1199 
1200         if ( m_nRowPos < 0 )
1201             goto Error;
1202 		else if (m_nRowPos == 0)
1203 		{
1204 			// COUNT(*) in Ergebnisrow packen
1205 			// (muss die erste und einzige Variable in der Row sein)
1206 			if (m_aRow->get().size() >= 2)
1207 			{
1208 				*(m_aRow->get())[1] = m_nRowCountResult;
1209 				*(m_aRow->get())[0] = sal_Int32(1);
1210 				(m_aRow->get())[1]->setBound(sal_True);
1211 				(m_aSelectRow->get())[1] = (m_aRow->get())[1];
1212 			}
1213 		}
1214 		else
1215 		{
1216 			m_bEOF = sal_True;
1217 			m_nRowPos = 1;
1218 			return sal_False;
1219 		}
1220 	}
1221 	else
1222 		// Fetch nur bei SELECT moeglich!
1223 		return sal_False;
1224 
1225 	return sal_True;
1226 
1227 Error:
1228 	// steht der Cursor vor dem ersten Satz
1229 	// dann wird die position beibehalten
1230 	if (nTempPos == -1)
1231 		m_nRowPos = nTempPos;
1232 	else
1233 	{
1234 		switch(eCursorPosition)
1235 		{
1236 			case IResultSetHelper::PRIOR:
1237 			case IResultSetHelper::FIRST:
1238 				m_nRowPos = -1;
1239 				break;
1240 			case IResultSetHelper::LAST:
1241 			case IResultSetHelper::NEXT:
1242 			case IResultSetHelper::ABSOLUTE:
1243 			case IResultSetHelper::RELATIVE:
1244 				if (nOffset > 0)
1245 					m_nRowPos = m_pFileSet.isValid() ? (sal_Int32)m_pFileSet->get().size() : -1;
1246 				else if (nOffset < 0)
1247 					m_nRowPos = -1;
1248 				break;
1249 			case IResultSetHelper::BOOKMARK:
1250 				m_nRowPos = nTempPos;	 // vorherige Position
1251 		}
1252 	}
1253 	//	delete pGuard;
1254     //  rMode = (!bShowDeleted && aStatus.IsSuccessful() && m_aRow->isDeleted()) ?  // keine Anzeige von geloeschten Saetzen
1255 				//	OCursor::SQL_MOD_INVALID : OCursor::SQL_MOD_NONE;
1256 	return sal_False;
1257 }
1258 // -------------------------------------------------------------------------
sortRows()1259 void OResultSet::sortRows()
1260 {
1261     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::sortRows" );
1262 	if (!m_pSQLAnalyzer->hasRestriction() && m_aOrderbyColumnNumber.size() == 1)
1263 	{
1264 		// Ist nur ein Feld fuer die Sortierung angegeben
1265 		// Und diese Feld ist indiziert, dann den Index ausnutzen
1266 		Reference<XIndexesSupplier> xIndexSup;
1267 		m_pTable->queryInterface(::getCppuType((const Reference<XIndexesSupplier>*)0)) >>= xIndexSup;
1268 		//	Reference<XIndexesSupplier> xIndexSup(m_pTable,UNO_QUERY);
1269 		Reference<XIndexAccess> xIndexes;
1270 		if(xIndexSup.is())
1271 		{
1272 			xIndexes.set(xIndexSup->getIndexes(),UNO_QUERY);
1273 			Reference<XPropertySet> xColProp;
1274 			if(m_aOrderbyColumnNumber[0] < xIndexes->getCount())
1275 			{
1276 				xColProp.set(xIndexes->getByIndex(m_aOrderbyColumnNumber[0]),UNO_QUERY);
1277 				// iterate through the indexes to find the matching column
1278 				const sal_Int32 nCount = xIndexes->getCount();
1279 				for(sal_Int32 i=0; i < nCount;++i)
1280 				{
1281 					Reference<XColumnsSupplier> xIndex(xIndexes->getByIndex(i),UNO_QUERY);
1282 					Reference<XNameAccess> xIndexCols = xIndex->getColumns();
1283 					if(xIndexCols->hasByName(comphelper::getString(xColProp->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME)))))
1284 					{
1285 						m_pFileSet = new OKeySet();
1286 
1287 						if(fillIndexValues(xIndex))
1288 							return;
1289 					}
1290 				}
1291 			}
1292 		}
1293 	}
1294 
1295 	OSortIndex::TKeyTypeVector eKeyType(m_aOrderbyColumnNumber.size());
1296 	::std::vector<sal_Int32>::iterator aOrderByIter = m_aOrderbyColumnNumber.begin();
1297 	for (::std::vector<sal_Int16>::size_type i=0;aOrderByIter != m_aOrderbyColumnNumber.end(); ++aOrderByIter,++i)
1298 	{
1299 		OSL_ENSURE((sal_Int32)m_aSelectRow->get().size() > *aOrderByIter,"Invalid Index");
1300 		switch ((*(m_aSelectRow->get().begin()+*aOrderByIter))->getValue().getTypeKind())
1301 		{
1302 		    case DataType::CHAR:
1303 			case DataType::VARCHAR:
1304             case DataType::LONGVARCHAR:
1305 				eKeyType[i] = SQL_ORDERBYKEY_STRING;
1306 				break;
1307 
1308 			case DataType::OTHER:
1309 			case DataType::TINYINT:
1310 			case DataType::SMALLINT:
1311 			case DataType::INTEGER:
1312 			case DataType::DECIMAL:
1313 			case DataType::NUMERIC:
1314 			case DataType::REAL:
1315 			case DataType::DOUBLE:
1316 			case DataType::DATE:
1317 			case DataType::TIME:
1318 			case DataType::TIMESTAMP:
1319 			case DataType::BIT:
1320 				eKeyType[i] = SQL_ORDERBYKEY_DOUBLE;
1321 				break;
1322 
1323 		// Andere Typen sind nicht implementiert (und damit immer sal_False)
1324 			default:
1325 				eKeyType[i] = SQL_ORDERBYKEY_NONE;
1326 				OSL_ASSERT("OFILECursor::Execute: Datentyp nicht implementiert");
1327 				break;
1328 		}
1329 		(m_aSelectRow->get())[*aOrderByIter]->setBound(sal_True);
1330 	}
1331 
1332 	m_pSortIndex = new OSortIndex(eKeyType,m_aOrderbyAscending);
1333 
1334 	if (m_pEvaluationKeySet)
1335 	{
1336 		m_aEvaluateIter = m_pEvaluationKeySet->begin();
1337 
1338 		while (m_aEvaluateIter != m_pEvaluationKeySet->end())
1339 		{
1340 			ExecuteRow(IResultSetHelper::BOOKMARK,(*m_aEvaluateIter),sal_True);
1341 			++m_aEvaluateIter;
1342 		}
1343 	}
1344 	else
1345 	{
1346         while ( ExecuteRow( IResultSetHelper::NEXT, 1, sal_False, sal_True ) )
1347 	    {
1348             m_aSelectRow->get()[0]->setValue( m_aRow->get()[0]->getValue() );
1349             if ( m_pSQLAnalyzer->hasFunctions() )
1350                 m_pSQLAnalyzer->setSelectionEvaluationResult( m_aSelectRow, m_aColMapping );
1351             const sal_Int32 nBookmark = (*m_aRow->get().begin())->getValue();
1352             ExecuteRow( IResultSetHelper::BOOKMARK, nBookmark, sal_True, sal_False );
1353 	    }
1354 	}
1355 
1356 	// Sortiertes Keyset erzeugen
1357 	//	DELETEZ(m_pEvaluationKeySet);
1358 	m_pEvaluationKeySet = NULL;
1359 	m_pFileSet = NULL;
1360 	m_pFileSet = m_pSortIndex->CreateKeySet();
1361 	//	if(!bDistinct)
1362 		//	SetRowCount(pFileSet->count());
1363 	DELETEZ(m_pSortIndex);
1364 	// Nun kann ueber den Index sortiert zugegriffen werden.
1365 }
1366 
1367 
1368 // -------------------------------------------------------------------------
OpenImpl()1369 sal_Bool OResultSet::OpenImpl()
1370 {
1371     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::OpenImpl" );
1372 	OSL_ENSURE(m_pSQLAnalyzer,"No analyzer set with setSqlAnalyzer!");
1373 	if(!m_pTable)
1374 	{
1375 		const OSQLTables& xTabs = m_aSQLIterator.getTables();
1376 		if ((xTabs.begin() == xTabs.end()) || !xTabs.begin()->second.is())
1377             lcl_throwError(STR_QUERY_TOO_COMPLEX,*this);
1378 
1379 		if ( xTabs.size() > 1 || m_aSQLIterator.hasErrors() )
1380             lcl_throwError(STR_QUERY_MORE_TABLES,*this);
1381 
1382 		OSQLTable xTable = xTabs.begin()->second;
1383 		m_xColumns = m_aSQLIterator.getSelectColumns();
1384 
1385 		m_xColNames = xTable->getColumns();
1386 		m_xColsIdx.set(m_xColNames,UNO_QUERY);
1387 		doTableSpecials(xTable);
1388 		Reference<XComponent> xComp(xTable,UNO_QUERY);
1389 		if(xComp.is())
1390 			xComp->addEventListener(this);
1391 	}
1392 
1393 	m_pTable->refreshHeader();
1394 
1395 	sal_Int32 nColumnCount = m_xColsIdx->getCount();
1396 
1397 	initializeRow(m_aRow,nColumnCount);
1398 	initializeRow(m_aEvaluateRow,nColumnCount);
1399 	initializeRow(m_aInsertRow,nColumnCount);
1400 
1401 
1402 	m_nResultSetConcurrency = (m_pTable->isReadOnly() || isCount()) ? ResultSetConcurrency::READ_ONLY : ResultSetConcurrency::UPDATABLE;
1403 
1404 	// Neuen Index aufbauen:
1405 	m_pFileSet = NULL;
1406 	//	DELETEZ(m_pEvaluationKeySet);
1407 
1408 	// An den Anfang positionieren
1409 	m_nRowPos = -1;
1410 	m_nFilePos  = 0;
1411 	m_nRowCountResult = -1;
1412 
1413 	// exclusiver zugriff auf die Tabelle
1414 	//	vos::OGuard* pGuard = pTable->Lock();
1415 	m_nLastVisitedPos = m_pTable->getCurrentLastPos();
1416 
1417 	switch(m_aSQLIterator.getStatementType())
1418 	{
1419 		case SQL_STATEMENT_SELECT:
1420 		{
1421 			if(isCount())
1422 			{
1423 				if(m_xColumns->get().size() > 1)
1424                     lcl_throwError(STR_QUERY_COMPLEX_COUNT,*this);
1425 
1426 				m_nRowCountResult = 0;
1427 				// Vorlaeufig einfach ueber alle Datensaetze iterieren und
1428 				// dabei die Aktionen bearbeiten (bzw. einfach nur zaehlen):
1429 				{
1430 					sal_Bool bOK = sal_True;
1431 					if (m_pEvaluationKeySet)
1432 					{
1433 						m_aEvaluateIter = m_pEvaluationKeySet->begin();
1434 						bOK = m_aEvaluateIter == m_pEvaluationKeySet->end();
1435 
1436 					}
1437 					while (bOK)
1438 					{
1439 						if (m_pEvaluationKeySet)
1440 							ExecuteRow(IResultSetHelper::BOOKMARK,(*m_aEvaluateIter),sal_True);
1441 						else
1442 							bOK = ExecuteRow(IResultSetHelper::NEXT,1,sal_True);
1443 
1444 						if (bOK)
1445 						{
1446 							m_nRowCountResult++;
1447 							if(m_pEvaluationKeySet)
1448 							{
1449 								++m_aEvaluateIter;
1450 								bOK = m_aEvaluateIter == m_pEvaluationKeySet->end();
1451 							}
1452 						}
1453 					}
1454 
1455 					// Ergebnis von COUNT(*) in m_nRowCountResult merken.
1456 					// nRowCount, also die Anzahl der Rows in der Ergebnismenge, ist bei dieser
1457 					// Anfrage = 1!
1458 					m_pEvaluationKeySet = NULL;
1459 					//	DELETEZ(m_pEvaluationKeySet);
1460 				}
1461 			}
1462 			else
1463 			{
1464 				sal_Bool bDistinct = sal_False;
1465 				sal_Bool bWasSorted = sal_False;
1466 				OSQLParseNode *pDistinct = m_pParseTree->getChild(1);
1467 				::std::vector<sal_Int32>				aOrderbyColumnNumberSave;
1468 				::std::vector<TAscendingOrder>          aOrderbyAscendingSave;
1469 
1470 				if (pDistinct && pDistinct->getTokenID() == SQL_TOKEN_DISTINCT )
1471 				{
1472 					// Sort on all columns, saving original order for later
1473 					if(IsSorted())
1474 					{
1475 						aOrderbyColumnNumberSave = m_aOrderbyColumnNumber;// .assign(m_aOrderbyColumnNumber.begin(), m_aOrderbyColumnNumber.end());
1476                         m_aOrderbyColumnNumber.clear();
1477 						aOrderbyAscendingSave.assign(m_aOrderbyAscending.begin(), m_aOrderbyAscending.end());
1478 						bWasSorted = sal_True;
1479 					}
1480 
1481 					// the first column is the bookmark column
1482 					::std::vector<sal_Int32>::iterator aColStart = (m_aColMapping.begin()+1);
1483 					::std::copy(aColStart, m_aColMapping.end(),::std::back_inserter(m_aOrderbyColumnNumber));
1484 //					m_aOrderbyColumnNumber.assign(aColStart, m_aColMapping.end());
1485 					m_aOrderbyAscending.assign(m_aColMapping.size()-1, SQL_ASC);
1486 					bDistinct = sal_True;
1487 				}
1488 
1489 				if (IsSorted())
1490 					sortRows();
1491 
1492 				if (!m_pFileSet.isValid())
1493 				{
1494 					m_pFileSet = new OKeySet();
1495 
1496 					if (!m_pSQLAnalyzer->hasRestriction())
1497 					// jetzt kann das Keyset schon gefuellt werden!
1498 					// Aber Achtung: es wird davon ausgegangen, das die FilePositionen als Folge 1..n
1499 					// abgelegt werden!
1500 					{
1501 						if ( m_nLastVisitedPos > 0)
1502 							m_pFileSet->get().reserve( m_nLastVisitedPos );
1503 						for (sal_Int32 i = 0; i < m_nLastVisitedPos; i++)
1504                             m_pFileSet->get().push_back(i + 1);
1505 					}
1506 				}
1507 				OSL_ENSURE(m_pFileSet.isValid(),"Kein KeySet vorhanden! :-(");
1508 
1509 				if(bDistinct && m_pFileSet.isValid())   // sicher ist sicher
1510 				{
1511 					OValueRow aSearchRow = new OValueVector(m_aRow->get().size());
1512 					OValueRefVector::Vector::iterator aRowIter = m_aRow->get().begin();
1513 					OValueVector::Vector::iterator aSearchIter = aSearchRow->get().begin();
1514 					for	(	++aRowIter,++aSearchIter;	// the first column is the bookmark column
1515 							aRowIter != m_aRow->get().end();
1516 							++aRowIter,++aSearchIter)
1517                         aSearchIter->setBound((*aRowIter)->isBound());
1518 
1519 					size_t nMaxRow = m_pFileSet->get().size();
1520 
1521 					if (nMaxRow)
1522 					{
1523     #if OSL_DEBUG_LEVEL > 1
1524 						sal_Int32 nFound=0;
1525 	#endif
1526 						sal_Int32 nPos;
1527 						sal_Int32 nKey;
1528 
1529 						for( size_t j = nMaxRow-1; j > 0; --j)
1530 						{
1531                             nPos = (m_pFileSet->get())[j];
1532 							ExecuteRow(IResultSetHelper::BOOKMARK,nPos,sal_False);
1533 							m_pSQLAnalyzer->setSelectionEvaluationResult(m_aSelectRow,m_aColMapping);
1534 							{ // copy row values
1535 								OValueRefVector::Vector::iterator copyFrom = m_aSelectRow->get().begin();
1536 								OValueVector::Vector::iterator copyTo = aSearchRow->get().begin();
1537 								for	(	++copyFrom,++copyTo;	// the first column is the bookmark column
1538 										copyFrom != m_aSelectRow->get().end();
1539 										++copyFrom,++copyTo)
1540 											*copyTo = *(*copyFrom);
1541 								// *aSearchRow = *m_aRow;
1542 							}
1543 
1544 							// compare with next row
1545 							nKey = (m_pFileSet->get())[j-1];
1546 							ExecuteRow(IResultSetHelper::BOOKMARK,nKey,sal_False);
1547 							m_pSQLAnalyzer->setSelectionEvaluationResult(m_aSelectRow,m_aColMapping);
1548 							OValueRefVector::Vector::iterator loopInRow = m_aSelectRow->get().begin();
1549 							OValueVector::Vector::iterator existentInSearchRow = aSearchRow->get().begin();
1550 							for	(	++loopInRow,++existentInSearchRow;	// the first column is the bookmark column
1551 									loopInRow != m_aSelectRow->get().end();
1552 									++loopInRow,++existentInSearchRow)
1553 							{
1554 								if ( (*loopInRow)->isBound() && !( *(*loopInRow) == *existentInSearchRow) )
1555 									break;
1556 							}
1557 
1558 							if(loopInRow == m_aSelectRow->get().end())
1559 								(m_pFileSet->get())[j] = 0; // Rows match -- Mark for deletion by setting key to 0
1560     #if OSL_DEBUG_LEVEL > 1
1561 							else
1562 								nFound++;
1563 	#endif
1564 						}
1565 
1566 						m_pFileSet->get().erase(::std::remove_if(m_pFileSet->get().begin(),m_pFileSet->get().end(),
1567 															::std::bind2nd(::std::equal_to<sal_Int32>(),0))
1568 										  ,m_pFileSet->get().end());
1569 
1570 						if (bWasSorted)
1571 						{
1572 							// Re-sort on original requested order
1573 							m_aOrderbyColumnNumber = aOrderbyColumnNumberSave;
1574 							m_aOrderbyAscending.assign(aOrderbyAscendingSave.begin(), aOrderbyAscendingSave.end());
1575 
1576 							TIntVector aEvaluationKeySet(m_pFileSet->get());
1577 							m_pEvaluationKeySet = &aEvaluationKeySet;
1578 							sortRows();
1579 						}
1580 						else
1581 						{
1582 							m_aOrderbyColumnNumber.clear();
1583 							m_aOrderbyAscending.clear();
1584 							::std::sort(m_pFileSet->get().begin(),m_pFileSet->get().end());
1585 						}
1586 					}
1587 					//	SetRowCount(m_pFileSet->count());
1588 				}
1589 			}
1590 		}	break;
1591 
1592 		case SQL_STATEMENT_UPDATE:
1593 		case SQL_STATEMENT_DELETE:
1594 			// waehrend der Bearbeitung die Anzahl der bearbeiteten Rows zaehlen:
1595 			m_nRowCountResult = 0;
1596 			// Vorlaeufig einfach ueber alle Datensaetze iterieren und
1597 			// dabei die Aktionen bearbeiten (bzw. einfach nur zaehlen):
1598 			{
1599 
1600 				sal_Bool bOK = sal_True;
1601 				if (m_pEvaluationKeySet)
1602 				{
1603 					m_aEvaluateIter = m_pEvaluationKeySet->begin();
1604 					bOK = m_aEvaluateIter == m_pEvaluationKeySet->end();
1605 
1606 				}
1607 				while (bOK)
1608 				{
1609 					if (m_pEvaluationKeySet)
1610 						ExecuteRow(IResultSetHelper::BOOKMARK,(*m_aEvaluateIter),sal_True);
1611 					else
1612 						bOK = ExecuteRow(IResultSetHelper::NEXT,1,sal_True);
1613 
1614 					if (bOK)
1615 					{
1616 						m_nRowCountResult++;
1617 						if(m_pEvaluationKeySet)
1618 						{
1619 							++m_aEvaluateIter;
1620 							bOK = m_aEvaluateIter == m_pEvaluationKeySet->end();
1621 						}
1622 					}
1623 				}
1624 
1625 				// Ergebnis von COUNT(*) in nRowCountResult merken.
1626 				// nRowCount, also die Anzahl der Rows in der Ergebnismenge, ist bei dieser
1627 				// Anfrage = 1!
1628 				//	DELETEZ(m_pEvaluationKeySet);
1629 				m_pEvaluationKeySet = NULL;
1630 			}
1631 			//	SetRowCount(1);
1632 			break;
1633 		case SQL_STATEMENT_INSERT:
1634 			m_nRowCountResult = 0;
1635 
1636 			OSL_ENSURE(m_aAssignValues.isValid(),"No assign values set!");
1637 			if(!m_pTable->InsertRow(m_aAssignValues.getBody(), sal_True,m_xColsIdx))
1638 			{
1639 				m_nFilePos  = 0;
1640 				return sal_False;
1641 			}
1642 
1643 			m_nRowCountResult = 1;
1644 			break;
1645         default:
1646             OSL_ENSURE( false, "OResultSet::OpenImpl: unsupported statement type!" );
1647             break;
1648 	}
1649 
1650 	// FilePos zuruecksetzen
1651 	m_nFilePos  = 0;
1652 
1653 	return sal_True;
1654 }
1655 //--------------------------------------------------------------------------
getUnoTunnelImplementationId()1656 Sequence< sal_Int8 > OResultSet::getUnoTunnelImplementationId()
1657 {
1658     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::getUnoTunnelImplementationId" );
1659 	static ::cppu::OImplementationId * pId = 0;
1660 	if (! pId)
1661 	{
1662 		::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
1663 		if (! pId)
1664 		{
1665 			static ::cppu::OImplementationId aId;
1666 			pId = &aId;
1667 		}
1668 	}
1669 	return pId->getImplementationId();
1670 }
1671 
1672 // com::sun::star::lang::XUnoTunnel
1673 //------------------------------------------------------------------
getSomething(const Sequence<sal_Int8> & rId)1674 sal_Int64 OResultSet::getSomething( const Sequence< sal_Int8 > & rId ) throw (RuntimeException)
1675 {
1676     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::getSomething" );
1677 	return (rId.getLength() == 16 && 0 == rtl_compareMemory(getUnoTunnelImplementationId().getConstArray(),  rId.getConstArray(), 16 ) )
1678 				? reinterpret_cast< sal_Int64 >( this )
1679 				: 0;
1680 }
1681 // -----------------------------------------------------------------------------
setBoundedColumns(const OValueRefRow & _rRow,const OValueRefRow & _rSelectRow,const::vos::ORef<connectivity::OSQLColumns> & _rxColumns,const Reference<XIndexAccess> & _xNames,sal_Bool _bSetColumnMapping,const Reference<XDatabaseMetaData> & _xMetaData,::std::vector<sal_Int32> & _rColMapping)1682 void OResultSet::setBoundedColumns(const OValueRefRow& _rRow,
1683 								   const OValueRefRow& _rSelectRow,
1684 								   const ::vos::ORef<connectivity::OSQLColumns>& _rxColumns,
1685 								   const Reference<XIndexAccess>& _xNames,
1686 								   sal_Bool _bSetColumnMapping,
1687 								   const Reference<XDatabaseMetaData>& _xMetaData,
1688 								   ::std::vector<sal_Int32>& _rColMapping)
1689 {
1690     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::setBoundedColumns" );
1691 	::comphelper::UStringMixEqual aCase(_xMetaData->supportsMixedCaseQuotedIdentifiers());
1692 
1693 	Reference<XPropertySet> xTableColumn;
1694 	::rtl::OUString sTableColumnName, sSelectColumnRealName;
1695 
1696 	const ::rtl::OUString sName		= OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME);
1697 	const ::rtl::OUString sRealName	= OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_REALNAME);
1698 	const ::rtl::OUString sType		= OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPE);
1699 
1700 	typedef ::std::map<OSQLColumns::Vector::iterator,sal_Bool> IterMap;
1701 	IterMap aSelectIters;
1702 	OValueRefVector::Vector::iterator aRowIter = _rRow->get().begin()+1;
1703 	for	(sal_Int32 i=0;	// the first column is the bookmark column
1704          aRowIter != _rRow->get().end();
1705 			++i, ++aRowIter
1706 		)
1707 	{
1708 		(*aRowIter)->setBound(sal_False);
1709 		try
1710 		{
1711 			// get the table column and it's name
1712 			_xNames->getByIndex(i) >>= xTableColumn;
1713 			OSL_ENSURE(xTableColumn.is(), "OResultSet::setBoundedColumns: invalid table column!");
1714 			if (xTableColumn.is())
1715 				xTableColumn->getPropertyValue(sName) >>= sTableColumnName;
1716 			else
1717 				sTableColumnName = ::rtl::OUString();
1718 
1719 			// look if we have such a select column
1720 			// TODO: would like to have a O(log n) search here ...
1721 			for (	OSQLColumns::Vector::iterator aIter = _rxColumns->get().begin();
1722 					aIter != _rxColumns->get().end();
1723 					++aIter
1724 				)
1725 			{
1726 				if((*aIter)->getPropertySetInfo()->hasPropertyByName(sRealName))
1727 					(*aIter)->getPropertyValue(sRealName) >>= sSelectColumnRealName;
1728 				else
1729 					(*aIter)->getPropertyValue(sName) >>= sSelectColumnRealName;
1730 
1731 				if ( aCase(sTableColumnName, sSelectColumnRealName) && !(*aRowIter)->isBound() && aSelectIters.end() == aSelectIters.find(aIter) )
1732 				{
1733 					aSelectIters.insert(IterMap::value_type(aIter,sal_True));
1734 					if(_bSetColumnMapping)
1735 					{
1736 						sal_Int32 nSelectColumnPos = aIter - _rxColumns->get().begin() + 1;
1737 							// the getXXX methods are 1-based ...
1738 						sal_Int32 nTableColumnPos = i + 1;
1739 							// get first table column is the bookmark column ...
1740 						_rColMapping[nSelectColumnPos] = nTableColumnPos;
1741 						(_rSelectRow->get())[nSelectColumnPos] = *aRowIter;
1742 					}
1743 
1744 					(*aRowIter)->setBound(sal_True);
1745 					sal_Int32 nType = DataType::OTHER;
1746 					if (xTableColumn.is())
1747 						xTableColumn->getPropertyValue(sType) >>= nType;
1748 					(*aRowIter)->setTypeKind(nType);
1749 
1750 					break;
1751 				}
1752 			}
1753 		}
1754 		catch (Exception&)
1755 		{
1756 			OSL_ENSURE(sal_False, "OResultSet::setBoundedColumns: caught an Exception!");
1757 		}
1758 	}
1759 	// in this case we got more select columns as columns exist in the table
1760 	if ( _bSetColumnMapping && aSelectIters.size() != _rColMapping.size() )
1761 	{
1762 		Reference<XNameAccess> xNameAccess(_xNames,UNO_QUERY);
1763 		Sequence< ::rtl::OUString > aSelectColumns = xNameAccess->getElementNames();
1764 
1765 		for (	OSQLColumns::Vector::iterator aIter = _rxColumns->get().begin();
1766                 aIter != _rxColumns->get().end();
1767 					++aIter
1768 				)
1769 		{
1770 			if ( aSelectIters.end() == aSelectIters.find(aIter) )
1771 			{
1772 				if ( (*aIter)->getPropertySetInfo()->hasPropertyByName(sRealName) )
1773 					(*aIter)->getPropertyValue(sRealName) >>= sSelectColumnRealName;
1774 				else
1775 					(*aIter)->getPropertyValue(sName) >>= sSelectColumnRealName;
1776 
1777 				if ( xNameAccess->hasByName( sSelectColumnRealName ) )
1778 				{
1779 					aSelectIters.insert(IterMap::value_type(aIter,sal_True));
1780 					sal_Int32 nSelectColumnPos = aIter - _rxColumns->get().begin() + 1;
1781 					const ::rtl::OUString* pBegin = aSelectColumns.getConstArray();
1782 					const ::rtl::OUString* pEnd	  = pBegin + aSelectColumns.getLength();
1783 					for(sal_Int32 i=0;pBegin != pEnd;++pBegin,++i)
1784 					{
1785 						if ( aCase(*pBegin, sSelectColumnRealName) )
1786 						{
1787 							// the getXXX methods are 1-based ...
1788 							sal_Int32 nTableColumnPos = i + 1;
1789 								// get first table column is the bookmark column ...
1790 							_rColMapping[nSelectColumnPos] = nTableColumnPos;
1791 							(_rSelectRow->get())[nSelectColumnPos] = (_rRow->get())[nTableColumnPos];
1792 							break;
1793 						}
1794 					}
1795 				}
1796 			}
1797 		}
1798 	}
1799 }
1800 // -----------------------------------------------------------------------------
acquire()1801 void SAL_CALL OResultSet::acquire() throw()
1802 {
1803 	OResultSet_BASE::acquire();
1804 }
1805 // -----------------------------------------------------------------------------
release()1806 void SAL_CALL OResultSet::release() throw()
1807 {
1808 	OResultSet_BASE::release();
1809 }
1810 // -----------------------------------------------------------------------------
getPropertySetInfo()1811 Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL OResultSet::getPropertySetInfo(  ) throw(RuntimeException)
1812 {
1813     //RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::getPropertySetInfo" );
1814 	return ::cppu::OPropertySetHelper::createPropertySetInfo(getInfoHelper());
1815 }
1816 // -----------------------------------------------------------------------------
doTableSpecials(const OSQLTable & _xTable)1817 void OResultSet::doTableSpecials(const OSQLTable& _xTable)
1818 {
1819     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::doTableSpecials" );
1820 	Reference< ::com::sun::star::lang::XUnoTunnel> xTunnel(_xTable,UNO_QUERY);
1821 	if(xTunnel.is())
1822 	{
1823 		m_pTable = reinterpret_cast< OFileTable* >( xTunnel->getSomething(OFileTable::getUnoTunnelImplementationId()) );
1824 		if(m_pTable)
1825 			m_pTable->acquire();
1826 	}
1827 }
1828 // -----------------------------------------------------------------------------
clearInsertRow()1829 void OResultSet::clearInsertRow()
1830 {
1831     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::clearInsertRow" );
1832 	m_aRow->setDeleted(sal_False); // set to false here because this is the new row
1833 	OValueRefVector::Vector::iterator aIter = m_aInsertRow->get().begin();
1834     const OValueRefVector::Vector::iterator aEnd = m_aInsertRow->get().end();
1835 	for(sal_Int32 nPos = 0;aIter != aEnd;++aIter,++nPos)
1836 	{
1837         ORowSetValueDecoratorRef& rValue = (*aIter);
1838 		if ( rValue->isBound() )
1839 		{
1840 			(m_aRow->get())[nPos]->setValue( (*aIter)->getValue() );
1841 		}
1842 		rValue->setBound(nPos == 0);
1843 		rValue->setModified(sal_False);
1844 		rValue->setNull();
1845 	}
1846 }
1847 // -----------------------------------------------------------------------------
initializeRow(OValueRefRow & _rRow,sal_Int32 _nColumnCount)1848 void OResultSet::initializeRow(OValueRefRow& _rRow,sal_Int32 _nColumnCount)
1849 {
1850     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::initializeRow" );
1851 	if(!_rRow.isValid())
1852 	{
1853 		_rRow	= new OValueRefVector(_nColumnCount);
1854 		(_rRow->get())[0]->setBound(sal_True);
1855 		::std::for_each(_rRow->get().begin()+1,_rRow->get().end(),TSetRefBound(sal_False));
1856 	}
1857 }
1858 // -----------------------------------------------------------------------------
fillIndexValues(const Reference<XColumnsSupplier> &)1859 sal_Bool OResultSet::fillIndexValues(const Reference< XColumnsSupplier> &/*_xIndex*/)
1860 {
1861     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::fillIndexValues" );
1862 	return sal_False;
1863 }
1864 // -----------------------------------------------------------------------------
move(IResultSetHelper::Movement _eCursorPosition,sal_Int32 _nOffset,sal_Bool _bRetrieveData)1865 sal_Bool OResultSet::move(IResultSetHelper::Movement _eCursorPosition, sal_Int32 _nOffset, sal_Bool _bRetrieveData)
1866 {
1867     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::move" );
1868 	return Move(_eCursorPosition,_nOffset,_bRetrieveData);
1869 }
1870 // -----------------------------------------------------------------------------
getDriverPos() const1871 sal_Int32 OResultSet::getDriverPos() const
1872 {
1873     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::getDriverPos" );
1874 	return (m_aRow->get())[0]->getValue();
1875 }
1876 // -----------------------------------------------------------------------------
deletedVisible() const1877 sal_Bool OResultSet::deletedVisible() const
1878 {
1879     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::deletedVisible" );
1880 	return m_bShowDeleted;
1881 }
1882 // -----------------------------------------------------------------------------
isRowDeleted() const1883 sal_Bool OResultSet::isRowDeleted() const
1884 {
1885     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::isRowDeleted" );
1886 	return m_aRow->isDeleted();
1887 }
1888 // -----------------------------------------------------------------------------
disposing(const EventObject & Source)1889 void SAL_CALL OResultSet::disposing( const EventObject& Source ) throw (RuntimeException)
1890 {
1891     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSet::disposing" );
1892 	//	Reference<XInterface> xInt = m_pTable;
1893 	Reference<XPropertySet> xProp = m_pTable;
1894 	if(m_pTable && Source.Source == xProp)
1895 	{
1896 		m_pTable->release();
1897 		m_pTable = NULL;
1898 	}
1899 }
1900 // -----------------------------------------------------------------------------
1901