update dev300-m58
[ooovba.git] / connectivity / source / drivers / mozab / MResultSet.cxx
blob081ff8369f23dc587c62e0b5447bd076c717c920
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: MResultSet.cxx,v $
10 * $Revision: 1.33.22.3 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_connectivity.hxx"
33 #include <com/sun/star/sdbc/DataType.hpp>
34 #include <com/sun/star/beans/PropertyAttribute.hpp>
35 #include <comphelper/property.hxx>
36 #include <comphelper/sequence.hxx>
37 #include <cppuhelper/typeprovider.hxx>
38 #include <comphelper/extract.hxx>
39 #include <com/sun/star/lang/DisposedException.hpp>
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 <comphelper/types.hxx>
44 #include <connectivity/dbexception.hxx>
45 #include <connectivity/dbtools.hxx>
47 #include <TSortIndex.hxx>
48 #include <rtl/string.hxx>
49 #include <vector>
50 #include <algorithm>
51 #include "MResultSet.hxx"
52 #include "MResultSetMetaData.hxx"
53 #include "FDatabaseMetaDataResultSet.hxx"
54 #include "resource/mozab_res.hrc"
55 #include "resource/common_res.hrc"
57 #if OSL_DEBUG_LEVEL > 0
58 # define OUtoCStr( x ) ( ::rtl::OUStringToOString ( (x), RTL_TEXTENCODING_ASCII_US).getStr())
59 #else /* OSL_DEBUG_LEVEL */
60 # define OUtoCStr( x ) ("dummy")
61 #endif /* OSL_DEBUG_LEVEL */
63 using namespace ::comphelper;
64 using namespace connectivity;
65 using namespace connectivity::mozab;
66 using namespace ::cppu;
67 using namespace com::sun::star::uno;
68 using namespace com::sun::star::lang;
69 using namespace com::sun::star::beans;
70 using namespace com::sun::star::sdbc;
71 using namespace com::sun::star::container;
72 using namespace com::sun::star::io;
73 using namespace com::sun::star::util;
75 //------------------------------------------------------------------------------
76 // IMPLEMENT_SERVICE_INFO(OResultSet,"com.sun.star.sdbcx.OResultSet","com.sun.star.sdbc.ResultSet");
77 ::rtl::OUString SAL_CALL OResultSet::getImplementationName( ) throw ( RuntimeException) \
79 return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sdbcx.mozab.ResultSet"));
81 // -------------------------------------------------------------------------
82 Sequence< ::rtl::OUString > SAL_CALL OResultSet::getSupportedServiceNames( ) throw( RuntimeException)
84 ::com::sun::star::uno::Sequence< ::rtl::OUString > aSupported(2);
85 aSupported[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sdbc.ResultSet"));
86 aSupported[1] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sdbcx.ResultSet"));
87 return aSupported;
89 // -------------------------------------------------------------------------
90 sal_Bool SAL_CALL OResultSet::supportsService( const ::rtl::OUString& _rServiceName ) throw( RuntimeException)
92 Sequence< ::rtl::OUString > aSupported(getSupportedServiceNames());
93 const ::rtl::OUString* pSupported = aSupported.getConstArray();
94 const ::rtl::OUString* pEnd = pSupported + aSupported.getLength();
95 for (;pSupported != pEnd && !pSupported->equals(_rServiceName); ++pSupported)
98 return pSupported != pEnd;
101 // -------------------------------------------------------------------------
102 OResultSet::OResultSet(OCommonStatement* pStmt, const ::boost::shared_ptr< connectivity::OSQLParseTreeIterator >& _pSQLIterator )
103 : OResultSet_BASE(m_aMutex)
104 ,OPropertySetHelper(OResultSet_BASE::rBHelper)
105 ,m_pStatement(pStmt)
106 ,m_xStatement(*pStmt)
107 ,m_xMetaData(NULL)
108 ,m_nRowPos(0)
109 ,m_nOldRowPos(0)
110 ,m_nFetchSize(0)
111 ,m_nResultSetType(ResultSetType::SCROLL_INSENSITIVE)
112 ,m_nFetchDirection(FetchDirection::FORWARD)
113 ,m_nResultSetConcurrency(ResultSetConcurrency::UPDATABLE)
114 ,m_pSQLIterator( _pSQLIterator )
115 ,m_pParseTree( _pSQLIterator->getParseTree() )
116 ,m_aQuery( pStmt->getOwnConnection()->getColumnAlias() )
117 ,m_pTable(NULL)
118 ,m_CurrentRowCount(0)
119 ,m_nParamIndex(0)
120 ,m_bIsAlwaysFalseQuery(sal_False)
121 ,m_pKeySet(NULL)
122 ,m_nNewRow(0)
123 ,m_nUpdatedRow(0)
124 ,m_RowStates(0)
125 ,m_bIsReadOnly(-1)
128 m_aQuery.setMaxNrOfReturns(pStmt->getOwnConnection()->getMaxResultRecords());
130 // -------------------------------------------------------------------------
131 OResultSet::~OResultSet()
135 // -------------------------------------------------------------------------
136 void OResultSet::disposing(void)
138 OPropertySetHelper::disposing();
140 ::osl::MutexGuard aGuard(m_aMutex);
142 m_xStatement.clear();
143 m_xMetaData.clear();
144 m_pParseTree = NULL;
145 m_xColumns = NULL;
146 m_xParamColumns = NULL;
147 m_pKeySet = NULL;
148 if(m_pTable)
150 m_pTable->release();
151 m_pTable = NULL;
154 // -------------------------------------------------------------------------
155 Any SAL_CALL OResultSet::queryInterface( const Type & rType ) throw(RuntimeException)
157 Any aRet = OPropertySetHelper::queryInterface(rType);
158 if(!aRet.hasValue())
159 aRet = OResultSet_BASE::queryInterface(rType);
160 return aRet;
162 // -------------------------------------------------------------------------
163 Sequence< Type > SAL_CALL OResultSet::getTypes( ) throw( RuntimeException)
165 OTypeCollection aTypes( ::getCppuType( (const Reference< ::com::sun::star::beans::XMultiPropertySet > *)0 ),
166 ::getCppuType( (const Reference< ::com::sun::star::beans::XFastPropertySet > *)0 ),
167 ::getCppuType( (const Reference< ::com::sun::star::beans::XPropertySet > *)0 ));
169 return ::comphelper::concatSequences(aTypes.getTypes(),OResultSet_BASE::getTypes());
171 // -------------------------------------------------------------------------
172 void OResultSet::methodEntry()
174 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
175 if ( !m_pTable )
177 OSL_ENSURE( false, "OResultSet::methodEntry: looks like we're disposed, but how is this possible?" );
178 throw DisposedException( ::rtl::OUString(), *this );
182 // -------------------------------------------------------------------------
183 sal_Int32 SAL_CALL OResultSet::findColumn( const ::rtl::OUString& columnName ) throw(SQLException, RuntimeException)
185 ResultSetEntryGuard aGuard( *this );
187 // find the first column with the name columnName
188 Reference< XResultSetMetaData > xMeta = getMetaData();
189 sal_Int32 nLen = xMeta->getColumnCount();
190 sal_Int32 i = 1;
191 for(;i<=nLen;++i)
192 if(xMeta->isCaseSensitive(i) ? columnName == xMeta->getColumnName(i) :
193 columnName.equalsIgnoreAsciiCase(xMeta->getColumnName(i)))
194 break;
195 return i;
197 // -------------------------------------------------------------------------
198 Reference< XInputStream > SAL_CALL OResultSet::getBinaryStream( sal_Int32 /*columnIndex*/ ) throw(SQLException, RuntimeException)
200 return NULL;
202 // -------------------------------------------------------------------------
203 Reference< XInputStream > SAL_CALL OResultSet::getCharacterStream( sal_Int32 /*columnIndex*/ ) throw(SQLException, RuntimeException)
205 return NULL;
208 // -------------------------------------------------------------------------
209 sal_Bool SAL_CALL OResultSet::getBoolean( sal_Int32 /*columnIndex*/ ) throw(SQLException, RuntimeException)
211 ResultSetEntryGuard aGuard( *this );
212 m_bWasNull = sal_True;
213 return sal_False;
215 // -------------------------------------------------------------------------
217 sal_Int8 SAL_CALL OResultSet::getByte( sal_Int32 /*columnIndex*/ ) throw(SQLException, RuntimeException)
219 ResultSetEntryGuard aGuard( *this );
220 return 0;
222 // -------------------------------------------------------------------------
224 Sequence< sal_Int8 > SAL_CALL OResultSet::getBytes( sal_Int32 /*columnIndex*/ ) throw(SQLException, RuntimeException)
226 ResultSetEntryGuard aGuard( *this );
227 return Sequence< sal_Int8 >();
229 // -------------------------------------------------------------------------
231 Date SAL_CALL OResultSet::getDate( sal_Int32 /*columnIndex*/ ) throw(SQLException, RuntimeException)
233 ResultSetEntryGuard aGuard( *this );
234 return Date();
236 // -------------------------------------------------------------------------
238 double SAL_CALL OResultSet::getDouble( sal_Int32 /*columnIndex*/ ) throw(SQLException, RuntimeException)
240 ResultSetEntryGuard aGuard( *this );
241 return 0.0;
243 // -------------------------------------------------------------------------
245 float SAL_CALL OResultSet::getFloat( sal_Int32 /*columnIndex*/ ) throw(SQLException, RuntimeException)
247 ResultSetEntryGuard aGuard( *this );
248 return 0;
250 // -------------------------------------------------------------------------
252 sal_Int32 SAL_CALL OResultSet::getInt( sal_Int32 /*columnIndex*/ ) throw(SQLException, RuntimeException)
254 ResultSetEntryGuard aGuard( *this );
255 return 0;
258 // -------------------------------------------------------------------------
259 sal_Int32 SAL_CALL OResultSet::getRow( ) throw(SQLException, RuntimeException)
261 ResultSetEntryGuard aGuard( *this );
263 OSL_TRACE("In/Out: OResultSet::getRow, return = %u", m_nRowPos );
264 return m_nRowPos;
266 // -------------------------------------------------------------------------
268 sal_Int64 SAL_CALL OResultSet::getLong( sal_Int32 /*columnIndex*/ ) throw(SQLException, RuntimeException)
270 ResultSetEntryGuard aGuard( *this );
271 return sal_Int64();
273 // -------------------------------------------------------------------------
275 Reference< XResultSetMetaData > SAL_CALL OResultSet::getMetaData( ) throw(SQLException, RuntimeException)
277 ResultSetEntryGuard aGuard( *this );
279 if(!m_xMetaData.is())
280 m_xMetaData = new OResultSetMetaData(
281 m_pSQLIterator->getSelectColumns(), m_pSQLIterator->getTables().begin()->first ,m_pTable,determineReadOnly());
282 return m_xMetaData;
284 // -------------------------------------------------------------------------
285 Reference< XArray > SAL_CALL OResultSet::getArray( sal_Int32 /*columnIndex*/ ) throw(SQLException, RuntimeException)
287 return NULL;
290 // -------------------------------------------------------------------------
292 Reference< XClob > SAL_CALL OResultSet::getClob( sal_Int32 /*columnIndex*/ ) throw(SQLException, RuntimeException)
294 return NULL;
296 // -------------------------------------------------------------------------
297 Reference< XBlob > SAL_CALL OResultSet::getBlob( sal_Int32 /*columnIndex*/ ) throw(SQLException, RuntimeException)
299 return NULL;
301 // -------------------------------------------------------------------------
303 Reference< XRef > SAL_CALL OResultSet::getRef( sal_Int32 /*columnIndex*/ ) throw(SQLException, RuntimeException)
305 return NULL;
307 // -------------------------------------------------------------------------
309 Any SAL_CALL OResultSet::getObject( sal_Int32 /*columnIndex*/, const Reference< ::com::sun::star::container::XNameAccess >& /*typeMap*/ ) throw(SQLException, RuntimeException)
311 return Any();
313 // -------------------------------------------------------------------------
315 sal_Int16 SAL_CALL OResultSet::getShort( sal_Int32 /*columnIndex*/ ) throw(SQLException, RuntimeException)
317 return 0;
319 // -------------------------------------------------------------------------
321 void OResultSet::checkIndex(sal_Int32 columnIndex ) throw(::com::sun::star::sdbc::SQLException)
323 if(columnIndex <= 0 || columnIndex > (sal_Int32)m_xColumns->get().size())
324 ::dbtools::throwInvalidIndexException(*this);
326 // -------------------------------------------------------------------------
327 sal_uInt32 OResultSet::currentRowCount()
329 if ( m_bIsAlwaysFalseQuery )
330 return 0;
331 return m_aQuery.getRealRowCount() - deletedCount();
334 // -------------------------------------------------------------------------
336 sal_Bool OResultSet::fetchCurrentRow( ) throw(SQLException, RuntimeException)
338 OSL_TRACE("fetchCurrentRow, m_nRowPos = %u", m_nRowPos );
339 return fetchRow(getCurrentCardNumber());
342 // -------------------------------------------------------------------------
343 sal_Bool OResultSet::pushCard(sal_uInt32 cardNumber) throw(SQLException, RuntimeException)
345 if (cardNumber == 0)
346 return sal_True;
347 // Check whether we are storing the updated row
348 if ( (m_aRow->get())[0].isNull() || (sal_Int32)(m_aRow->get())[0] != (sal_Int32)cardNumber )
349 return sal_False;
351 sal_Int32 nCount = m_aColumnNames.getLength();
352 m_aQuery.setRowStates(cardNumber,m_RowStates);
353 for( sal_Int32 i = 1; i <= nCount; i++ )
355 if ( (m_aRow->get())[i].isBound() )
358 // Everything in the addressbook is a string!
360 if ( !m_aQuery.setRowValue( (m_aRow->get())[i], cardNumber, m_aColumnNames[i-1], DataType::VARCHAR ))
362 m_pStatement->getOwnConnection()->throwSQLException( m_aQuery.getError(), *this );
366 return sal_True;
369 // -------------------------------------------------------------------------
370 sal_Bool OResultSet::fetchRow(sal_Int32 cardNumber,sal_Bool bForceReload) throw(SQLException, RuntimeException)
372 OSL_TRACE("fetchRow, cardNumber = %u", cardNumber );
373 if (!bForceReload)
375 // Check whether we've already fetched the row...
376 if ( !(m_aRow->get())[0].isNull() && (sal_Int32)(m_aRow->get())[0] == (sal_Int32)cardNumber )
377 return sal_True;
378 //Check whether the old row has been changed
379 if (cardNumber == m_nUpdatedRow)
381 //write back the changes first
382 if (!pushCard(cardNumber)) //error write back the changes
383 throw SQLException();
386 else
387 m_aQuery.resyncRow(cardNumber);
389 if ( validRow( cardNumber ) == sal_False )
390 return sal_False;
392 (m_aRow->get())[0] = (sal_Int32)cardNumber;
393 sal_Int32 nCount = m_aColumnNames.getLength();
394 m_RowStates = m_aQuery.getRowStates(cardNumber);
395 for( sal_Int32 i = 1; i <= nCount; i++ )
397 if ( (m_aRow->get())[i].isBound() )
400 // Everything in the addressbook is a string!
402 if ( !m_aQuery.getRowValue( (m_aRow->get())[i], cardNumber, m_aColumnNames[i-1], DataType::VARCHAR ))
404 m_pStatement->getOwnConnection()->throwSQLException( m_aQuery.getError(), *this );
408 return sal_True;
410 // -------------------------------------------------------------------------
412 const ORowSetValue& OResultSet::getValue(sal_Int32 cardNumber, sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
414 if ( fetchRow( cardNumber ) == sal_False )
416 OSL_ASSERT("fetchRow() returned False" );
417 m_bWasNull = sal_True;
418 return *ODatabaseMetaDataResultSet::getEmptyValue();
421 m_bWasNull = (m_aRow->get())[columnIndex].isNull();
422 return (m_aRow->get())[columnIndex];
425 // -------------------------------------------------------------------------
428 ::rtl::OUString SAL_CALL OResultSet::getString( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
430 ResultSetEntryGuard aGuard( *this );
432 OSL_ENSURE(m_xColumns.isValid(), "Need the Columns!!");
433 OSL_ENSURE(columnIndex <= (sal_Int32)m_xColumns->get().size(), "Trying to access invalid columns number");
434 checkIndex( columnIndex );
436 // If this query was sorted then we should have a valid KeySet, so use it
437 return getValue(getCurrentCardNumber(), mapColumn( columnIndex ) );
440 // -------------------------------------------------------------------------
442 Time SAL_CALL OResultSet::getTime( sal_Int32 /*columnIndex*/ ) throw(SQLException, RuntimeException)
444 ResultSetEntryGuard aGuard( *this );
445 return Time();
447 // -------------------------------------------------------------------------
450 DateTime SAL_CALL OResultSet::getTimestamp( sal_Int32 /*columnIndex*/ ) throw(SQLException, RuntimeException)
452 ResultSetEntryGuard aGuard( *this );
453 return DateTime();
455 // -------------------------------------------------------------------------
457 sal_Bool SAL_CALL OResultSet::isBeforeFirst( ) throw(SQLException, RuntimeException)
459 ResultSetEntryGuard aGuard( *this );
461 // here you have to implement your movements
462 // return true means there is no data
463 OSL_TRACE("In/Out: OResultSet::isBeforeFirst" );
464 return( m_nRowPos < 1 );
466 // -------------------------------------------------------------------------
467 sal_Bool SAL_CALL OResultSet::isAfterLast( ) throw(SQLException, RuntimeException)
469 ResultSetEntryGuard aGuard( *this );
471 OSL_TRACE("In/Out: OResultSet::isAfterLast" );
472 return m_nRowPos > currentRowCount() && m_aQuery.queryComplete();
474 // -------------------------------------------------------------------------
475 sal_Bool SAL_CALL OResultSet::isFirst( ) throw(SQLException, RuntimeException)
477 ResultSetEntryGuard aGuard( *this );
479 OSL_TRACE("In/Out: OResultSet::isFirst" );
480 return m_nRowPos == 1;
482 // -------------------------------------------------------------------------
483 sal_Bool SAL_CALL OResultSet::isLast( ) throw(SQLException, RuntimeException)
485 ResultSetEntryGuard aGuard( *this );
487 OSL_TRACE("In/Out: OResultSet::isLast" );
488 return m_nRowPos == currentRowCount() && m_aQuery.queryComplete();
490 // -------------------------------------------------------------------------
491 void SAL_CALL OResultSet::beforeFirst( ) throw(SQLException, RuntimeException)
493 ResultSetEntryGuard aGuard( *this );
495 // move before the first row so that isBeforeFirst returns false
496 OSL_TRACE("In/Out: OResultSet::beforeFirst" );
497 if ( first() )
498 previous();
500 // -------------------------------------------------------------------------
501 void SAL_CALL OResultSet::afterLast( ) throw(SQLException, RuntimeException)
503 ResultSetEntryGuard aGuard( *this );
504 OSL_TRACE("In/Out: OResultSet::afterLast" );
506 if(last())
507 next();
509 // -------------------------------------------------------------------------
511 void SAL_CALL OResultSet::close( ) throw(SQLException, RuntimeException)
513 ResultSetEntryGuard aGuard( *this );
514 OSL_TRACE("In/Out: OResultSet::close" );
515 dispose();
517 // -------------------------------------------------------------------------
519 sal_Bool SAL_CALL OResultSet::first( ) throw(SQLException, RuntimeException)
521 OSL_TRACE("In/Out: OResultSet::first" );
522 return seekRow( FIRST_POS );
524 // -------------------------------------------------------------------------
526 sal_Bool SAL_CALL OResultSet::last( ) throw(SQLException, RuntimeException)
528 OSL_TRACE("In/Out: OResultSet::last" );
529 return seekRow( LAST_POS );
531 // -------------------------------------------------------------------------
532 sal_Bool SAL_CALL OResultSet::absolute( sal_Int32 row ) throw(SQLException, RuntimeException)
534 OSL_TRACE("In/Out: OResultSet::absolute" );
535 return seekRow( ABSOLUTE_POS, row );
537 // -------------------------------------------------------------------------
538 sal_Bool SAL_CALL OResultSet::relative( sal_Int32 row ) throw(SQLException, RuntimeException)
540 OSL_TRACE("In/Out: OResultSet::relative" );
541 return seekRow( RELATIVE_POS, row );
543 // -------------------------------------------------------------------------
544 sal_Bool SAL_CALL OResultSet::previous( ) throw(SQLException, RuntimeException)
546 ResultSetEntryGuard aGuard( *this );
547 OSL_TRACE("In/Out: OResultSet::previous" );
548 return seekRow( PRIOR_POS );
550 // -------------------------------------------------------------------------
551 Reference< XInterface > SAL_CALL OResultSet::getStatement( ) throw(SQLException, RuntimeException)
553 ResultSetEntryGuard aGuard( *this );
555 OSL_TRACE("In/Out: OResultSet::getStatement" );
556 return m_xStatement;
558 // -------------------------------------------------------------------------
560 sal_Bool SAL_CALL OResultSet::rowDeleted( ) throw(SQLException, RuntimeException)
562 ResultSetEntryGuard aGuard( *this );
563 OSL_TRACE("In/Out: OResultSet::rowDeleted, m_RowStates=%u",m_RowStates );
564 return ((m_RowStates & RowStates_Deleted) == RowStates_Deleted) ;
566 // -------------------------------------------------------------------------
567 sal_Bool SAL_CALL OResultSet::rowInserted( ) throw(SQLException, RuntimeException)
569 ResultSetEntryGuard aGuard( *this );
570 OSL_TRACE("In/Out: OResultSet::rowInserted,m_RowStates=%u",m_RowStates );
571 return ((m_RowStates & RowStates_Inserted) == RowStates_Inserted);
573 // -------------------------------------------------------------------------
574 sal_Bool SAL_CALL OResultSet::rowUpdated( ) throw(SQLException, RuntimeException)
576 ResultSetEntryGuard aGuard( *this );
577 OSL_TRACE("In/Out: OResultSet::rowUpdated,m_RowStates=%u",m_RowStates );
578 return ((m_RowStates & RowStates_Updated) == RowStates_Updated) ;
580 // -------------------------------------------------------------------------
582 sal_Bool SAL_CALL OResultSet::next( ) throw(SQLException, RuntimeException)
584 return seekRow( NEXT_POS );
586 // -------------------------------------------------------------------------
588 sal_Bool SAL_CALL OResultSet::wasNull( ) throw(SQLException, RuntimeException)
590 ResultSetEntryGuard aGuard( *this );
592 return m_bWasNull;
594 // -------------------------------------------------------------------------
596 void SAL_CALL OResultSet::cancel( ) throw(RuntimeException)
598 ResultSetEntryGuard aGuard( *this );
599 OSL_TRACE("In/Out: OResultSet::cancel" );
602 // -------------------------------------------------------------------------
603 void SAL_CALL OResultSet::clearWarnings( ) throw(SQLException, RuntimeException)
605 OSL_TRACE("In/Out: OResultSet::clearWarnings" );
607 // -------------------------------------------------------------------------
608 Any SAL_CALL OResultSet::getWarnings( ) throw(SQLException, RuntimeException)
610 OSL_TRACE("In/Out: OResultSet::getWarnings" );
611 return Any();
613 // -------------------------------------------------------------------------
614 void SAL_CALL OResultSet::refreshRow( ) throw(SQLException, RuntimeException)
616 OSL_TRACE("In/Out: OResultSet::refreshRow" );
617 if (fetchRow(getCurrentCardNumber(),sal_True)) //force fetch current row will cause we lose all change to the current row
618 m_pStatement->getOwnConnection()->throwSQLException( STR_ERROR_REFRESH_ROW, *this );
620 // -------------------------------------------------------------------------
621 IPropertyArrayHelper* OResultSet::createArrayHelper( ) const
623 Sequence< Property > aProps(5);
624 Property* pProperties = aProps.getArray();
625 sal_Int32 nPos = 0;
626 DECL_PROP0(FETCHDIRECTION, sal_Int32);
627 DECL_PROP0(FETCHSIZE, sal_Int32);
628 DECL_BOOL_PROP1IMPL(ISBOOKMARKABLE) PropertyAttribute::READONLY);
629 DECL_PROP1IMPL(RESULTSETCONCURRENCY,sal_Int32) PropertyAttribute::READONLY);
630 DECL_PROP1IMPL(RESULTSETTYPE, sal_Int32) PropertyAttribute::READONLY);
632 return new OPropertyArrayHelper(aProps);
634 // -------------------------------------------------------------------------
635 IPropertyArrayHelper & OResultSet::getInfoHelper()
637 return *const_cast<OResultSet*>(this)->getArrayHelper();
639 // -------------------------------------------------------------------------
640 sal_Bool OResultSet::convertFastPropertyValue(
641 Any & /*rConvertedValue*/,
642 Any & /*rOldValue*/,
643 sal_Int32 nHandle,
644 const Any& /*rValue*/ )
645 throw (::com::sun::star::lang::IllegalArgumentException)
647 OSL_ENSURE( false, "OResultSet::convertFastPropertyValue: not implemented!" );
648 switch(nHandle)
650 case PROPERTY_ID_ISBOOKMARKABLE:
651 case PROPERTY_ID_RESULTSETCONCURRENCY:
652 case PROPERTY_ID_RESULTSETTYPE:
653 throw ::com::sun::star::lang::IllegalArgumentException();
654 case PROPERTY_ID_FETCHDIRECTION:
655 case PROPERTY_ID_FETCHSIZE:
656 default:
659 return sal_False;
661 // -------------------------------------------------------------------------
662 void OResultSet::setFastPropertyValue_NoBroadcast(
663 sal_Int32 nHandle,
664 const Any& /*rValue*/
666 throw (Exception)
668 OSL_ENSURE( false, "OResultSet::setFastPropertyValue_NoBroadcast: not implemented!" );
669 switch(nHandle)
671 case PROPERTY_ID_ISBOOKMARKABLE:
672 case PROPERTY_ID_RESULTSETCONCURRENCY:
673 case PROPERTY_ID_RESULTSETTYPE:
674 throw Exception();
675 case PROPERTY_ID_FETCHDIRECTION:
676 break;
677 case PROPERTY_ID_FETCHSIZE:
678 break;
679 default:
683 // -------------------------------------------------------------------------
684 void OResultSet::getFastPropertyValue(
685 Any& rValue,
686 sal_Int32 nHandle
687 ) const
689 switch(nHandle)
691 case PROPERTY_ID_RESULTSETCONCURRENCY:
692 rValue <<= (sal_Int32)m_nResultSetConcurrency;
693 break;
694 case PROPERTY_ID_RESULTSETTYPE:
695 rValue <<= m_nResultSetType;
696 break;
697 case PROPERTY_ID_FETCHDIRECTION:
698 rValue <<= m_nFetchDirection;
699 break;
700 case PROPERTY_ID_FETCHSIZE:
701 rValue <<= m_nFetchSize;
702 break;
703 case PROPERTY_ID_ISBOOKMARKABLE:
704 const_cast< OResultSet* >( this )->determineReadOnly();
705 rValue <<= !m_bIsReadOnly;
706 break;
709 // -----------------------------------------------------------------------------
710 void SAL_CALL OResultSet::acquire() throw()
712 OResultSet_BASE::acquire();
714 // -----------------------------------------------------------------------------
715 void SAL_CALL OResultSet::release() throw()
717 OResultSet_BASE::release();
719 // -----------------------------------------------------------------------------
720 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL OResultSet::getPropertySetInfo( ) throw(::com::sun::star::uno::RuntimeException)
722 return ::cppu::OPropertySetHelper::createPropertySetInfo(getInfoHelper());
724 // -----------------------------------------------------------------------------
725 void OResultSet::initializeRow(OValueRow& _rRow,sal_Int32 _nColumnCount)
727 if(!_rRow.isValid())
729 _rRow = new OValueVector(_nColumnCount);
730 (_rRow->get())[0].setBound(sal_True);
731 ::std::for_each(_rRow->get().begin()+1,_rRow->get().end(),TSetBound(sal_False));
735 // -------------------------------------------------------------------------
736 void OResultSet::parseParameter( const OSQLParseNode* pNode, rtl::OUString& rMatchString )
738 OSL_ENSURE(pNode->count() > 0,"Error parsing parameter in Parse Tree");
739 OSQLParseNode *pMark = pNode->getChild(0);
741 // Initialize to empty string
742 rMatchString = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(""));
744 rtl::OUString aParameterName;
745 if (SQL_ISPUNCTUATION(pMark,"?")) {
746 aParameterName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("?"));
748 else if (SQL_ISPUNCTUATION(pMark,":")) {
749 aParameterName = pNode->getChild(1)->getTokenValue();
751 // XXX - Now we know name, what's value????
752 m_nParamIndex ++;
753 OSL_TRACE("Parameter name [%d]: %s\n", m_nParamIndex,OUtoCStr(aParameterName) );
755 if ( m_aParameterRow.isValid() ) {
756 OSL_ENSURE( m_nParamIndex < (sal_Int32)m_aParameterRow->get().size() + 1, "More parameters than values found" );
757 rMatchString = (m_aParameterRow->get())[(sal_uInt16)m_nParamIndex];
758 #if OSL_DEBUG_LEVEL > 0
759 OSL_TRACE("Prop Value : %s\n", OUtoCStr( rMatchString ) );
760 #endif
762 #if OSL_DEBUG_LEVEL > 0
763 else {
764 OSL_TRACE("Prop Value : Invalid ParameterRow!\n" );
766 #endif
769 void OResultSet::analyseWhereClause( const OSQLParseNode* parseTree,
770 MQueryExpression &queryExpression)
772 ::rtl::OUString columnName;
773 MQueryOp::cond_type op( MQueryOp::Is );
774 ::rtl::OUString matchString;
776 if ( parseTree == NULL )
777 return;
779 if ( m_pSQLIterator->getParseTree() != NULL ) {
780 ::vos::ORef<OSQLColumns> xColumns = m_pSQLIterator->getParameters();
781 if(xColumns.isValid())
783 ::rtl::OUString aTabName,aColName,aParameterName,aParameterValue;
784 OSQLColumns::Vector::iterator aIter = xColumns->get().begin();
785 sal_Int32 i = 1;
786 for(;aIter != xColumns->get().end();++aIter)
788 (*aIter)->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME)) >>= aColName;
789 OSL_TRACE("Prop Column Name : %s\n", OUtoCStr( aColName ) );
790 if ( m_aParameterRow.isValid() ) {
791 aParameterValue = (m_aParameterRow->get())[(sal_uInt16)i];
792 #if OSL_DEBUG_LEVEL > 0
793 OSL_TRACE("Prop Value : %s\n", OUtoCStr( aParameterValue ) );
794 #endif
796 #if OSL_DEBUG_LEVEL > 0
797 else {
798 OSL_TRACE("Prop Value : Invalid ParameterRow!\n" );
800 #endif
801 i++;
807 if ( SQL_ISRULE(parseTree,where_clause) )
809 OSL_TRACE("analyseSQL : Got WHERE clause\n");
810 // Reset Parameter Counter
811 resetParameters();
812 analyseWhereClause( parseTree->getChild( 1 ), queryExpression );
814 else if ( parseTree->count() == 3 && // Handle ()'s
815 SQL_ISPUNCTUATION(parseTree->getChild(0),"(") &&
816 SQL_ISPUNCTUATION(parseTree->getChild(2),")"))
819 OSL_TRACE("analyseSQL : Got Punctuation ()\n");
820 MQueryExpression *subExpression = new MQueryExpression();
821 analyseWhereClause( parseTree->getChild( 1 ), *subExpression );
822 queryExpression.getExpressions().push_back( subExpression );
824 else if ((SQL_ISRULE(parseTree,search_condition) || (SQL_ISRULE(parseTree,boolean_term)))
825 && parseTree->count() == 3) // Handle AND/OR
828 OSL_TRACE("analyseSQL : Got AND/OR clause\n");
830 // TODO - Need to take care or AND, for now match is always OR
831 analyseWhereClause( parseTree->getChild( 0 ), queryExpression );
832 analyseWhereClause( parseTree->getChild( 2 ), queryExpression );
834 if (SQL_ISTOKEN(parseTree->getChild(1),OR)) { // OR-Operator
835 queryExpression.setExpressionCondition( MQueryExpression::OR );
837 else if (SQL_ISTOKEN(parseTree->getChild(1),AND)) { // AND-Operator
838 queryExpression.setExpressionCondition( MQueryExpression::AND );
840 else {
841 OSL_ASSERT("analyseSQL: Error in Parse Tree");
844 else if (SQL_ISRULE(parseTree,comparison_predicate))
846 OSL_ENSURE(parseTree->count() == 3, "Error parsing COMPARE predicate");
847 if (!(SQL_ISRULE(parseTree->getChild(0),column_ref) ||
848 parseTree->getChild(2)->getNodeType() == SQL_NODE_STRING ||
849 parseTree->getChild(2)->getNodeType() == SQL_NODE_INTNUM ||
850 parseTree->getChild(2)->getNodeType() == SQL_NODE_APPROXNUM ||
851 SQL_ISTOKEN(parseTree->getChild(2),TRUE) ||
852 SQL_ISTOKEN(parseTree->getChild(2),FALSE) ||
853 SQL_ISRULE(parseTree->getChild(2),parameter) ||
854 // odbc date
855 (SQL_ISRULE(parseTree->getChild(2),set_fct_spec) && SQL_ISPUNCTUATION(parseTree->getChild(2)->getChild(0),"{"))))
857 m_pStatement->getOwnConnection()->throwSQLException( STR_QUERY_TOO_COMPLEX, *this );
860 OSQLParseNode *pPrec = parseTree->getChild(1);
861 if (pPrec->getNodeType() == SQL_NODE_EQUAL)
862 op = MQueryOp::Is;
863 else if (pPrec->getNodeType() == SQL_NODE_NOTEQUAL)
864 op = MQueryOp::IsNot;
866 ::rtl::OUString sTableRange;
867 if(SQL_ISRULE(parseTree->getChild(0),column_ref))
868 m_pSQLIterator->getColumnRange(parseTree->getChild(0),columnName,sTableRange);
869 else if(parseTree->getChild(0)->isToken())
870 columnName = parseTree->getChild(0)->getTokenValue();
872 if ( SQL_ISRULE(parseTree->getChild(2),parameter) ) {
873 parseParameter( parseTree->getChild(2), matchString );
875 else {
876 matchString = parseTree->getChild(2)->getTokenValue();
879 if ( columnName.compareToAscii("0") ==0 && op == MQueryOp::Is &&
880 matchString.compareToAscii("1") == 0 ) {
881 OSL_TRACE("Query always evaluates to FALSE");
882 m_bIsAlwaysFalseQuery = sal_True;
884 queryExpression.getExpressions().push_back( new MQueryExpressionString( columnName, op, matchString ));
886 else if (SQL_ISRULE(parseTree,like_predicate))
888 OSL_ENSURE(parseTree->count() >= 4, "Error parsing LIKE predicate");
890 OSL_TRACE("analyseSQL : Got LIKE rule\n");
892 if ( !(SQL_ISRULE(parseTree->getChild(0), column_ref)) )
894 m_pStatement->getOwnConnection()->throwSQLException( STR_QUERY_INVALID_LIKE_COLUMN, *this );
898 OSQLParseNode *pColumn;
899 OSQLParseNode *pAtom;
900 OSQLParseNode *pOptEscape;
901 pColumn = parseTree->getChild(0); // Match Item
902 pAtom = parseTree->getChild(parseTree->count()-2); // Match String
903 pOptEscape = parseTree->getChild(parseTree->count()-1); // Opt Escape Rule
905 if (!(pAtom->getNodeType() == SQL_NODE_STRING ||
906 pAtom->getNodeType() == SQL_NODE_NAME ||
907 SQL_ISRULE(pAtom,parameter) ||
908 ( pAtom->getChild(0) && pAtom->getChild(0)->getNodeType() == SQL_NODE_NAME ) ||
909 ( pAtom->getChild(0) && pAtom->getChild(0)->getNodeType() == SQL_NODE_STRING )
912 OSL_TRACE("analyseSQL : pAtom->count() = %d\n", pAtom->count() );
914 m_pStatement->getOwnConnection()->throwSQLException( STR_QUERY_INVALID_LIKE_STRING, *this );
917 const sal_Unicode WILDCARD = '%';
918 const sal_Unicode ALT_WILDCARD = '*';
919 const sal_Unicode MATCHCHAR = '_';
921 ::rtl::OUString sTableRange;
922 if(SQL_ISRULE(pColumn,column_ref))
923 m_pSQLIterator->getColumnRange(pColumn,columnName,sTableRange);
925 OSL_TRACE("ColumnName = %s\n", OUtoCStr( columnName ) );
927 if ( SQL_ISRULE(pAtom,parameter) ) {
928 parseParameter( pAtom, matchString );
929 // Replace all '*' with '%' : UI Usually does this but not with
930 // Parameters for some reason.
931 matchString = matchString.replace( ALT_WILDCARD, WILDCARD );
933 else
935 matchString = pAtom->getTokenValue();
938 // Determine where '%' character is...
940 if ( matchString.equals( ::rtl::OUString::valueOf( WILDCARD ) ) )
942 // String containing only a '%' and nothing else
943 op = MQueryOp::Exists;
944 // Will be ignored for Exists case, but clear anyway.
945 matchString = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(""));
947 else if ( matchString.indexOf ( WILDCARD ) == -1 &&
948 matchString.indexOf ( MATCHCHAR ) == -1 )
950 // Simple string , eg. "to match"
951 if ( parseTree->count() == 5 )
952 op = MQueryOp::DoesNotContain;
953 else
954 op = MQueryOp::Contains;
956 else if ( matchString.indexOf ( WILDCARD ) == 0
957 && matchString.lastIndexOf ( WILDCARD ) == matchString.getLength() -1
958 && matchString.indexOf ( WILDCARD, 1 ) == matchString.lastIndexOf ( WILDCARD )
959 && matchString.indexOf( MATCHCHAR ) == -1
962 // Relatively simple "%string%" - ie, contains...
963 // Cut '%' from front and rear
964 matchString = matchString.replaceAt( 0, 1, rtl::OUString() );
965 matchString = matchString.replaceAt( matchString.getLength() -1 , 1, rtl::OUString() );
967 if ( parseTree->count() == 5 )
968 op = MQueryOp::DoesNotContain;
969 else
970 op = MQueryOp::Contains;
972 else if ( parseTree->count() == 5 )
974 // We currently can't handle a 'NOT LIKE' when there are '%' or
975 // '_' dispersed throughout
976 m_pStatement->getOwnConnection()->throwSQLException( STR_QUERY_NOT_LIKE_TOO_COMPLEX, *this );
978 else
980 if ( (matchString.indexOf ( WILDCARD ) == matchString.lastIndexOf ( WILDCARD ))
981 && matchString.indexOf( MATCHCHAR ) == -1
984 // One occurance of '%' - no '_' matches...
985 if ( matchString.indexOf ( WILDCARD ) == 0 )
987 op = MQueryOp::EndsWith;
988 matchString = matchString.replaceAt( 0, 1, rtl::OUString());
990 else if ( matchString.indexOf ( WILDCARD ) == matchString.getLength() -1 )
992 op = MQueryOp::BeginsWith;
993 matchString = matchString.replaceAt( matchString.getLength() -1 , 1, rtl::OUString() );
995 else
997 sal_Int32 pos = matchString.indexOf ( WILDCARD );
998 matchString = matchString.replaceAt( pos, 1,::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(".*")) );
999 op = MQueryOp::RegExp;
1003 else
1005 // Most Complex, need to use an RE
1006 sal_Int32 pos = matchString.indexOf ( WILDCARD );
1007 while ( (pos = matchString.indexOf ( WILDCARD )) != -1 )
1009 matchString = matchString.replaceAt( pos, 1, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(".*")) );
1012 pos = matchString.indexOf ( MATCHCHAR );
1013 while ( (pos = matchString.indexOf( MATCHCHAR )) != -1 )
1015 matchString = matchString.replaceAt( pos, 1, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(".")) );
1018 op = MQueryOp::RegExp;
1022 queryExpression.getExpressions().push_back( new MQueryExpressionString( columnName, op, matchString ));
1024 else if (SQL_ISRULE(parseTree,test_for_null))
1026 OSL_ENSURE(parseTree->count() >= 3,"Error in ParseTree");
1027 OSL_ENSURE(SQL_ISTOKEN(parseTree->getChild(1),IS),"Error in ParseTree");
1029 if (!SQL_ISRULE(parseTree->getChild(0),column_ref))
1031 m_pStatement->getOwnConnection()->throwSQLException( STR_QUERY_INVALID_IS_NULL_COLUMN, *this );
1034 if (SQL_ISTOKEN(parseTree->getChild(2),NOT))
1036 op = MQueryOp::Exists;
1038 else
1039 op = MQueryOp::DoesNotExist;
1041 ::rtl::OUString sTableRange;
1042 m_pSQLIterator->getColumnRange(parseTree->getChild(0),columnName,sTableRange);
1044 queryExpression.getExpressions().push_back( new MQueryExpressionString( columnName, op ));
1046 else
1048 OSL_TRACE( "Unexpected statement!!!" );
1050 m_pStatement->getOwnConnection()->throwSQLException( STR_QUERY_TOO_COMPLEX, *this );
1055 // -----------------------------------------------------------------------------
1057 void OResultSet::fillRowData()
1058 throw( ::com::sun::star::sdbc::SQLException )
1060 OSL_ENSURE( m_pStatement, "Require a statement" );
1062 MQueryExpression queryExpression;
1064 OConnection* xConnection = static_cast<OConnection*>(m_pStatement->getConnection().get());
1065 m_xColumns = m_pSQLIterator->getSelectColumns();
1067 OSL_ENSURE(m_xColumns.isValid(), "Need the Columns!!");
1069 OSQLColumns::Vector::const_iterator aIter = m_xColumns->get().begin();
1070 const ::rtl::OUString sProprtyName = OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME);
1071 ::rtl::OUString sName;
1072 m_aAttributeStrings.clear();
1073 m_aAttributeStrings.reserve(m_xColumns->get().size());
1074 for (sal_Int32 i = 1; aIter != m_xColumns->get().end();++aIter, i++)
1076 (*aIter)->getPropertyValue(sProprtyName) >>= sName;
1077 #if OSL_DEBUG_LEVEL > 0
1078 OSL_TRACE("Query Columns : (%d) %s\n", i, OUtoCStr(sName) );
1079 #endif
1080 m_aAttributeStrings.push_back( sName );
1084 // Generate Match Conditions for Query
1085 const OSQLParseNode* pParseTree = m_pSQLIterator->getWhereTree();
1087 // const OSQLParseNode* pParseTree = NULL;
1089 m_bIsAlwaysFalseQuery = sal_False;
1090 if ( pParseTree != NULL )
1092 // Extract required info
1094 OSL_TRACE("\tHave a Where Clause\n");
1096 analyseWhereClause( pParseTree, queryExpression );
1098 else
1100 OSL_TRACE("\tDon't have a Where Clause\n");
1102 MQueryExpression::ExprVector eVector;
1104 // LDAP does not allow a query without restriction, so we add a dummy
1105 // for PrimaryEmail
1106 // For other types we stick to the old behaviour of using
1107 // card:nsIAbCard.
1108 OSL_ENSURE(m_pStatement, "Cannot determine Parent Statement");
1109 ::rtl::OUString aStr;
1110 if (xConnection->isLDAP())
1111 aStr = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("PrimaryEmail"));
1112 else
1113 aStr = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("card:nsIAbCard"));
1114 eVector.push_back( new MQueryExpressionString(aStr, MQueryOp::Exists) );
1116 queryExpression.setExpressions( eVector );
1119 // If the query is a 0=1 then set Row count to 0 and return
1120 if ( m_bIsAlwaysFalseQuery )
1122 m_bIsReadOnly = 1;
1123 return;
1126 m_aQuery.setExpression( queryExpression );
1128 rtl::OUString aStr( m_pTable->getName() );
1129 m_aQuery.setAddressbook( aStr );
1131 sal_Int32 rv = m_aQuery.executeQuery(xConnection);
1132 if ( rv == -1 ) {
1133 m_pStatement->getOwnConnection()->throwSQLException( STR_ERR_EXECUTING_QUERY, *this );
1135 //determine whether the address book is readonly
1136 determineReadOnly();
1138 #if OSL_DEBUG_LEVEL > 0
1139 OSL_TRACE( "executeQuery returned %d\n", rv );
1141 OSL_TRACE( "\tOUT OResultSet::fillRowData()\n" );
1142 #endif
1145 // -----------------------------------------------------------------------------
1146 static sal_Bool matchRow( OValueRow& row1, OValueRow& row2 )
1148 OValueVector::Vector::iterator row1Iter = row1->get().begin();
1149 OValueVector::Vector::iterator row2Iter = row2->get().begin();
1150 for ( ++row1Iter,++row2Iter; // the first column is the bookmark column
1151 row1Iter != row1->get().end(); ++row1Iter,++row2Iter)
1153 if ( row1Iter->isBound())
1155 // Compare values, if at anytime there's a mismatch return false
1156 if ( !( (*row1Iter) == (*row2Iter) ) )
1157 return sal_False;
1161 // If we get to here the rows match
1162 return sal_True;
1164 sal_Int32 OResultSet::getRowForCardNumber(sal_Int32 nCardNum)
1166 OSL_TRACE("In/Out: OResultSet::getRowForCardNumber, nCardNum = %u", nCardNum );
1168 if ( m_pKeySet.isValid() )
1170 sal_Int32 nPos;
1171 for(nPos=0;nPos < (sal_Int32)m_pKeySet->get().size();nPos++)
1173 if (nCardNum == (m_pKeySet->get())[nPos])
1175 OSL_TRACE("In/Out: OResultSet::getRowForCardNumber, return = %u", nPos+1 );
1176 return nPos+1;
1181 m_pStatement->getOwnConnection()->throwSQLException( STR_INVALID_BOOKMARK, *this );
1182 return 0;
1185 // -----------------------------------------------------------------------------
1186 void SAL_CALL OResultSet::executeQuery() throw( ::com::sun::star::sdbc::SQLException,
1187 ::com::sun::star::uno::RuntimeException)
1189 ResultSetEntryGuard aGuard( *this );
1191 OSL_ENSURE( m_pTable, "Need a Table object");
1192 if(!m_pTable)
1194 const OSQLTables& xTabs = m_pSQLIterator->getTables();
1195 if ((xTabs.begin() == xTabs.end()) || !xTabs.begin()->second.is())
1196 m_pStatement->getOwnConnection()->throwSQLException( STR_QUERY_TOO_COMPLEX, *this );
1198 m_pTable = static_cast< OTable* > ((xTabs.begin()->second).get());
1202 m_nRowPos = 0;
1204 fillRowData();
1206 OSL_ENSURE(m_xColumns.isValid(), "Need the Columns!!");
1208 // sal_Int32 nColumnCount = m_xColumns->size();
1209 // initializeRow(m_aRow,nColumnCount);
1210 // initializeRow(m_aEvaluateRow,nColumnCount);
1212 switch( m_pSQLIterator->getStatementType() )
1214 case SQL_STATEMENT_SELECT:
1216 if(m_bIsAlwaysFalseQuery) {
1217 break;
1219 else if(isCount())
1221 m_pStatement->getOwnConnection()->throwSQLException( STR_NO_COUNT_SUPPORT, *this );
1223 else
1225 sal_Bool bDistinct = sal_False;
1226 sal_Bool bWasSorted = sal_False;
1227 OSQLParseNode *pDistinct = m_pParseTree->getChild(1);
1228 if (pDistinct && pDistinct->getTokenID() == SQL_TOKEN_DISTINCT)
1230 if(!IsSorted())
1232 m_aOrderbyColumnNumber.push_back(m_aColMapping[1]);
1233 m_aOrderbyAscending.push_back(SQL_DESC);
1235 else
1236 bWasSorted = sal_True;
1237 bDistinct = sal_True;
1240 OSortIndex::TKeyTypeVector eKeyType(m_aOrderbyColumnNumber.size());
1241 ::std::vector<sal_Int32>::iterator aOrderByIter = m_aOrderbyColumnNumber.begin();
1242 for ( ::std::vector<sal_Int16>::size_type i = 0; aOrderByIter != m_aOrderbyColumnNumber.end(); ++aOrderByIter,++i)
1244 OSL_ENSURE((sal_Int32)m_aRow->get().size() > *aOrderByIter,"Invalid Index");
1245 switch ((m_aRow->get().begin()+*aOrderByIter)->getTypeKind())
1247 case DataType::CHAR:
1248 case DataType::VARCHAR:
1249 eKeyType[i] = SQL_ORDERBYKEY_STRING;
1250 break;
1252 case DataType::OTHER:
1253 case DataType::TINYINT:
1254 case DataType::SMALLINT:
1255 case DataType::INTEGER:
1256 case DataType::DECIMAL:
1257 case DataType::NUMERIC:
1258 case DataType::REAL:
1259 case DataType::DOUBLE:
1260 case DataType::DATE:
1261 case DataType::TIME:
1262 case DataType::TIMESTAMP:
1263 case DataType::BIT:
1264 eKeyType[i] = SQL_ORDERBYKEY_DOUBLE;
1265 break;
1267 // Andere Typen sind nicht implementiert (und damit immer
1268 // FALSE)
1269 default:
1270 eKeyType[i] = SQL_ORDERBYKEY_NONE;
1271 OSL_ASSERT("MResultSet::executeQuery: Order By Data Type not implemented");
1272 break;
1276 if (IsSorted())
1278 // Implement Sorting
1280 // So that we can sort we need to wait until the executed
1281 // query to the mozilla addressbooks has returned all
1282 // values.
1284 OSL_TRACE("Query is to be sorted");
1285 if( ! m_aQuery.queryComplete() )
1286 if ( !m_aQuery.waitForQueryComplete() )
1288 m_pStatement->getOwnConnection()->throwSQLException( m_aQuery.getError(), *this );
1291 OSL_ENSURE( m_aQuery.queryComplete(), "Query not complete!!");
1293 m_pSortIndex = new OSortIndex(eKeyType,m_aOrderbyAscending);
1295 OSL_TRACE("OrderbyColumnNumber->size() = %d",m_aOrderbyColumnNumber.size());
1296 #if OSL_DEBUG_LEVEL > 0
1297 for ( ::std::vector<sal_Int32>::size_type i = 0; i < m_aColMapping.size(); i++ )
1298 OSL_TRACE("Mapped: %d -> %d", i, m_aColMapping[i] );
1299 #endif
1300 for ( sal_Int32 nRow = 1; nRow <= m_aQuery.getRowCount(); nRow++ ) {
1302 OKeyValue* pKeyValue = OKeyValue::createKeyValue((nRow));
1304 ::std::vector<sal_Int32>::iterator aIter = m_aOrderbyColumnNumber.begin();
1305 for (;aIter != m_aOrderbyColumnNumber.end(); ++aIter)
1307 const ORowSetValue& value = getValue(nRow, *aIter);
1309 OSL_TRACE( "Adding Value: (%d,%d) : %s", nRow, *aIter,OUtoCStr( value ));
1311 pKeyValue->pushKey(new ORowSetValueDecorator(value));
1314 m_pSortIndex->AddKeyValue( pKeyValue );
1317 m_pKeySet = m_pSortIndex->CreateKeySet();
1318 m_CurrentRowCount = m_pKeySet->get().size();
1319 #if OSL_DEBUG_LEVEL > 0
1320 for( OKeySet::Vector::size_type i = 0; i < m_pKeySet->get().size(); i++ )
1321 OSL_TRACE("Sorted: %d -> %d", i, (m_pKeySet->get())[i] );
1322 #endif
1324 m_pSortIndex = NULL;
1325 beforeFirst(); // Go back to start
1327 else //we always need m_pKeySet now
1328 m_pKeySet = new OKeySet();
1330 // Handle the DISTINCT case
1331 if ( bDistinct && m_pKeySet.isValid() )
1333 OValueRow aSearchRow = new OValueVector( m_aRow->get().size() );
1335 for( OKeySet::Vector::size_type i = 0; i < m_pKeySet->get().size(); i++ )
1337 fetchRow( (m_pKeySet->get())[i] ); // Fills m_aRow
1338 if ( matchRow( m_aRow, aSearchRow ) )
1340 (m_pKeySet->get())[i] = 0; // Marker for later to be removed
1342 else
1344 // They don't match, so it's not a duplicate.
1345 // Use the current Row as the next one to match against
1346 *aSearchRow = *m_aRow;
1349 // Now remove any keys marked with a 0
1350 m_pKeySet->get().erase(::std::remove_if(m_pKeySet->get().begin(),m_pKeySet->get().end()
1351 ,::std::bind2nd(::std::equal_to<sal_Int32>(),0))
1352 ,m_pKeySet->get().end());
1356 } break;
1358 case SQL_STATEMENT_UPDATE:
1359 case SQL_STATEMENT_DELETE:
1360 case SQL_STATEMENT_INSERT:
1361 break;
1362 default:
1363 m_pStatement->getOwnConnection()->throwSQLException( STR_STMT_TYPE_NOT_SUPPORTED, *this );
1364 break;
1368 // -----------------------------------------------------------------------------
1370 void OResultSet::setBoundedColumns(const OValueRow& _rRow,
1371 const ::vos::ORef<connectivity::OSQLColumns>& _rxColumns,
1372 const Reference<XIndexAccess>& _xNames,
1373 sal_Bool _bSetColumnMapping,
1374 const Reference<XDatabaseMetaData>& _xMetaData,
1375 ::std::vector<sal_Int32>& _rColMapping)
1377 ::comphelper::UStringMixEqual aCase(_xMetaData->storesMixedCaseQuotedIdentifiers());
1379 Reference<XPropertySet> xTableColumn;
1380 ::rtl::OUString sTableColumnName, sSelectColumnRealName;
1382 const ::rtl::OUString sName = OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME);
1383 const ::rtl::OUString sRealName = OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_REALNAME);
1385 ::std::vector< ::rtl::OUString> aColumnNames;
1386 aColumnNames.reserve(_rxColumns->get().size());
1387 OValueVector::Vector::iterator aRowIter = _rRow->get().begin()+1;
1388 for (sal_Int32 i=0; // the first column is the bookmark column
1389 aRowIter != _rRow->get().end();
1390 ++i, ++aRowIter
1395 // get the table column and it's name
1396 _xNames->getByIndex(i) >>= xTableColumn;
1397 OSL_ENSURE(xTableColumn.is(), "OResultSet::setBoundedColumns: invalid table column!");
1398 if (xTableColumn.is())
1399 xTableColumn->getPropertyValue(sName) >>= sTableColumnName;
1400 else
1401 sTableColumnName = ::rtl::OUString();
1403 // look if we have such a select column
1404 // TODO: would like to have a O(log n) search here ...
1405 sal_Int32 nColumnPos = 0;
1406 for ( OSQLColumns::Vector::iterator aIter = _rxColumns->get().begin();
1407 aIter != _rxColumns->get().end();
1408 ++aIter,++nColumnPos
1411 if ( nColumnPos < (sal_Int32)aColumnNames.size() )
1412 sSelectColumnRealName = aColumnNames[nColumnPos];
1413 else
1415 if((*aIter)->getPropertySetInfo()->hasPropertyByName(sRealName))
1416 (*aIter)->getPropertyValue(sRealName) >>= sSelectColumnRealName;
1417 else
1418 (*aIter)->getPropertyValue(sName) >>= sSelectColumnRealName;
1419 aColumnNames.push_back(sSelectColumnRealName);
1422 if (aCase(sTableColumnName, sSelectColumnRealName))
1424 if(_bSetColumnMapping)
1426 sal_Int32 nSelectColumnPos = aIter - _rxColumns->get().begin() + 1;
1427 // the getXXX methods are 1-based ...
1428 sal_Int32 nTableColumnPos = i + 1;
1429 // get first table column is the bookmark column
1430 // ...
1431 #if OSL_DEBUG_LEVEL > 0
1432 OSL_TRACE("Set Col Mapping: %d -> %d", nSelectColumnPos, nTableColumnPos );
1433 #endif
1434 _rColMapping[nSelectColumnPos] = nTableColumnPos;
1437 aRowIter->setBound(sal_True);
1438 aRowIter->setTypeKind(DataType::VARCHAR);
1442 catch (Exception&)
1444 OSL_ENSURE(sal_False, "OResultSet::setBoundedColumns: caught an Exception!");
1450 // -----------------------------------------------------------------------------
1451 sal_Bool OResultSet::isCount() const
1453 return (m_pParseTree &&
1454 m_pParseTree->count() > 2 &&
1455 SQL_ISRULE(m_pParseTree->getChild(2),scalar_exp_commalist) &&
1456 SQL_ISRULE(m_pParseTree->getChild(2)->getChild(0),derived_column) &&
1457 SQL_ISRULE(m_pParseTree->getChild(2)->getChild(0)->getChild(0),general_set_fct) &&
1458 m_pParseTree->getChild(2)->getChild(0)->getChild(0)->count() == 4
1462 // -----------------------------------------------------------------------------
1464 // Check for valid row in m_aQuery
1466 sal_Bool OResultSet::validRow( sal_uInt32 nRow )
1468 sal_Int32 nNumberOfRecords = m_aQuery.getRealRowCount();
1470 while ( nRow > (sal_uInt32)nNumberOfRecords && !m_aQuery.queryComplete() ) {
1471 #if OSL_DEBUG_LEVEL > 0
1472 OSL_TRACE("validRow: waiting...");
1473 #endif
1474 m_aQuery.checkRowAvailable( nRow );
1475 if ( m_aQuery.hadError() )
1477 m_pStatement->getOwnConnection()->throwSQLException( m_aQuery.getError(), *this );
1479 nNumberOfRecords = m_aQuery.getRealRowCount();
1482 if (( nRow == 0 ) ||
1483 ( nRow > (sal_uInt32)nNumberOfRecords && m_aQuery.queryComplete()) ){
1484 OSL_TRACE("validRow(%u): return False", nRow);
1485 return sal_False;
1487 #if OSL_DEBUG_LEVEL > 0
1488 OSL_TRACE("validRow(%u): return True", nRow);
1489 #endif
1490 return sal_True;
1492 sal_Bool OResultSet::fillKeySet(sal_Int32 nMaxCardNumber)
1494 impl_ensureKeySet();
1495 if (m_CurrentRowCount < nMaxCardNumber)
1497 sal_Int32 nKeyValue;
1498 if ( (sal_Int32)m_pKeySet->get().capacity() < nMaxCardNumber )
1499 m_pKeySet->get().reserve(nMaxCardNumber + 20 );
1501 for (nKeyValue = m_CurrentRowCount+1; nKeyValue <= nMaxCardNumber; nKeyValue ++)
1502 m_pKeySet->get().push_back( nKeyValue );
1503 m_CurrentRowCount = nMaxCardNumber;
1505 return sal_True;
1508 sal_Int32 OResultSet::deletedCount()
1510 impl_ensureKeySet();
1511 return m_CurrentRowCount - m_pKeySet->get().size();
1514 // -----------------------------------------------------------------------------
1515 sal_Bool OResultSet::seekRow( eRowPosition pos, sal_Int32 nOffset )
1517 ResultSetEntryGuard aGuard( *this );
1518 if ( !m_pKeySet.isValid() )
1519 m_pStatement->getOwnConnection()->throwSQLException( STR_ILLEGAL_MOVEMENT, *this );
1521 sal_Int32 nNumberOfRecords = m_aQuery.getRealRowCount();
1522 sal_Int32 nRetrivedRows = currentRowCount();
1523 sal_Int32 nCurPos = m_nRowPos;
1525 OSL_TRACE("seekRow: nCurPos = %d", nCurPos );
1526 switch( pos ) {
1527 case NEXT_POS:
1528 OSL_TRACE("seekRow: NEXT");
1529 nCurPos++;
1530 break;
1531 case PRIOR_POS:
1532 OSL_TRACE("seekRow: PRIOR");
1533 if ( nCurPos > 0 )
1534 nCurPos--;
1535 break;
1537 case FIRST_POS:
1538 OSL_TRACE("seekRow: FIRST");
1539 nCurPos = 1;
1540 break;
1542 case LAST_POS:
1543 OSL_TRACE("seekRow: LAST");
1544 nCurPos = nRetrivedRows;
1545 break;
1546 case ABSOLUTE_POS:
1547 OSL_TRACE("seekRow: ABSOLUTE : %d", nOffset);
1548 nCurPos = nOffset;
1549 break;
1550 case RELATIVE_POS:
1551 OSL_TRACE("seekRow: RELATIVE : %d", nOffset);
1552 nCurPos += sal_uInt32( nOffset );
1553 break;
1556 if ( nCurPos <= 0 ) {
1557 m_nRowPos = 0;
1558 OSL_TRACE("seekRow: return False, m_nRowPos = %u", m_nRowPos );
1559 return sal_False;
1561 sal_Int32 nCurCard = nCurPos;
1562 if ( nCurPos < (sal_Int32)m_pKeySet->get().size() ) //The requested row is exist in m_pKeySet, so we just use it
1564 nCurCard = (m_pKeySet->get())[nCurPos-1];
1566 else //The requested row has not been retrived until now. We should get the right card for it.
1567 nCurCard = nCurPos + deletedCount();
1569 while ( nCurCard > nNumberOfRecords && !m_aQuery.queryComplete() ) {
1570 m_aQuery.checkRowAvailable( nCurCard );
1571 if ( m_aQuery.hadError() )
1573 m_pStatement->getOwnConnection()->throwSQLException( m_aQuery.getError(), *this );
1575 nNumberOfRecords = m_aQuery.getRealRowCount();
1578 if ( nCurCard > nNumberOfRecords && m_aQuery.queryComplete()) {
1579 fillKeySet(nNumberOfRecords);
1580 m_nRowPos = m_pKeySet->get().size() + 1;
1581 OSL_TRACE("seekRow: return False, m_nRowPos = %u", m_nRowPos );
1582 return sal_False;
1584 //Insert new retrived items for later use
1585 fillKeySet(nNumberOfRecords);
1586 m_nRowPos = (sal_uInt32)nCurPos;
1587 OSL_TRACE("seekRow: return True, m_nRowPos = %u", m_nRowPos );
1588 fetchCurrentRow();
1589 return sal_True;
1591 // -----------------------------------------------------------------------------
1592 void OResultSet::setColumnMapping(const ::std::vector<sal_Int32>& _aColumnMapping)
1594 m_aColMapping = _aColumnMapping;
1595 #if OSL_DEBUG_LEVEL > 0
1596 for ( sal_uInt32 i = 0; i < m_aColMapping.size(); i++ )
1597 OSL_TRACE("Set Mapped: %d -> %d", i, m_aColMapping[i] );
1598 #endif
1600 // -----------------------------------------------------------------------------
1602 ::com::sun::star::uno::Any OResultSet::getBookmark( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException)
1604 OSL_TRACE("getBookmark, m_nRowPos = %u", m_nRowPos );
1605 ResultSetEntryGuard aGuard( *this );
1606 if ( fetchCurrentRow() == sal_False )
1607 m_pStatement->getOwnConnection()->throwSQLException( STR_ERROR_GET_ROW, *this );
1609 OSL_ENSURE((!m_aRow->isDeleted()),"getBookmark called for deleted row");
1610 return makeAny((sal_Int32)(m_aRow->get())[0]);
1612 sal_Bool OResultSet::moveToBookmark( const ::com::sun::star::uno::Any& bookmark ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException)
1614 ResultSetEntryGuard aGuard( *this );
1615 OSL_TRACE("moveToBookmark, bookmark = %u", comphelper::getINT32(bookmark) );
1616 sal_Int32 nCardNum = comphelper::getINT32(bookmark);
1617 m_nRowPos = getRowForCardNumber(nCardNum);
1618 fetchCurrentRow();
1619 return sal_True;
1621 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)
1623 ResultSetEntryGuard aGuard( *this );
1624 OSL_TRACE("moveRelativeToBookmark, bookmark = %u rows= %u", comphelper::getINT32(bookmark),rows );
1625 sal_Int32 nCardNum = comphelper::getINT32(bookmark);
1626 m_nRowPos = getRowForCardNumber(nCardNum);
1627 return seekRow(RELATIVE_POS,rows );
1629 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)
1631 ResultSetEntryGuard aGuard( *this );
1632 OSL_TRACE("compareBookmarks, m_nRowPos = %u", m_nRowPos );
1633 sal_Int32 nFirst=0;
1634 sal_Int32 nSecond=0;
1635 sal_Int32 nResult=0;
1637 if ( !( lhs >>= nFirst ) || !( rhs >>= nSecond ) )
1638 m_pStatement->getOwnConnection()->throwSQLException( STR_INVALID_BOOKMARK, *this );
1640 if(nFirst < nSecond)
1641 nResult = -1;
1642 else if(nFirst > nSecond)
1643 nResult = 1;
1644 else
1645 nResult = 0;
1647 return nResult;
1649 sal_Bool OResultSet::hasOrderedBookmarks( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException)
1651 ResultSetEntryGuard aGuard( *this );
1652 OSL_TRACE("hasOrderedBookmarks, m_nRowPos = %u", m_nRowPos );
1653 return sal_True;
1655 sal_Int32 OResultSet::hashBookmark( const ::com::sun::star::uno::Any& bookmark ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException)
1657 ResultSetEntryGuard aGuard( *this );
1658 OSL_TRACE("hashBookmark, m_nRowPos = %u", m_nRowPos );
1659 return comphelper::getINT32(bookmark);
1662 sal_Int32 OResultSet::getCurrentCardNumber()
1664 if ( ( m_nRowPos == 0 ) || !m_pKeySet.isValid() )
1665 return 0;
1666 if (m_pKeySet->get().size() < m_nRowPos)
1667 return 0;
1668 return (m_pKeySet->get())[m_nRowPos-1];
1670 void OResultSet::checkPendingUpdate() throw(SQLException, RuntimeException)
1672 OSL_TRACE("checkPendingUpdate, m_nRowPos = %u", m_nRowPos );
1673 const sal_Int32 nCurrentRow = getCurrentCardNumber();
1675 if ((m_nNewRow && nCurrentRow != m_nNewRow)
1676 || ( m_nUpdatedRow && m_nUpdatedRow != nCurrentRow))
1678 const ::rtl::OUString sError( m_pStatement->getOwnConnection()->getResources().getResourceStringWithSubstitution(
1679 STR_COMMIT_ROW,
1680 "$position$", ::rtl::OUString::valueOf(nCurrentRow)
1681 ) );
1682 ::dbtools::throwGenericSQLException(sError,*this);
1686 void OResultSet::updateValue(sal_Int32 columnIndex ,const ORowSetValue& x) throw(SQLException, RuntimeException)
1688 OSL_TRACE("updateValue, m_nRowPos = %u", m_nRowPos );
1689 ResultSetEntryGuard aGuard( *this );
1690 if ( fetchCurrentRow() == sal_False )
1691 m_pStatement->getOwnConnection()->throwSQLException( STR_ERROR_GET_ROW, *this );
1694 checkPendingUpdate();
1696 checkIndex(columnIndex );
1697 columnIndex = mapColumn(columnIndex);
1699 (m_aRow->get())[columnIndex].setBound(sal_True);
1700 (m_aRow->get())[columnIndex] = x;
1701 m_nUpdatedRow = getCurrentCardNumber();
1702 m_RowStates = m_RowStates | RowStates_Updated;
1704 // -----------------------------------------------------------------------------
1706 void SAL_CALL OResultSet::updateNull( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
1708 OSL_TRACE("updateNull, m_nRowPos = %u", m_nRowPos );
1709 ResultSetEntryGuard aGuard( *this );
1710 if ( fetchCurrentRow() == sal_False )
1711 m_pStatement->getOwnConnection()->throwSQLException( STR_ERROR_GET_ROW, *this );
1713 checkPendingUpdate();
1714 checkIndex(columnIndex );
1715 columnIndex = mapColumn(columnIndex);
1717 (m_aRow->get())[columnIndex].setBound(sal_True);
1718 (m_aRow->get())[columnIndex].setNull();
1719 m_nUpdatedRow = getCurrentCardNumber();
1720 m_RowStates = m_RowStates | RowStates_Updated;
1722 // -------------------------------------------------------------------------
1724 void SAL_CALL OResultSet::updateBoolean( sal_Int32 columnIndex, sal_Bool x ) throw(SQLException, RuntimeException)
1726 updateValue(columnIndex,x);
1728 // -------------------------------------------------------------------------
1729 void SAL_CALL OResultSet::updateByte( sal_Int32 columnIndex, sal_Int8 x ) throw(SQLException, RuntimeException)
1731 updateValue(columnIndex,x);
1733 // -------------------------------------------------------------------------
1735 void SAL_CALL OResultSet::updateShort( sal_Int32 columnIndex, sal_Int16 x ) throw(SQLException, RuntimeException)
1737 updateValue(columnIndex,x);
1739 // -------------------------------------------------------------------------
1740 void SAL_CALL OResultSet::updateInt( sal_Int32 columnIndex, sal_Int32 x ) throw(SQLException, RuntimeException)
1742 updateValue(columnIndex,x);
1744 // -------------------------------------------------------------------------
1745 void SAL_CALL OResultSet::updateLong( sal_Int32 /*columnIndex*/, sal_Int64 /*x*/ ) throw(SQLException, RuntimeException)
1747 ::dbtools::throwFeatureNotImplementedException( "XRowUpdate::updateLong", *this );
1749 // -----------------------------------------------------------------------
1750 void SAL_CALL OResultSet::updateFloat( sal_Int32 columnIndex, float x ) throw(SQLException, RuntimeException)
1752 updateValue(columnIndex,x);
1754 // -------------------------------------------------------------------------
1756 void SAL_CALL OResultSet::updateDouble( sal_Int32 columnIndex, double x ) throw(SQLException, RuntimeException)
1758 updateValue(columnIndex,x);
1760 // -------------------------------------------------------------------------
1761 void SAL_CALL OResultSet::updateString( sal_Int32 columnIndex, const ::rtl::OUString& x ) throw(SQLException, RuntimeException)
1763 updateValue(columnIndex,x);
1765 // -------------------------------------------------------------------------
1766 void SAL_CALL OResultSet::updateBytes( sal_Int32 columnIndex, const Sequence< sal_Int8 >& x ) throw(SQLException, RuntimeException)
1768 updateValue(columnIndex,x);
1770 // -------------------------------------------------------------------------
1771 void SAL_CALL OResultSet::updateDate( sal_Int32 columnIndex, const ::com::sun::star::util::Date& x ) throw(SQLException, RuntimeException)
1773 updateValue(columnIndex,x);
1775 // -------------------------------------------------------------------------
1777 void SAL_CALL OResultSet::updateTime( sal_Int32 columnIndex, const ::com::sun::star::util::Time& x ) throw(SQLException, RuntimeException)
1779 updateValue(columnIndex,x);
1781 // -------------------------------------------------------------------------
1783 void SAL_CALL OResultSet::updateTimestamp( sal_Int32 columnIndex, const ::com::sun::star::util::DateTime& x ) throw(SQLException, RuntimeException)
1785 updateValue(columnIndex,x);
1787 // -------------------------------------------------------------------------
1789 void SAL_CALL OResultSet::updateBinaryStream( sal_Int32 columnIndex, const Reference< ::com::sun::star::io::XInputStream >& x, sal_Int32 length ) throw(SQLException, RuntimeException)
1791 ResultSetEntryGuard aGuard( *this );
1793 if(!x.is())
1794 ::dbtools::throwFunctionSequenceException(*this);
1796 Sequence<sal_Int8> aSeq;
1797 x->readBytes(aSeq,length);
1798 updateValue(columnIndex,aSeq);
1800 // -------------------------------------------------------------------------
1801 void SAL_CALL OResultSet::updateCharacterStream( sal_Int32 columnIndex, const Reference< ::com::sun::star::io::XInputStream >& x, sal_Int32 length ) throw(SQLException, RuntimeException)
1803 updateBinaryStream(columnIndex,x,length);
1805 // -------------------------------------------------------------------------
1806 void SAL_CALL OResultSet::updateObject( sal_Int32 columnIndex, const Any& x ) throw(SQLException, RuntimeException)
1808 if (!::dbtools::implUpdateObject(this, columnIndex, x))
1810 const ::rtl::OUString sError( m_pStatement->getOwnConnection()->getResources().getResourceStringWithSubstitution(
1811 STR_COLUMN_NOT_UPDATEABLE,
1812 "$position$", ::rtl::OUString::valueOf(columnIndex)
1813 ) );
1814 ::dbtools::throwGenericSQLException(sError,*this);
1815 } // if (!::dbtools::implUpdateObject(this, columnIndex, x))
1817 // -------------------------------------------------------------------------
1819 void SAL_CALL OResultSet::updateNumericObject( sal_Int32 columnIndex, const Any& x, sal_Int32 /*scale*/ ) throw(SQLException, RuntimeException)
1821 if (!::dbtools::implUpdateObject(this, columnIndex, x))
1823 const ::rtl::OUString sError( m_pStatement->getOwnConnection()->getResources().getResourceStringWithSubstitution(
1824 STR_COLUMN_NOT_UPDATEABLE,
1825 "$position$", ::rtl::OUString::valueOf(columnIndex)
1826 ) );
1827 ::dbtools::throwGenericSQLException(sError,*this);
1831 // XResultSetUpdate
1832 // -------------------------------------------------------------------------
1833 void SAL_CALL OResultSet::insertRow( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException)
1835 ResultSetEntryGuard aGuard( *this );
1836 OSL_TRACE("insertRow in, m_nRowPos = %u", m_nRowPos );
1837 m_RowStates = RowStates_Inserted;
1838 updateRow();
1839 m_nOldRowPos = 0;
1840 m_nNewRow = 0;
1841 m_aQuery.setRowStates(getCurrentCardNumber(),m_RowStates);
1842 OSL_TRACE("insertRow out, m_nRowPos = %u", m_nRowPos );
1844 // -------------------------------------------------------------------------
1845 void SAL_CALL OResultSet::updateRow( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException)
1847 OSL_TRACE("updateRow in, m_nRowPos = %u", m_nRowPos );
1848 ResultSetEntryGuard aGuard( *this );
1849 impl_ensureKeySet();
1851 if (!m_nRowPos || m_pKeySet->get().size() < m_nRowPos )
1852 m_pStatement->getOwnConnection()->throwSQLException( STR_INVALID_ROW_UPDATE, *this );
1854 const sal_Int32 nCurrentCard = getCurrentCardNumber();
1856 if (!pushCard(nCurrentCard))
1858 m_RowStates = RowStates_Error;
1859 m_pStatement->getOwnConnection()->throwSQLException( STR_ROW_CAN_NOT_SAVE, *this );
1862 if (!m_aQuery.commitRow(nCurrentCard))
1864 m_RowStates = RowStates_Error;
1865 m_nUpdatedRow = 0;
1866 m_pStatement->getOwnConnection()->throwSQLException( m_aQuery.getError(), *this );
1869 m_nUpdatedRow = 0;
1870 fetchCurrentRow();
1871 OSL_TRACE("updateRow out, m_nRowPos = %u", m_nRowPos );
1873 // -------------------------------------------------------------------------
1874 void SAL_CALL OResultSet::deleteRow( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException)
1876 OSL_TRACE("deleteRow, m_nRowPos = %u", m_nRowPos );
1877 ResultSetEntryGuard aGuard( *this );
1878 if (rowDeleted())
1879 m_pStatement->getOwnConnection()->throwSQLException( STR_ROW_ALREADY_DELETED, *this );
1881 const sal_Int32 nCurrentRow = getCurrentCardNumber();
1882 //fetchRow(nCurrentRow);
1883 if (!nCurrentRow)
1884 m_pStatement->getOwnConnection()->throwSQLException( STR_ERROR_GET_ROW, *this );
1886 sal_Bool m_bRowDeleted = ( m_aQuery.deleteRow( nCurrentRow ) > 0 );
1887 if (!m_bRowDeleted)
1888 m_pStatement->getOwnConnection()->throwSQLException( m_aQuery.getError(), *this );
1890 m_aQuery.setRowStates(nCurrentRow,RowStates_Deleted);
1891 m_pKeySet->get().erase(m_pKeySet->get().begin() + m_nRowPos -1);
1892 m_RowStates = RowStates_Deleted;
1893 OSL_TRACE("deleteRow out, m_nRowPos = %u", m_nRowPos );
1895 // -------------------------------------------------------------------------
1896 void SAL_CALL OResultSet::cancelRowUpdates( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException)
1898 ResultSetEntryGuard aGuard( *this );
1899 OSL_TRACE("cancelRowUpdates, m_nRowPos = %u", m_nRowPos );
1900 if (fetchRow(getCurrentCardNumber(),sal_True)) //force fetch current row will cause we lose all change to the current row
1901 m_pStatement->getOwnConnection()->throwSQLException( STR_CAN_NOT_CANCEL_ROW_UPDATE, *this );
1903 // -------------------------------------------------------------------------
1904 void SAL_CALL OResultSet::moveToInsertRow( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException)
1906 OSL_TRACE("moveToInsertRow in, m_nRowPos = %u", m_nRowPos );
1907 ResultSetEntryGuard aGuard( *this );
1908 m_nOldRowPos = m_nRowPos;
1910 if (!m_nNewRow) //no new row now, insert one
1912 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
1913 checkPendingUpdate();
1914 if (rowUpdated())
1916 if (m_nRowPos && !pushCard(getCurrentCardNumber()))
1917 throw SQLException();
1919 m_nNewRow = m_aQuery.createNewCard();
1920 if (!m_nNewRow)
1921 m_pStatement->getOwnConnection()->throwSQLException( STR_CAN_NOT_CREATE_ROW, *this );
1923 m_RowStates = RowStates_Normal;
1924 fillKeySet(m_nNewRow);
1926 else
1927 m_nUpdatedRow = 0;
1929 m_nRowPos = m_pKeySet->get().size();
1930 fetchCurrentRow();
1931 OSL_TRACE("moveToInsertRow out, m_nRowPos = %u", m_nRowPos );
1933 // -------------------------------------------------------------------------
1934 void SAL_CALL OResultSet::moveToCurrentRow( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException)
1936 ResultSetEntryGuard aGuard( *this );
1937 OSL_TRACE("moveToCurrentRow, m_nRowPos = %u", m_nRowPos );
1938 if (rowInserted())
1940 m_nRowPos = m_nOldRowPos;
1941 fetchCurrentRow();
1945 sal_Bool OResultSet::determineReadOnly()
1947 if (m_bIsReadOnly == -1)
1949 OConnection* xConnection = static_cast<OConnection*>(m_pStatement->getConnection().get());
1950 m_bIsReadOnly = !m_aQuery.isWritable(xConnection) || m_bIsAlwaysFalseQuery;
1953 return m_bIsReadOnly != 0;
1956 void OResultSet::setTable(OTable* _rTable)
1958 OSL_TRACE("In : setTable");
1959 m_pTable = _rTable;
1960 m_pTable->acquire();
1961 m_xTableColumns = m_pTable->getColumns();
1962 if(m_xTableColumns.is())
1963 m_aColumnNames = m_xTableColumns->getElementNames();
1964 OSL_TRACE("Out : setTable");
1967 void OResultSet::setOrderByColumns(const ::std::vector<sal_Int32>& _aColumnOrderBy)
1969 m_aOrderbyColumnNumber = _aColumnOrderBy;
1972 void OResultSet::setOrderByAscending(const ::std::vector<TAscendingOrder>& _aOrderbyAsc)
1974 m_aOrderbyAscending = _aOrderbyAsc;
1976 Sequence< sal_Int32 > SAL_CALL OResultSet::deleteRows( const Sequence< Any >& /*rows*/ ) throw(SQLException, RuntimeException)
1978 ::dbtools::throwFeatureNotImplementedException( "XDeleteRows::deleteRows", *this );
1979 return Sequence< sal_Int32 >();