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