Update ooo320-m1
[ooovba.git] / connectivity / source / drivers / ado / AResultSet.cxx
blob10295db9a49bff3c94ca89050dab57386a2316f9
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: AResultSet.cxx,v $
10 * $Revision: 1.24 $
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 "ado/AResultSet.hxx"
34 #include "ado/AResultSetMetaData.hxx"
35 #include <com/sun/star/sdbc/DataType.hpp>
36 #include <com/sun/star/sdbc/KeyRule.hpp>
37 #include <com/sun/star/sdbc/IndexType.hpp>
38 #include <comphelper/property.hxx>
39 #include <com/sun/star/lang/DisposedException.hpp>
40 #include <com/sun/star/sdbc/ResultSetConcurrency.hpp>
41 #include <com/sun/star/sdbc/ResultSetType.hpp>
42 #include <com/sun/star/sdbc/FetchDirection.hpp>
43 #include <cppuhelper/typeprovider.hxx>
44 #include <comphelper/sequence.hxx>
45 #include <com/sun/star/beans/PropertyAttribute.hpp>
46 #include <comphelper/seqstream.hxx>
47 #include "connectivity/dbexception.hxx"
48 #include "connectivity/dbtools.hxx"
49 #include <comphelper/types.hxx>
51 using namespace ::comphelper;
54 #include <oledb.h>
56 #define CHECK_RETURN(x) \
57 if(!SUCCEEDED(x)) \
58 ADOS::ThrowException(*m_pStmt->m_pConnection->getConnection(),*this);
60 using namespace connectivity::ado;
61 using namespace com::sun::star::uno;
62 using namespace com::sun::star::lang;
63 using namespace com::sun::star::beans;
64 using namespace com::sun::star::sdbc;
66 //------------------------------------------------------------------------------
67 // IMPLEMENT_SERVICE_INFO(OResultSet,"com.sun.star.sdbcx.AResultSet","com.sun.star.sdbc.ResultSet");
68 ::rtl::OUString SAL_CALL OResultSet::getImplementationName( ) throw (::com::sun::star::uno::RuntimeException) \
70 return ::rtl::OUString::createFromAscii("com.sun.star.sdbcx.ado.ResultSet");
72 // -------------------------------------------------------------------------
73 ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL OResultSet::getSupportedServiceNames( ) throw(::com::sun::star::uno::RuntimeException)
75 ::com::sun::star::uno::Sequence< ::rtl::OUString > aSupported(2);
76 aSupported[0] = ::rtl::OUString::createFromAscii("com.sun.star.sdbc.ResultSet");
77 aSupported[1] = ::rtl::OUString::createFromAscii("com.sun.star.sdbcx.ResultSet");
78 return aSupported;
80 // -------------------------------------------------------------------------
81 sal_Bool SAL_CALL OResultSet::supportsService( const ::rtl::OUString& _rServiceName ) throw(::com::sun::star::uno::RuntimeException)
83 Sequence< ::rtl::OUString > aSupported(getSupportedServiceNames());
84 const ::rtl::OUString* pSupported = aSupported.getConstArray();
85 const ::rtl::OUString* pEnd = pSupported + aSupported.getLength();
86 for (;pSupported != pEnd && !pSupported->equals(_rServiceName); ++pSupported)
89 return pSupported != pEnd;
91 // -------------------------------------------------------------------------
92 OResultSet::OResultSet(ADORecordset* _pRecordSet,OStatement_Base* pStmt) : OResultSet_BASE(m_aMutex)
93 ,OPropertySetHelper(OResultSet_BASE::rBHelper)
94 ,m_xStatement(*pStmt)
95 ,m_pStmt(pStmt)
96 ,m_nRowPos(0)
97 ,m_xMetaData(NULL)
98 ,m_pRecordSet(_pRecordSet)
99 ,m_bEOF(sal_False)
102 // -------------------------------------------------------------------------
103 OResultSet::OResultSet(ADORecordset* _pRecordSet) : OResultSet_BASE(m_aMutex)
104 ,OPropertySetHelper(OResultSet_BASE::rBHelper)
105 ,m_xStatement(NULL)
106 ,m_xMetaData(NULL)
107 ,m_pRecordSet(_pRecordSet)
108 ,m_bEOF(sal_False)
111 // -----------------------------------------------------------------------------
112 void OResultSet::construct()
114 osl_incrementInterlockedCount( &m_refCount );
115 if (!m_pRecordSet)
117 OSL_ENSURE( sal_False, "OResultSet::construct: no RecordSet!" );
118 Reference< XInterface > xInt( *this );
119 osl_decrementInterlockedCount( &m_refCount );
120 ::dbtools::throwFunctionSequenceException( xInt );
122 m_pRecordSet->AddRef();
123 VARIANT_BOOL bIsAtBOF;
124 CHECK_RETURN(m_pRecordSet->get_BOF(&bIsAtBOF))
125 m_bOnFirstAfterOpen = bIsAtBOF != VARIANT_TRUE;
126 osl_decrementInterlockedCount( &m_refCount );
128 // -------------------------------------------------------------------------
129 OResultSet::~OResultSet()
131 if(m_pRecordSet)
132 m_pRecordSet->Release();
134 // -------------------------------------------------------------------------
135 void OResultSet::disposing(void)
137 OPropertySetHelper::disposing();
139 ::osl::MutexGuard aGuard(m_aMutex);
140 if(m_pRecordSet)
141 m_pRecordSet->Close();
142 m_xStatement.clear();
143 m_xMetaData.clear();
145 // -------------------------------------------------------------------------
146 Any SAL_CALL OResultSet::queryInterface( const Type & rType ) throw(RuntimeException)
148 Any aRet = OPropertySetHelper::queryInterface(rType);
149 return aRet.hasValue() ? aRet : OResultSet_BASE::queryInterface(rType);
151 // -------------------------------------------------------------------------
152 ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL OResultSet::getTypes( ) throw(::com::sun::star::uno::RuntimeException)
154 ::cppu::OTypeCollection aTypes( ::getCppuType( (const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XMultiPropertySet > *)0 ),
155 ::getCppuType( (const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XFastPropertySet > *)0 ),
156 ::getCppuType( (const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > *)0 ));
158 return ::comphelper::concatSequences(aTypes.getTypes(),OResultSet_BASE::getTypes());
161 // -------------------------------------------------------------------------
163 sal_Int32 SAL_CALL OResultSet::findColumn( const ::rtl::OUString& columnName ) throw(SQLException, RuntimeException)
165 ::osl::MutexGuard aGuard( m_aMutex );
166 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
169 Reference< XResultSetMetaData > xMeta = getMetaData();
170 sal_Int32 nLen = xMeta->getColumnCount();
171 sal_Int32 i = 1;
172 for(;i<=nLen;++i)
173 if(xMeta->isCaseSensitive(i) ? columnName == xMeta->getColumnName(i) :
174 columnName.equalsIgnoreAsciiCase(xMeta->getColumnName(i)))
175 break;
176 return i;
178 #define BLOCK_SIZE 256
179 // -------------------------------------------------------------------------
180 Reference< ::com::sun::star::io::XInputStream > SAL_CALL OResultSet::getBinaryStream( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
182 ::osl::MutexGuard aGuard( m_aMutex );
183 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
185 WpADOField aField = ADOS::getField(m_pRecordSet,columnIndex);
187 if((aField.GetAttributes() & adFldLong) == adFldLong)
189 //Copy the data only upto the Actual Size of Field.
190 sal_Int32 nSize = aField.GetActualSize();
191 Sequence<sal_Int8> aData(nSize);
192 long index = 0;
193 while(index < nSize)
195 m_aValue = aField.GetChunk(BLOCK_SIZE);
196 if(m_aValue.isNull())
197 break;
198 UCHAR chData;
199 for(long index2 = 0;index2 < BLOCK_SIZE;++index2)
201 HRESULT hr = ::SafeArrayGetElement(m_aValue.parray,&index2,&chData);
202 if(SUCCEEDED(hr))
204 //Take BYTE by BYTE and advance Memory Location
205 aData.getArray()[index++] = chData;
207 else
208 break;
212 return new ::comphelper::SequenceInputStream(aData);
214 // else we ask for a bytesequence
215 aField.get_Value(m_aValue);
217 return m_aValue.isNull() ? NULL : new ::comphelper::SequenceInputStream(m_aValue);
219 // -------------------------------------------------------------------------
220 Reference< ::com::sun::star::io::XInputStream > SAL_CALL OResultSet::getCharacterStream( sal_Int32 /*columnIndex*/ ) throw(SQLException, RuntimeException)
222 ::dbtools::throwFeatureNotImplementedException( "XRow::getCharacterStream", *this );
223 return NULL;
225 // -----------------------------------------------------------------------------
226 OLEVariant OResultSet::getValue(sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
228 ::osl::MutexGuard aGuard( m_aMutex );
229 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
231 WpADOField aField = ADOS::getField(m_pRecordSet,columnIndex);
232 aField.get_Value(m_aValue);
233 return m_aValue;
235 // -------------------------------------------------------------------------
236 sal_Bool SAL_CALL OResultSet::getBoolean( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
238 return getValue(columnIndex);
240 // -------------------------------------------------------------------------
242 sal_Int8 SAL_CALL OResultSet::getByte( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
244 return getValue(columnIndex);
246 // -------------------------------------------------------------------------
248 Sequence< sal_Int8 > SAL_CALL OResultSet::getBytes( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
250 return getValue(columnIndex);
252 // -------------------------------------------------------------------------
254 ::com::sun::star::util::Date SAL_CALL OResultSet::getDate( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
256 return getValue(columnIndex);
258 // -------------------------------------------------------------------------
260 double SAL_CALL OResultSet::getDouble( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
262 return getValue(columnIndex);
264 // -------------------------------------------------------------------------
266 float SAL_CALL OResultSet::getFloat( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
268 return getValue(columnIndex);
270 // -------------------------------------------------------------------------
272 sal_Int32 SAL_CALL OResultSet::getInt( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
274 return getValue(columnIndex);
276 // -------------------------------------------------------------------------
278 sal_Int32 SAL_CALL OResultSet::getRow( ) throw(SQLException, RuntimeException)
280 ::osl::MutexGuard aGuard( m_aMutex );
281 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
284 PositionEnum aPos;
285 m_pRecordSet->get_AbsolutePosition(&aPos);
286 return (aPos > 0) ? aPos : m_nRowPos;
287 // return the rowcount from driver if the driver doesn't support this return our count
289 // -------------------------------------------------------------------------
291 sal_Int64 SAL_CALL OResultSet::getLong( sal_Int32 /*columnIndex*/ ) throw(SQLException, RuntimeException)
293 ::dbtools::throwFeatureNotImplementedException( "XRow::getLong", *this );
294 return sal_Int64(0);
296 // -------------------------------------------------------------------------
298 Reference< XResultSetMetaData > SAL_CALL OResultSet::getMetaData( ) throw(SQLException, RuntimeException)
300 ::osl::MutexGuard aGuard( m_aMutex );
301 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
304 if(!m_xMetaData.is())
305 m_xMetaData = new OResultSetMetaData(m_pRecordSet);
306 return m_xMetaData;
308 // -------------------------------------------------------------------------
309 Reference< XArray > SAL_CALL OResultSet::getArray( sal_Int32 /*columnIndex*/ ) throw(SQLException, RuntimeException)
311 ::dbtools::throwFeatureNotImplementedException( "XRow::getArray", *this );
312 return NULL;
315 // -------------------------------------------------------------------------
317 Reference< XClob > SAL_CALL OResultSet::getClob( sal_Int32 /*columnIndex*/ ) throw(SQLException, RuntimeException)
319 ::dbtools::throwFeatureNotImplementedException( "XRow::getClob", *this );
320 return NULL;
322 // -------------------------------------------------------------------------
323 Reference< XBlob > SAL_CALL OResultSet::getBlob( sal_Int32 /*columnIndex*/ ) throw(SQLException, RuntimeException)
325 ::dbtools::throwFeatureNotImplementedException( "XRow::getBlob", *this );
326 return NULL;
328 // -------------------------------------------------------------------------
330 Reference< XRef > SAL_CALL OResultSet::getRef( sal_Int32 /*columnIndex*/ ) throw(SQLException, RuntimeException)
332 ::dbtools::throwFeatureNotImplementedException( "XRow::getRef", *this );
333 return NULL;
335 // -------------------------------------------------------------------------
337 Any SAL_CALL OResultSet::getObject( sal_Int32 /*columnIndex*/, const Reference< ::com::sun::star::container::XNameAccess >& /*typeMap*/ ) throw(SQLException, RuntimeException)
340 ::dbtools::throwFeatureNotImplementedException( "XRow::getObject", *this );
341 return Any();
343 // -------------------------------------------------------------------------
345 sal_Int16 SAL_CALL OResultSet::getShort( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
347 return getValue(columnIndex);
349 // -------------------------------------------------------------------------
351 ::rtl::OUString SAL_CALL OResultSet::getString( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
353 return getValue(columnIndex);
356 // -------------------------------------------------------------------------
359 ::com::sun::star::util::Time SAL_CALL OResultSet::getTime( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
361 return getValue(columnIndex);
363 // -------------------------------------------------------------------------
366 ::com::sun::star::util::DateTime SAL_CALL OResultSet::getTimestamp( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
368 return getValue(columnIndex);
370 // -------------------------------------------------------------------------
372 sal_Bool SAL_CALL OResultSet::isAfterLast( ) throw(SQLException, RuntimeException)
374 ::osl::MutexGuard aGuard( m_aMutex );
375 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
378 VARIANT_BOOL bIsAtEOF;
379 CHECK_RETURN(m_pRecordSet->get_EOF(&bIsAtEOF))
380 return bIsAtEOF == VARIANT_TRUE;
382 // -------------------------------------------------------------------------
383 sal_Bool SAL_CALL OResultSet::isFirst( ) throw(SQLException, RuntimeException)
385 ::osl::MutexGuard aGuard( m_aMutex );
386 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
389 return m_nRowPos == 1;
391 // -------------------------------------------------------------------------
392 sal_Bool SAL_CALL OResultSet::isLast( ) throw(SQLException, RuntimeException)
394 ::osl::MutexGuard aGuard( m_aMutex );
395 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
398 return sal_True;
400 // -------------------------------------------------------------------------
401 void SAL_CALL OResultSet::beforeFirst( ) throw(SQLException, RuntimeException)
403 ::osl::MutexGuard aGuard( m_aMutex );
404 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
407 if(first())
408 previous();
410 // -------------------------------------------------------------------------
411 void SAL_CALL OResultSet::afterLast( ) throw(SQLException, RuntimeException)
413 ::osl::MutexGuard aGuard( m_aMutex );
414 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
417 if(last())
418 next();
419 m_bEOF = sal_True;
421 // -------------------------------------------------------------------------
423 void SAL_CALL OResultSet::close( ) throw(SQLException, RuntimeException)
426 ::osl::MutexGuard aGuard( m_aMutex );
427 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
430 dispose();
432 // -------------------------------------------------------------------------
434 sal_Bool SAL_CALL OResultSet::first( ) throw(SQLException, RuntimeException)
436 ::osl::MutexGuard aGuard( m_aMutex );
437 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
440 if(SUCCEEDED(m_pRecordSet->MoveFirst()))
442 m_nRowPos = 1;
443 m_bOnFirstAfterOpen = sal_False;
444 return sal_True;
446 return sal_False;
448 // -------------------------------------------------------------------------
450 sal_Bool SAL_CALL OResultSet::last( ) throw(SQLException, RuntimeException)
452 ::osl::MutexGuard aGuard( m_aMutex );
453 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
456 sal_Bool bRet = SUCCEEDED(m_pRecordSet->MoveLast());
457 if(bRet)
459 m_pRecordSet->get_RecordCount(&m_nRowPos);
460 m_bOnFirstAfterOpen = sal_False;
462 return bRet;
464 // -------------------------------------------------------------------------
465 sal_Bool SAL_CALL OResultSet::absolute( sal_Int32 row ) throw(SQLException, RuntimeException)
467 ::osl::MutexGuard aGuard( m_aMutex );
468 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
471 if(!row) // absolute with zero not allowed
472 ::dbtools::throwFunctionSequenceException(*this);
474 sal_Bool bCheck = sal_True;
475 if(row < 0)
477 bCheck = SUCCEEDED(m_pRecordSet->MoveLast());
478 if ( bCheck )
480 while(++row < 0 && bCheck)
481 bCheck = SUCCEEDED(m_pRecordSet->MovePrevious());
484 else
486 first();
487 OLEVariant aEmpty;
488 aEmpty.setNoArg();
489 bCheck = SUCCEEDED(m_pRecordSet->Move(row-1,aEmpty)); // move to row -1 because we stand already on the first
490 if(bCheck)
491 m_nRowPos = row;
493 if(bCheck)
494 m_bOnFirstAfterOpen = sal_False;
495 return bCheck;
497 // -------------------------------------------------------------------------
498 sal_Bool SAL_CALL OResultSet::relative( sal_Int32 row ) throw(SQLException, RuntimeException)
500 ::osl::MutexGuard aGuard( m_aMutex );
501 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
504 OLEVariant aEmpty;
505 aEmpty.setNoArg();
506 sal_Int32 nNewPos = row;
507 if ( m_bOnFirstAfterOpen && nNewPos > 0 )
508 --nNewPos;
509 sal_Bool bRet = SUCCEEDED(m_pRecordSet->Move(row,aEmpty));
510 if(bRet)
512 m_nRowPos += row;
513 m_bOnFirstAfterOpen = sal_False;
515 return bRet;
517 // -------------------------------------------------------------------------
518 sal_Bool SAL_CALL OResultSet::previous( ) throw(SQLException, RuntimeException)
520 ::osl::MutexGuard aGuard( m_aMutex );
521 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
523 sal_Bool bRet = SUCCEEDED(m_pRecordSet->MovePrevious());
524 if(bRet)
526 --m_nRowPos;
527 m_bOnFirstAfterOpen = sal_False;
529 return bRet;
531 // -------------------------------------------------------------------------
532 Reference< XInterface > SAL_CALL OResultSet::getStatement( ) throw(SQLException, RuntimeException)
534 ::osl::MutexGuard aGuard( m_aMutex );
535 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
536 return m_xStatement;
538 // -------------------------------------------------------------------------
540 sal_Bool SAL_CALL OResultSet::rowDeleted( ) throw(SQLException, RuntimeException)
542 ::osl::MutexGuard aGuard( m_aMutex );
543 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
546 RecordStatusEnum eRec;
547 m_pRecordSet->get_Status((sal_Int32*)&eRec);
548 sal_Bool bRet = (eRec & adRecDeleted) == adRecDeleted;
549 if(bRet)
550 --m_nRowPos;
551 return bRet;
553 // -------------------------------------------------------------------------
554 sal_Bool SAL_CALL OResultSet::rowInserted( ) throw(SQLException, RuntimeException)
555 { ::osl::MutexGuard aGuard( m_aMutex );
556 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
559 RecordStatusEnum eRec;
560 m_pRecordSet->get_Status((sal_Int32*)&eRec);
561 sal_Bool bRet = (eRec & adRecNew) == adRecNew;
562 if(bRet)
563 ++m_nRowPos;
564 return bRet;
566 // -------------------------------------------------------------------------
567 sal_Bool SAL_CALL OResultSet::rowUpdated( ) throw(SQLException, RuntimeException)
569 ::osl::MutexGuard aGuard( m_aMutex );
570 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
573 RecordStatusEnum eRec;
574 m_pRecordSet->get_Status((sal_Int32*)&eRec);
575 return (eRec & adRecModified) == adRecModified;
577 // -------------------------------------------------------------------------
579 sal_Bool SAL_CALL OResultSet::isBeforeFirst( ) throw(SQLException, RuntimeException)
581 ::osl::MutexGuard aGuard( m_aMutex );
582 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
585 OSL_ENSURE(!m_nRowPos,"OResultSet::isBeforeFirst: Error in setting m_nRowPos!");
586 VARIANT_BOOL bIsAtBOF = VARIANT_TRUE;
587 if(!m_bOnFirstAfterOpen)
589 OSL_ENSURE(!m_nRowPos,"OResultSet::isBeforeFirst: Error in setting m_nRowPos!");
590 m_pRecordSet->get_BOF(&bIsAtBOF);
592 return bIsAtBOF == VARIANT_TRUE;
594 // -------------------------------------------------------------------------
596 sal_Bool SAL_CALL OResultSet::next( ) throw(SQLException, RuntimeException)
598 ::osl::MutexGuard aGuard( m_aMutex );
599 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
602 sal_Bool bRet = sal_True;
603 if(m_bOnFirstAfterOpen)
605 m_bOnFirstAfterOpen = sal_False;
606 ++m_nRowPos;
608 else
610 bRet = SUCCEEDED(m_pRecordSet->MoveNext());
612 if(bRet)
614 VARIANT_BOOL bIsAtEOF;
615 CHECK_RETURN(m_pRecordSet->get_EOF(&bIsAtEOF))
616 bRet = bIsAtEOF != VARIANT_TRUE;
617 ++m_nRowPos;
619 else
620 ADOS::ThrowException(*m_pStmt->m_pConnection->getConnection(),*this);
623 return bRet;
625 // -------------------------------------------------------------------------
627 sal_Bool SAL_CALL OResultSet::wasNull( ) throw(SQLException, RuntimeException)
629 ::osl::MutexGuard aGuard( m_aMutex );
630 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
633 return m_aValue.isNull();
635 // -------------------------------------------------------------------------
637 void SAL_CALL OResultSet::cancel( ) throw(RuntimeException)
639 ::osl::MutexGuard aGuard( m_aMutex );
640 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
643 m_pRecordSet->Cancel();
645 // -------------------------------------------------------------------------
646 void SAL_CALL OResultSet::clearWarnings( ) throw(SQLException, RuntimeException)
649 // -------------------------------------------------------------------------
650 Any SAL_CALL OResultSet::getWarnings( ) throw(SQLException, RuntimeException)
652 return Any();
654 // -------------------------------------------------------------------------
655 void SAL_CALL OResultSet::insertRow( ) throw(SQLException, RuntimeException)
657 ::osl::MutexGuard aGuard( m_aMutex );
658 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
661 OLEVariant aEmpty;
662 aEmpty.setNoArg();
663 m_pRecordSet->AddNew(aEmpty,aEmpty);
665 // -------------------------------------------------------------------------
666 void SAL_CALL OResultSet::updateRow( ) throw(SQLException, RuntimeException)
668 ::osl::MutexGuard aGuard( m_aMutex );
669 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
672 OLEVariant aEmpty;
673 aEmpty.setNoArg();
674 m_pRecordSet->Update(aEmpty,aEmpty);
676 // -------------------------------------------------------------------------
677 void SAL_CALL OResultSet::deleteRow( ) throw(SQLException, RuntimeException)
679 ::osl::MutexGuard aGuard( m_aMutex );
680 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
683 m_pRecordSet->Delete(adAffectCurrent);
684 m_pRecordSet->UpdateBatch(adAffectCurrent);
686 // -------------------------------------------------------------------------
688 void SAL_CALL OResultSet::cancelRowUpdates( ) throw(SQLException, RuntimeException)
690 ::osl::MutexGuard aGuard( m_aMutex );
691 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
694 m_pRecordSet->CancelUpdate();
696 // -------------------------------------------------------------------------
698 void SAL_CALL OResultSet::moveToInsertRow( ) throw(SQLException, RuntimeException)
701 // -------------------------------------------------------------------------
703 void SAL_CALL OResultSet::moveToCurrentRow( ) throw(SQLException, RuntimeException)
706 // -----------------------------------------------------------------------------
707 void OResultSet::updateValue(sal_Int32 columnIndex,const OLEVariant& x)
709 ::osl::MutexGuard aGuard( m_aMutex );
710 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
712 WpADOField aField = ADOS::getField(m_pRecordSet,columnIndex);
713 aField.PutValue(x);
715 // -------------------------------------------------------------------------
716 void SAL_CALL OResultSet::updateNull( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
718 OLEVariant x;
719 x.setNull();
720 updateValue(columnIndex,x);
722 // -------------------------------------------------------------------------
724 void SAL_CALL OResultSet::updateBoolean( sal_Int32 columnIndex, sal_Bool x ) throw(SQLException, RuntimeException)
726 updateValue(columnIndex,x);
728 // -------------------------------------------------------------------------
729 void SAL_CALL OResultSet::updateByte( sal_Int32 columnIndex, sal_Int8 x ) throw(SQLException, RuntimeException)
731 updateValue(columnIndex,x);
733 // -------------------------------------------------------------------------
735 void SAL_CALL OResultSet::updateShort( sal_Int32 columnIndex, sal_Int16 x ) throw(SQLException, RuntimeException)
737 updateValue(columnIndex,x);
739 // -------------------------------------------------------------------------
740 void SAL_CALL OResultSet::updateInt( sal_Int32 columnIndex, sal_Int32 x ) throw(SQLException, RuntimeException)
742 updateValue(columnIndex,x);
744 // -------------------------------------------------------------------------
745 void SAL_CALL OResultSet::updateLong( sal_Int32 columnIndex, sal_Int64 x ) throw(SQLException, RuntimeException)
747 updateValue(columnIndex,x);
749 // -----------------------------------------------------------------------
750 void SAL_CALL OResultSet::updateFloat( sal_Int32 columnIndex, float x ) throw(SQLException, RuntimeException)
752 updateValue(columnIndex,x);
754 // -------------------------------------------------------------------------
756 void SAL_CALL OResultSet::updateDouble( sal_Int32 columnIndex, double x ) throw(SQLException, RuntimeException)
758 updateValue(columnIndex,x);
760 // -------------------------------------------------------------------------
761 void SAL_CALL OResultSet::updateString( sal_Int32 columnIndex, const ::rtl::OUString& x ) throw(SQLException, RuntimeException)
763 updateValue(columnIndex,x);
765 // -------------------------------------------------------------------------
766 void SAL_CALL OResultSet::updateBytes( sal_Int32 columnIndex, const Sequence< sal_Int8 >& x ) throw(SQLException, RuntimeException)
768 updateValue(columnIndex,x);
770 // -------------------------------------------------------------------------
771 void SAL_CALL OResultSet::updateDate( sal_Int32 columnIndex, const ::com::sun::star::util::Date& x ) throw(SQLException, RuntimeException)
773 updateValue(columnIndex,x);
775 // -------------------------------------------------------------------------
777 void SAL_CALL OResultSet::updateTime( sal_Int32 columnIndex, const ::com::sun::star::util::Time& x ) throw(SQLException, RuntimeException)
779 updateValue(columnIndex,x);
781 // -------------------------------------------------------------------------
783 void SAL_CALL OResultSet::updateTimestamp( sal_Int32 columnIndex, const ::com::sun::star::util::DateTime& x ) throw(SQLException, RuntimeException)
785 updateValue(columnIndex,x);
787 // -------------------------------------------------------------------------
789 void SAL_CALL OResultSet::updateBinaryStream( sal_Int32 /*columnIndex*/, const Reference< ::com::sun::star::io::XInputStream >& /*x*/, sal_Int32 /*length*/ ) throw(SQLException, RuntimeException)
791 ::dbtools::throwFeatureNotImplementedException( "XRowUpdate::updateBinaryStream", *this );
793 // -------------------------------------------------------------------------
794 void SAL_CALL OResultSet::updateCharacterStream( sal_Int32 /*columnIndex*/, const Reference< ::com::sun::star::io::XInputStream >& /*x*/, sal_Int32 /*length*/ ) throw(SQLException, RuntimeException)
796 ::dbtools::throwFeatureNotImplementedException( "XRowUpdate::updateCharacterStream", *this );
798 // -------------------------------------------------------------------------
799 void SAL_CALL OResultSet::refreshRow( ) throw(SQLException, RuntimeException)
801 ::osl::MutexGuard aGuard( m_aMutex );
802 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
805 m_pRecordSet->Resync(adAffectCurrent,adResyncAllValues);
807 // -------------------------------------------------------------------------
808 void SAL_CALL OResultSet::updateObject( sal_Int32 columnIndex, const Any& x ) throw(SQLException, RuntimeException)
810 if (!::dbtools::implUpdateObject(this, columnIndex, x))
811 throw SQLException();
813 // -------------------------------------------------------------------------
815 void SAL_CALL OResultSet::updateNumericObject( sal_Int32 columnIndex, const Any& x, sal_Int32 /*scale*/ ) throw(SQLException, RuntimeException)
817 if (!::dbtools::implUpdateObject(this, columnIndex, x))
818 throw SQLException();
820 //------------------------------------------------------------------------------
821 // XRowLocate
822 Any SAL_CALL OResultSet::getBookmark( ) throw(SQLException, RuntimeException)
824 ::osl::MutexGuard aGuard( m_aMutex );
825 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
827 if(m_nRowPos < (sal_Int32)m_aBookmarks.size()) // this bookmark was already fetched
828 return makeAny(sal_Int32(m_nRowPos-1));
830 OLEVariant aVar;
831 m_pRecordSet->get_Bookmark(&aVar);
832 m_aBookmarks.push_back(aVar);
833 return makeAny((sal_Int32)(m_aBookmarks.size()-1));
836 //------------------------------------------------------------------------------
837 sal_Bool SAL_CALL OResultSet::moveToBookmark( const Any& bookmark ) throw(SQLException, RuntimeException)
839 ::osl::MutexGuard aGuard( m_aMutex );
840 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
843 sal_Int32 nPos;
844 bookmark >>= nPos;
845 OSL_ENSURE(nPos >= 0 && nPos < (sal_Int32)m_aBookmarks.size(),"Invalid Index for vector");
846 if(nPos < 0 || nPos >= (sal_Int32)m_aBookmarks.size())
847 ::dbtools::throwFunctionSequenceException(*this);
849 return SUCCEEDED(m_pRecordSet->Move(0,m_aBookmarks[nPos]));
851 //------------------------------------------------------------------------------
852 sal_Bool SAL_CALL OResultSet::moveRelativeToBookmark( const Any& bookmark, sal_Int32 rows ) throw(SQLException, RuntimeException)
854 ::osl::MutexGuard aGuard( m_aMutex );
855 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
858 sal_Int32 nPos;
859 bookmark >>= nPos;
860 nPos += rows;
861 OSL_ENSURE(nPos >= 0 && nPos < (sal_Int32)m_aBookmarks.size(),"Invalid Index for vector");
862 if(nPos < 0 || nPos >= (sal_Int32)m_aBookmarks.size())
863 ::dbtools::throwFunctionSequenceException(*this);
864 return SUCCEEDED(m_pRecordSet->Move(rows,m_aBookmarks[nPos]));
866 //------------------------------------------------------------------------------
867 sal_Int32 SAL_CALL OResultSet::compareBookmarks( const Any& first, const Any& second ) throw(SQLException, RuntimeException)
869 ::osl::MutexGuard aGuard( m_aMutex );
870 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
872 sal_Int32 nPos1;
873 first >>= nPos1;
874 sal_Int32 nPos2;
875 second >>= nPos2;
876 if(nPos1 == nPos2) // they should be equal
877 return sal_True;
879 OSL_ENSURE((nPos1 >= 0 && nPos1 < (sal_Int32)m_aBookmarks.size()) || (nPos1 >= 0 && nPos2 < (sal_Int32)m_aBookmarks.size()),"Invalid Index for vector");
881 CompareEnum eNum;
882 m_pRecordSet->CompareBookmarks(m_aBookmarks[nPos1],m_aBookmarks[nPos2],&eNum);
883 return ((sal_Int32)eNum) +1;
885 //------------------------------------------------------------------------------
886 sal_Bool SAL_CALL OResultSet::hasOrderedBookmarks( ) throw(SQLException, RuntimeException)
888 ::osl::MutexGuard aGuard( m_aMutex );
889 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
892 ADOProperties* pProps = NULL;
893 m_pRecordSet->get_Properties(&pProps);
894 WpADOProperties aProps;
895 aProps.setWithOutAddRef(pProps);
896 ADOS::ThrowException(*((OConnection*)m_pStmt->getConnection().get())->getConnection(),*this);
897 OSL_ENSURE(aProps.IsValid(),"There are no properties at the connection");
899 WpADOProperty aProp(aProps.GetItem(::rtl::OUString::createFromAscii("Bookmarks Ordered")));
900 OLEVariant aVar;
901 if(aProp.IsValid())
902 aVar = aProp.GetValue();
903 else
904 ADOS::ThrowException(*((OConnection*)m_pStmt->getConnection().get())->getConnection(),*this);
906 sal_Bool bValue(sal_False);
907 if(!aVar.isNull() && !aVar.isEmpty())
908 bValue = aVar;
909 return bValue;
911 //------------------------------------------------------------------------------
912 sal_Int32 SAL_CALL OResultSet::hashBookmark( const Any& bookmark ) throw(SQLException, RuntimeException)
914 ::osl::MutexGuard aGuard( m_aMutex );
915 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
918 sal_Int32 nPos;
919 bookmark >>= nPos;
920 return nPos;
922 //------------------------------------------------------------------------------
923 // XDeleteRows
924 Sequence< sal_Int32 > SAL_CALL OResultSet::deleteRows( const Sequence< Any >& rows ) throw(SQLException, RuntimeException)
926 ::osl::MutexGuard aGuard( m_aMutex );
927 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
930 OLEVariant aVar;
931 sal_Int32 nPos;
933 // Create SafeArray Bounds and initialize the array
934 SAFEARRAYBOUND rgsabound[1];
935 rgsabound[0].lLbound = 0;
936 rgsabound[0].cElements = rows.getLength();
937 SAFEARRAY *psa = SafeArrayCreate( VT_VARIANT, 1, rgsabound );
939 const Any* pBegin = rows.getConstArray();
940 const Any* pEnd = pBegin + rows.getLength();
941 for(sal_Int32 i=0;pBegin != pEnd ;++pBegin,++i)
943 *pBegin >>= nPos;
944 SafeArrayPutElement(psa,&i,&m_aBookmarks[nPos]);
947 // Initialize and fill the SafeArray
948 OLEVariant vsa;
949 vsa.setArray(psa,VT_VARIANT);
951 m_pRecordSet->put_Filter(vsa);
952 m_pRecordSet->Delete(adAffectGroup);
953 m_pRecordSet->UpdateBatch(adAffectGroup);
955 Sequence< sal_Int32 > aSeq(rows.getLength());
956 if(first())
958 sal_Int32* pSeq = aSeq.getArray();
959 sal_Int32 i=0;
962 OSL_ENSURE(i<aSeq.getLength(),"Index greater than length of sequence");
963 m_pRecordSet->get_Status(&pSeq[i]);
964 if(pSeq[i++] == adRecDeleted)
965 --m_nRowPos;
967 while(next());
969 return aSeq;
971 //------------------------------------------------------------------------------
972 sal_Int32 OResultSet::getResultSetConcurrency() const
973 throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException)
975 sal_Int32 nValue=0;
976 LockTypeEnum eRet;
977 if(!SUCCEEDED(m_pRecordSet->get_LockType(&eRet)))
979 switch(eRet)
981 case adLockReadOnly:
982 nValue = ResultSetConcurrency::READ_ONLY;
983 break;
984 default:
985 nValue = ResultSetConcurrency::UPDATABLE;
986 break;
989 return nValue;
991 //------------------------------------------------------------------------------
992 sal_Int32 OResultSet::getResultSetType() const
993 throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException)
995 sal_Int32 nValue=0;
996 CursorTypeEnum eRet;
997 if(!SUCCEEDED(m_pRecordSet->get_CursorType(&eRet)))
999 switch(eRet)
1001 case adOpenUnspecified:
1002 case adOpenForwardOnly:
1003 nValue = ResultSetType::FORWARD_ONLY;
1004 break;
1005 case adOpenStatic:
1006 case adOpenKeyset:
1007 nValue = ResultSetType::SCROLL_INSENSITIVE;
1008 break;
1009 case adOpenDynamic:
1010 nValue = ResultSetType::SCROLL_SENSITIVE;
1011 break;
1014 return nValue;
1016 //------------------------------------------------------------------------------
1017 sal_Int32 OResultSet::getFetchDirection() const
1018 throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException)
1020 return FetchDirection::FORWARD;
1022 //------------------------------------------------------------------------------
1023 sal_Int32 OResultSet::getFetchSize() const
1024 throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException)
1026 sal_Int32 nValue=-1;
1027 m_pRecordSet->get_CacheSize(&nValue);
1028 return nValue;
1030 //------------------------------------------------------------------------------
1031 ::rtl::OUString OResultSet::getCursorName() const
1032 throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException)
1034 return ::rtl::OUString();
1037 //------------------------------------------------------------------------------
1038 void OResultSet::setFetchDirection(sal_Int32 /*_par0*/)
1039 throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException)
1041 ::dbtools::throwFeatureNotImplementedException( "ResultSet::FetchDirection", *this );
1043 //------------------------------------------------------------------------------
1044 void OResultSet::setFetchSize(sal_Int32 _par0)
1045 throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException)
1047 m_pRecordSet->put_CacheSize(_par0);
1049 // -------------------------------------------------------------------------
1050 ::cppu::IPropertyArrayHelper* OResultSet::createArrayHelper( ) const
1052 Sequence< com::sun::star::beans::Property > aProps(5);
1053 com::sun::star::beans::Property* pProperties = aProps.getArray();
1054 sal_Int32 nPos = 0;
1056 // DECL_PROP1IMPL(CURSORNAME, ::rtl::OUString) PropertyAttribute::READONLY);
1057 DECL_PROP0(FETCHDIRECTION, sal_Int32);
1058 DECL_PROP0(FETCHSIZE, sal_Int32);
1059 DECL_BOOL_PROP1IMPL(ISBOOKMARKABLE) PropertyAttribute::READONLY);
1060 DECL_PROP1IMPL(RESULTSETCONCURRENCY,sal_Int32) PropertyAttribute::READONLY);
1061 DECL_PROP1IMPL(RESULTSETTYPE, sal_Int32) PropertyAttribute::READONLY);
1063 return new ::cppu::OPropertyArrayHelper(aProps);
1065 // -------------------------------------------------------------------------
1066 ::cppu::IPropertyArrayHelper & OResultSet::getInfoHelper()
1068 return *const_cast<OResultSet*>(this)->getArrayHelper();
1070 // -------------------------------------------------------------------------
1071 sal_Bool OResultSet::convertFastPropertyValue(
1072 Any & rConvertedValue,
1073 Any & rOldValue,
1074 sal_Int32 nHandle,
1075 const Any& rValue )
1076 throw (::com::sun::star::lang::IllegalArgumentException)
1078 switch(nHandle)
1080 case PROPERTY_ID_ISBOOKMARKABLE:
1081 case PROPERTY_ID_CURSORNAME:
1082 case PROPERTY_ID_RESULTSETCONCURRENCY:
1083 case PROPERTY_ID_RESULTSETTYPE:
1084 throw ::com::sun::star::lang::IllegalArgumentException();
1085 break;
1086 case PROPERTY_ID_FETCHDIRECTION:
1087 return ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, getFetchDirection());
1088 case PROPERTY_ID_FETCHSIZE:
1089 return ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, getFetchSize());
1090 default:
1093 return sal_False;
1095 // -------------------------------------------------------------------------
1096 void OResultSet::setFastPropertyValue_NoBroadcast(sal_Int32 nHandle,const Any& rValue)throw (Exception)
1098 switch(nHandle)
1100 case PROPERTY_ID_ISBOOKMARKABLE:
1101 case PROPERTY_ID_CURSORNAME:
1102 case PROPERTY_ID_RESULTSETCONCURRENCY:
1103 case PROPERTY_ID_RESULTSETTYPE:
1104 throw Exception();
1105 break;
1106 case PROPERTY_ID_FETCHDIRECTION:
1107 setFetchDirection(getINT32(rValue));
1108 break;
1109 case PROPERTY_ID_FETCHSIZE:
1110 setFetchSize(getINT32(rValue));
1111 break;
1112 default:
1116 // -------------------------------------------------------------------------
1117 void OResultSet::getFastPropertyValue(Any& rValue,sal_Int32 nHandle) const
1119 switch(nHandle)
1121 case PROPERTY_ID_ISBOOKMARKABLE:
1123 VARIANT_BOOL bBool;
1124 m_pRecordSet->Supports(adBookmark,&bBool);
1125 sal_Bool bRet = bBool == VARIANT_TRUE;
1126 rValue.setValue(&bRet, ::getCppuBooleanType() );
1128 break;
1129 case PROPERTY_ID_CURSORNAME:
1130 rValue <<= getCursorName();
1131 break;
1132 case PROPERTY_ID_RESULTSETCONCURRENCY:
1133 rValue <<= getResultSetConcurrency();
1134 break;
1135 case PROPERTY_ID_RESULTSETTYPE:
1136 rValue <<= getResultSetType();
1137 break;
1138 case PROPERTY_ID_FETCHDIRECTION:
1139 rValue <<= getFetchDirection();
1140 break;
1141 case PROPERTY_ID_FETCHSIZE:
1142 rValue <<= getFetchSize();
1143 break;
1146 // -----------------------------------------------------------------------------
1147 void SAL_CALL OResultSet::acquire() throw()
1149 OResultSet_BASE::acquire();
1151 // -----------------------------------------------------------------------------
1152 void SAL_CALL OResultSet::release() throw()
1154 OResultSet_BASE::release();
1156 // -----------------------------------------------------------------------------
1157 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL OResultSet::getPropertySetInfo( ) throw(::com::sun::star::uno::RuntimeException)
1159 return ::cppu::OPropertySetHelper::createPropertySetInfo(getInfoHelper());
1161 // -----------------------------------------------------------------------------