update dev300-m58
[ooovba.git] / connectivity / source / drivers / evoab2 / NResultSet.cxx
blobc7e6a1617d37092d40d0d78e00acc7cf0e5db9ed
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_connectivity.hxx"
31 #include "NDatabaseMetaData.hxx"
32 #include "NConnection.hxx"
33 #include "NResultSet.hxx"
34 #include "propertyids.hxx"
35 #include "resource/evoab2_res.hrc"
36 #include "TSortIndex.hxx"
37 #include <algorithm>
39 #include <com/sun/star/beans/PropertyAttribute.hpp>
40 #include <com/sun/star/lang/DisposedException.hpp>
41 #include <com/sun/star/sdb/ErrorCondition.hpp>
42 #include <com/sun/star/sdbc/DataType.hpp>
43 #include <com/sun/star/sdbc/FetchDirection.hpp>
44 #include <com/sun/star/sdbc/ResultSetConcurrency.hpp>
45 #include <com/sun/star/sdbc/ResultSetType.hpp>
47 #include <comphelper/componentcontext.hxx>
48 #include <comphelper/extract.hxx>
49 #include <comphelper/property.hxx>
50 #include <comphelper/sequence.hxx>
51 #include <comphelper/types.hxx>
52 #include <connectivity/dbexception.hxx>
53 #include <connectivity/sqlerror.hxx>
54 #include <cppuhelper/typeprovider.hxx>
55 #include <rtl/string.hxx>
56 #include <tools/diagnose_ex.h>
57 #include <svtools/syslocale.hxx>
58 #include <unotools/intlwrapper.hxx>
60 #include <cstring>
61 #include <vector>
63 namespace connectivity { namespace evoab {
65 using namespace ::comphelper;
66 using namespace com::sun::star;
67 using namespace com::sun::star::uno;
68 using namespace com::sun::star::lang;
69 using namespace com::sun::star::beans;
70 using namespace com::sun::star::sdbc;
71 using namespace com::sun::star::sdbcx;
72 using namespace com::sun::star::container;
73 using namespace com::sun::star::io;
74 namespace ErrorCondition = ::com::sun::star::sdb::ErrorCondition;
76 //------------------------------------------------------------------------------
77 ::rtl::OUString SAL_CALL OEvoabResultSet::getImplementationName( ) throw ( RuntimeException) \
79 return ::rtl::OUString::createFromAscii("com.sun.star.sdbcx.evoab.ResultSet");
81 // -------------------------------------------------------------------------
82 Sequence< ::rtl::OUString > SAL_CALL OEvoabResultSet::getSupportedServiceNames( ) throw( RuntimeException)
84 Sequence< ::rtl::OUString > aSupported(1);
85 aSupported[0] = ::rtl::OUString::createFromAscii("com.sun.star.sdbc.ResultSet");
86 return aSupported;
88 // -------------------------------------------------------------------------
89 sal_Bool SAL_CALL OEvoabResultSet::supportsService( const ::rtl::OUString& _rServiceName ) throw( RuntimeException)
91 Sequence< ::rtl::OUString > aSupported(getSupportedServiceNames());
92 const ::rtl::OUString* pSupported = aSupported.getConstArray();
93 const ::rtl::OUString* pEnd = pSupported + aSupported.getLength();
94 for (;pSupported != pEnd && !pSupported->equals(_rServiceName); ++pSupported)
97 return pSupported != pEnd;
100 // -------------------------------------------------------------------------
101 OEvoabResultSet::OEvoabResultSet( OCommonStatement* pStmt, OEvoabConnection *pConnection )
102 :OResultSet_BASE(m_aMutex)
103 ,::comphelper::OPropertyContainer( OResultSet_BASE::rBHelper )
104 ,m_pStatement(pStmt)
105 ,m_pConnection(pConnection)
106 ,m_xMetaData(NULL)
107 ,m_bWasNull(sal_True)
108 ,m_nFetchSize(0)
109 ,m_nResultSetType(ResultSetType::SCROLL_INSENSITIVE)
110 ,m_nFetchDirection(FetchDirection::FORWARD)
111 ,m_nResultSetConcurrency(ResultSetConcurrency::READ_ONLY)
112 ,m_pContacts(NULL)
113 ,m_nIndex(-1)
114 ,m_nLength(0)
116 #define REGISTER_PROP( id, member ) \
117 registerProperty( \
118 OMetaConnection::getPropMap().getNameByIndex( id ), \
119 id, \
120 PropertyAttribute::READONLY, \
121 &member, \
122 ::getCppuType( &member ) \
125 REGISTER_PROP( PROPERTY_ID_FETCHSIZE, m_nFetchSize );
126 REGISTER_PROP( PROPERTY_ID_RESULTSETTYPE, m_nResultSetType );
127 REGISTER_PROP( PROPERTY_ID_FETCHDIRECTION, m_nFetchDirection );
128 REGISTER_PROP( PROPERTY_ID_RESULTSETCONCURRENCY, m_nResultSetConcurrency );
131 // -------------------------------------------------------------------------
132 OEvoabResultSet::~OEvoabResultSet()
136 // -------------------------------------------------------------------------
138 static ESource *
139 findSource( const char *name )
141 ESourceList *pSourceList = NULL;
143 g_return_val_if_fail (name != NULL, NULL);
145 if (!e_book_get_addressbooks (&pSourceList, NULL))
146 pSourceList = NULL;
148 for ( GSList *g = e_source_list_peek_groups (pSourceList); g; g = g->next)
150 for (GSList *s = e_source_group_peek_sources (E_SOURCE_GROUP (g->data)); s; s = s->next)
152 ESource *pSource = E_SOURCE (s->data);
153 if (!strcmp (e_source_peek_name (pSource), name))
154 return pSource;
157 return NULL;
160 static EBook *
161 openBook( const char *abname )
163 ESource *pSource = findSource (abname);
164 EBook *pBook = NULL;
165 if (pSource)
166 pBook = e_book_new (pSource, NULL);
168 if (pBook && !e_book_open (pBook, TRUE, NULL))
170 g_object_unref (G_OBJECT (pBook));
171 pBook = NULL;
174 return pBook;
177 static bool isLDAP( EBook *pBook )
179 return pBook && !strncmp( "ldap://", e_book_get_uri( pBook ), 6 );
182 static bool isLocal( EBook *pBook )
184 return pBook && !strncmp( "file://", e_book_get_uri( pBook ), 6 );
187 static bool isAuthRequired( EBook *pBook )
189 return e_source_get_property( e_book_get_source( pBook ),
190 "auth" ) != NULL;
193 static rtl::OString getUserName( EBook *pBook )
195 rtl::OString aName;
196 if( isLDAP( pBook ) )
197 aName = e_source_get_property( e_book_get_source( pBook ), "binddn" );
198 else
199 aName = e_source_get_property( e_book_get_source( pBook ), "user" );
200 return aName;
203 static ::rtl::OUString
204 valueToOUString( GValue& _rValue )
206 const char *pStr = g_value_get_string( &_rValue );
207 rtl::OString aStr( pStr ? pStr : "" );
208 ::rtl::OUString sResult( ::rtl::OStringToOUString( aStr, RTL_TEXTENCODING_UTF8 ) );
209 g_value_unset( &_rValue );
210 return sResult;
213 static bool
214 valueToBool( GValue& _rValue )
216 bool bResult = g_value_get_boolean( &_rValue );
217 g_value_unset( &_rValue );
218 return bResult;
221 static bool
222 executeQuery (EBook* pBook, EBookQuery* pQuery, GList **ppList,
223 rtl::OString &rPassword, GError **pError)
225 ESource *pSource = e_book_get_source( pBook );
226 bool bSuccess = false;
227 bool bAuthSuccess = true;
229 *ppList = NULL;
231 if( isAuthRequired( pBook ) )
233 rtl::OString aUser( getUserName( pBook ) );
234 const char *pAuth = e_source_get_property( pSource, "auth" );
235 bAuthSuccess = e_book_authenticate_user( pBook, aUser, rPassword, pAuth, pError );
238 if (bAuthSuccess)
239 bSuccess = e_book_get_contacts( pBook, pQuery, ppList, pError );
241 return bSuccess;
244 static int
245 whichAddress(int value)
247 int fieldEnum;
248 switch (value)
250 case HOME_ADDR_LINE1:
251 case HOME_ADDR_LINE2:
252 case HOME_CITY:
253 case HOME_STATE:
254 case HOME_COUNTRY:
255 case HOME_ZIP:
256 fieldEnum = e_contact_field_id("address_home");
257 break;
259 case WORK_ADDR_LINE1:
260 case WORK_ADDR_LINE2:
261 case WORK_CITY:
262 case WORK_STATE:
263 case WORK_COUNTRY:
264 case WORK_ZIP:
265 fieldEnum = e_contact_field_id("address_work");
266 break;
268 case OTHER_ADDR_LINE1:
269 case OTHER_ADDR_LINE2:
270 case OTHER_CITY:
271 case OTHER_STATE:
272 case OTHER_COUNTRY:
273 case OTHER_ZIP:
274 fieldEnum = e_contact_field_id("address_other");
275 break;
277 default: fieldEnum = e_contact_field_id("address_home");
279 return fieldEnum;
283 * This function decides the default column values based on the first field of EContactAddress.
284 * The search order is Work->Home->other(defaults).
286 static EContactAddress *
287 getDefaultContactAddress( EContact *pContact,int *value )
289 EContactAddress *ec = (EContactAddress *)e_contact_get(pContact,whichAddress(WORK_ADDR_LINE1));
290 if ( ec && (strlen(ec->street)>0) )
292 *value= *value +WORK_ADDR_LINE1 -1;
293 return ec;
295 else
297 ec = (EContactAddress *)e_contact_get(pContact,whichAddress(HOME_ADDR_LINE1));
298 if ( ec && (strlen(ec->street)>0) )
300 *value=*value+HOME_ADDR_LINE1-1;
301 return ec;
305 *value=*value+OTHER_ADDR_LINE1-1;
306 return (EContactAddress *)e_contact_get(pContact,whichAddress(OTHER_ADDR_LINE1));
309 static EContactAddress*
310 getContactAddress( EContact *pContact, int * address_enum )
312 EContactAddress *ec = NULL;
313 switch (*address_enum) {
315 case DEFAULT_ADDR_LINE1:
316 case DEFAULT_ADDR_LINE2:
317 case DEFAULT_CITY:
318 case DEFAULT_STATE:
319 case DEFAULT_COUNTRY:
320 case DEFAULT_ZIP:
321 ec = getDefaultContactAddress(pContact,address_enum);break;
322 default:
323 ec = (EContactAddress *)e_contact_get(pContact,whichAddress(*address_enum));
325 return ec;
328 static bool
329 handleSplitAddress( EContact *pContact,GValue *pStackValue, int value )
331 EContactAddress *ec = getContactAddress(pContact,&value) ;
333 if (ec==NULL)
334 return true;
336 switch (value) {
337 case WORK_ADDR_LINE1:
338 g_value_set_string(pStackValue,ec->street ); break;
339 case WORK_ADDR_LINE2:
340 g_value_set_string(pStackValue,ec->po ); break;
341 case WORK_CITY:
342 g_value_set_string(pStackValue,ec->locality ); break;
343 case WORK_STATE:
344 g_value_set_string(pStackValue,ec->region ); break;
345 case WORK_COUNTRY:
346 g_value_set_string(pStackValue,ec->country ); break;
347 case WORK_ZIP:
348 g_value_set_string(pStackValue,ec->code ); break;
350 case HOME_ADDR_LINE1:
351 g_value_set_string(pStackValue,ec->street ); break;
352 case HOME_ADDR_LINE2:
353 g_value_set_string(pStackValue,ec->po ); break;
354 case HOME_CITY:
355 g_value_set_string(pStackValue,ec->locality ); break;
356 case HOME_STATE:
357 g_value_set_string(pStackValue,ec->region ); break;
358 case HOME_COUNTRY:
359 g_value_set_string(pStackValue,ec->country ); break;
360 case HOME_ZIP:
361 g_value_set_string(pStackValue,ec->code ); break;
363 case OTHER_ADDR_LINE1:
364 g_value_set_string(pStackValue,ec->street ); break;
365 case OTHER_ADDR_LINE2:
366 g_value_set_string(pStackValue,ec->po ); break;
367 case OTHER_CITY:
368 g_value_set_string(pStackValue,ec->locality ); break;
369 case OTHER_STATE:
370 g_value_set_string(pStackValue,ec->region ); break;
371 case OTHER_COUNTRY:
372 g_value_set_string(pStackValue,ec->country ); break;
373 case OTHER_ZIP:
374 g_value_set_string(pStackValue,ec->code ); break;
378 return false;
380 static bool
381 getValue( EContact* pContact, sal_Int32 nColumnNum, GType nType, GValue* pStackValue, bool& _out_rWasNull )
383 const ColumnProperty * pSpecs = evoab::getField( nColumnNum );
384 if ( !pSpecs )
385 return false;
387 GParamSpec* pSpec = pSpecs->pField;
388 gboolean bIsSplittedColumn = pSpecs->bIsSplittedValue;
390 _out_rWasNull = true;
391 if ( !pSpec || !pContact)
392 return false;
394 if ( G_PARAM_SPEC_VALUE_TYPE (pSpec) != nType )
397 OSL_TRACE( "Wrong type (0x%x) (0x%x) '%s'",
398 (int)G_PARAM_SPEC_VALUE_TYPE (pSpec), (int) nType,
399 pSpec->name ? pSpec->name : "<noname>");
400 return false;
403 g_value_init( pStackValue, nType );
404 if ( bIsSplittedColumn )
406 const SplitEvoColumns* evo_addr( get_evo_addr() );
407 for (int i=0;i<OTHER_ZIP;i++)
409 if (0 == strcmp (g_param_spec_get_name ((GParamSpec *)pSpec), evo_addr[i].pColumnName))
411 _out_rWasNull = handleSplitAddress( pContact, pStackValue, evo_addr[i].value );
412 return true;
416 else
418 g_object_get_property( G_OBJECT (pContact),
419 g_param_spec_get_name ((GParamSpec *) pSpec),
420 pStackValue );
421 if ( G_VALUE_TYPE( pStackValue ) != nType )
423 OSL_TRACE( "Fetched type mismatch" );
424 g_value_unset( pStackValue );
425 return false;
428 _out_rWasNull = false;
429 return true;
432 namespace
434 struct ComparisonData
436 const SortDescriptor& rSortOrder;
437 IntlWrapper aIntlWrapper;
439 ComparisonData( const SortDescriptor& _rSortOrder, const Reference< XMultiServiceFactory >& _rxFactory )
440 :rSortOrder( _rSortOrder )
441 ,aIntlWrapper( _rxFactory, SvtSysLocale().GetLocaleData().getLocale() )
447 extern "C"
448 int CompareContacts( gconstpointer _lhs, gconstpointer _rhs, gpointer _userData )
450 EContact* lhs = static_cast< EContact* >( const_cast< gpointer >( _lhs ) );
451 EContact* rhs = static_cast< EContact* >( const_cast< gpointer >( _rhs ) );
453 GValue aLhsValue = { 0, { { 0 } } };
454 GValue aRhsValue = { 0, { { 0 } } };
455 bool bLhsNull = true;
456 bool bRhsNull = true;
458 ::rtl::OUString sLhs, sRhs;
459 bool bLhs(false), bRhs(false);
461 const ComparisonData& rCompData = *static_cast< const ComparisonData* >( _userData );
462 for ( SortDescriptor::const_iterator sortCol = rCompData.rSortOrder.begin();
463 sortCol != rCompData.rSortOrder.end();
464 ++sortCol
467 sal_Int32 nField = sortCol->nField;
468 GType eFieldType = evoab::getGFieldType( nField );
470 bool success = getValue( lhs, nField, eFieldType, &aLhsValue, bLhsNull )
471 && getValue( rhs, nField, eFieldType, &aRhsValue, bRhsNull );
472 OSL_ENSURE( success, "CompareContacts: could not retrieve both values!" );
473 if ( !success )
474 return 0;
476 if ( bLhsNull && !bRhsNull )
477 return -1;
478 if ( !bLhsNull && bRhsNull )
479 return 1;
480 if ( bLhsNull && bRhsNull )
481 continue;
483 if ( eFieldType == G_TYPE_STRING )
485 sLhs = valueToOUString( aLhsValue );
486 sRhs = valueToOUString( aRhsValue );
487 sal_Int32 nCompResult = rCompData.aIntlWrapper.getCaseCollator()->compareString( sLhs, sRhs );
488 if ( nCompResult != 0 )
489 return nCompResult;
490 continue;
493 bLhs = valueToBool( aLhsValue );
494 bRhs = valueToBool( aRhsValue );
495 if ( bLhs && !bRhs )
496 return -1;
497 if ( !bLhs && bRhs )
498 return 1;
499 continue;
502 return 0;
505 static GList*
506 sortContacts( GList* _pContactList, const ComparisonData& _rCompData )
508 OSL_ENSURE( !_rCompData.rSortOrder.empty(), "sortContacts: no need to call this without any sort order!" );
509 ENSURE_OR_THROW( _rCompData.aIntlWrapper.getCaseCollator(), "no collator for comparing strings" );
511 return g_list_sort_with_data( _pContactList, &CompareContacts, const_cast< gpointer >( static_cast< gconstpointer >( &_rCompData ) ) );
514 // -------------------------------------------------------------------------
515 void OEvoabResultSet::construct( const QueryData& _rData )
517 ENSURE_OR_THROW( _rData.getQuery(), "internal error: no EBookQuery" );
519 EBook *pBook = openBook( ::rtl::OUStringToOString( _rData.sTable, RTL_TEXTENCODING_UTF8 ) );
520 if ( !pBook )
521 m_pConnection->throwGenericSQLException( STR_CANNOT_OPEN_BOOK, *this );
523 g_list_free(m_pContacts);
524 m_pContacts = NULL;
525 bool bExecuteQuery = true;
526 switch ( _rData.eFilterType )
528 case eFilterNone:
529 if ( !isLocal( pBook ) )
531 SQLError aErrorFactory( m_pConnection->getDriver().getMSFactory() );
532 SQLException aAsException = aErrorFactory.getSQLException( ErrorCondition::DATA_CANNOT_SELECT_UNFILTERED, *this );
533 m_aWarnings.appendWarning( SQLWarning(
534 aAsException.Message,
535 aAsException.Context,
536 aAsException.SQLState,
537 aAsException.ErrorCode,
538 aAsException.NextException
539 ) );
540 bExecuteQuery = false;
542 break;
543 case eFilterAlwaysFalse:
544 bExecuteQuery = false;
545 break;
546 case eFilterOther:
547 bExecuteQuery = true;
548 break;
550 if ( bExecuteQuery )
552 rtl::OString aPassword = m_pConnection->getPassword();
553 executeQuery( pBook, _rData.getQuery(), &m_pContacts, aPassword, NULL );
554 m_pConnection->setPassword( aPassword );
556 if ( m_pContacts && !_rData.aSortOrder.empty() )
558 ComparisonData aCompData( _rData.aSortOrder, getConnection()->getDriver().getMSFactory() );
559 m_pContacts = sortContacts( m_pContacts, aCompData );
562 m_nLength = g_list_length( m_pContacts );
563 OSL_TRACE( "Query return %d records", m_nLength );
564 m_nIndex = -1;
566 // create our meta data (need the EBookQuery for this)
567 OEvoabResultSetMetaData* pMeta = new OEvoabResultSetMetaData( _rData.sTable );
568 m_xMetaData = pMeta;
570 pMeta->setEvoabFields( _rData.xSelectColumns );
573 // -------------------------------------------------------------------------
574 void OEvoabResultSet::disposing(void)
576 ::comphelper::OPropertyContainer::disposing();
578 ::osl::MutexGuard aGuard(m_aMutex);
579 g_list_free(m_pContacts);
580 m_pContacts = NULL;
581 m_pStatement = NULL;
582 m_xMetaData.clear();
584 // -------------------------------------------------------------------------
585 Any SAL_CALL OEvoabResultSet::queryInterface( const Type & rType ) throw(RuntimeException)
587 Any aRet = ::comphelper::OPropertyContainer::queryInterface(rType);
588 if(!aRet.hasValue())
589 aRet = OResultSet_BASE::queryInterface(rType);
590 return aRet;
592 // -------------------------------------------------------------------------
593 Sequence< Type > SAL_CALL OEvoabResultSet::getTypes( ) throw( RuntimeException)
595 return ::comphelper::concatSequences(
596 OResultSet_BASE::getTypes(),
597 ::comphelper::OPropertyContainer::getTypes()
601 // -------------------------------------------------------------------------
602 // XRow Interface
605 * getString:
606 * @nColumnNum: The column index from the table.
608 * If the equivalent NResultSetMetaData.cxx marks the columntype of
609 * nColumnNum as DataType::VARCHAR this accessor is used.
611 ::rtl::OUString SAL_CALL OEvoabResultSet::getString( sal_Int32 nColumnNum ) throw(SQLException, RuntimeException)
613 ::osl::MutexGuard aGuard( m_aMutex );
614 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
615 rtl::OUString aResult;
616 if ( m_xMetaData.is())
618 OEvoabResultSetMetaData *pMeta = (OEvoabResultSetMetaData *) m_xMetaData.get();
619 sal_Int32 nFieldNumber = pMeta->fieldAtColumn(nColumnNum);
620 GValue aValue = { 0, { { 0 } } };
621 if ( getValue( getCur(), nFieldNumber, G_TYPE_STRING, &aValue, m_bWasNull ) )
622 aResult = valueToOUString( aValue );
624 return aResult;
626 // -------------------------------------------------------------------------
627 sal_Bool SAL_CALL OEvoabResultSet::getBoolean( sal_Int32 nColumnNum ) throw(SQLException, RuntimeException)
629 ::osl::MutexGuard aGuard( m_aMutex );
630 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
631 sal_Bool bResult = sal_False;
633 if ( m_xMetaData.is())
635 OEvoabResultSetMetaData *pMeta = (OEvoabResultSetMetaData *) m_xMetaData.get();
636 sal_Int32 nFieldNumber = pMeta->fieldAtColumn(nColumnNum);
637 GValue aValue = { 0, { { 0 } } };
638 if ( getValue( getCur(), nFieldNumber, G_TYPE_BOOLEAN, &aValue, m_bWasNull ) )
639 bResult = valueToBool( aValue );
641 return bResult ? sal_True : sal_False;
643 // -------------------------------------------------------------------------
644 sal_Int64 SAL_CALL OEvoabResultSet::getLong( sal_Int32 /*nColumnNum*/ ) throw(SQLException, RuntimeException)
646 ::dbtools::throwFunctionNotSupportedException( "XRow::getLong", *this );
647 return sal_Int64();
649 // -------------------------------------------------------------------------
650 Reference< XArray > SAL_CALL OEvoabResultSet::getArray( sal_Int32 /*nColumnNum*/ ) throw(SQLException, RuntimeException)
652 ::dbtools::throwFunctionNotSupportedException( "XRow::getArray", *this );
653 return NULL;
655 // -------------------------------------------------------------------------
656 Reference< XClob > SAL_CALL OEvoabResultSet::getClob( sal_Int32 /*nColumnNum*/ ) throw(SQLException, RuntimeException)
658 ::dbtools::throwFunctionNotSupportedException( "XRow::getClob", *this );
659 return NULL;
661 // -------------------------------------------------------------------------
662 Reference< XBlob > SAL_CALL OEvoabResultSet::getBlob( sal_Int32 /*nColumnNum*/ ) throw(SQLException, RuntimeException)
664 ::dbtools::throwFunctionNotSupportedException( "XRow::getBlob", *this );
665 return NULL;
667 // -------------------------------------------------------------------------
668 Reference< XRef > SAL_CALL OEvoabResultSet::getRef( sal_Int32 /*nColumnNum*/ ) throw(SQLException, RuntimeException)
670 ::dbtools::throwFunctionNotSupportedException( "XRow::getRef", *this );
671 return NULL;
673 // -------------------------------------------------------------------------
674 Any SAL_CALL OEvoabResultSet::getObject( sal_Int32 /*nColumnNum*/, const Reference< ::com::sun::star::container::XNameAccess >& /*typeMap*/ ) throw(SQLException, RuntimeException)
676 ::dbtools::throwFunctionNotSupportedException( "XRow::getObject", *this );
677 return Any();
679 // -------------------------------------------------------------------------
680 sal_Int16 SAL_CALL OEvoabResultSet::getShort( sal_Int32 /*nColumnNum*/ ) throw(SQLException, RuntimeException)
682 ::dbtools::throwFunctionNotSupportedException( "XRow::getShort", *this );
683 return 0;
685 // -------------------------------------------------------------------------
686 ::com::sun::star::util::Time SAL_CALL OEvoabResultSet::getTime( sal_Int32 /*nColumnNum*/ ) throw(SQLException, RuntimeException)
688 ::dbtools::throwFunctionNotSupportedException( "XRow::getTime", *this );
689 return ::com::sun::star::util::Time();
691 // -------------------------------------------------------------------------
692 util::DateTime SAL_CALL OEvoabResultSet::getTimestamp( sal_Int32 /*nColumnNum*/ ) throw(SQLException, RuntimeException)
694 ::dbtools::throwFunctionNotSupportedException( "XRow::getTimestamp", *this );
695 return ::com::sun::star::util::DateTime();
697 // -------------------------------------------------------------------------
698 Reference< XInputStream > SAL_CALL OEvoabResultSet::getBinaryStream( sal_Int32 /*nColumnNum*/ ) throw(SQLException, RuntimeException)
700 ::dbtools::throwFunctionNotSupportedException( "XRow::getBinaryStream", *this );
701 return NULL;
703 // -------------------------------------------------------------------------
704 Reference< XInputStream > SAL_CALL OEvoabResultSet::getCharacterStream( sal_Int32 /*nColumnNum*/ ) throw(SQLException, RuntimeException)
706 ::dbtools::throwFunctionNotSupportedException( "XRow::getCharacterStream", *this );
707 return NULL;
709 // -------------------------------------------------------------------------
710 sal_Int8 SAL_CALL OEvoabResultSet::getByte( sal_Int32 /*nColumnNum*/ ) throw(SQLException, RuntimeException)
712 ::dbtools::throwFunctionNotSupportedException( "XRow::getByte", *this );
713 return 0;
715 // -------------------------------------------------------------------------
716 Sequence< sal_Int8 > SAL_CALL OEvoabResultSet::getBytes( sal_Int32 /*nColumnNum*/ ) throw(SQLException, RuntimeException)
718 ::dbtools::throwFunctionNotSupportedException( "XRow::getBytes", *this );
719 return Sequence< sal_Int8 >();
721 // -------------------------------------------------------------------------
722 ::com::sun::star::util::Date SAL_CALL OEvoabResultSet::getDate( sal_Int32 /*nColumnNum*/ ) throw(SQLException, RuntimeException)
724 ::dbtools::throwFunctionNotSupportedException( "XRow::getDate", *this );
725 return ::com::sun::star::util::Date();
727 // -------------------------------------------------------------------------
728 double SAL_CALL OEvoabResultSet::getDouble( sal_Int32 /*nColumnNum*/ ) throw(SQLException, RuntimeException)
730 ::dbtools::throwFunctionNotSupportedException( "XRow::getDouble", *this );
731 return 0;
733 // -------------------------------------------------------------------------
734 float SAL_CALL OEvoabResultSet::getFloat( sal_Int32 /*nColumnNum*/ ) throw(SQLException, RuntimeException)
736 ::dbtools::throwFunctionNotSupportedException( "XRow::getFloat", *this );
737 return 0;
739 // -------------------------------------------------------------------------
740 sal_Int32 SAL_CALL OEvoabResultSet::getInt( sal_Int32 /*nColumnNum*/ ) throw(SQLException, RuntimeException)
742 ::dbtools::throwFunctionNotSupportedException( "XRow::getInt", *this );
743 return 0;
745 // XRow Interface Ends
746 // -------------------------------------------------------------------------
748 // XResultSetMetaDataSupplier Interface
749 Reference< XResultSetMetaData > SAL_CALL OEvoabResultSet::getMetaData( ) throw(SQLException, RuntimeException)
751 ::osl::MutexGuard aGuard( m_aMutex );
752 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
754 // the meta data should have been created at construction time
755 ENSURE_OR_THROW( m_xMetaData.is(), "internal error: no meta data" );
756 return m_xMetaData;
758 // XResultSetMetaDataSupplier Interface Ends
759 // -------------------------------------------------------------------------
761 // XResultSet Interface
762 sal_Bool SAL_CALL OEvoabResultSet::next( ) throw(SQLException, RuntimeException)
764 ::osl::MutexGuard aGuard( m_aMutex );
765 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
766 if (m_nIndex+1 < m_nLength) {
767 ++m_nIndex ;
768 return true;
770 else
771 return false;
773 // -------------------------------------------------------------------------
774 sal_Bool SAL_CALL OEvoabResultSet::wasNull( ) throw(SQLException, RuntimeException)
776 ::osl::MutexGuard aGuard( m_aMutex );
777 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
779 return m_bWasNull;
781 // -------------------------------------------------------------------------
782 sal_Bool SAL_CALL OEvoabResultSet::isBeforeFirst( ) throw(SQLException, RuntimeException)
784 ::osl::MutexGuard aGuard( m_aMutex );
785 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
787 return m_nIndex < 0;
789 // -------------------------------------------------------------------------
790 sal_Int32 SAL_CALL OEvoabResultSet::getRow( ) throw(SQLException, RuntimeException)
792 ::osl::MutexGuard aGuard( m_aMutex );
793 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
795 return m_nIndex;
797 // -------------------------------------------------------------------------
798 sal_Bool SAL_CALL OEvoabResultSet::isAfterLast( ) throw(SQLException, RuntimeException)
800 ::osl::MutexGuard aGuard( m_aMutex );
801 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
803 return m_nIndex >= m_nLength;
805 // -------------------------------------------------------------------------
806 sal_Bool SAL_CALL OEvoabResultSet::isFirst( ) throw(SQLException, RuntimeException)
808 ::osl::MutexGuard aGuard( m_aMutex );
809 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
811 return m_nIndex == 0;
813 // -------------------------------------------------------------------------
814 sal_Bool SAL_CALL OEvoabResultSet::isLast( ) throw(SQLException, RuntimeException)
816 ::osl::MutexGuard aGuard( m_aMutex );
817 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
819 return m_nIndex == m_nLength - 1;
821 // -------------------------------------------------------------------------
822 void SAL_CALL OEvoabResultSet::beforeFirst( ) throw(SQLException, RuntimeException)
824 ::osl::MutexGuard aGuard( m_aMutex );
825 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
827 m_nIndex = -1;
829 // -------------------------------------------------------------------------
830 void SAL_CALL OEvoabResultSet::afterLast( ) throw(SQLException, RuntimeException)
832 ::osl::MutexGuard aGuard( m_aMutex );
833 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
835 m_nIndex = m_nLength;
837 // -------------------------------------------------------------------------
839 sal_Bool SAL_CALL OEvoabResultSet::first( ) throw(SQLException, RuntimeException)
841 ::osl::MutexGuard aGuard( m_aMutex );
842 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
844 m_nIndex = 0;
845 return true;
847 // -------------------------------------------------------------------------
849 sal_Bool SAL_CALL OEvoabResultSet::last( ) throw(SQLException, RuntimeException)
851 ::osl::MutexGuard aGuard( m_aMutex );
852 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
854 m_nIndex = m_nLength - 1;
855 return true;
857 // -------------------------------------------------------------------------
858 sal_Bool SAL_CALL OEvoabResultSet::absolute( sal_Int32 row ) throw(SQLException, RuntimeException)
860 ::osl::MutexGuard aGuard( m_aMutex );
861 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
862 if (row < m_nLength) {
863 m_nIndex = row;
864 return true;
866 else
867 return false;
869 // -------------------------------------------------------------------------
870 sal_Bool SAL_CALL OEvoabResultSet::relative( sal_Int32 row ) throw(SQLException, RuntimeException)
872 ::osl::MutexGuard aGuard( m_aMutex );
873 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
875 if ((m_nIndex+row) < m_nLength) {
876 m_nIndex += row;
877 return true;
879 else
880 return false;
882 // -------------------------------------------------------------------------
883 sal_Bool SAL_CALL OEvoabResultSet::previous( ) throw(SQLException, RuntimeException)
885 ::osl::MutexGuard aGuard( m_aMutex );
886 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
888 if(m_nIndex > 0) {
889 m_nIndex--;
890 return true;
892 else
893 return false;
895 // -------------------------------------------------------------------------
896 Reference< XInterface > SAL_CALL OEvoabResultSet::getStatement( ) throw(SQLException, RuntimeException)
898 ::osl::MutexGuard aGuard( m_aMutex );
899 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
900 ::com::sun::star::uno::WeakReferenceHelper aStatement((OWeakObject*)m_pStatement);
901 return aStatement.get();
903 // -------------------------------------------------------------------------
905 sal_Bool SAL_CALL OEvoabResultSet::rowDeleted( ) throw(SQLException, RuntimeException)
907 ::osl::MutexGuard aGuard( m_aMutex );
908 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
910 return sal_False;
912 // -------------------------------------------------------------------------
913 sal_Bool SAL_CALL OEvoabResultSet::rowInserted( ) throw(SQLException, RuntimeException)
915 ::osl::MutexGuard aGuard( m_aMutex );
916 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
918 return sal_False;
920 // -------------------------------------------------------------------------
921 sal_Bool SAL_CALL OEvoabResultSet::rowUpdated( ) throw(SQLException, RuntimeException)
923 ::osl::MutexGuard aGuard( m_aMutex );
924 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
926 return sal_False;
928 // -------------------------------------------------------------------------
929 void SAL_CALL OEvoabResultSet::refreshRow( ) throw(SQLException, RuntimeException)
931 ::osl::MutexGuard aGuard( m_aMutex );
932 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
934 //XResult Interface ends
935 // -------------------------------------------------------------------------
936 // XCancellable
938 void SAL_CALL OEvoabResultSet::cancel( ) throw(RuntimeException)
940 ::osl::MutexGuard aGuard( m_aMutex );
941 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
942 OSL_TRACE("In/Out: OEvoabResultSet::cancel" );
946 //XCloseable
947 void SAL_CALL OEvoabResultSet::close( ) throw(SQLException, RuntimeException)
950 ::osl::MutexGuard aGuard( m_aMutex );
951 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
953 OSL_TRACE("In/Out: OEvoabResultSet::close" );
954 dispose();
957 // XWarningsSupplier
958 // -------------------------------------------------------------------------
959 void SAL_CALL OEvoabResultSet::clearWarnings( ) throw(SQLException, RuntimeException)
961 OSL_TRACE("In/Out: OEvoabResultSet::clearWarnings" );
962 m_aWarnings.clearWarnings();
964 // -------------------------------------------------------------------------
965 Any SAL_CALL OEvoabResultSet::getWarnings( ) throw(SQLException, RuntimeException)
967 OSL_TRACE("In/Out: OEvoabResultSet::getWarnings" );
968 return m_aWarnings.getWarnings();
970 // -------------------------------------------------------------------------
971 //XColumnLocate Interface
972 sal_Int32 SAL_CALL OEvoabResultSet::findColumn( const ::rtl::OUString& columnName ) throw(SQLException, RuntimeException)
974 ::osl::MutexGuard aGuard( m_aMutex );
975 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
977 // find the first column with the name columnName
978 Reference< XResultSetMetaData > xMeta = getMetaData();
979 sal_Int32 nLen = xMeta->getColumnCount();
980 sal_Int32 i = 1;
981 for(;i<=nLen;++i)
982 if(xMeta->isCaseSensitive(i) ? columnName == xMeta->getColumnName(i) :
983 columnName.equalsIgnoreAsciiCase(xMeta->getColumnName(i)))
984 break;
985 return i;
987 // -------------------------------------------------------------------------
988 //XColumnLocate interface ends
990 // -------------------------------------------------------------------------
991 ::cppu::IPropertyArrayHelper* OEvoabResultSet::createArrayHelper( ) const
993 Sequence< Property > aProps;
994 describeProperties( aProps );
995 return new ::cppu::OPropertyArrayHelper( aProps );
997 // -------------------------------------------------------------------------
998 ::cppu::IPropertyArrayHelper & OEvoabResultSet::getInfoHelper()
1000 return *const_cast<OEvoabResultSet*>(this)->getArrayHelper();
1002 // -----------------------------------------------------------------------------
1003 void SAL_CALL OEvoabResultSet::acquire() throw()
1005 OResultSet_BASE::acquire();
1007 // -----------------------------------------------------------------------------
1008 void SAL_CALL OEvoabResultSet::release() throw()
1010 OResultSet_BASE::release();
1012 // -----------------------------------------------------------------------------
1013 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL
1014 OEvoabResultSet::getPropertySetInfo( ) throw(::com::sun::star::uno::RuntimeException)
1016 return ::cppu::OPropertySetHelper::createPropertySetInfo(getInfoHelper());
1018 // -----------------------------------------------------------------------------
1020 } } // connectivity::evoab