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