1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "ado/AResultSet.hxx"
21 #include "ado/AResultSetMetaData.hxx"
22 #include <com/sun/star/sdbc/DataType.hpp>
23 #include <com/sun/star/sdbc/KeyRule.hpp>
24 #include <com/sun/star/sdbc/IndexType.hpp>
25 #include <comphelper/property.hxx>
26 #include <com/sun/star/lang/DisposedException.hpp>
27 #include <com/sun/star/sdbc/ResultSetConcurrency.hpp>
28 #include <com/sun/star/sdbc/ResultSetType.hpp>
29 #include <com/sun/star/sdbc/FetchDirection.hpp>
30 #include <cppuhelper/typeprovider.hxx>
31 #include <comphelper/sequence.hxx>
32 #include <com/sun/star/beans/PropertyAttribute.hpp>
33 #include <comphelper/seqstream.hxx>
34 #include "connectivity/dbexception.hxx"
35 #include "connectivity/dbtools.hxx"
36 #include <comphelper/types.hxx>
38 using namespace ::comphelper
;
43 #define CHECK_RETURN(x) \
45 ADOS::ThrowException(*m_pStmt->m_pConnection->getConnection(),*this);
47 using namespace connectivity::ado
;
48 using namespace com::sun::star::uno
;
49 using namespace com::sun::star::lang
;
50 using namespace com::sun::star::beans
;
51 using namespace com::sun::star::sdbc
;
53 //------------------------------------------------------------------------------
54 // IMPLEMENT_SERVICE_INFO(OResultSet,"com.sun.star.sdbcx.AResultSet","com.sun.star.sdbc.ResultSet");
55 OUString SAL_CALL
OResultSet::getImplementationName( ) throw (::com::sun::star::uno::RuntimeException
) \
57 return OUString("com.sun.star.sdbcx.ado.ResultSet");
59 // -------------------------------------------------------------------------
60 ::com::sun::star::uno::Sequence
< OUString
> SAL_CALL
OResultSet::getSupportedServiceNames( ) throw(::com::sun::star::uno::RuntimeException
)
62 ::com::sun::star::uno::Sequence
< OUString
> aSupported(2);
63 aSupported
[0] = OUString("com.sun.star.sdbc.ResultSet");
64 aSupported
[1] = OUString("com.sun.star.sdbcx.ResultSet");
67 // -------------------------------------------------------------------------
68 sal_Bool SAL_CALL
OResultSet::supportsService( const OUString
& _rServiceName
) throw(::com::sun::star::uno::RuntimeException
)
70 Sequence
< OUString
> aSupported(getSupportedServiceNames());
71 const OUString
* pSupported
= aSupported
.getConstArray();
72 const OUString
* pEnd
= pSupported
+ aSupported
.getLength();
73 for (;pSupported
!= pEnd
&& !pSupported
->equals(_rServiceName
); ++pSupported
)
76 return pSupported
!= pEnd
;
78 // -------------------------------------------------------------------------
79 OResultSet::OResultSet(ADORecordset
* _pRecordSet
,OStatement_Base
* pStmt
) : OResultSet_BASE(m_aMutex
)
80 ,OPropertySetHelper(OResultSet_BASE::rBHelper
)
81 ,m_pRecordSet(_pRecordSet
)
86 ,m_bWasNull(sal_False
)
88 ,m_bOnFirstAfterOpen(sal_False
)
91 // -------------------------------------------------------------------------
92 OResultSet::OResultSet(ADORecordset
* _pRecordSet
) : OResultSet_BASE(m_aMutex
)
93 ,OPropertySetHelper(OResultSet_BASE::rBHelper
)
94 ,m_pRecordSet(_pRecordSet
)
99 ,m_bWasNull(sal_False
)
101 ,m_bOnFirstAfterOpen(sal_False
)
104 // -----------------------------------------------------------------------------
105 void OResultSet::construct()
107 osl_atomic_increment( &m_refCount
);
110 OSL_FAIL( "OResultSet::construct: no RecordSet!" );
111 Reference
< XInterface
> xInt( *this );
112 osl_atomic_decrement( &m_refCount
);
113 ::dbtools::throwFunctionSequenceException( xInt
);
115 m_pRecordSet
->AddRef();
116 VARIANT_BOOL bIsAtBOF
;
117 CHECK_RETURN(m_pRecordSet
->get_BOF(&bIsAtBOF
))
118 m_bOnFirstAfterOpen
= bIsAtBOF
!= VARIANT_TRUE
;
119 osl_atomic_decrement( &m_refCount
);
121 // -------------------------------------------------------------------------
122 OResultSet::~OResultSet()
125 m_pRecordSet
->Release();
127 // -------------------------------------------------------------------------
128 void OResultSet::disposing(void)
130 OPropertySetHelper::disposing();
132 ::osl::MutexGuard
aGuard(m_aMutex
);
134 m_pRecordSet
->Close();
135 m_xStatement
.clear();
138 // -------------------------------------------------------------------------
139 Any SAL_CALL
OResultSet::queryInterface( const Type
& rType
) throw(RuntimeException
)
141 Any aRet
= OPropertySetHelper::queryInterface(rType
);
142 return aRet
.hasValue() ? aRet
: OResultSet_BASE::queryInterface(rType
);
144 // -------------------------------------------------------------------------
145 ::com::sun::star::uno::Sequence
< ::com::sun::star::uno::Type
> SAL_CALL
OResultSet::getTypes( ) throw(::com::sun::star::uno::RuntimeException
)
147 ::cppu::OTypeCollection
aTypes( ::getCppuType( (const ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XMultiPropertySet
> *)0 ),
148 ::getCppuType( (const ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XFastPropertySet
> *)0 ),
149 ::getCppuType( (const ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySet
> *)0 ));
151 return ::comphelper::concatSequences(aTypes
.getTypes(),OResultSet_BASE::getTypes());
154 // -------------------------------------------------------------------------
156 sal_Int32 SAL_CALL
OResultSet::findColumn( const OUString
& columnName
) throw(SQLException
, RuntimeException
)
158 ::osl::MutexGuard
aGuard( m_aMutex
);
159 checkDisposed(OResultSet_BASE::rBHelper
.bDisposed
);
162 Reference
< XResultSetMetaData
> xMeta
= getMetaData();
163 sal_Int32 nLen
= xMeta
->getColumnCount();
166 if(xMeta
->isCaseSensitive(i
) ? columnName
== xMeta
->getColumnName(i
) :
167 columnName
.equalsIgnoreAsciiCase(xMeta
->getColumnName(i
)))
171 #define BLOCK_SIZE 256
172 // -------------------------------------------------------------------------
173 Reference
< ::com::sun::star::io::XInputStream
> SAL_CALL
OResultSet::getBinaryStream( sal_Int32 columnIndex
) throw(SQLException
, RuntimeException
)
175 ::osl::MutexGuard
aGuard( m_aMutex
);
176 checkDisposed(OResultSet_BASE::rBHelper
.bDisposed
);
178 WpADOField aField
= ADOS::getField(m_pRecordSet
,columnIndex
);
180 if((aField
.GetAttributes() & adFldLong
) == adFldLong
)
182 //Copy the data only upto the Actual Size of Field.
183 sal_Int32 nSize
= aField
.GetActualSize();
184 Sequence
<sal_Int8
> aData(nSize
);
188 m_aValue
= aField
.GetChunk(BLOCK_SIZE
);
189 if(m_aValue
.isNull())
192 for(long index2
= 0;index2
< BLOCK_SIZE
;++index2
)
194 HRESULT hr
= ::SafeArrayGetElement(m_aValue
.parray
,&index2
,&chData
);
197 //Take BYTE by BYTE and advance Memory Location
198 aData
.getArray()[index
++] = chData
;
205 return new ::comphelper::SequenceInputStream(aData
);
207 // else we ask for a bytesequence
208 aField
.get_Value(m_aValue
);
210 return m_aValue
.isNull() ? NULL
: new ::comphelper::SequenceInputStream(m_aValue
);
212 // -------------------------------------------------------------------------
213 Reference
< ::com::sun::star::io::XInputStream
> SAL_CALL
OResultSet::getCharacterStream( sal_Int32
/*columnIndex*/ ) throw(SQLException
, RuntimeException
)
215 ::dbtools::throwFeatureNotImplementedException( "XRow::getCharacterStream", *this );
218 // -----------------------------------------------------------------------------
219 OLEVariant
OResultSet::getValue(sal_Int32 columnIndex
) throw(SQLException
, RuntimeException
)
221 ::osl::MutexGuard
aGuard( m_aMutex
);
222 checkDisposed(OResultSet_BASE::rBHelper
.bDisposed
);
224 WpADOField aField
= ADOS::getField(m_pRecordSet
,columnIndex
);
225 aField
.get_Value(m_aValue
);
228 // -------------------------------------------------------------------------
229 sal_Bool SAL_CALL
OResultSet::getBoolean( sal_Int32 columnIndex
) throw(SQLException
, RuntimeException
)
231 return getValue(columnIndex
);
233 // -------------------------------------------------------------------------
235 sal_Int8 SAL_CALL
OResultSet::getByte( sal_Int32 columnIndex
) throw(SQLException
, RuntimeException
)
237 return getValue(columnIndex
);
239 // -------------------------------------------------------------------------
241 Sequence
< sal_Int8
> SAL_CALL
OResultSet::getBytes( sal_Int32 columnIndex
) throw(SQLException
, RuntimeException
)
243 return getValue(columnIndex
);
245 // -------------------------------------------------------------------------
247 ::com::sun::star::util::Date SAL_CALL
OResultSet::getDate( sal_Int32 columnIndex
) throw(SQLException
, RuntimeException
)
249 return getValue(columnIndex
);
251 // -------------------------------------------------------------------------
253 double SAL_CALL
OResultSet::getDouble( sal_Int32 columnIndex
) throw(SQLException
, RuntimeException
)
255 return getValue(columnIndex
);
257 // -------------------------------------------------------------------------
259 float SAL_CALL
OResultSet::getFloat( sal_Int32 columnIndex
) throw(SQLException
, RuntimeException
)
261 return getValue(columnIndex
);
263 // -------------------------------------------------------------------------
265 sal_Int32 SAL_CALL
OResultSet::getInt( sal_Int32 columnIndex
) throw(SQLException
, RuntimeException
)
267 return getValue(columnIndex
);
269 // -------------------------------------------------------------------------
271 sal_Int32 SAL_CALL
OResultSet::getRow( ) throw(SQLException
, RuntimeException
)
273 ::osl::MutexGuard
aGuard( m_aMutex
);
274 checkDisposed(OResultSet_BASE::rBHelper
.bDisposed
);
277 PositionEnum_Param aPos
;
278 m_pRecordSet
->get_AbsolutePosition(&aPos
);
279 return (aPos
> 0) ? static_cast<sal_Int32
>(aPos
) : m_nRowPos
;
280 // return the rowcount from driver if the driver doesn't support this return our count
282 // -------------------------------------------------------------------------
284 sal_Int64 SAL_CALL
OResultSet::getLong( sal_Int32
/*columnIndex*/ ) throw(SQLException
, RuntimeException
)
286 ::dbtools::throwFeatureNotImplementedException( "XRow::getLong", *this );
289 // -------------------------------------------------------------------------
291 Reference
< XResultSetMetaData
> SAL_CALL
OResultSet::getMetaData( ) throw(SQLException
, RuntimeException
)
293 ::osl::MutexGuard
aGuard( m_aMutex
);
294 checkDisposed(OResultSet_BASE::rBHelper
.bDisposed
);
297 if(!m_xMetaData
.is())
298 m_xMetaData
= new OResultSetMetaData(m_pRecordSet
);
301 // -------------------------------------------------------------------------
302 Reference
< XArray
> SAL_CALL
OResultSet::getArray( sal_Int32
/*columnIndex*/ ) throw(SQLException
, RuntimeException
)
304 ::dbtools::throwFeatureNotImplementedException( "XRow::getArray", *this );
308 // -------------------------------------------------------------------------
310 Reference
< XClob
> SAL_CALL
OResultSet::getClob( sal_Int32
/*columnIndex*/ ) throw(SQLException
, RuntimeException
)
312 ::dbtools::throwFeatureNotImplementedException( "XRow::getClob", *this );
315 // -------------------------------------------------------------------------
316 Reference
< XBlob
> SAL_CALL
OResultSet::getBlob( sal_Int32
/*columnIndex*/ ) throw(SQLException
, RuntimeException
)
318 ::dbtools::throwFeatureNotImplementedException( "XRow::getBlob", *this );
321 // -------------------------------------------------------------------------
323 Reference
< XRef
> SAL_CALL
OResultSet::getRef( sal_Int32
/*columnIndex*/ ) throw(SQLException
, RuntimeException
)
325 ::dbtools::throwFeatureNotImplementedException( "XRow::getRef", *this );
328 // -------------------------------------------------------------------------
330 Any SAL_CALL
OResultSet::getObject( sal_Int32 columnIndex
, const Reference
< ::com::sun::star::container::XNameAccess
>& /*typeMap*/ ) throw(SQLException
, RuntimeException
)
332 return getValue(columnIndex
).makeAny();
334 // -------------------------------------------------------------------------
336 sal_Int16 SAL_CALL
OResultSet::getShort( sal_Int32 columnIndex
) throw(SQLException
, RuntimeException
)
338 return getValue(columnIndex
);
340 // -------------------------------------------------------------------------
342 OUString SAL_CALL
OResultSet::getString( sal_Int32 columnIndex
) throw(SQLException
, RuntimeException
)
344 return getValue(columnIndex
);
347 // -------------------------------------------------------------------------
350 ::com::sun::star::util::Time SAL_CALL
OResultSet::getTime( sal_Int32 columnIndex
) throw(SQLException
, RuntimeException
)
352 return getValue(columnIndex
);
354 // -------------------------------------------------------------------------
357 ::com::sun::star::util::DateTime SAL_CALL
OResultSet::getTimestamp( sal_Int32 columnIndex
) throw(SQLException
, RuntimeException
)
359 return getValue(columnIndex
);
361 // -------------------------------------------------------------------------
363 sal_Bool SAL_CALL
OResultSet::isAfterLast( ) throw(SQLException
, RuntimeException
)
365 ::osl::MutexGuard
aGuard( m_aMutex
);
366 checkDisposed(OResultSet_BASE::rBHelper
.bDisposed
);
369 VARIANT_BOOL bIsAtEOF
;
370 CHECK_RETURN(m_pRecordSet
->get_EOF(&bIsAtEOF
))
371 return bIsAtEOF
== VARIANT_TRUE
;
373 // -------------------------------------------------------------------------
374 sal_Bool SAL_CALL
OResultSet::isFirst( ) throw(SQLException
, RuntimeException
)
376 ::osl::MutexGuard
aGuard( m_aMutex
);
377 checkDisposed(OResultSet_BASE::rBHelper
.bDisposed
);
380 return m_nRowPos
== 1;
382 // -------------------------------------------------------------------------
383 sal_Bool SAL_CALL
OResultSet::isLast( ) throw(SQLException
, RuntimeException
)
385 ::osl::MutexGuard
aGuard( m_aMutex
);
386 checkDisposed(OResultSet_BASE::rBHelper
.bDisposed
);
391 // -------------------------------------------------------------------------
392 void SAL_CALL
OResultSet::beforeFirst( ) throw(SQLException
, RuntimeException
)
394 ::osl::MutexGuard
aGuard( m_aMutex
);
395 checkDisposed(OResultSet_BASE::rBHelper
.bDisposed
);
399 m_bOnFirstAfterOpen
= !previous();
401 // -------------------------------------------------------------------------
402 void SAL_CALL
OResultSet::afterLast( ) throw(SQLException
, RuntimeException
)
404 ::osl::MutexGuard
aGuard( m_aMutex
);
405 checkDisposed(OResultSet_BASE::rBHelper
.bDisposed
);
412 // -------------------------------------------------------------------------
414 void SAL_CALL
OResultSet::close( ) throw(SQLException
, RuntimeException
)
417 ::osl::MutexGuard
aGuard( m_aMutex
);
418 checkDisposed(OResultSet_BASE::rBHelper
.bDisposed
);
423 // -------------------------------------------------------------------------
425 sal_Bool SAL_CALL
OResultSet::first( ) throw(SQLException
, RuntimeException
)
427 ::osl::MutexGuard
aGuard( m_aMutex
);
428 checkDisposed(OResultSet_BASE::rBHelper
.bDisposed
);
431 if(SUCCEEDED(m_pRecordSet
->MoveFirst()))
434 m_bOnFirstAfterOpen
= sal_False
;
439 // -------------------------------------------------------------------------
441 sal_Bool SAL_CALL
OResultSet::last( ) throw(SQLException
, RuntimeException
)
443 ::osl::MutexGuard
aGuard( m_aMutex
);
444 checkDisposed(OResultSet_BASE::rBHelper
.bDisposed
);
447 sal_Bool bRet
= SUCCEEDED(m_pRecordSet
->MoveLast());
450 m_pRecordSet
->get_RecordCount(&m_nRowPos
);
451 m_bOnFirstAfterOpen
= sal_False
;
455 // -------------------------------------------------------------------------
456 sal_Bool SAL_CALL
OResultSet::absolute( sal_Int32 row
) throw(SQLException
, RuntimeException
)
458 ::osl::MutexGuard
aGuard( m_aMutex
);
459 checkDisposed(OResultSet_BASE::rBHelper
.bDisposed
);
462 if(!row
) // absolute with zero not allowed
463 ::dbtools::throwFunctionSequenceException(*this);
465 sal_Bool bCheck
= sal_True
;
468 bCheck
= SUCCEEDED(m_pRecordSet
->MoveLast());
471 while(++row
< 0 && bCheck
)
472 bCheck
= SUCCEEDED(m_pRecordSet
->MovePrevious());
480 bCheck
= SUCCEEDED(m_pRecordSet
->Move(row
-1,aEmpty
)); // move to row -1 because we stand already on the first
485 m_bOnFirstAfterOpen
= sal_False
;
488 // -------------------------------------------------------------------------
489 sal_Bool SAL_CALL
OResultSet::relative( sal_Int32 row
) throw(SQLException
, RuntimeException
)
491 ::osl::MutexGuard
aGuard( m_aMutex
);
492 checkDisposed(OResultSet_BASE::rBHelper
.bDisposed
);
497 sal_Int32 nNewPos
= row
;
498 if ( m_bOnFirstAfterOpen
&& nNewPos
> 0 )
500 sal_Bool bRet
= SUCCEEDED(m_pRecordSet
->Move(row
,aEmpty
));
504 m_bOnFirstAfterOpen
= sal_False
;
508 // -------------------------------------------------------------------------
509 sal_Bool SAL_CALL
OResultSet::previous( ) throw(SQLException
, RuntimeException
)
511 ::osl::MutexGuard
aGuard( m_aMutex
);
512 checkDisposed(OResultSet_BASE::rBHelper
.bDisposed
);
514 sal_Bool bRet
= SUCCEEDED(m_pRecordSet
->MovePrevious());
518 m_bOnFirstAfterOpen
= sal_False
;
522 // -------------------------------------------------------------------------
523 Reference
< XInterface
> SAL_CALL
OResultSet::getStatement( ) throw(SQLException
, RuntimeException
)
525 ::osl::MutexGuard
aGuard( m_aMutex
);
526 checkDisposed(OResultSet_BASE::rBHelper
.bDisposed
);
529 // -------------------------------------------------------------------------
531 sal_Bool SAL_CALL
OResultSet::rowDeleted( ) throw(SQLException
, RuntimeException
)
533 ::osl::MutexGuard
aGuard( m_aMutex
);
534 checkDisposed(OResultSet_BASE::rBHelper
.bDisposed
);
537 RecordStatusEnum eRec
;
538 m_pRecordSet
->get_Status((sal_Int32
*)&eRec
);
539 sal_Bool bRet
= (eRec
& adRecDeleted
) == adRecDeleted
;
544 // -------------------------------------------------------------------------
545 sal_Bool SAL_CALL
OResultSet::rowInserted( ) throw(SQLException
, RuntimeException
)
546 { ::osl::MutexGuard
aGuard( m_aMutex
);
547 checkDisposed(OResultSet_BASE::rBHelper
.bDisposed
);
550 RecordStatusEnum eRec
;
551 m_pRecordSet
->get_Status((sal_Int32
*)&eRec
);
552 sal_Bool bRet
= (eRec
& adRecNew
) == adRecNew
;
557 // -------------------------------------------------------------------------
558 sal_Bool SAL_CALL
OResultSet::rowUpdated( ) throw(SQLException
, RuntimeException
)
560 ::osl::MutexGuard
aGuard( m_aMutex
);
561 checkDisposed(OResultSet_BASE::rBHelper
.bDisposed
);
564 RecordStatusEnum eRec
;
565 m_pRecordSet
->get_Status((sal_Int32
*)&eRec
);
566 return (eRec
& adRecModified
) == adRecModified
;
568 // -------------------------------------------------------------------------
570 sal_Bool SAL_CALL
OResultSet::isBeforeFirst( ) throw(SQLException
, RuntimeException
)
572 ::osl::MutexGuard
aGuard( m_aMutex
);
573 checkDisposed(OResultSet_BASE::rBHelper
.bDisposed
);
576 OSL_ENSURE(!m_nRowPos
,"OResultSet::isBeforeFirst: Error in setting m_nRowPos!");
577 VARIANT_BOOL bIsAtBOF
= VARIANT_TRUE
;
578 if(!m_bOnFirstAfterOpen
)
580 OSL_ENSURE(!m_nRowPos
,"OResultSet::isBeforeFirst: Error in setting m_nRowPos!");
581 m_pRecordSet
->get_BOF(&bIsAtBOF
);
583 return bIsAtBOF
== VARIANT_TRUE
;
585 // -------------------------------------------------------------------------
587 sal_Bool SAL_CALL
OResultSet::next( ) throw(SQLException
, RuntimeException
)
589 ::osl::MutexGuard
aGuard( m_aMutex
);
590 checkDisposed(OResultSet_BASE::rBHelper
.bDisposed
);
593 sal_Bool bRet
= sal_True
;
594 if(m_bOnFirstAfterOpen
)
596 m_bOnFirstAfterOpen
= sal_False
;
601 bRet
= SUCCEEDED(m_pRecordSet
->MoveNext());
605 VARIANT_BOOL bIsAtEOF
;
606 CHECK_RETURN(m_pRecordSet
->get_EOF(&bIsAtEOF
))
607 bRet
= bIsAtEOF
!= VARIANT_TRUE
;
611 ADOS::ThrowException(*m_pStmt
->m_pConnection
->getConnection(),*this);
616 // -------------------------------------------------------------------------
618 sal_Bool SAL_CALL
OResultSet::wasNull( ) throw(SQLException
, RuntimeException
)
620 ::osl::MutexGuard
aGuard( m_aMutex
);
621 checkDisposed(OResultSet_BASE::rBHelper
.bDisposed
);
624 return m_aValue
.isNull();
626 // -------------------------------------------------------------------------
628 void SAL_CALL
OResultSet::cancel( ) throw(RuntimeException
)
630 ::osl::MutexGuard
aGuard( m_aMutex
);
631 checkDisposed(OResultSet_BASE::rBHelper
.bDisposed
);
634 m_pRecordSet
->Cancel();
636 // -------------------------------------------------------------------------
637 void SAL_CALL
OResultSet::clearWarnings( ) throw(SQLException
, RuntimeException
)
640 // -------------------------------------------------------------------------
641 Any SAL_CALL
OResultSet::getWarnings( ) throw(SQLException
, RuntimeException
)
645 // -------------------------------------------------------------------------
646 void SAL_CALL
OResultSet::insertRow( ) throw(SQLException
, RuntimeException
)
648 ::osl::MutexGuard
aGuard( m_aMutex
);
649 checkDisposed(OResultSet_BASE::rBHelper
.bDisposed
);
654 m_pRecordSet
->AddNew(aEmpty
,aEmpty
);
656 // -------------------------------------------------------------------------
657 void SAL_CALL
OResultSet::updateRow( ) throw(SQLException
, RuntimeException
)
659 ::osl::MutexGuard
aGuard( m_aMutex
);
660 checkDisposed(OResultSet_BASE::rBHelper
.bDisposed
);
665 m_pRecordSet
->Update(aEmpty
,aEmpty
);
667 // -------------------------------------------------------------------------
668 void SAL_CALL
OResultSet::deleteRow( ) throw(SQLException
, RuntimeException
)
670 ::osl::MutexGuard
aGuard( m_aMutex
);
671 checkDisposed(OResultSet_BASE::rBHelper
.bDisposed
);
674 m_pRecordSet
->Delete(adAffectCurrent
);
675 m_pRecordSet
->UpdateBatch(adAffectCurrent
);
677 // -------------------------------------------------------------------------
679 void SAL_CALL
OResultSet::cancelRowUpdates( ) throw(SQLException
, RuntimeException
)
681 ::osl::MutexGuard
aGuard( m_aMutex
);
682 checkDisposed(OResultSet_BASE::rBHelper
.bDisposed
);
685 m_pRecordSet
->CancelUpdate();
687 // -------------------------------------------------------------------------
689 void SAL_CALL
OResultSet::moveToInsertRow( ) throw(SQLException
, RuntimeException
)
691 // ::osl::MutexGuard aGuard( m_aMutex );
692 //checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
693 // if ( getResultSetConcurrency() == ResultSetConcurrency::READ_ONLY )
694 // throw SQLException();
696 // -------------------------------------------------------------------------
698 void SAL_CALL
OResultSet::moveToCurrentRow( ) throw(SQLException
, RuntimeException
)
701 // -----------------------------------------------------------------------------
702 void OResultSet::updateValue(sal_Int32 columnIndex
,const OLEVariant
& x
)
704 ::osl::MutexGuard
aGuard( m_aMutex
);
705 checkDisposed(OResultSet_BASE::rBHelper
.bDisposed
);
707 WpADOField aField
= ADOS::getField(m_pRecordSet
,columnIndex
);
710 // -------------------------------------------------------------------------
711 void SAL_CALL
OResultSet::updateNull( sal_Int32 columnIndex
) throw(SQLException
, RuntimeException
)
715 updateValue(columnIndex
,x
);
717 // -------------------------------------------------------------------------
719 void SAL_CALL
OResultSet::updateBoolean( sal_Int32 columnIndex
, sal_Bool x
) throw(SQLException
, RuntimeException
)
721 updateValue(columnIndex
,x
);
723 // -------------------------------------------------------------------------
724 void SAL_CALL
OResultSet::updateByte( sal_Int32 columnIndex
, sal_Int8 x
) throw(SQLException
, RuntimeException
)
726 updateValue(columnIndex
,x
);
728 // -------------------------------------------------------------------------
730 void SAL_CALL
OResultSet::updateShort( sal_Int32 columnIndex
, sal_Int16 x
) throw(SQLException
, RuntimeException
)
732 updateValue(columnIndex
,x
);
734 // -------------------------------------------------------------------------
735 void SAL_CALL
OResultSet::updateInt( sal_Int32 columnIndex
, sal_Int32 x
) throw(SQLException
, RuntimeException
)
737 updateValue(columnIndex
,x
);
739 // -------------------------------------------------------------------------
740 void SAL_CALL
OResultSet::updateLong( sal_Int32 columnIndex
, sal_Int64 x
) throw(SQLException
, RuntimeException
)
742 updateValue(columnIndex
,x
);
744 // -----------------------------------------------------------------------
745 void SAL_CALL
OResultSet::updateFloat( sal_Int32 columnIndex
, float x
) throw(SQLException
, RuntimeException
)
747 updateValue(columnIndex
,x
);
749 // -------------------------------------------------------------------------
751 void SAL_CALL
OResultSet::updateDouble( sal_Int32 columnIndex
, double x
) throw(SQLException
, RuntimeException
)
753 updateValue(columnIndex
,x
);
755 // -------------------------------------------------------------------------
756 void SAL_CALL
OResultSet::updateString( sal_Int32 columnIndex
, const OUString
& x
) throw(SQLException
, RuntimeException
)
758 updateValue(columnIndex
,x
);
760 // -------------------------------------------------------------------------
761 void SAL_CALL
OResultSet::updateBytes( sal_Int32 columnIndex
, const Sequence
< sal_Int8
>& x
) throw(SQLException
, RuntimeException
)
763 updateValue(columnIndex
,x
);
765 // -------------------------------------------------------------------------
766 void SAL_CALL
OResultSet::updateDate( sal_Int32 columnIndex
, const ::com::sun::star::util::Date
& x
) throw(SQLException
, RuntimeException
)
768 updateValue(columnIndex
,x
);
770 // -------------------------------------------------------------------------
772 void SAL_CALL
OResultSet::updateTime( sal_Int32 columnIndex
, const ::com::sun::star::util::Time
& x
) throw(SQLException
, RuntimeException
)
774 updateValue(columnIndex
,x
);
776 // -------------------------------------------------------------------------
778 void SAL_CALL
OResultSet::updateTimestamp( sal_Int32 columnIndex
, const ::com::sun::star::util::DateTime
& x
) throw(SQLException
, RuntimeException
)
780 updateValue(columnIndex
,x
);
782 // -------------------------------------------------------------------------
784 void SAL_CALL
OResultSet::updateBinaryStream( sal_Int32 columnIndex
, const Reference
< ::com::sun::star::io::XInputStream
>& x
, sal_Int32 length
) throw(SQLException
, RuntimeException
)
787 ::dbtools::throwFunctionSequenceException(*this);
789 Sequence
<sal_Int8
> aSeq
;
790 x
->readBytes(aSeq
,length
);
791 updateBytes(columnIndex
,aSeq
);
793 // -------------------------------------------------------------------------
794 void SAL_CALL
OResultSet::updateCharacterStream( sal_Int32 columnIndex
, const Reference
< ::com::sun::star::io::XInputStream
>& x
, sal_Int32 length
) throw(SQLException
, RuntimeException
)
797 ::dbtools::throwFunctionSequenceException(*this);
799 Sequence
<sal_Int8
> aSeq
;
800 x
->readBytes(aSeq
,length
);
801 updateBytes(columnIndex
,aSeq
);
803 // -------------------------------------------------------------------------
804 void SAL_CALL
OResultSet::refreshRow( ) throw(SQLException
, RuntimeException
)
806 ::osl::MutexGuard
aGuard( m_aMutex
);
807 checkDisposed(OResultSet_BASE::rBHelper
.bDisposed
);
810 m_pRecordSet
->Resync(adAffectCurrent
,adResyncAllValues
);
812 // -------------------------------------------------------------------------
813 void SAL_CALL
OResultSet::updateObject( sal_Int32 columnIndex
, const Any
& x
) throw(SQLException
, RuntimeException
)
815 if (!::dbtools::implUpdateObject(this, columnIndex
, x
))
816 throw SQLException();
818 // -------------------------------------------------------------------------
820 void SAL_CALL
OResultSet::updateNumericObject( sal_Int32 columnIndex
, const Any
& x
, sal_Int32
/*scale*/ ) throw(SQLException
, RuntimeException
)
822 if (!::dbtools::implUpdateObject(this, columnIndex
, x
))
823 throw SQLException();
825 //------------------------------------------------------------------------------
827 Any SAL_CALL
OResultSet::getBookmark( ) throw(SQLException
, RuntimeException
)
829 ::osl::MutexGuard
aGuard( m_aMutex
);
830 checkDisposed(OResultSet_BASE::rBHelper
.bDisposed
);
832 if(m_nRowPos
< (sal_Int32
)m_aBookmarks
.size()) // this bookmark was already fetched
833 return makeAny(sal_Int32(m_nRowPos
-1));
836 m_pRecordSet
->get_Bookmark(&aVar
);
837 m_aBookmarks
.push_back(aVar
);
838 return makeAny((sal_Int32
)(m_aBookmarks
.size()-1));
841 //------------------------------------------------------------------------------
842 sal_Bool SAL_CALL
OResultSet::moveToBookmark( const Any
& bookmark
) throw(SQLException
, RuntimeException
)
844 ::osl::MutexGuard
aGuard( m_aMutex
);
845 checkDisposed(OResultSet_BASE::rBHelper
.bDisposed
);
850 OSL_ENSURE(nPos
>= 0 && nPos
< (sal_Int32
)m_aBookmarks
.size(),"Invalid Index for vector");
851 if(nPos
< 0 || nPos
>= (sal_Int32
)m_aBookmarks
.size())
852 ::dbtools::throwFunctionSequenceException(*this);
854 return SUCCEEDED(m_pRecordSet
->Move(0,m_aBookmarks
[nPos
]));
856 //------------------------------------------------------------------------------
857 sal_Bool SAL_CALL
OResultSet::moveRelativeToBookmark( const Any
& bookmark
, sal_Int32 rows
) throw(SQLException
, RuntimeException
)
859 ::osl::MutexGuard
aGuard( m_aMutex
);
860 checkDisposed(OResultSet_BASE::rBHelper
.bDisposed
);
866 OSL_ENSURE(nPos
>= 0 && nPos
< (sal_Int32
)m_aBookmarks
.size(),"Invalid Index for vector");
867 if(nPos
< 0 || nPos
>= (sal_Int32
)m_aBookmarks
.size())
868 ::dbtools::throwFunctionSequenceException(*this);
869 return SUCCEEDED(m_pRecordSet
->Move(rows
,m_aBookmarks
[nPos
]));
871 //------------------------------------------------------------------------------
872 sal_Int32 SAL_CALL
OResultSet::compareBookmarks( const Any
& bookmark1
, const Any
& bookmark2
) throw(SQLException
, RuntimeException
)
874 ::osl::MutexGuard
aGuard( m_aMutex
);
875 checkDisposed(OResultSet_BASE::rBHelper
.bDisposed
);
881 if(nPos1
== nPos2
) // they should be equal
884 OSL_ENSURE((nPos1
>= 0 && nPos1
< (sal_Int32
)m_aBookmarks
.size()) || (nPos1
>= 0 && nPos2
< (sal_Int32
)m_aBookmarks
.size()),"Invalid Index for vector");
887 m_pRecordSet
->CompareBookmarks(m_aBookmarks
[nPos1
],m_aBookmarks
[nPos2
],&eNum
);
888 return ((sal_Int32
)eNum
) +1;
890 //------------------------------------------------------------------------------
891 sal_Bool SAL_CALL
OResultSet::hasOrderedBookmarks( ) throw(SQLException
, RuntimeException
)
893 ::osl::MutexGuard
aGuard( m_aMutex
);
894 checkDisposed(OResultSet_BASE::rBHelper
.bDisposed
);
897 ADOProperties
* pProps
= NULL
;
898 m_pRecordSet
->get_Properties(&pProps
);
899 WpADOProperties aProps
;
900 aProps
.setWithOutAddRef(pProps
);
901 ADOS::ThrowException(*((OConnection
*)m_pStmt
->getConnection().get())->getConnection(),*this);
902 OSL_ENSURE(aProps
.IsValid(),"There are no properties at the connection");
904 WpADOProperty
aProp(aProps
.GetItem(OUString("Bookmarks Ordered")));
907 aVar
= aProp
.GetValue();
909 ADOS::ThrowException(*((OConnection
*)m_pStmt
->getConnection().get())->getConnection(),*this);
911 sal_Bool
bValue(sal_False
);
912 if(!aVar
.isNull() && !aVar
.isEmpty())
916 //------------------------------------------------------------------------------
917 sal_Int32 SAL_CALL
OResultSet::hashBookmark( const Any
& bookmark
) throw(SQLException
, RuntimeException
)
919 ::osl::MutexGuard
aGuard( m_aMutex
);
920 checkDisposed(OResultSet_BASE::rBHelper
.bDisposed
);
927 //------------------------------------------------------------------------------
929 Sequence
< sal_Int32
> SAL_CALL
OResultSet::deleteRows( const Sequence
< Any
>& rows
) throw(SQLException
, RuntimeException
)
931 ::osl::MutexGuard
aGuard( m_aMutex
);
932 checkDisposed(OResultSet_BASE::rBHelper
.bDisposed
);
938 // Create SafeArray Bounds and initialize the array
939 SAFEARRAYBOUND rgsabound
[1];
940 rgsabound
[0].lLbound
= 0;
941 rgsabound
[0].cElements
= rows
.getLength();
942 SAFEARRAY
*psa
= SafeArrayCreate( VT_VARIANT
, 1, rgsabound
);
944 const Any
* pBegin
= rows
.getConstArray();
945 const Any
* pEnd
= pBegin
+ rows
.getLength();
946 for(sal_Int32 i
=0;pBegin
!= pEnd
;++pBegin
,++i
)
949 SafeArrayPutElement(psa
,&i
,&m_aBookmarks
[nPos
]);
952 // Initialize and fill the SafeArray
954 vsa
.setArray(psa
,VT_VARIANT
);
956 m_pRecordSet
->put_Filter(vsa
);
957 m_pRecordSet
->Delete(adAffectGroup
);
958 m_pRecordSet
->UpdateBatch(adAffectGroup
);
960 Sequence
< sal_Int32
> aSeq(rows
.getLength());
963 sal_Int32
* pSeq
= aSeq
.getArray();
967 OSL_ENSURE(i
<aSeq
.getLength(),"Index greater than length of sequence");
968 m_pRecordSet
->get_Status(&pSeq
[i
]);
969 if(pSeq
[i
++] == adRecDeleted
)
976 //------------------------------------------------------------------------------
977 sal_Int32
OResultSet::getResultSetConcurrency() const
978 throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
)
980 sal_Int32 nValue
=ResultSetConcurrency::READ_ONLY
;
982 if(!SUCCEEDED(m_pRecordSet
->get_LockType(&eRet
)))
987 nValue
= ResultSetConcurrency::READ_ONLY
;
990 nValue
= ResultSetConcurrency::UPDATABLE
;
996 //------------------------------------------------------------------------------
997 sal_Int32
OResultSet::getResultSetType() const
998 throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
)
1001 CursorTypeEnum eRet
;
1002 if(!SUCCEEDED(m_pRecordSet
->get_CursorType(&eRet
)))
1006 case adOpenUnspecified
:
1007 case adOpenForwardOnly
:
1008 nValue
= ResultSetType::FORWARD_ONLY
;
1012 nValue
= ResultSetType::SCROLL_INSENSITIVE
;
1015 nValue
= ResultSetType::SCROLL_SENSITIVE
;
1021 //------------------------------------------------------------------------------
1022 sal_Int32
OResultSet::getFetchDirection() const
1023 throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
)
1025 return FetchDirection::FORWARD
;
1027 //------------------------------------------------------------------------------
1028 sal_Int32
OResultSet::getFetchSize() const
1029 throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
)
1031 sal_Int32 nValue
=-1;
1032 m_pRecordSet
->get_CacheSize(&nValue
);
1035 //------------------------------------------------------------------------------
1036 OUString
OResultSet::getCursorName() const
1037 throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
)
1042 //------------------------------------------------------------------------------
1043 void OResultSet::setFetchDirection(sal_Int32
/*_par0*/)
1044 throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
)
1046 ::dbtools::throwFeatureNotImplementedException( "ResultSet::FetchDirection", *this );
1048 //------------------------------------------------------------------------------
1049 void OResultSet::setFetchSize(sal_Int32 _par0
)
1050 throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
)
1052 m_pRecordSet
->put_CacheSize(_par0
);
1054 // -------------------------------------------------------------------------
1055 ::cppu::IPropertyArrayHelper
* OResultSet::createArrayHelper( ) const
1057 Sequence
< com::sun::star::beans::Property
> aProps(5);
1058 com::sun::star::beans::Property
* pProperties
= aProps
.getArray();
1061 // DECL_PROP1IMPL(CURSORNAME, OUString) PropertyAttribute::READONLY);
1062 DECL_PROP0(FETCHDIRECTION
, sal_Int32
);
1063 DECL_PROP0(FETCHSIZE
, sal_Int32
);
1064 DECL_BOOL_PROP1IMPL(ISBOOKMARKABLE
) PropertyAttribute::READONLY
);
1065 DECL_PROP1IMPL(RESULTSETCONCURRENCY
,sal_Int32
) PropertyAttribute::READONLY
);
1066 DECL_PROP1IMPL(RESULTSETTYPE
, sal_Int32
) PropertyAttribute::READONLY
);
1068 return new ::cppu::OPropertyArrayHelper(aProps
);
1070 // -------------------------------------------------------------------------
1071 ::cppu::IPropertyArrayHelper
& OResultSet::getInfoHelper()
1073 return *const_cast<OResultSet
*>(this)->getArrayHelper();
1075 // -------------------------------------------------------------------------
1076 sal_Bool
OResultSet::convertFastPropertyValue(
1077 Any
& rConvertedValue
,
1081 throw (::com::sun::star::lang::IllegalArgumentException
)
1085 case PROPERTY_ID_ISBOOKMARKABLE
:
1086 case PROPERTY_ID_CURSORNAME
:
1087 case PROPERTY_ID_RESULTSETCONCURRENCY
:
1088 case PROPERTY_ID_RESULTSETTYPE
:
1089 throw ::com::sun::star::lang::IllegalArgumentException();
1091 case PROPERTY_ID_FETCHDIRECTION
:
1092 return ::comphelper::tryPropertyValue(rConvertedValue
, rOldValue
, rValue
, getFetchDirection());
1093 case PROPERTY_ID_FETCHSIZE
:
1094 return ::comphelper::tryPropertyValue(rConvertedValue
, rOldValue
, rValue
, getFetchSize());
1100 // -------------------------------------------------------------------------
1101 void OResultSet::setFastPropertyValue_NoBroadcast(sal_Int32 nHandle
,const Any
& rValue
)throw (Exception
)
1105 case PROPERTY_ID_ISBOOKMARKABLE
:
1106 case PROPERTY_ID_CURSORNAME
:
1107 case PROPERTY_ID_RESULTSETCONCURRENCY
:
1108 case PROPERTY_ID_RESULTSETTYPE
:
1111 case PROPERTY_ID_FETCHDIRECTION
:
1112 setFetchDirection(getINT32(rValue
));
1114 case PROPERTY_ID_FETCHSIZE
:
1115 setFetchSize(getINT32(rValue
));
1121 // -------------------------------------------------------------------------
1122 void OResultSet::getFastPropertyValue(Any
& rValue
,sal_Int32 nHandle
) const
1126 case PROPERTY_ID_ISBOOKMARKABLE
:
1129 m_pRecordSet
->Supports(adBookmark
,&bBool
);
1130 sal_Bool bRet
= bBool
== VARIANT_TRUE
;
1131 rValue
.setValue(&bRet
, ::getCppuBooleanType() );
1134 case PROPERTY_ID_CURSORNAME
:
1135 rValue
<<= getCursorName();
1137 case PROPERTY_ID_RESULTSETCONCURRENCY
:
1138 rValue
<<= getResultSetConcurrency();
1140 case PROPERTY_ID_RESULTSETTYPE
:
1141 rValue
<<= getResultSetType();
1143 case PROPERTY_ID_FETCHDIRECTION
:
1144 rValue
<<= getFetchDirection();
1146 case PROPERTY_ID_FETCHSIZE
:
1147 rValue
<<= getFetchSize();
1151 // -----------------------------------------------------------------------------
1152 void SAL_CALL
OResultSet::acquire() throw()
1154 OResultSet_BASE::acquire();
1156 // -----------------------------------------------------------------------------
1157 void SAL_CALL
OResultSet::release() throw()
1159 OResultSet_BASE::release();
1161 // -----------------------------------------------------------------------------
1162 ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySetInfo
> SAL_CALL
OResultSet::getPropertySetInfo( ) throw(::com::sun::star::uno::RuntimeException
)
1164 return ::cppu::OPropertySetHelper::createPropertySetInfo(getInfoHelper());
1166 // -----------------------------------------------------------------------------
1170 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */