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 : #include <com/sun/star/sdbc/DataType.hpp>
21 : #include <com/sun/star/beans/PropertyAttribute.hpp>
22 : #include <comphelper/property.hxx>
23 : #include <comphelper/sequence.hxx>
24 : #include <cppuhelper/typeprovider.hxx>
25 : #include <comphelper/extract.hxx>
26 : #include <com/sun/star/lang/DisposedException.hpp>
27 : #include <com/sun/star/sdbc/ResultSetType.hpp>
28 : #include <com/sun/star/sdbc/FetchDirection.hpp>
29 : #include <com/sun/star/sdbc/ResultSetConcurrency.hpp>
30 : #include <comphelper/types.hxx>
31 : #include <connectivity/dbexception.hxx>
32 : #include <connectivity/dbtools.hxx>
33 :
34 : #include <TSortIndex.hxx>
35 : #include <rtl/string.hxx>
36 : #include <vector>
37 : #include <algorithm>
38 : #include "MResultSet.hxx"
39 : #include "MResultSetMetaData.hxx"
40 : #include "FDatabaseMetaDataResultSet.hxx"
41 :
42 : #include "resource/mork_res.hrc"
43 : #include "resource/common_res.hrc"
44 :
45 : #if OSL_DEBUG_LEVEL > 0
46 : # define OUtoCStr( x ) ( ::rtl::OUStringToOString ( (x), RTL_TEXTENCODING_ASCII_US).getStr())
47 : #else /* OSL_DEBUG_LEVEL */
48 : # define OUtoCStr( x ) ("dummy")
49 : #endif /* OSL_DEBUG_LEVEL */
50 :
51 : using namespace ::comphelper;
52 : using namespace connectivity;
53 : using namespace connectivity::mork;
54 : using namespace ::cppu;
55 : using namespace com::sun::star::uno;
56 : using namespace com::sun::star::lang;
57 : using namespace com::sun::star::beans;
58 : using namespace com::sun::star::sdbc;
59 : using namespace com::sun::star::container;
60 : using namespace com::sun::star::io;
61 : using namespace com::sun::star::util;
62 :
63 : //------------------------------------------------------------------------------
64 : // IMPLEMENT_SERVICE_INFO(OResultSet,"com.sun.star.sdbcx.OResultSet","com.sun.star.sdbc.ResultSet");
65 0 : ::rtl::OUString SAL_CALL OResultSet::getImplementationName( ) throw ( RuntimeException) \
66 : {
67 0 : return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sdbcx.mork.ResultSet"));
68 : }
69 : // -------------------------------------------------------------------------
70 0 : Sequence< ::rtl::OUString > SAL_CALL OResultSet::getSupportedServiceNames( ) throw( RuntimeException)
71 : {
72 0 : ::com::sun::star::uno::Sequence< ::rtl::OUString > aSupported(2);
73 0 : aSupported[0] = OUString("com.sun.star.sdbc.ResultSet");
74 0 : aSupported[1] = OUString("com.sun.star.sdbcx.ResultSet");
75 0 : return aSupported;
76 : }
77 : // -------------------------------------------------------------------------
78 0 : sal_Bool SAL_CALL OResultSet::supportsService( const ::rtl::OUString& _rServiceName ) throw( RuntimeException)
79 : {
80 0 : Sequence< ::rtl::OUString > aSupported(getSupportedServiceNames());
81 0 : const ::rtl::OUString* pSupported = aSupported.getConstArray();
82 0 : const ::rtl::OUString* pEnd = pSupported + aSupported.getLength();
83 0 : for (;pSupported != pEnd && !pSupported->equals(_rServiceName); ++pSupported)
84 : ;
85 :
86 0 : return pSupported != pEnd;
87 : }
88 :
89 : // -------------------------------------------------------------------------
90 2 : OResultSet::OResultSet(OCommonStatement* pStmt, const ::boost::shared_ptr< connectivity::OSQLParseTreeIterator >& _pSQLIterator )
91 : : OResultSet_BASE(m_aMutex)
92 : ,OPropertySetHelper(OResultSet_BASE::rBHelper)
93 : ,m_pStatement(pStmt)
94 : ,m_xStatement(*pStmt)
95 : ,m_xMetaData(NULL)
96 : ,m_nRowPos(0)
97 : ,m_nOldRowPos(0)
98 : ,m_nFetchSize(0)
99 : ,m_nResultSetType(ResultSetType::SCROLL_INSENSITIVE)
100 : ,m_nFetchDirection(FetchDirection::FORWARD)
101 : ,m_nResultSetConcurrency(ResultSetConcurrency::UPDATABLE)
102 : ,m_pSQLIterator( _pSQLIterator )
103 2 : ,m_pParseTree( _pSQLIterator->getParseTree() )
104 2 : ,m_aQueryHelper(pStmt->getOwnConnection()->getColumnAlias())
105 : ,m_pTable(NULL)
106 : ,m_CurrentRowCount(0)
107 : ,m_nParamIndex(0)
108 : ,m_bIsAlwaysFalseQuery(sal_False)
109 : ,m_pKeySet(NULL)
110 : ,m_nNewRow(0)
111 : ,m_nUpdatedRow(0)
112 : ,m_RowStates(0)
113 6 : ,m_bIsReadOnly(-1)
114 : {
115 :
116 : //m_aQuery.setMaxNrOfReturns(pStmt->getOwnConnection()->getMaxResultRecords());
117 2 : }
118 : // -------------------------------------------------------------------------
119 0 : OResultSet::~OResultSet()
120 : {
121 0 : }
122 :
123 : // -------------------------------------------------------------------------
124 0 : void OResultSet::disposing(void)
125 : {
126 0 : OPropertySetHelper::disposing();
127 :
128 0 : ::osl::MutexGuard aGuard(m_aMutex);
129 :
130 0 : m_xStatement.clear();
131 0 : m_xMetaData.clear();
132 0 : m_pParseTree = NULL;
133 0 : m_xColumns = NULL;
134 0 : m_xParamColumns = NULL;
135 0 : m_pKeySet = NULL;
136 0 : if(m_pTable)
137 : {
138 0 : m_pTable->release();
139 0 : m_pTable = NULL;
140 0 : }
141 0 : }
142 : // -------------------------------------------------------------------------
143 4 : Any SAL_CALL OResultSet::queryInterface( const Type & rType ) throw(RuntimeException)
144 : {
145 4 : Any aRet = OPropertySetHelper::queryInterface(rType);
146 4 : if(!aRet.hasValue())
147 4 : aRet = OResultSet_BASE::queryInterface(rType);
148 4 : return aRet;
149 : }
150 : // -------------------------------------------------------------------------
151 0 : Sequence< Type > SAL_CALL OResultSet::getTypes( ) throw( RuntimeException)
152 : {
153 0 : OTypeCollection aTypes( ::getCppuType( (const Reference< ::com::sun::star::beans::XMultiPropertySet > *)0 ),
154 0 : ::getCppuType( (const Reference< ::com::sun::star::beans::XFastPropertySet > *)0 ),
155 0 : ::getCppuType( (const Reference< ::com::sun::star::beans::XPropertySet > *)0 ));
156 :
157 0 : return ::comphelper::concatSequences(aTypes.getTypes(),OResultSet_BASE::getTypes());
158 : }
159 : // -------------------------------------------------------------------------
160 14 : void OResultSet::methodEntry()
161 : {
162 14 : checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
163 14 : if ( !m_pTable )
164 : {
165 : OSL_FAIL( "OResultSet::methodEntry: looks like we're disposed, but how is this possible?" );
166 0 : throw DisposedException( ::rtl::OUString(), *this );
167 : }
168 14 : }
169 :
170 : // -------------------------------------------------------------------------
171 0 : sal_Int32 SAL_CALL OResultSet::findColumn( const ::rtl::OUString& columnName ) throw(SQLException, RuntimeException)
172 : {
173 0 : ResultSetEntryGuard aGuard( *this );
174 :
175 : // find the first column with the name columnName
176 0 : Reference< XResultSetMetaData > xMeta = getMetaData();
177 0 : sal_Int32 nLen = xMeta->getColumnCount();
178 0 : sal_Int32 i = 1;
179 0 : for(;i<=nLen;++i)
180 0 : if(xMeta->isCaseSensitive(i) ? columnName == xMeta->getColumnName(i) :
181 0 : columnName.equalsIgnoreAsciiCase(xMeta->getColumnName(i)))
182 0 : break;
183 0 : return i;
184 : }
185 : // -------------------------------------------------------------------------
186 0 : Reference< XInputStream > SAL_CALL OResultSet::getBinaryStream( sal_Int32 /*columnIndex*/ ) throw(SQLException, RuntimeException)
187 : {
188 0 : return NULL;
189 : }
190 : // -------------------------------------------------------------------------
191 0 : Reference< XInputStream > SAL_CALL OResultSet::getCharacterStream( sal_Int32 /*columnIndex*/ ) throw(SQLException, RuntimeException)
192 : {
193 0 : return NULL;
194 : }
195 :
196 : // -------------------------------------------------------------------------
197 0 : sal_Bool SAL_CALL OResultSet::getBoolean( sal_Int32 /*columnIndex*/ ) throw(SQLException, RuntimeException)
198 : {
199 0 : ResultSetEntryGuard aGuard( *this );
200 0 : m_bWasNull = sal_True;
201 0 : return sal_False;
202 : }
203 : // -------------------------------------------------------------------------
204 :
205 0 : sal_Int8 SAL_CALL OResultSet::getByte( sal_Int32 /*columnIndex*/ ) throw(SQLException, RuntimeException)
206 : {
207 0 : ResultSetEntryGuard aGuard( *this );
208 0 : return 0;
209 : }
210 : // -------------------------------------------------------------------------
211 :
212 0 : Sequence< sal_Int8 > SAL_CALL OResultSet::getBytes( sal_Int32 /*columnIndex*/ ) throw(SQLException, RuntimeException)
213 : {
214 0 : ResultSetEntryGuard aGuard( *this );
215 0 : return Sequence< sal_Int8 >();
216 : }
217 : // -------------------------------------------------------------------------
218 :
219 0 : Date SAL_CALL OResultSet::getDate( sal_Int32 /*columnIndex*/ ) throw(SQLException, RuntimeException)
220 : {
221 0 : ResultSetEntryGuard aGuard( *this );
222 0 : return Date();
223 : }
224 : // -------------------------------------------------------------------------
225 :
226 0 : double SAL_CALL OResultSet::getDouble( sal_Int32 /*columnIndex*/ ) throw(SQLException, RuntimeException)
227 : {
228 0 : ResultSetEntryGuard aGuard( *this );
229 0 : return 0.0;
230 : }
231 : // -------------------------------------------------------------------------
232 :
233 0 : float SAL_CALL OResultSet::getFloat( sal_Int32 /*columnIndex*/ ) throw(SQLException, RuntimeException)
234 : {
235 0 : ResultSetEntryGuard aGuard( *this );
236 0 : return 0;
237 : }
238 : // -------------------------------------------------------------------------
239 :
240 0 : sal_Int32 SAL_CALL OResultSet::getInt( sal_Int32 /*columnIndex*/ ) throw(SQLException, RuntimeException)
241 : {
242 0 : ResultSetEntryGuard aGuard( *this );
243 0 : return 0;
244 : }
245 :
246 : // -------------------------------------------------------------------------
247 0 : sal_Int32 SAL_CALL OResultSet::getRow( ) throw(SQLException, RuntimeException)
248 : {
249 0 : ResultSetEntryGuard aGuard( *this );
250 :
251 : OSL_TRACE("In/Out: OResultSet::getRow, return = %u", m_nRowPos );
252 0 : return m_nRowPos;
253 : }
254 : // -------------------------------------------------------------------------
255 :
256 0 : sal_Int64 SAL_CALL OResultSet::getLong( sal_Int32 /*columnIndex*/ ) throw(SQLException, RuntimeException)
257 : {
258 0 : ResultSetEntryGuard aGuard( *this );
259 0 : return sal_Int64();
260 : }
261 : // -------------------------------------------------------------------------
262 :
263 0 : Reference< XResultSetMetaData > SAL_CALL OResultSet::getMetaData( ) throw(SQLException, RuntimeException)
264 : {
265 0 : ResultSetEntryGuard aGuard( *this );
266 :
267 0 : if(!m_xMetaData.is())
268 : m_xMetaData = new OResultSetMetaData(
269 0 : m_pSQLIterator->getSelectColumns(), m_pSQLIterator->getTables().begin()->first ,m_pTable,determineReadOnly());
270 0 : return m_xMetaData;
271 : }
272 : // -------------------------------------------------------------------------
273 0 : Reference< XArray > SAL_CALL OResultSet::getArray( sal_Int32 /*columnIndex*/ ) throw(SQLException, RuntimeException)
274 : {
275 0 : return NULL;
276 : }
277 :
278 : // -------------------------------------------------------------------------
279 :
280 0 : Reference< XClob > SAL_CALL OResultSet::getClob( sal_Int32 /*columnIndex*/ ) throw(SQLException, RuntimeException)
281 : {
282 0 : return NULL;
283 : }
284 : // -------------------------------------------------------------------------
285 0 : Reference< XBlob > SAL_CALL OResultSet::getBlob( sal_Int32 /*columnIndex*/ ) throw(SQLException, RuntimeException)
286 : {
287 0 : return NULL;
288 : }
289 : // -------------------------------------------------------------------------
290 :
291 0 : Reference< XRef > SAL_CALL OResultSet::getRef( sal_Int32 /*columnIndex*/ ) throw(SQLException, RuntimeException)
292 : {
293 0 : return NULL;
294 : }
295 : // -------------------------------------------------------------------------
296 :
297 0 : Any SAL_CALL OResultSet::getObject( sal_Int32 /*columnIndex*/, const Reference< ::com::sun::star::container::XNameAccess >& /*typeMap*/ ) throw(SQLException, RuntimeException)
298 : {
299 0 : return Any();
300 : }
301 : // -------------------------------------------------------------------------
302 :
303 0 : sal_Int16 SAL_CALL OResultSet::getShort( sal_Int32 /*columnIndex*/ ) throw(SQLException, RuntimeException)
304 : {
305 0 : return 0;
306 : }
307 : // -------------------------------------------------------------------------
308 :
309 4 : void OResultSet::checkIndex(sal_Int32 columnIndex ) throw(::com::sun::star::sdbc::SQLException)
310 : {
311 4 : if(columnIndex <= 0 || columnIndex > (sal_Int32)m_xColumns->get().size())
312 0 : ::dbtools::throwInvalidIndexException(*this);
313 4 : }
314 : // -------------------------------------------------------------------------
315 6 : sal_uInt32 OResultSet::currentRowCount()
316 : {
317 6 : if ( m_bIsAlwaysFalseQuery )
318 0 : return 0;
319 : //return 0;//m_aQuery.getRealRowCount() - deletedCount();
320 : // new implementation
321 6 : return m_aQueryHelper.getResultCount();
322 : }
323 :
324 : // -------------------------------------------------------------------------
325 :
326 5 : sal_Bool OResultSet::fetchCurrentRow( ) throw(SQLException, RuntimeException)
327 : {
328 : OSL_TRACE("fetchCurrentRow, m_nRowPos = %u", m_nRowPos );
329 5 : return fetchRow(getCurrentCardNumber());
330 : }
331 :
332 : // -------------------------------------------------------------------------
333 0 : sal_Bool OResultSet::pushCard(sal_uInt32 /*cardNumber*/) throw(SQLException, RuntimeException)
334 : {
335 : SAL_INFO("connectivity.mork", "=> OResultSet::pushCard()" );
336 0 : return sal_True;
337 : /*
338 : if (cardNumber == 0)
339 : return sal_True;
340 : // Check whether we are storing the updated row
341 : if ( (m_aRow->get())[0].isNull() || (sal_Int32)(m_aRow->get())[0] != (sal_Int32)cardNumber )
342 : return sal_False;
343 :
344 : sal_Int32 nCount = m_aColumnNames.getLength();
345 : m_aQuery.setRowStates(cardNumber,m_RowStates);
346 : for( sal_Int32 i = 1; i <= nCount; i++ )
347 : {
348 : if ( (m_aRow->get())[i].isBound() )
349 : {
350 : //
351 : // Everything in the addressbook is a string!
352 : //
353 : if ( !m_aQuery.setRowValue( (m_aRow->get())[i], cardNumber, m_aColumnNames[i-1], DataType::VARCHAR ))
354 : {
355 : m_pStatement->getOwnConnection()->throwSQLException( m_aQuery.getError(), *this );
356 : }
357 : }
358 : }
359 : return sal_True;
360 : */
361 : }
362 : // -------------------------------------------------------------------------
363 19 : sal_Bool OResultSet::fetchRow(sal_Int32 cardNumber,sal_Bool bForceReload) throw(SQLException, RuntimeException)
364 : {
365 : SAL_INFO("connectivity.mork", "=> OResultSet::fetchRow()" );
366 :
367 : OSL_TRACE("fetchRow, cardNumber = %u", cardNumber );
368 19 : if (!bForceReload)
369 : {
370 : // Check whether we've already fetched the row...
371 19 : if ( !(m_aRow->get())[0].isNull() && (sal_Int32)(m_aRow->get())[0] == (sal_Int32)cardNumber )
372 5 : return sal_True;
373 : //Check whether the old row has been changed
374 14 : if (cardNumber == m_nUpdatedRow)
375 : {
376 : //write back the changes first
377 0 : if (!pushCard(cardNumber)) //error write back the changes
378 0 : throw SQLException();
379 : }
380 : }
381 : // else
382 : // m_aQuery.resyncRow(cardNumber);
383 :
384 14 : if ( validRow( cardNumber ) == sal_False )
385 0 : return sal_False;
386 :
387 14 : (m_aRow->get())[0] = (sal_Int32)cardNumber;
388 14 : sal_Int32 nCount = m_aColumnNames.getLength();
389 : //m_RowStates = m_aQuery.getRowStates(cardNumber);
390 532 : for( sal_Int32 i = 1; i <= nCount; i++ )
391 : {
392 518 : if ( (m_aRow->get())[i].isBound() )
393 : {
394 : //
395 : // Everything in the addressbook is a string!
396 : //
397 14 : if ( !m_aQueryHelper.getRowValue( (m_aRow->get())[i], cardNumber, m_aColumnNames[i-1], DataType::VARCHAR ))
398 : {
399 0 : m_pStatement->getOwnConnection()->throwSQLException( m_aQueryHelper.getError(), *this );
400 : }
401 : }
402 : }
403 14 : return sal_True;
404 :
405 : }
406 : // -------------------------------------------------------------------------
407 :
408 14 : const ORowSetValue& OResultSet::getValue(sal_Int32 cardNumber, sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
409 : {
410 14 : if ( fetchRow( cardNumber ) == sal_False )
411 : {
412 : OSL_FAIL("fetchRow() returned False" );
413 0 : m_bWasNull = sal_True;
414 0 : return *ODatabaseMetaDataResultSet::getEmptyValue();
415 : }
416 :
417 14 : m_bWasNull = (m_aRow->get())[columnIndex].isNull();
418 14 : return (m_aRow->get())[columnIndex];
419 :
420 : }
421 : // -------------------------------------------------------------------------
422 :
423 :
424 4 : ::rtl::OUString SAL_CALL OResultSet::getString( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
425 : {
426 4 : ResultSetEntryGuard aGuard( *this );
427 :
428 : OSL_ENSURE(m_xColumns.is(), "Need the Columns!!");
429 : OSL_ENSURE(columnIndex <= (sal_Int32)m_xColumns->get().size(), "Trying to access invalid columns number");
430 4 : checkIndex( columnIndex );
431 :
432 : // If this query was sorted then we should have a valid KeySet, so use it
433 4 : return getValue(getCurrentCardNumber(), mapColumn( columnIndex ) );
434 :
435 : }
436 : // -------------------------------------------------------------------------
437 :
438 0 : Time SAL_CALL OResultSet::getTime( sal_Int32 /*columnIndex*/ ) throw(SQLException, RuntimeException)
439 : {
440 0 : ResultSetEntryGuard aGuard( *this );
441 0 : return Time();
442 : }
443 : // -------------------------------------------------------------------------
444 :
445 :
446 0 : DateTime SAL_CALL OResultSet::getTimestamp( sal_Int32 /*columnIndex*/ ) throw(SQLException, RuntimeException)
447 : {
448 0 : ResultSetEntryGuard aGuard( *this );
449 0 : return DateTime();
450 : }
451 : // -------------------------------------------------------------------------
452 :
453 0 : sal_Bool SAL_CALL OResultSet::isBeforeFirst( ) throw(SQLException, RuntimeException)
454 : {
455 0 : ResultSetEntryGuard aGuard( *this );
456 :
457 : // here you have to implement your movements
458 : // return true means there is no data
459 : OSL_TRACE("In/Out: OResultSet::isBeforeFirst" );
460 0 : return( m_nRowPos < 1 );
461 : }
462 : // -------------------------------------------------------------------------
463 0 : sal_Bool SAL_CALL OResultSet::isAfterLast( ) throw(SQLException, RuntimeException)
464 : {
465 : SAL_WARN("connectivity.mork", "OResultSet::isAfterLast() NOT IMPLEMENTED!");
466 0 : ResultSetEntryGuard aGuard( *this );
467 :
468 : OSL_TRACE("In/Out: OResultSet::isAfterLast" );
469 : // return sal_True;
470 0 : return m_nRowPos > currentRowCount() && m_aQueryHelper.queryComplete();
471 : }
472 : // -------------------------------------------------------------------------
473 0 : sal_Bool SAL_CALL OResultSet::isFirst( ) throw(SQLException, RuntimeException)
474 : {
475 0 : ResultSetEntryGuard aGuard( *this );
476 :
477 : OSL_TRACE("In/Out: OResultSet::isFirst" );
478 0 : return m_nRowPos == 1;
479 : }
480 : // -------------------------------------------------------------------------
481 0 : sal_Bool SAL_CALL OResultSet::isLast( ) throw(SQLException, RuntimeException)
482 : {
483 : SAL_WARN("connectivity.mork", "OResultSet::isLast() NOT IMPLEMENTED!");
484 0 : ResultSetEntryGuard aGuard( *this );
485 :
486 : OSL_TRACE("In/Out: OResultSet::isLast" );
487 : // return sal_True;
488 0 : return m_nRowPos == currentRowCount() && m_aQueryHelper.queryComplete();
489 : }
490 : // -------------------------------------------------------------------------
491 1 : void SAL_CALL OResultSet::beforeFirst( ) throw(SQLException, RuntimeException)
492 : {
493 1 : ResultSetEntryGuard aGuard( *this );
494 :
495 : // move before the first row so that isBeforeFirst returns false
496 : OSL_TRACE("In/Out: OResultSet::beforeFirst" );
497 1 : if ( first() )
498 1 : previous();
499 1 : }
500 : // -------------------------------------------------------------------------
501 0 : void SAL_CALL OResultSet::afterLast( ) throw(SQLException, RuntimeException)
502 : {
503 0 : ResultSetEntryGuard aGuard( *this );
504 : OSL_TRACE("In/Out: OResultSet::afterLast" );
505 :
506 0 : if(last())
507 0 : next();
508 0 : }
509 : // -------------------------------------------------------------------------
510 :
511 0 : void SAL_CALL OResultSet::close() throw(SQLException, RuntimeException)
512 : {
513 : OSL_TRACE("In/Out: OResultSet::close" );
514 0 : dispose();
515 0 : }
516 : // -------------------------------------------------------------------------
517 :
518 3 : sal_Bool SAL_CALL OResultSet::first( ) throw(SQLException, RuntimeException)
519 : {
520 : OSL_TRACE("In/Out: OResultSet::first" );
521 3 : return seekRow( FIRST_POS );
522 : }
523 : // -------------------------------------------------------------------------
524 :
525 1 : sal_Bool SAL_CALL OResultSet::last( ) throw(SQLException, RuntimeException)
526 : {
527 : OSL_TRACE("In/Out: OResultSet::last" );
528 1 : return seekRow( LAST_POS );
529 : }
530 : // -------------------------------------------------------------------------
531 0 : sal_Bool SAL_CALL OResultSet::absolute( sal_Int32 row ) throw(SQLException, RuntimeException)
532 : {
533 : OSL_TRACE("In/Out: OResultSet::absolute" );
534 0 : return seekRow( ABSOLUTE_POS, row );
535 : }
536 : // -------------------------------------------------------------------------
537 0 : sal_Bool SAL_CALL OResultSet::relative( sal_Int32 row ) throw(SQLException, RuntimeException)
538 : {
539 : OSL_TRACE("In/Out: OResultSet::relative" );
540 0 : return seekRow( RELATIVE_POS, row );
541 : }
542 : // -------------------------------------------------------------------------
543 1 : sal_Bool SAL_CALL OResultSet::previous( ) throw(SQLException, RuntimeException)
544 : {
545 1 : ResultSetEntryGuard aGuard( *this );
546 : OSL_TRACE("In/Out: OResultSet::previous" );
547 1 : return seekRow( PRIOR_POS );
548 : }
549 : // -------------------------------------------------------------------------
550 0 : Reference< XInterface > SAL_CALL OResultSet::getStatement( ) throw(SQLException, RuntimeException)
551 : {
552 0 : ResultSetEntryGuard aGuard( *this );
553 :
554 : OSL_TRACE("In/Out: OResultSet::getStatement" );
555 0 : return m_xStatement;
556 : }
557 : // -------------------------------------------------------------------------
558 :
559 0 : sal_Bool SAL_CALL OResultSet::rowDeleted( ) throw(SQLException, RuntimeException)
560 : {
561 : SAL_WARN("connectivity.mork", "OResultSet::rowDeleted() NOT IMPLEMENTED!");
562 0 : ResultSetEntryGuard aGuard( *this );
563 : OSL_TRACE("In/Out: OResultSet::rowDeleted, m_RowStates=%u",m_RowStates );
564 0 : return sal_True;//return ((m_RowStates & RowStates_Deleted) == RowStates_Deleted) ;
565 : }
566 : // -------------------------------------------------------------------------
567 0 : sal_Bool SAL_CALL OResultSet::rowInserted( ) throw(SQLException, RuntimeException)
568 : {
569 : SAL_WARN("connectivity.mork", "OResultSet::rowInserted() NOT IMPLEMENTED!");
570 0 : ResultSetEntryGuard aGuard( *this );
571 : OSL_TRACE("In/Out: OResultSet::rowInserted,m_RowStates=%u",m_RowStates );
572 0 : return sal_True;//return ((m_RowStates & RowStates_Inserted) == RowStates_Inserted);
573 : }
574 : // -------------------------------------------------------------------------
575 0 : sal_Bool SAL_CALL OResultSet::rowUpdated( ) throw(SQLException, RuntimeException)
576 : {
577 : SAL_WARN("connectivity.mork", "OResultSet::rowUpdated() NOT IMPLEMENTED!");
578 0 : ResultSetEntryGuard aGuard( *this );
579 : OSL_TRACE("In/Out: OResultSet::rowUpdated,m_RowStates=%u",m_RowStates );
580 0 : return sal_True;// return ((m_RowStates & RowStates_Updated) == RowStates_Updated) ;
581 : }
582 : // -------------------------------------------------------------------------
583 :
584 1 : sal_Bool SAL_CALL OResultSet::next( ) throw(SQLException, RuntimeException)
585 : {
586 1 : return seekRow( NEXT_POS );
587 : }
588 : // -------------------------------------------------------------------------
589 :
590 0 : sal_Bool SAL_CALL OResultSet::wasNull( ) throw(SQLException, RuntimeException)
591 : {
592 0 : ResultSetEntryGuard aGuard( *this );
593 :
594 0 : return m_bWasNull;
595 : }
596 : // -------------------------------------------------------------------------
597 :
598 0 : void SAL_CALL OResultSet::cancel( ) throw(RuntimeException)
599 : {
600 0 : ResultSetEntryGuard aGuard( *this );
601 0 : OSL_TRACE("In/Out: OResultSet::cancel" );
602 :
603 0 : }
604 : // -------------------------------------------------------------------------
605 0 : void SAL_CALL OResultSet::clearWarnings( ) throw(SQLException, RuntimeException)
606 : {
607 : OSL_TRACE("In/Out: OResultSet::clearWarnings" );
608 0 : }
609 : // -------------------------------------------------------------------------
610 0 : Any SAL_CALL OResultSet::getWarnings( ) throw(SQLException, RuntimeException)
611 : {
612 : OSL_TRACE("In/Out: OResultSet::getWarnings" );
613 0 : return Any();
614 : }
615 : // -------------------------------------------------------------------------
616 0 : void SAL_CALL OResultSet::refreshRow( ) throw(SQLException, RuntimeException)
617 : {
618 : OSL_TRACE("In/Out: OResultSet::refreshRow" );
619 0 : if (fetchRow(getCurrentCardNumber(),sal_True)) {
620 : //force fetch current row will cause we lose all change to the current row
621 0 : m_pStatement->getOwnConnection()->throwSQLException( STR_ERROR_REFRESH_ROW, *this );
622 : }
623 0 : }
624 : // -------------------------------------------------------------------------
625 0 : IPropertyArrayHelper* OResultSet::createArrayHelper( ) const
626 : {
627 0 : Sequence< Property > aProps(5);
628 0 : Property* pProperties = aProps.getArray();
629 0 : sal_Int32 nPos = 0;
630 0 : DECL_PROP0(FETCHDIRECTION, sal_Int32);
631 0 : DECL_PROP0(FETCHSIZE, sal_Int32);
632 0 : DECL_BOOL_PROP1IMPL(ISBOOKMARKABLE) PropertyAttribute::READONLY);
633 0 : DECL_PROP1IMPL(RESULTSETCONCURRENCY,sal_Int32) PropertyAttribute::READONLY);
634 0 : DECL_PROP1IMPL(RESULTSETTYPE, sal_Int32) PropertyAttribute::READONLY);
635 :
636 0 : return new OPropertyArrayHelper(aProps);
637 : }
638 : // -------------------------------------------------------------------------
639 0 : IPropertyArrayHelper & OResultSet::getInfoHelper()
640 : {
641 0 : return *const_cast<OResultSet*>(this)->getArrayHelper();
642 : }
643 : // -------------------------------------------------------------------------
644 0 : sal_Bool OResultSet::convertFastPropertyValue(
645 : Any & /*rConvertedValue*/,
646 : Any & /*rOldValue*/,
647 : sal_Int32 nHandle,
648 : const Any& /*rValue*/ )
649 : throw (::com::sun::star::lang::IllegalArgumentException)
650 : {
651 : OSL_FAIL( "OResultSet::convertFastPropertyValue: not implemented!" );
652 0 : switch(nHandle)
653 : {
654 : case PROPERTY_ID_ISBOOKMARKABLE:
655 : case PROPERTY_ID_RESULTSETCONCURRENCY:
656 : case PROPERTY_ID_RESULTSETTYPE:
657 0 : throw ::com::sun::star::lang::IllegalArgumentException();
658 : case PROPERTY_ID_FETCHDIRECTION:
659 : case PROPERTY_ID_FETCHSIZE:
660 : default:
661 : ;
662 : }
663 0 : return sal_False;
664 : }
665 : // -------------------------------------------------------------------------
666 0 : void OResultSet::setFastPropertyValue_NoBroadcast(
667 : sal_Int32 nHandle,
668 : const Any& /*rValue*/
669 : )
670 : throw (Exception)
671 : {
672 : OSL_FAIL( "OResultSet::setFastPropertyValue_NoBroadcast: not implemented!" );
673 0 : switch(nHandle)
674 : {
675 : case PROPERTY_ID_ISBOOKMARKABLE:
676 : case PROPERTY_ID_RESULTSETCONCURRENCY:
677 : case PROPERTY_ID_RESULTSETTYPE:
678 0 : throw Exception();
679 : case PROPERTY_ID_FETCHDIRECTION:
680 0 : break;
681 : case PROPERTY_ID_FETCHSIZE:
682 0 : break;
683 : default:
684 : ;
685 : }
686 0 : }
687 : // -------------------------------------------------------------------------
688 0 : void OResultSet::getFastPropertyValue(
689 : Any& rValue,
690 : sal_Int32 nHandle
691 : ) const
692 : {
693 0 : switch(nHandle)
694 : {
695 : case PROPERTY_ID_RESULTSETCONCURRENCY:
696 0 : rValue <<= (sal_Int32)m_nResultSetConcurrency;
697 0 : break;
698 : case PROPERTY_ID_RESULTSETTYPE:
699 0 : rValue <<= m_nResultSetType;
700 0 : break;
701 : case PROPERTY_ID_FETCHDIRECTION:
702 0 : rValue <<= m_nFetchDirection;
703 0 : break;
704 : case PROPERTY_ID_FETCHSIZE:
705 0 : rValue <<= m_nFetchSize;
706 0 : break;
707 : case PROPERTY_ID_ISBOOKMARKABLE:
708 0 : const_cast< OResultSet* >( this )->determineReadOnly();
709 0 : rValue <<= !m_bIsReadOnly;
710 0 : break;
711 : }
712 0 : }
713 : // -----------------------------------------------------------------------------
714 16 : void SAL_CALL OResultSet::acquire() throw()
715 : {
716 16 : OResultSet_BASE::acquire();
717 16 : }
718 : // -----------------------------------------------------------------------------
719 14 : void SAL_CALL OResultSet::release() throw()
720 : {
721 14 : OResultSet_BASE::release();
722 14 : }
723 : // -----------------------------------------------------------------------------
724 0 : ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL OResultSet::getPropertySetInfo( ) throw(::com::sun::star::uno::RuntimeException)
725 : {
726 0 : return ::cppu::OPropertySetHelper::createPropertySetInfo(getInfoHelper());
727 : }
728 :
729 : // -------------------------------------------------------------------------
730 0 : void OResultSet::parseParameter( const OSQLParseNode* pNode, rtl::OUString& rMatchString )
731 : {
732 : OSL_ENSURE(pNode->count() > 0,"Error parsing parameter in Parse Tree");
733 0 : OSQLParseNode *pMark = pNode->getChild(0);
734 :
735 : // Initialize to empty string
736 0 : rMatchString = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(""));
737 :
738 0 : rtl::OUString aParameterName;
739 0 : if (SQL_ISPUNCTUATION(pMark,"?")) {
740 0 : aParameterName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("?"));
741 : }
742 0 : else if (SQL_ISPUNCTUATION(pMark,":")) {
743 0 : aParameterName = pNode->getChild(1)->getTokenValue();
744 : }
745 : // XXX - Now we know name, what's value????
746 0 : m_nParamIndex ++;
747 : OSL_TRACE("Parameter name [%d]: %s", m_nParamIndex,OUtoCStr(aParameterName) );
748 :
749 0 : if ( m_aParameterRow.is() ) {
750 : OSL_ENSURE( m_nParamIndex < (sal_Int32)m_aParameterRow->get().size() + 1, "More parameters than values found" );
751 0 : rMatchString = (m_aParameterRow->get())[(sal_uInt16)m_nParamIndex];
752 : #if OSL_DEBUG_LEVEL > 0
753 : OSL_TRACE("Prop Value : %s", OUtoCStr( rMatchString ) );
754 : #endif
755 0 : }
756 : #if OSL_DEBUG_LEVEL > 0
757 : else {
758 : OSL_TRACE("Prop Value : Invalid ParameterRow!" );
759 : }
760 : #endif
761 0 : }
762 :
763 2 : void OResultSet::analyseWhereClause( const OSQLParseNode* parseTree,
764 : MQueryExpression &queryExpression)
765 : {
766 2 : ::rtl::OUString columnName;
767 2 : MQueryOp::cond_type op( MQueryOp::Is );
768 2 : ::rtl::OUString matchString;
769 :
770 2 : if ( parseTree == NULL )
771 2 : return;
772 :
773 2 : if ( m_pSQLIterator->getParseTree() != NULL ) {
774 2 : ::rtl::Reference<OSQLColumns> xColumns = m_pSQLIterator->getParameters();
775 2 : if(xColumns.is())
776 : {
777 2 : ::rtl::OUString aColName, aParameterValue;
778 2 : OSQLColumns::Vector::iterator aIter = xColumns->get().begin();
779 2 : sal_Int32 i = 1;
780 2 : for(;aIter != xColumns->get().end();++aIter)
781 : {
782 0 : (*aIter)->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME)) >>= aColName;
783 : OSL_TRACE("Prop Column Name : %s", OUtoCStr( aColName ) );
784 0 : if ( m_aParameterRow.is() ) {
785 0 : aParameterValue = (m_aParameterRow->get())[(sal_uInt16)i];
786 : #if OSL_DEBUG_LEVEL > 0
787 : OSL_TRACE("Prop Value : %s", OUtoCStr( aParameterValue ) );
788 : #endif
789 : }
790 : #if OSL_DEBUG_LEVEL > 0
791 : else {
792 : OSL_TRACE("Prop Value : Invalid ParameterRow!" );
793 : }
794 : #endif
795 0 : i++;
796 2 : }
797 2 : }
798 :
799 : }
800 :
801 2 : if ( SQL_ISRULE(parseTree,where_clause) )
802 : {
803 : OSL_TRACE("analyseSQL : Got WHERE clause");
804 : // Reset Parameter Counter
805 1 : resetParameters();
806 1 : analyseWhereClause( parseTree->getChild( 1 ), queryExpression );
807 : }
808 1 : else if ( parseTree->count() == 3 && // Handle ()'s
809 0 : SQL_ISPUNCTUATION(parseTree->getChild(0),"(") &&
810 0 : SQL_ISPUNCTUATION(parseTree->getChild(2),")"))
811 : {
812 :
813 : OSL_TRACE("analyseSQL : Got Punctuation ()");
814 0 : MQueryExpression *subExpression = new MQueryExpression();
815 0 : analyseWhereClause( parseTree->getChild( 1 ), *subExpression );
816 0 : queryExpression.getExpressions().push_back( subExpression );
817 : }
818 1 : else if ((SQL_ISRULE(parseTree,search_condition) || (SQL_ISRULE(parseTree,boolean_term)))
819 0 : && parseTree->count() == 3) // Handle AND/OR
820 : {
821 :
822 : OSL_TRACE("analyseSQL : Got AND/OR clause");
823 :
824 : // TODO - Need to take care or AND, for now match is always OR
825 0 : analyseWhereClause( parseTree->getChild( 0 ), queryExpression );
826 0 : analyseWhereClause( parseTree->getChild( 2 ), queryExpression );
827 :
828 0 : if (SQL_ISTOKEN(parseTree->getChild(1),OR)) { // OR-Operator
829 0 : queryExpression.setExpressionCondition( MQueryExpression::OR );
830 : }
831 0 : else if (SQL_ISTOKEN(parseTree->getChild(1),AND)) { // AND-Operator
832 0 : queryExpression.setExpressionCondition( MQueryExpression::AND );
833 : }
834 : else {
835 : OSL_FAIL("analyseSQL: Error in Parse Tree");
836 : }
837 : }
838 1 : else if (SQL_ISRULE(parseTree,comparison_predicate))
839 : {
840 : OSL_ENSURE(parseTree->count() == 3, "Error parsing COMPARE predicate");
841 0 : if (!(SQL_ISRULE(parseTree->getChild(0),column_ref) ||
842 0 : parseTree->getChild(2)->getNodeType() == SQL_NODE_STRING ||
843 0 : parseTree->getChild(2)->getNodeType() == SQL_NODE_INTNUM ||
844 0 : parseTree->getChild(2)->getNodeType() == SQL_NODE_APPROXNUM ||
845 0 : SQL_ISTOKEN(parseTree->getChild(2),TRUE) ||
846 0 : SQL_ISTOKEN(parseTree->getChild(2),FALSE) ||
847 0 : SQL_ISRULE(parseTree->getChild(2),parameter) ||
848 : // odbc date
849 0 : (SQL_ISRULE(parseTree->getChild(2),set_fct_spec) && SQL_ISPUNCTUATION(parseTree->getChild(2)->getChild(0),"{"))))
850 : {
851 0 : m_pStatement->getOwnConnection()->throwSQLException( STR_QUERY_TOO_COMPLEX, *this );
852 : }
853 :
854 0 : OSQLParseNode *pPrec = parseTree->getChild(1);
855 0 : if (pPrec->getNodeType() == SQL_NODE_EQUAL)
856 0 : op = MQueryOp::Is;
857 0 : else if (pPrec->getNodeType() == SQL_NODE_NOTEQUAL)
858 0 : op = MQueryOp::IsNot;
859 :
860 0 : ::rtl::OUString sTableRange;
861 0 : if(SQL_ISRULE(parseTree->getChild(0),column_ref))
862 0 : m_pSQLIterator->getColumnRange(parseTree->getChild(0),columnName,sTableRange);
863 0 : else if(parseTree->getChild(0)->isToken())
864 0 : columnName = parseTree->getChild(0)->getTokenValue();
865 :
866 0 : if ( SQL_ISRULE(parseTree->getChild(2),parameter) ) {
867 0 : parseParameter( parseTree->getChild(2), matchString );
868 : }
869 : else {
870 0 : matchString = parseTree->getChild(2)->getTokenValue();
871 : }
872 :
873 0 : if ( columnName.compareToAscii("0") ==0 && op == MQueryOp::Is &&
874 0 : matchString.compareToAscii("1") == 0 ) {
875 : OSL_TRACE("Query always evaluates to FALSE");
876 0 : m_bIsAlwaysFalseQuery = sal_True;
877 : }
878 0 : queryExpression.getExpressions().push_back( new MQueryExpressionString( columnName, op, matchString ));
879 : }
880 1 : else if (SQL_ISRULE(parseTree,like_predicate))
881 : {
882 : OSL_ENSURE(parseTree->count() == 2, "Error parsing LIKE predicate");
883 :
884 : OSL_TRACE("analyseSQL : Got LIKE rule");
885 :
886 1 : if ( !(SQL_ISRULE(parseTree->getChild(0), column_ref)) )
887 : {
888 0 : m_pStatement->getOwnConnection()->throwSQLException( STR_QUERY_INVALID_LIKE_COLUMN, *this );
889 : }
890 :
891 :
892 : OSQLParseNode *pColumn;
893 : OSQLParseNode *pAtom;
894 : OSQLParseNode *pOptEscape;
895 1 : const OSQLParseNode* pPart2 = parseTree->getChild(1);
896 1 : pColumn = parseTree->getChild(0); // Match Item
897 1 : pAtom = pPart2->getChild(static_cast<sal_uInt32>(pPart2->count()-2)); // Match String
898 1 : pOptEscape = pPart2->getChild(static_cast<sal_uInt32>(pPart2->count()-1)); // Opt Escape Rule
899 : (void)pOptEscape;
900 1 : const bool bNot = SQL_ISTOKEN(pPart2->getChild(0), NOT);
901 :
902 2 : if (!(pAtom->getNodeType() == SQL_NODE_STRING ||
903 0 : pAtom->getNodeType() == SQL_NODE_NAME ||
904 0 : SQL_ISRULE(pAtom,parameter) ||
905 0 : ( pAtom->getChild(0) && pAtom->getChild(0)->getNodeType() == SQL_NODE_NAME ) ||
906 0 : ( pAtom->getChild(0) && pAtom->getChild(0)->getNodeType() == SQL_NODE_STRING )
907 1 : ) )
908 : {
909 : OSL_TRACE("analyseSQL : pAtom->count() = %d", pAtom->count() );
910 :
911 0 : m_pStatement->getOwnConnection()->throwSQLException( STR_QUERY_INVALID_LIKE_STRING, *this );
912 : }
913 :
914 1 : const sal_Unicode WILDCARD = '%';
915 1 : const sal_Unicode ALT_WILDCARD = '*';
916 1 : const sal_Unicode MATCHCHAR = '_';
917 :
918 1 : ::rtl::OUString sTableRange;
919 1 : if(SQL_ISRULE(pColumn,column_ref))
920 1 : m_pSQLIterator->getColumnRange(pColumn,columnName,sTableRange);
921 :
922 : OSL_TRACE("ColumnName = %s", OUtoCStr( columnName ) );
923 :
924 1 : if ( SQL_ISRULE(pAtom,parameter) ) {
925 0 : parseParameter( pAtom, matchString );
926 : // Replace all '*' with '%' : UI Usually does this but not with
927 : // Parameters for some reason.
928 0 : matchString = matchString.replace( ALT_WILDCARD, WILDCARD );
929 : }
930 : else
931 : {
932 1 : matchString = pAtom->getTokenValue();
933 : }
934 :
935 : // Determine where '%' character is...
936 :
937 1 : if ( matchString.equals( ::rtl::OUString::valueOf( WILDCARD ) ) )
938 : {
939 : // String containing only a '%' and nothing else
940 0 : op = MQueryOp::Exists;
941 : // Will be ignored for Exists case, but clear anyway.
942 0 : matchString = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(""));
943 : }
944 1 : else if ( matchString.indexOf ( WILDCARD ) == -1 &&
945 0 : matchString.indexOf ( MATCHCHAR ) == -1 )
946 : {
947 : // Simple string , eg. "to match"
948 0 : if ( bNot )
949 0 : op = MQueryOp::DoesNotContain;
950 : else
951 0 : op = MQueryOp::Contains;
952 : }
953 2 : else if ( matchString.indexOf ( WILDCARD ) == 0
954 1 : && matchString.lastIndexOf ( WILDCARD ) == matchString.getLength() -1
955 0 : && matchString.indexOf ( WILDCARD, 1 ) == matchString.lastIndexOf ( WILDCARD )
956 0 : && matchString.indexOf( MATCHCHAR ) == -1
957 : )
958 : {
959 : // Relatively simple "%string%" - ie, contains...
960 : // Cut '%' from front and rear
961 0 : matchString = matchString.replaceAt( 0, 1, rtl::OUString() );
962 0 : matchString = matchString.replaceAt( matchString.getLength() -1 , 1, rtl::OUString() );
963 :
964 0 : if (bNot)
965 0 : op = MQueryOp::DoesNotContain;
966 : else
967 0 : op = MQueryOp::Contains;
968 : }
969 1 : else if ( bNot )
970 : {
971 : // We currently can't handle a 'NOT LIKE' when there are '%' or
972 : // '_' dispersed throughout
973 0 : m_pStatement->getOwnConnection()->throwSQLException( STR_QUERY_NOT_LIKE_TOO_COMPLEX, *this );
974 : }
975 : else
976 : {
977 2 : if ( (matchString.indexOf ( WILDCARD ) == matchString.lastIndexOf ( WILDCARD ))
978 1 : && matchString.indexOf( MATCHCHAR ) == -1
979 : )
980 : {
981 : // One occurrence of '%' - no '_' matches...
982 1 : if ( matchString.indexOf ( WILDCARD ) == 0 )
983 : {
984 1 : op = MQueryOp::EndsWith;
985 1 : matchString = matchString.replaceAt( 0, 1, rtl::OUString());
986 : }
987 0 : else if ( matchString.indexOf ( WILDCARD ) == matchString.getLength() -1 )
988 : {
989 0 : op = MQueryOp::BeginsWith;
990 0 : matchString = matchString.replaceAt( matchString.getLength() -1 , 1, rtl::OUString() );
991 : }
992 : else
993 : {
994 0 : sal_Int32 pos = matchString.indexOf ( WILDCARD );
995 0 : matchString = matchString.replaceAt( pos, 1,::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(".*")) );
996 0 : op = MQueryOp::RegExp;
997 : }
998 :
999 : }
1000 : else
1001 : {
1002 : // Most Complex, need to use an RE
1003 0 : sal_Int32 pos = matchString.indexOf ( WILDCARD );
1004 0 : while ( (pos = matchString.indexOf ( WILDCARD )) != -1 )
1005 : {
1006 0 : matchString = matchString.replaceAt( pos, 1, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(".*")) );
1007 : }
1008 :
1009 0 : pos = matchString.indexOf ( MATCHCHAR );
1010 0 : while ( (pos = matchString.indexOf( MATCHCHAR )) != -1 )
1011 : {
1012 0 : matchString = matchString.replaceAt( pos, 1, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(".")) );
1013 : }
1014 :
1015 0 : op = MQueryOp::RegExp;
1016 : }
1017 : }
1018 :
1019 1 : queryExpression.getExpressions().push_back( new MQueryExpressionString( columnName, op, matchString ));
1020 : }
1021 0 : else if (SQL_ISRULE(parseTree,test_for_null))
1022 : {
1023 : OSL_ENSURE(parseTree->count() == 2,"Error in ParseTree");
1024 0 : const OSQLParseNode* pPart2 = parseTree->getChild(1);
1025 : OSL_ENSURE(SQL_ISTOKEN(pPart2->getChild(0),IS),"Error in ParseTree");
1026 :
1027 0 : if (!SQL_ISRULE(parseTree->getChild(0),column_ref))
1028 : {
1029 0 : m_pStatement->getOwnConnection()->throwSQLException( STR_QUERY_INVALID_IS_NULL_COLUMN, *this );
1030 : }
1031 :
1032 0 : if (SQL_ISTOKEN(pPart2->getChild(1),NOT))
1033 : {
1034 0 : op = MQueryOp::Exists;
1035 : }
1036 : else
1037 : {
1038 0 : op = MQueryOp::DoesNotExist;
1039 : }
1040 :
1041 0 : ::rtl::OUString sTableRange;
1042 0 : m_pSQLIterator->getColumnRange(parseTree->getChild(0),columnName,sTableRange);
1043 :
1044 0 : queryExpression.getExpressions().push_back( new MQueryExpressionString( columnName, op ));
1045 : }
1046 : else
1047 : {
1048 : OSL_TRACE( "Unexpected statement!!!" );
1049 :
1050 0 : m_pStatement->getOwnConnection()->throwSQLException( STR_QUERY_TOO_COMPLEX, *this );
1051 2 : }
1052 : }
1053 :
1054 : // -----------------------------------------------------------------------------
1055 :
1056 2 : void OResultSet::fillRowData()
1057 : throw( ::com::sun::star::sdbc::SQLException )
1058 : {
1059 : OSL_ENSURE( m_pStatement, "Require a statement" );
1060 :
1061 2 : MQueryExpression queryExpression;
1062 :
1063 2 : OConnection* xConnection = static_cast<OConnection*>(m_pStatement->getConnection().get());
1064 2 : m_xColumns = m_pSQLIterator->getSelectColumns();
1065 :
1066 : OSL_ENSURE(m_xColumns.is(), "Need the Columns!!");
1067 :
1068 2 : OSQLColumns::Vector::const_iterator aIter = m_xColumns->get().begin();
1069 2 : const ::rtl::OUString sProprtyName = OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME);
1070 2 : ::rtl::OUString sName;
1071 2 : m_aAttributeStrings.clear();
1072 2 : m_aAttributeStrings.reserve(m_xColumns->get().size());
1073 4 : for (sal_Int32 i = 1; aIter != m_xColumns->get().end();++aIter, i++)
1074 : {
1075 2 : (*aIter)->getPropertyValue(sProprtyName) >>= sName;
1076 : #if OSL_DEBUG_LEVEL > 0
1077 : OSL_TRACE("Query Columns : (%d) %s", i, OUtoCStr(sName) );
1078 : #endif
1079 2 : m_aAttributeStrings.push_back( sName );
1080 : }
1081 :
1082 : // Generate Match Conditions for Query
1083 2 : const OSQLParseNode* pParseTree = m_pSQLIterator->getWhereTree();
1084 :
1085 2 : m_bIsAlwaysFalseQuery = sal_False;
1086 2 : if ( pParseTree != NULL )
1087 : {
1088 : // Extract required info
1089 :
1090 : OSL_TRACE("\tHave a Where Clause");
1091 :
1092 1 : analyseWhereClause( pParseTree, queryExpression );
1093 : }
1094 : // If the query is a 0=1 then set Row count to 0 and return
1095 2 : if ( m_bIsAlwaysFalseQuery )
1096 : {
1097 0 : m_bIsReadOnly = 1;
1098 2 : return;
1099 : }
1100 :
1101 2 : m_aQueryHelper.setExpression( queryExpression );
1102 :
1103 2 : rtl::OUString aStr( m_pTable->getName() );
1104 2 : m_aQueryHelper.setAddressbook( aStr );
1105 :
1106 2 : sal_Int32 rv = m_aQueryHelper.executeQuery(xConnection);
1107 2 : if ( rv == -1 ) {
1108 0 : m_pStatement->getOwnConnection()->throwSQLException( STR_ERR_EXECUTING_QUERY, *this );
1109 : }
1110 :
1111 2 : if (m_aQueryHelper.hadError())
1112 : {
1113 0 : m_pStatement->getOwnConnection()->throwSQLException( m_aQueryHelper.getError(), *this );
1114 : }
1115 :
1116 : //determine whether the address book is readonly
1117 2 : determineReadOnly();
1118 :
1119 : #if OSL_DEBUG_LEVEL > 0
1120 : OSL_TRACE( "executeQuery returned %d", rv );
1121 :
1122 : OSL_TRACE( "\tOUT OResultSet::fillRowData()" );
1123 : #endif
1124 : }
1125 :
1126 : // -----------------------------------------------------------------------------
1127 0 : static sal_Bool matchRow( OValueRow& row1, OValueRow& row2 )
1128 : {
1129 0 : OValueVector::Vector::iterator row1Iter = row1->get().begin();
1130 0 : OValueVector::Vector::iterator row2Iter = row2->get().begin();
1131 0 : for ( ++row1Iter,++row2Iter; // the first column is the bookmark column
1132 0 : row1Iter != row1->get().end(); ++row1Iter,++row2Iter)
1133 : {
1134 0 : if ( row1Iter->isBound())
1135 : {
1136 : // Compare values, if at anytime there's a mismatch return false
1137 0 : if ( !( (*row1Iter) == (*row2Iter) ) )
1138 0 : return sal_False;
1139 : }
1140 : }
1141 :
1142 : // If we get to here the rows match
1143 0 : return sal_True;
1144 : }
1145 :
1146 0 : sal_Int32 OResultSet::getRowForCardNumber(sal_Int32 nCardNum)
1147 : {
1148 : OSL_TRACE("In/Out: OResultSet::getRowForCardNumber, nCardNum = %u", nCardNum );
1149 :
1150 0 : if ( m_pKeySet.is() )
1151 : {
1152 : sal_Int32 nPos;
1153 0 : for(nPos=0;nPos < (sal_Int32)m_pKeySet->get().size();nPos++)
1154 : {
1155 0 : if (nCardNum == (m_pKeySet->get())[nPos])
1156 : {
1157 : OSL_TRACE("In/Out: OResultSet::getRowForCardNumber, return = %u", nPos+1 );
1158 0 : return nPos+1;
1159 : }
1160 : }
1161 : }
1162 :
1163 0 : m_pStatement->getOwnConnection()->throwSQLException( STR_INVALID_BOOKMARK, *this );
1164 :
1165 0 : return 0;
1166 : }
1167 :
1168 : // -----------------------------------------------------------------------------
1169 2 : void SAL_CALL OResultSet::executeQuery() throw( ::com::sun::star::sdbc::SQLException,
1170 : ::com::sun::star::uno::RuntimeException)
1171 : {
1172 2 : ResultSetEntryGuard aGuard( *this );
1173 :
1174 : OSL_ENSURE( m_pTable, "Need a Table object");
1175 2 : if(!m_pTable)
1176 : {
1177 0 : const OSQLTables& xTabs = m_pSQLIterator->getTables();
1178 0 : if ((xTabs.begin() == xTabs.end()) || !xTabs.begin()->second.is())
1179 0 : m_pStatement->getOwnConnection()->throwSQLException( STR_QUERY_TOO_COMPLEX, *this );
1180 :
1181 0 : m_pTable = static_cast< OTable* > ((xTabs.begin()->second).get());
1182 :
1183 : }
1184 :
1185 2 : m_nRowPos = 0;
1186 :
1187 2 : fillRowData();
1188 :
1189 : OSL_ENSURE(m_xColumns.is(), "Need the Columns!!");
1190 :
1191 2 : switch( m_pSQLIterator->getStatementType() )
1192 : {
1193 : case SQL_STATEMENT_SELECT:
1194 : {
1195 2 : if(m_bIsAlwaysFalseQuery) {
1196 0 : break;
1197 : }
1198 2 : else if(isCount())
1199 : {
1200 0 : m_pStatement->getOwnConnection()->throwSQLException( STR_NO_COUNT_SUPPORT, *this );
1201 : }
1202 : else
1203 : {
1204 2 : sal_Bool bDistinct = sal_False;
1205 2 : OSQLParseNode *pDistinct = m_pParseTree->getChild(1);
1206 2 : if (pDistinct && pDistinct->getTokenID() == SQL_TOKEN_DISTINCT)
1207 : {
1208 0 : if(!IsSorted())
1209 : {
1210 0 : m_aOrderbyColumnNumber.push_back(m_aColMapping[1]);
1211 0 : m_aOrderbyAscending.push_back(SQL_DESC);
1212 : }
1213 0 : bDistinct = sal_True;
1214 : }
1215 :
1216 2 : OSortIndex::TKeyTypeVector eKeyType(m_aOrderbyColumnNumber.size());
1217 2 : ::std::vector<sal_Int32>::iterator aOrderByIter = m_aOrderbyColumnNumber.begin();
1218 3 : for ( ::std::vector<sal_Int16>::size_type i = 0; aOrderByIter != m_aOrderbyColumnNumber.end(); ++aOrderByIter,++i)
1219 : {
1220 : OSL_ENSURE((sal_Int32)m_aRow->get().size() > *aOrderByIter,"Invalid Index");
1221 1 : switch ((m_aRow->get().begin()+*aOrderByIter)->getTypeKind())
1222 : {
1223 : case DataType::CHAR:
1224 : case DataType::VARCHAR:
1225 1 : eKeyType[i] = SQL_ORDERBYKEY_STRING;
1226 1 : break;
1227 :
1228 : case DataType::OTHER:
1229 : case DataType::TINYINT:
1230 : case DataType::SMALLINT:
1231 : case DataType::INTEGER:
1232 : case DataType::DECIMAL:
1233 : case DataType::NUMERIC:
1234 : case DataType::REAL:
1235 : case DataType::DOUBLE:
1236 : case DataType::DATE:
1237 : case DataType::TIME:
1238 : case DataType::TIMESTAMP:
1239 : case DataType::BIT:
1240 0 : eKeyType[i] = SQL_ORDERBYKEY_DOUBLE;
1241 0 : break;
1242 :
1243 : // Other types aren't implemented (so they are always FALSE)
1244 : default:
1245 0 : eKeyType[i] = SQL_ORDERBYKEY_NONE;
1246 : OSL_FAIL("MResultSet::executeQuery: Order By Data Type not implemented");
1247 0 : break;
1248 : }
1249 : }
1250 :
1251 2 : if (IsSorted())
1252 : {
1253 : // Implement Sorting
1254 :
1255 : // So that we can sort we need to wait until the executed
1256 : // query to the mozilla addressbooks has returned all
1257 : // values.
1258 :
1259 : OSL_TRACE("Query is to be sorted");
1260 :
1261 : OSL_ENSURE( m_aQueryHelper.queryComplete(), "Query not complete!!");
1262 :
1263 1 : m_pSortIndex = new OSortIndex(eKeyType,m_aOrderbyAscending);
1264 :
1265 : OSL_TRACE("OrderbyColumnNumber->size() = %d",m_aOrderbyColumnNumber.size());
1266 : #if OSL_DEBUG_LEVEL > 0
1267 : for ( ::std::vector<sal_Int32>::size_type i = 0; i < m_aColMapping.size(); i++ )
1268 : OSL_TRACE("Mapped: %d -> %d", i, m_aColMapping[i] );
1269 : #endif
1270 11 : for ( sal_Int32 nRow = 1; nRow <= m_aQueryHelper.getResultCount(); nRow++ ) {
1271 :
1272 10 : OKeyValue* pKeyValue = OKeyValue::createKeyValue((nRow));
1273 :
1274 10 : ::std::vector<sal_Int32>::iterator aIter = m_aOrderbyColumnNumber.begin();
1275 20 : for (;aIter != m_aOrderbyColumnNumber.end(); ++aIter)
1276 : {
1277 10 : const ORowSetValue& value = getValue(nRow, *aIter);
1278 :
1279 : OSL_TRACE( "Adding Value: (%d,%d) : %s", nRow, *aIter,OUtoCStr( value ));
1280 :
1281 10 : pKeyValue->pushKey(new ORowSetValueDecorator(value));
1282 : }
1283 :
1284 10 : m_pSortIndex->AddKeyValue( pKeyValue );
1285 : }
1286 :
1287 1 : m_pKeySet = m_pSortIndex->CreateKeySet();
1288 1 : m_CurrentRowCount = static_cast<sal_Int32>(m_pKeySet->get().size());
1289 : #if OSL_DEBUG_LEVEL > 0
1290 : for( OKeySet::Vector::size_type i = 0; i < m_pKeySet->get().size(); i++ )
1291 : OSL_TRACE("Sorted: %d -> %d", i, (m_pKeySet->get())[i] );
1292 : #endif
1293 :
1294 1 : m_pSortIndex = NULL;
1295 1 : beforeFirst(); // Go back to start
1296 : }
1297 : else //we always need m_pKeySet now
1298 1 : m_pKeySet = new OKeySet();
1299 :
1300 : // Handle the DISTINCT case
1301 2 : if ( bDistinct && m_pKeySet.is() )
1302 : {
1303 0 : OValueRow aSearchRow = new OValueVector( m_aRow->get().size() );
1304 :
1305 0 : for( OKeySet::Vector::size_type i = 0; i < m_pKeySet->get().size(); i++ )
1306 : {
1307 0 : fetchRow( (m_pKeySet->get())[i] ); // Fills m_aRow
1308 0 : if ( matchRow( m_aRow, aSearchRow ) )
1309 : {
1310 0 : (m_pKeySet->get())[i] = 0; // Marker for later to be removed
1311 : }
1312 : else
1313 : {
1314 : // They don't match, so it's not a duplicate.
1315 : // Use the current Row as the next one to match against
1316 0 : *aSearchRow = *m_aRow;
1317 : }
1318 : }
1319 : // Now remove any keys marked with a 0
1320 0 : m_pKeySet->get().erase(::std::remove_if(m_pKeySet->get().begin(),m_pKeySet->get().end()
1321 : ,::std::bind2nd(::std::equal_to<sal_Int32>(),0))
1322 0 : ,m_pKeySet->get().end());
1323 :
1324 2 : }
1325 : }
1326 2 : } break;
1327 :
1328 : case SQL_STATEMENT_UPDATE:
1329 : case SQL_STATEMENT_DELETE:
1330 : case SQL_STATEMENT_INSERT:
1331 0 : break;
1332 : default:
1333 0 : m_pStatement->getOwnConnection()->throwSQLException( STR_STMT_TYPE_NOT_SUPPORTED, *this );
1334 0 : break;
1335 2 : }
1336 2 : }
1337 :
1338 : // -----------------------------------------------------------------------------
1339 :
1340 :
1341 4 : void OResultSet::setBoundedColumns(const OValueRow& _rRow,
1342 : const ::rtl::Reference<connectivity::OSQLColumns>& _rxColumns,
1343 : const Reference<XIndexAccess>& _xNames,
1344 : sal_Bool _bSetColumnMapping,
1345 : const Reference<XDatabaseMetaData>& _xMetaData,
1346 : ::std::vector<sal_Int32>& _rColMapping)
1347 : {
1348 4 : ::comphelper::UStringMixEqual aCase(_xMetaData->supportsMixedCaseQuotedIdentifiers());
1349 :
1350 4 : Reference<XPropertySet> xTableColumn;
1351 4 : ::rtl::OUString sTableColumnName, sSelectColumnRealName;
1352 :
1353 4 : const ::rtl::OUString sName = OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME);
1354 4 : const ::rtl::OUString sRealName = OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_REALNAME);
1355 :
1356 4 : ::std::vector< ::rtl::OUString> aColumnNames;
1357 4 : aColumnNames.reserve(_rxColumns->get().size());
1358 4 : OValueVector::Vector::iterator aRowIter = _rRow->get().begin()+1;
1359 456 : for (sal_Int32 i=0; // the first column is the bookmark column
1360 304 : aRowIter != _rRow->get().end();
1361 : ++i, ++aRowIter
1362 : )
1363 : {
1364 : try
1365 : {
1366 : // get the table column and it's name
1367 148 : _xNames->getByIndex(i) >>= xTableColumn;
1368 : OSL_ENSURE(xTableColumn.is(), "OResultSet::setBoundedColumns: invalid table column!");
1369 148 : if (xTableColumn.is())
1370 148 : xTableColumn->getPropertyValue(sName) >>= sTableColumnName;
1371 : else
1372 0 : sTableColumnName = ::rtl::OUString();
1373 :
1374 : // look if we have such a select column
1375 : // TODO: would like to have a O(log n) search here ...
1376 148 : sal_Int32 nColumnPos = 0;
1377 666 : for ( OSQLColumns::Vector::iterator aIter = _rxColumns->get().begin();
1378 444 : aIter != _rxColumns->get().end();
1379 : ++aIter,++nColumnPos
1380 : )
1381 : {
1382 74 : if ( nColumnPos < (sal_Int32)aColumnNames.size() )
1383 72 : sSelectColumnRealName = aColumnNames[nColumnPos];
1384 : else
1385 : {
1386 2 : if((*aIter)->getPropertySetInfo()->hasPropertyByName(sRealName))
1387 2 : (*aIter)->getPropertyValue(sRealName) >>= sSelectColumnRealName;
1388 : else
1389 0 : (*aIter)->getPropertyValue(sName) >>= sSelectColumnRealName;
1390 2 : aColumnNames.push_back(sSelectColumnRealName);
1391 : }
1392 :
1393 74 : if (aCase(sTableColumnName, sSelectColumnRealName))
1394 : {
1395 2 : if(_bSetColumnMapping)
1396 : {
1397 2 : sal_Int32 nSelectColumnPos = static_cast<sal_Int32>(aIter - _rxColumns->get().begin() + 1);
1398 : // the getXXX methods are 1-based ...
1399 2 : sal_Int32 nTableColumnPos = i + 1;
1400 : // get first table column is the bookmark column
1401 : // ...
1402 : #if OSL_DEBUG_LEVEL > 0
1403 : OSL_TRACE("Set Col Mapping: %d -> %d", nSelectColumnPos, nTableColumnPos );
1404 : #endif
1405 2 : _rColMapping[nSelectColumnPos] = nTableColumnPos;
1406 : }
1407 :
1408 2 : aRowIter->setBound(sal_True);
1409 2 : aRowIter->setTypeKind(DataType::VARCHAR);
1410 : }
1411 : }
1412 : }
1413 0 : catch (Exception&)
1414 : {
1415 : OSL_FAIL("OResultSet::setBoundedColumns: caught an Exception!");
1416 : }
1417 4 : }
1418 4 : }
1419 :
1420 :
1421 : // -----------------------------------------------------------------------------
1422 2 : sal_Bool OResultSet::isCount() const
1423 : {
1424 : return (m_pParseTree &&
1425 2 : m_pParseTree->count() > 2 &&
1426 4 : SQL_ISRULE(m_pParseTree->getChild(2),scalar_exp_commalist) &&
1427 4 : SQL_ISRULE(m_pParseTree->getChild(2)->getChild(0),derived_column) &&
1428 4 : SQL_ISRULE(m_pParseTree->getChild(2)->getChild(0)->getChild(0),general_set_fct) &&
1429 0 : m_pParseTree->getChild(2)->getChild(0)->getChild(0)->count() == 4
1430 16 : );
1431 : }
1432 :
1433 : // -----------------------------------------------------------------------------
1434 : //
1435 : // Check for valid row in m_aQuery
1436 : //
1437 14 : sal_Bool OResultSet::validRow( sal_uInt32 nRow)
1438 : {
1439 14 : sal_Int32 nNumberOfRecords = m_aQueryHelper.getResultCount();
1440 :
1441 28 : while ( nRow > (sal_uInt32)nNumberOfRecords && !m_aQueryHelper.queryComplete() ) {
1442 : #if OSL_DEBUG_LEVEL > 0
1443 : OSL_TRACE("validRow: waiting...");
1444 : #endif
1445 0 : if (m_aQueryHelper.checkRowAvailable( nRow ) == sal_False)
1446 : {
1447 : OSL_TRACE("validRow(%u): return False", nRow);
1448 0 : return sal_False;
1449 : }
1450 :
1451 0 : if ( m_aQueryHelper.hadError() )
1452 : {
1453 0 : m_pStatement->getOwnConnection()->throwSQLException( m_aQueryHelper.getError(), *this );
1454 : }
1455 :
1456 0 : nNumberOfRecords = m_aQueryHelper.getResultCount();
1457 : }
1458 :
1459 14 : if (( nRow == 0 ) ||
1460 0 : ( nRow > (sal_uInt32)nNumberOfRecords && m_aQueryHelper.queryComplete()) ){
1461 : OSL_TRACE("validRow(%u): return False", nRow);
1462 0 : return sal_False;
1463 : }
1464 : #if OSL_DEBUG_LEVEL > 0
1465 : OSL_TRACE("validRow(%u): return True", nRow);
1466 : #endif
1467 :
1468 14 : return sal_True;
1469 : }
1470 5 : sal_Bool OResultSet::fillKeySet(sal_Int32 nMaxCardNumber)
1471 : {
1472 5 : impl_ensureKeySet();
1473 5 : if (m_CurrentRowCount < nMaxCardNumber)
1474 : {
1475 : sal_Int32 nKeyValue;
1476 1 : if ( (sal_Int32)m_pKeySet->get().capacity() < nMaxCardNumber )
1477 1 : m_pKeySet->get().reserve(nMaxCardNumber + 20 );
1478 :
1479 2 : for (nKeyValue = m_CurrentRowCount+1; nKeyValue <= nMaxCardNumber; nKeyValue ++)
1480 1 : m_pKeySet->get().push_back( nKeyValue );
1481 1 : m_CurrentRowCount = nMaxCardNumber;
1482 : }
1483 5 : return sal_True;
1484 : }
1485 :
1486 2 : sal_Int32 OResultSet::deletedCount()
1487 : {
1488 2 : impl_ensureKeySet();
1489 2 : return m_CurrentRowCount - static_cast<sal_Int32>(m_pKeySet->get().size());
1490 :
1491 : }
1492 : // -----------------------------------------------------------------------------
1493 6 : sal_Bool OResultSet::seekRow( eRowPosition pos, sal_Int32 nOffset )
1494 : {
1495 : SAL_INFO("connectivity.mork", "=> OResultSet::seekRow()" );
1496 :
1497 6 : ResultSetEntryGuard aGuard( *this );
1498 6 : if ( !m_pKeySet.is() )
1499 0 : m_pStatement->getOwnConnection()->throwSQLException( STR_ILLEGAL_MOVEMENT, *this );
1500 :
1501 6 : sal_Int32 nNumberOfRecords = m_aQueryHelper.getResultCount();
1502 6 : sal_Int32 nRetrivedRows = currentRowCount();
1503 6 : sal_Int32 nCurPos = m_nRowPos;
1504 :
1505 : OSL_TRACE("seekRow: nCurPos = %d", nCurPos );
1506 6 : switch( pos ) {
1507 : case NEXT_POS:
1508 : OSL_TRACE("seekRow: NEXT");
1509 1 : nCurPos++;
1510 1 : break;
1511 : case PRIOR_POS:
1512 : OSL_TRACE("seekRow: PRIOR");
1513 1 : if ( nCurPos > 0 )
1514 1 : nCurPos--;
1515 1 : break;
1516 :
1517 : case FIRST_POS:
1518 : OSL_TRACE("seekRow: FIRST");
1519 3 : nCurPos = 1;
1520 3 : break;
1521 :
1522 : case LAST_POS:
1523 : OSL_TRACE("seekRow: LAST");
1524 1 : nCurPos = nRetrivedRows;
1525 1 : break;
1526 : case ABSOLUTE_POS:
1527 : OSL_TRACE("seekRow: ABSOLUTE : %d", nOffset);
1528 0 : nCurPos = nOffset;
1529 0 : break;
1530 : case RELATIVE_POS:
1531 : OSL_TRACE("seekRow: RELATIVE : %d", nOffset);
1532 0 : nCurPos += sal_uInt32( nOffset );
1533 0 : break;
1534 : }
1535 :
1536 6 : if ( nCurPos <= 0 ) {
1537 1 : m_nRowPos = 0;
1538 : OSL_TRACE("seekRow: return False, m_nRowPos = %u", m_nRowPos );
1539 1 : return sal_False;
1540 : }
1541 5 : sal_Int32 nCurCard = nCurPos;
1542 5 : if ( nCurPos < (sal_Int32)m_pKeySet->get().size() ) //The requested row is exist in m_pKeySet, so we just use it
1543 : {
1544 3 : nCurCard = (m_pKeySet->get())[nCurPos-1];
1545 : }
1546 : else //The requested row has not been retrived until now. We should get the right card for it.
1547 2 : nCurCard = nCurPos + deletedCount();
1548 :
1549 5 : if ( nCurCard > nNumberOfRecords) {
1550 0 : fillKeySet(nNumberOfRecords);
1551 0 : m_nRowPos = static_cast<sal_uInt32>(m_pKeySet->get().size() + 1);
1552 : OSL_TRACE("seekRow: return False, m_nRowPos = %u", m_nRowPos );
1553 0 : return sal_False;
1554 : }
1555 : //Insert new retrived items for later use
1556 5 : fillKeySet(nNumberOfRecords);
1557 5 : m_nRowPos = (sal_uInt32)nCurPos;
1558 : OSL_TRACE("seekRow: return True, m_nRowPos = %u", m_nRowPos );
1559 5 : fetchCurrentRow();
1560 5 : return sal_True;
1561 : }
1562 : // -----------------------------------------------------------------------------
1563 2 : void OResultSet::setColumnMapping(const ::std::vector<sal_Int32>& _aColumnMapping)
1564 : {
1565 2 : m_aColMapping = _aColumnMapping;
1566 : #if OSL_DEBUG_LEVEL > 0
1567 : for ( sal_uInt32 i = 0; i < m_aColMapping.size(); i++ )
1568 : OSL_TRACE("Set Mapped: %d -> %d", i, m_aColMapping[i] );
1569 : #endif
1570 2 : }
1571 : // -----------------------------------------------------------------------------
1572 :
1573 0 : ::com::sun::star::uno::Any OResultSet::getBookmark( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException)
1574 : {
1575 : OSL_TRACE("getBookmark, m_nRowPos = %u", m_nRowPos );
1576 0 : ResultSetEntryGuard aGuard( *this );
1577 0 : if ( fetchCurrentRow() == sal_False ) {
1578 0 : m_pStatement->getOwnConnection()->throwSQLException( STR_ERROR_GET_ROW, *this );
1579 : }
1580 :
1581 : OSL_ENSURE((!m_aRow->isDeleted()),"getBookmark called for deleted row");
1582 0 : return makeAny((sal_Int32)(m_aRow->get())[0]);
1583 : }
1584 0 : sal_Bool OResultSet::moveToBookmark( const ::com::sun::star::uno::Any& bookmark ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException)
1585 : {
1586 0 : ResultSetEntryGuard aGuard( *this );
1587 : OSL_TRACE("moveToBookmark, bookmark = %u", comphelper::getINT32(bookmark) );
1588 0 : sal_Int32 nCardNum = comphelper::getINT32(bookmark);
1589 0 : m_nRowPos = getRowForCardNumber(nCardNum);
1590 0 : fetchCurrentRow();
1591 0 : return sal_True;
1592 : }
1593 0 : sal_Bool OResultSet::moveRelativeToBookmark( const ::com::sun::star::uno::Any& bookmark, sal_Int32 rows ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException)
1594 : {
1595 0 : ResultSetEntryGuard aGuard( *this );
1596 : OSL_TRACE("moveRelativeToBookmark, bookmark = %u rows= %u", comphelper::getINT32(bookmark),rows );
1597 0 : sal_Int32 nCardNum = comphelper::getINT32(bookmark);
1598 0 : m_nRowPos = getRowForCardNumber(nCardNum);
1599 0 : return seekRow(RELATIVE_POS,rows );
1600 : }
1601 0 : sal_Int32 OResultSet::compareBookmarks( const ::com::sun::star::uno::Any& lhs, const ::com::sun::star::uno::Any& rhs ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException)
1602 : {
1603 0 : ResultSetEntryGuard aGuard( *this );
1604 : OSL_TRACE("compareBookmarks, m_nRowPos = %u", m_nRowPos );
1605 0 : sal_Int32 nFirst=0;
1606 0 : sal_Int32 nSecond=0;
1607 0 : sal_Int32 nResult=0;
1608 :
1609 0 : if ( !( lhs >>= nFirst ) || !( rhs >>= nSecond ) ) {
1610 0 : m_pStatement->getOwnConnection()->throwSQLException( STR_INVALID_BOOKMARK, *this );
1611 : }
1612 :
1613 0 : if(nFirst < nSecond)
1614 0 : nResult = -1;
1615 0 : else if(nFirst > nSecond)
1616 0 : nResult = 1;
1617 : else
1618 0 : nResult = 0;
1619 :
1620 0 : return nResult;
1621 : }
1622 0 : sal_Bool OResultSet::hasOrderedBookmarks( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException)
1623 : {
1624 0 : ResultSetEntryGuard aGuard( *this );
1625 : OSL_TRACE("hasOrderedBookmarks, m_nRowPos = %u", m_nRowPos );
1626 0 : return sal_True;
1627 : }
1628 0 : sal_Int32 OResultSet::hashBookmark( const ::com::sun::star::uno::Any& bookmark ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException)
1629 : {
1630 0 : ResultSetEntryGuard aGuard( *this );
1631 : OSL_TRACE("hashBookmark, m_nRowPos = %u", m_nRowPos );
1632 0 : return comphelper::getINT32(bookmark);
1633 : }
1634 :
1635 9 : sal_Int32 OResultSet::getCurrentCardNumber()
1636 : {
1637 9 : if ( ( m_nRowPos == 0 ) || !m_pKeySet.is() )
1638 0 : return 0;
1639 9 : if (m_pKeySet->get().size() < m_nRowPos)
1640 0 : return 0;
1641 9 : return (m_pKeySet->get())[m_nRowPos-1];
1642 : }
1643 0 : void OResultSet::checkPendingUpdate() throw(SQLException, RuntimeException)
1644 : {
1645 : OSL_FAIL( "OResultSet::checkPendingUpdate() not implemented" );
1646 : /*
1647 : OSL_TRACE("checkPendingUpdate, m_nRowPos = %u", m_nRowPos );
1648 : const sal_Int32 nCurrentRow = getCurrentCardNumber();
1649 :
1650 : if ((m_nNewRow && nCurrentRow != m_nNewRow)
1651 : || ( m_nUpdatedRow && m_nUpdatedRow != nCurrentRow))
1652 : {
1653 : const ::rtl::OUString sError( m_pStatement->getOwnConnection()->getResources().getResourceStringWithSubstitution(
1654 : STR_COMMIT_ROW,
1655 : "$position$", ::rtl::OUString::valueOf(nCurrentRow)
1656 : ) );
1657 : ::dbtools::throwGenericSQLException(sError,*this);
1658 : }
1659 : */
1660 :
1661 0 : }
1662 0 : void OResultSet::updateValue(sal_Int32 columnIndex ,const ORowSetValue& x) throw(SQLException, RuntimeException)
1663 : {
1664 : OSL_TRACE("updateValue, m_nRowPos = %u", m_nRowPos );
1665 0 : ResultSetEntryGuard aGuard( *this );
1666 0 : if ( fetchCurrentRow() == sal_False ) {
1667 0 : m_pStatement->getOwnConnection()->throwSQLException( STR_ERROR_GET_ROW, *this );
1668 : }
1669 :
1670 0 : checkPendingUpdate();
1671 :
1672 0 : checkIndex(columnIndex );
1673 0 : columnIndex = mapColumn(columnIndex);
1674 :
1675 0 : (m_aRow->get())[columnIndex].setBound(sal_True);
1676 0 : (m_aRow->get())[columnIndex] = x;
1677 0 : m_nUpdatedRow = getCurrentCardNumber();
1678 : // m_RowStates = m_RowStates | RowStates_Updated;
1679 0 : }
1680 : // -----------------------------------------------------------------------------
1681 :
1682 0 : void SAL_CALL OResultSet::updateNull( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
1683 : {
1684 : OSL_TRACE("updateNull, m_nRowPos = %u", m_nRowPos );
1685 0 : ResultSetEntryGuard aGuard( *this );
1686 0 : if ( fetchCurrentRow() == sal_False )
1687 0 : m_pStatement->getOwnConnection()->throwSQLException( STR_ERROR_GET_ROW, *this );
1688 :
1689 0 : checkPendingUpdate();
1690 0 : checkIndex(columnIndex );
1691 0 : columnIndex = mapColumn(columnIndex);
1692 :
1693 0 : (m_aRow->get())[columnIndex].setBound(sal_True);
1694 0 : (m_aRow->get())[columnIndex].setNull();
1695 0 : m_nUpdatedRow = getCurrentCardNumber();
1696 : // m_RowStates = m_RowStates | RowStates_Updated;
1697 0 : }
1698 : // -------------------------------------------------------------------------
1699 :
1700 0 : void SAL_CALL OResultSet::updateBoolean( sal_Int32 columnIndex, sal_Bool x ) throw(SQLException, RuntimeException)
1701 : {
1702 0 : updateValue(columnIndex,x);
1703 0 : }
1704 : // -------------------------------------------------------------------------
1705 0 : void SAL_CALL OResultSet::updateByte( sal_Int32 columnIndex, sal_Int8 x ) throw(SQLException, RuntimeException)
1706 : {
1707 0 : updateValue(columnIndex,x);
1708 0 : }
1709 : // -------------------------------------------------------------------------
1710 :
1711 0 : void SAL_CALL OResultSet::updateShort( sal_Int32 columnIndex, sal_Int16 x ) throw(SQLException, RuntimeException)
1712 : {
1713 0 : updateValue(columnIndex,x);
1714 0 : }
1715 : // -------------------------------------------------------------------------
1716 0 : void SAL_CALL OResultSet::updateInt( sal_Int32 columnIndex, sal_Int32 x ) throw(SQLException, RuntimeException)
1717 : {
1718 0 : updateValue(columnIndex,x);
1719 0 : }
1720 : // -------------------------------------------------------------------------
1721 0 : void SAL_CALL OResultSet::updateLong( sal_Int32 /*columnIndex*/, sal_Int64 /*x*/ ) throw(SQLException, RuntimeException)
1722 : {
1723 0 : ::dbtools::throwFeatureNotImplementedException( "XRowUpdate::updateLong", *this );
1724 0 : }
1725 : // -----------------------------------------------------------------------
1726 0 : void SAL_CALL OResultSet::updateFloat( sal_Int32 columnIndex, float x ) throw(SQLException, RuntimeException)
1727 : {
1728 0 : updateValue(columnIndex,x);
1729 0 : }
1730 : // -------------------------------------------------------------------------
1731 :
1732 0 : void SAL_CALL OResultSet::updateDouble( sal_Int32 columnIndex, double x ) throw(SQLException, RuntimeException)
1733 : {
1734 0 : updateValue(columnIndex,x);
1735 0 : }
1736 : // -------------------------------------------------------------------------
1737 0 : void SAL_CALL OResultSet::updateString( sal_Int32 columnIndex, const ::rtl::OUString& x ) throw(SQLException, RuntimeException)
1738 : {
1739 0 : updateValue(columnIndex,x);
1740 0 : }
1741 : // -------------------------------------------------------------------------
1742 0 : void SAL_CALL OResultSet::updateBytes( sal_Int32 columnIndex, const Sequence< sal_Int8 >& x ) throw(SQLException, RuntimeException)
1743 : {
1744 0 : updateValue(columnIndex,x);
1745 0 : }
1746 : // -------------------------------------------------------------------------
1747 0 : void SAL_CALL OResultSet::updateDate( sal_Int32 columnIndex, const ::com::sun::star::util::Date& x ) throw(SQLException, RuntimeException)
1748 : {
1749 0 : updateValue(columnIndex,x);
1750 0 : }
1751 : // -------------------------------------------------------------------------
1752 :
1753 0 : void SAL_CALL OResultSet::updateTime( sal_Int32 columnIndex, const ::com::sun::star::util::Time& x ) throw(SQLException, RuntimeException)
1754 : {
1755 0 : updateValue(columnIndex,x);
1756 0 : }
1757 : // -------------------------------------------------------------------------
1758 :
1759 0 : void SAL_CALL OResultSet::updateTimestamp( sal_Int32 columnIndex, const ::com::sun::star::util::DateTime& x ) throw(SQLException, RuntimeException)
1760 : {
1761 0 : updateValue(columnIndex,x);
1762 0 : }
1763 : // -------------------------------------------------------------------------
1764 :
1765 0 : void SAL_CALL OResultSet::updateBinaryStream( sal_Int32 columnIndex, const Reference< ::com::sun::star::io::XInputStream >& x, sal_Int32 length ) throw(SQLException, RuntimeException)
1766 : {
1767 0 : ResultSetEntryGuard aGuard( *this );
1768 :
1769 0 : if(!x.is())
1770 0 : ::dbtools::throwFunctionSequenceException(*this);
1771 :
1772 0 : Sequence<sal_Int8> aSeq;
1773 0 : x->readBytes(aSeq,length);
1774 0 : updateValue(columnIndex,aSeq);
1775 0 : }
1776 : // -------------------------------------------------------------------------
1777 0 : void SAL_CALL OResultSet::updateCharacterStream( sal_Int32 columnIndex, const Reference< ::com::sun::star::io::XInputStream >& x, sal_Int32 length ) throw(SQLException, RuntimeException)
1778 : {
1779 0 : updateBinaryStream(columnIndex,x,length);
1780 0 : }
1781 : // -------------------------------------------------------------------------
1782 0 : void SAL_CALL OResultSet::updateObject( sal_Int32 columnIndex, const Any& x ) throw(SQLException, RuntimeException)
1783 : {
1784 0 : if (!::dbtools::implUpdateObject(this, columnIndex, x))
1785 : {
1786 0 : const ::rtl::OUString sError( m_pStatement->getOwnConnection()->getResources().getResourceStringWithSubstitution(
1787 : STR_COLUMN_NOT_UPDATEABLE,
1788 : "$position$", ::rtl::OUString::valueOf(columnIndex)
1789 0 : ) );
1790 0 : ::dbtools::throwGenericSQLException(sError,*this);
1791 : } // if (!::dbtools::implUpdateObject(this, columnIndex, x))
1792 0 : }
1793 : // -------------------------------------------------------------------------
1794 :
1795 0 : void SAL_CALL OResultSet::updateNumericObject( sal_Int32 columnIndex, const Any& x, sal_Int32 /*scale*/ ) throw(SQLException, RuntimeException)
1796 : {
1797 0 : if (!::dbtools::implUpdateObject(this, columnIndex, x))
1798 : {
1799 0 : const ::rtl::OUString sError( m_pStatement->getOwnConnection()->getResources().getResourceStringWithSubstitution(
1800 : STR_COLUMN_NOT_UPDATEABLE,
1801 : "$position$", ::rtl::OUString::valueOf(columnIndex)
1802 0 : ) );
1803 0 : ::dbtools::throwGenericSQLException(sError,*this);
1804 : }
1805 0 : }
1806 :
1807 : // XResultSetUpdate
1808 : // -------------------------------------------------------------------------
1809 0 : void SAL_CALL OResultSet::insertRow( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException)
1810 : {
1811 0 : ResultSetEntryGuard aGuard( *this );
1812 : OSL_TRACE("insertRow in, m_nRowPos = %u", m_nRowPos );
1813 : // m_RowStates = RowStates_Inserted;
1814 0 : updateRow();
1815 0 : m_nOldRowPos = 0;
1816 0 : m_nNewRow = 0;
1817 : //m_aQueryHelper.setRowStates(getCurrentCardNumber(),m_RowStates);
1818 0 : OSL_TRACE("insertRow out, m_nRowPos = %u", m_nRowPos );
1819 0 : }
1820 : // -------------------------------------------------------------------------
1821 0 : void SAL_CALL OResultSet::updateRow( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException)
1822 : {
1823 : OSL_FAIL( "OResultSet::updateRow( ) not implemented" );
1824 0 : }
1825 : // -------------------------------------------------------------------------
1826 0 : void SAL_CALL OResultSet::deleteRow( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException)
1827 : {
1828 : OSL_FAIL( "OResultSet::deleteRow( ) not implemented" );
1829 0 : }
1830 : // -------------------------------------------------------------------------
1831 0 : void SAL_CALL OResultSet::cancelRowUpdates( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException)
1832 : {
1833 : OSL_FAIL( "OResultSet::cancelRowUpdates( ) not implemented" );
1834 0 : }
1835 : // -------------------------------------------------------------------------
1836 0 : void SAL_CALL OResultSet::moveToInsertRow( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException)
1837 : {
1838 : OSL_FAIL( "OResultSet::moveToInsertRow( ) not implemented" );
1839 0 : }
1840 : // -------------------------------------------------------------------------
1841 0 : void SAL_CALL OResultSet::moveToCurrentRow( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException)
1842 : {
1843 0 : ResultSetEntryGuard aGuard( *this );
1844 : OSL_TRACE("moveToCurrentRow, m_nRowPos = %u", m_nRowPos );
1845 0 : if (rowInserted())
1846 : {
1847 0 : m_nRowPos = m_nOldRowPos;
1848 0 : fetchCurrentRow();
1849 0 : }
1850 0 : }
1851 :
1852 2 : sal_Bool OResultSet::determineReadOnly()
1853 : {
1854 : // OSL_FAIL( "OResultSet::determineReadOnly( ) not implemented" );
1855 :
1856 2 : if (m_bIsReadOnly == -1)
1857 : {
1858 2 : m_bIsReadOnly = sal_True;
1859 : // OConnection* xConnection = static_cast<OConnection*>(m_pStatement->getConnection().get());
1860 : // m_bIsReadOnly = !m_aQueryHelper.isWritable(xConnection) || m_bIsAlwaysFalseQuery;
1861 : }
1862 :
1863 2 : return m_bIsReadOnly != 0;
1864 : }
1865 :
1866 2 : void OResultSet::setTable(OTable* _rTable)
1867 : {
1868 : OSL_TRACE("In : setTable");
1869 2 : m_pTable = _rTable;
1870 2 : m_pTable->acquire();
1871 2 : m_xTableColumns = m_pTable->getColumns();
1872 2 : if(m_xTableColumns.is())
1873 2 : m_aColumnNames = m_xTableColumns->getElementNames();
1874 : OSL_TRACE("Out : setTable");
1875 2 : }
1876 :
1877 2 : void OResultSet::setOrderByColumns(const ::std::vector<sal_Int32>& _aColumnOrderBy)
1878 : {
1879 2 : m_aOrderbyColumnNumber = _aColumnOrderBy;
1880 2 : }
1881 :
1882 2 : void OResultSet::setOrderByAscending(const ::std::vector<TAscendingOrder>& _aOrderbyAsc)
1883 : {
1884 2 : m_aOrderbyAscending = _aOrderbyAsc;
1885 2 : }
1886 0 : Sequence< sal_Int32 > SAL_CALL OResultSet::deleteRows( const Sequence< Any >& /*rows*/ ) throw(SQLException, RuntimeException)
1887 : {
1888 0 : ::dbtools::throwFeatureNotImplementedException( "XDeleteRows::deleteRows", *this );
1889 0 : return Sequence< sal_Int32 >();
1890 : };
1891 :
1892 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|