Update ooo320-m1
[ooovba.git] / connectivity / source / drivers / odbcbase / OResultSet.cxx
blobe48cfe0259f0388fbcb4a295b03071b369cd40b3
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: OResultSet.cxx,v $
10 * $Revision: 1.66 $
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 "odbc/OResultSet.hxx"
34 #include "odbc/OTools.hxx"
35 #include "odbc/OResultSetMetaData.hxx"
36 #include <com/sun/star/sdbc/DataType.hpp>
37 #include <com/sun/star/beans/PropertyAttribute.hpp>
38 #include <com/sun/star/sdbcx/CompareBookmark.hpp>
39 #include <com/sun/star/sdbc/ResultSetConcurrency.hpp>
40 #include <com/sun/star/sdbc/FetchDirection.hpp>
41 #include <com/sun/star/sdbc/ResultSetType.hpp>
42 #include <comphelper/property.hxx>
43 #include <comphelper/sequence.hxx>
44 #include <cppuhelper/typeprovider.hxx>
45 #include <comphelper/extract.hxx>
46 #include <com/sun/star/lang/DisposedException.hpp>
47 #include <comphelper/types.hxx>
48 #include "connectivity/dbtools.hxx"
49 #include "connectivity/dbexception.hxx"
50 #include "diagnose_ex.h"
51 #include <rtl/logfile.hxx>
53 using namespace ::comphelper;
54 using namespace connectivity;
55 using namespace connectivity::odbc;
56 using namespace cppu;
57 using namespace com::sun::star::uno;
58 using namespace com::sun::star::lang;
59 using namespace com::sun::star::beans;
60 using namespace com::sun::star::sdbc;
61 using namespace com::sun::star::sdbcx;
62 using namespace com::sun::star::container;
63 using namespace com::sun::star::io;
64 using namespace com::sun::star::util;
66 #define ODBC_SQL_NOT_DEFINED 99UL
68 //------------------------------------------------------------------------------
69 // IMPLEMENT_SERVICE_INFO(OResultSet,"com.sun.star.sdbcx.OResultSet","com.sun.star.sdbc.ResultSet");
70 ::rtl::OUString SAL_CALL OResultSet::getImplementationName( ) throw ( RuntimeException)
72 return ::rtl::OUString::createFromAscii("com.sun.star.sdbcx.odbc.ResultSet");
74 // -------------------------------------------------------------------------
75 Sequence< ::rtl::OUString > SAL_CALL OResultSet::getSupportedServiceNames( ) throw( RuntimeException)
77 Sequence< ::rtl::OUString > aSupported(2);
78 aSupported[0] = ::rtl::OUString::createFromAscii("com.sun.star.sdbc.ResultSet");
79 aSupported[1] = ::rtl::OUString::createFromAscii("com.sun.star.sdbcx.ResultSet");
80 return aSupported;
82 // -------------------------------------------------------------------------
83 sal_Bool SAL_CALL OResultSet::supportsService( const ::rtl::OUString& _rServiceName ) throw( RuntimeException)
85 Sequence< ::rtl::OUString > aSupported(getSupportedServiceNames());
86 const ::rtl::OUString* pSupported = aSupported.getConstArray();
87 const ::rtl::OUString* pEnd = pSupported + aSupported.getLength();
88 for (;pSupported != pEnd && !pSupported->equals(_rServiceName); ++pSupported)
91 return pSupported != pEnd;
94 // -------------------------------------------------------------------------
95 OResultSet::OResultSet(SQLHANDLE _pStatementHandle ,OStatement_Base* pStmt) : OResultSet_BASE(m_aMutex)
96 ,OPropertySetHelper(OResultSet_BASE::rBHelper)
97 ,m_aStatementHandle(_pStatementHandle)
98 ,m_aConnectionHandle(pStmt->getConnectionHandle())
99 ,m_pStatement(pStmt)
100 ,m_pSkipDeletedSet(NULL)
101 ,m_xStatement(*pStmt)
102 ,m_xMetaData(NULL)
103 ,m_pRowStatusArray( NULL )
104 ,m_nTextEncoding(pStmt->getOwnConnection()->getTextEncoding())
105 ,m_nRowPos(0)
106 ,m_nLastColumnPos(0)
107 ,m_nUseBookmarks(ODBC_SQL_NOT_DEFINED)
108 ,m_nCurrentFetchState(0)
109 ,m_bWasNull(sal_True)
110 ,m_bEOF(sal_True)
111 ,m_bLastRecord(sal_False)
112 ,m_bFreeHandle(sal_False)
113 ,m_bInserting(sal_False)
114 ,m_bFetchData(sal_True)
115 ,m_bRowInserted(sal_False)
116 ,m_bRowDeleted(sal_False)
117 ,m_bUseFetchScroll(sal_False)
119 osl_incrementInterlockedCount( &m_refCount );
122 m_pRowStatusArray = new SQLUSMALLINT[1]; // the default value
123 N3SQLSetStmtAttr(m_aStatementHandle,SQL_ATTR_ROW_STATUS_PTR,m_pRowStatusArray,SQL_IS_POINTER);
125 catch(Exception&)
126 { // we don't want our result destroy here
128 SQLINTEGER nCurType = 0;
131 N3SQLGetStmtAttr(m_aStatementHandle,SQL_ATTR_CURSOR_TYPE,&nCurType,SQL_IS_UINTEGER,0);
132 SQLUINTEGER nValueLen = m_pStatement->getCursorProperties(nCurType,sal_False);
133 if( (nValueLen & SQL_CA2_SENSITIVITY_DELETIONS) != SQL_CA2_SENSITIVITY_DELETIONS ||
134 (nValueLen & SQL_CA2_CRC_EXACT) != SQL_CA2_CRC_EXACT)
135 m_pSkipDeletedSet = new OSkipDeletedSet(this);
137 catch(Exception&)
138 { // we don't want our result destroy here
142 SQLUINTEGER nValueLen = 0;
143 OTools::GetInfo(m_pStatement->getOwnConnection(),m_aConnectionHandle,SQL_GETDATA_EXTENSIONS,nValueLen,NULL);
144 m_bFetchData = !((SQL_GD_ANY_ORDER & nValueLen) == SQL_GD_ANY_ORDER && nCurType != SQL_CURSOR_FORWARD_ONLY);
146 catch(Exception&)
147 { // we don't want our result destroy here
148 m_bFetchData = sal_True;
152 if ( getOdbcFunction(ODBC3SQLGetFunctions) )
154 SQLUSMALLINT nSupported = 0;
155 m_bUseFetchScroll = ( N3SQLGetFunctions(m_aConnectionHandle,SQL_API_SQLFETCHSCROLL,&nSupported) == SQL_SUCCESS && nSupported == 1 );
158 catch(Exception&)
160 m_bUseFetchScroll = sal_False;
163 osl_decrementInterlockedCount( &m_refCount );
165 // -------------------------------------------------------------------------
166 OResultSet::~OResultSet()
168 delete m_pRowStatusArray;
169 delete m_pSkipDeletedSet;
171 // -----------------------------------------------------------------------------
172 void OResultSet::construct()
174 osl_incrementInterlockedCount( &m_refCount );
175 allocBuffer();
176 osl_decrementInterlockedCount( &m_refCount );
178 // -------------------------------------------------------------------------
179 void OResultSet::disposing(void)
181 SQLRETURN nRet = N3SQLCloseCursor(m_aStatementHandle);
182 OSL_UNUSED( nRet );
183 OPropertySetHelper::disposing();
185 ::osl::MutexGuard aGuard(m_aMutex);
186 if(!m_aBindVector.empty())
187 releaseBuffer();
188 if(m_bFreeHandle)
189 m_pStatement->getOwnConnection()->freeStatementHandle(m_aStatementHandle);
191 m_xStatement.clear();
192 m_xMetaData.clear();
194 // -------------------------------------------------------------------------
195 SQLRETURN OResultSet::unbind(sal_Bool _bUnbindHandle)
197 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OResultSet::unbind" );
198 SQLRETURN nRet = 0;
199 if ( _bUnbindHandle )
200 nRet = N3SQLFreeStmt(m_aStatementHandle,SQL_UNBIND);
202 if ( m_aBindVector.size() > 1 )
204 TVoidVector::iterator pValue = m_aBindVector.begin() + 1;
205 TVoidVector::iterator pEnd = m_aBindVector.end();
206 for(; pValue != pEnd; ++pValue)
208 switch (pValue->second)
210 case DataType::CHAR:
211 case DataType::VARCHAR:
212 delete static_cast< ::rtl::OString* >(reinterpret_cast< void * >(pValue->first));
213 break;
214 case DataType::BIGINT:
215 delete static_cast< sal_Int64* >(reinterpret_cast< void * >(pValue->first));
216 break;
217 case DataType::DECIMAL:
218 case DataType::NUMERIC:
219 delete static_cast< ::rtl::OString* >(reinterpret_cast< void * >(pValue->first));
220 break;
221 case DataType::REAL:
222 case DataType::DOUBLE:
223 delete static_cast< double* >(reinterpret_cast< void * >(pValue->first));
224 break;
225 case DataType::LONGVARCHAR:
226 delete [] static_cast< char* >(reinterpret_cast< void * >(pValue->first));
227 break;
228 case DataType::LONGVARBINARY:
229 delete [] static_cast< char* >(reinterpret_cast< void * >(pValue->first));
230 break;
231 case DataType::DATE:
232 delete static_cast< DATE_STRUCT* >(reinterpret_cast< void * >(pValue->first));
233 break;
234 case DataType::TIME:
235 delete static_cast< TIME_STRUCT* >(reinterpret_cast< void * >(pValue->first));
236 break;
237 case DataType::TIMESTAMP:
238 delete static_cast< TIMESTAMP_STRUCT* >(reinterpret_cast< void * >(pValue->first));
239 break;
240 case DataType::BIT:
241 case DataType::TINYINT:
242 delete static_cast< sal_Int8* >(reinterpret_cast< void * >(pValue->first));
243 break;
244 case DataType::SMALLINT:
245 delete static_cast< sal_Int16* >(reinterpret_cast< void * >(pValue->first));
246 break;
247 case DataType::INTEGER:
248 delete static_cast< sal_Int32* >(reinterpret_cast< void * >(pValue->first));
249 break;
250 case DataType::FLOAT:
251 delete static_cast< float* >(reinterpret_cast< void * >(pValue->first));
252 break;
253 case DataType::BINARY:
254 case DataType::VARBINARY:
255 delete static_cast< sal_Int8* >(reinterpret_cast< void * >(pValue->first));
256 break;
259 m_aBindVector.clear();
260 m_aBindVector.push_back(TVoidPtr(0,0)); // the first is reserved for the bookmark
262 return nRet;
264 // -------------------------------------------------------------------------
265 TVoidPtr OResultSet::allocBindColumn(sal_Int32 _nType,sal_Int32 _nColumnIndex)
267 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OResultSet::allocBindColumn" );
268 TVoidPtr aPair;
269 switch (_nType)
271 case DataType::CHAR:
272 case DataType::VARCHAR:
273 aPair = TVoidPtr(reinterpret_cast< sal_Int64 >(new ::rtl::OString()),_nType);
274 break;
275 case DataType::BIGINT:
276 aPair = TVoidPtr(reinterpret_cast< sal_Int64 >(new sal_Int64(0)),_nType);
277 break;
278 case DataType::DECIMAL:
279 case DataType::NUMERIC:
280 aPair = TVoidPtr(reinterpret_cast< sal_Int64 >(new ::rtl::OString()),_nType);
281 break;
282 case DataType::REAL:
283 case DataType::DOUBLE:
284 aPair = TVoidPtr(reinterpret_cast< sal_Int64 >(new double(0.0)),_nType);
285 break;
286 case DataType::LONGVARCHAR:
287 aPair = TVoidPtr(reinterpret_cast< sal_Int64 >(new char[2]),_nType); // dient nur zum auffinden
288 break;
289 case DataType::LONGVARBINARY:
290 aPair = TVoidPtr(reinterpret_cast< sal_Int64 >(new char[2]),_nType); // dient nur zum auffinden
291 break;
292 case DataType::DATE:
293 aPair = TVoidPtr(reinterpret_cast< sal_Int64 >(new DATE_STRUCT),_nType);
294 break;
295 case DataType::TIME:
296 aPair = TVoidPtr(reinterpret_cast< sal_Int64 >(new TIME_STRUCT),_nType);
297 break;
298 case DataType::TIMESTAMP:
299 aPair = TVoidPtr(reinterpret_cast< sal_Int64 >(new TIMESTAMP_STRUCT),_nType);
300 break;
301 case DataType::BIT:
302 case DataType::TINYINT:
303 aPair = TVoidPtr(reinterpret_cast< sal_Int64 >(new sal_Int8(0)),_nType);
304 break;
305 case DataType::SMALLINT:
306 aPair = TVoidPtr(reinterpret_cast< sal_Int64 >(new sal_Int16(0)),_nType);
307 break;
308 case DataType::INTEGER:
309 aPair = TVoidPtr(reinterpret_cast< sal_Int64 >(new sal_Int32(0)),_nType);
310 break;
311 case DataType::FLOAT:
312 aPair = TVoidPtr(reinterpret_cast< sal_Int64 >(new float(0)),_nType);
313 break;
314 case DataType::BINARY:
315 case DataType::VARBINARY:
316 aPair = TVoidPtr(reinterpret_cast< sal_Int64 >(new sal_Int8[m_aRow[_nColumnIndex].getSequence().getLength()]),_nType);
317 break;
318 default:
319 OSL_ENSURE(0,"Unknown type");
320 aPair = TVoidPtr(0,_nType);
322 return aPair;
324 // -------------------------------------------------------------------------
325 void OResultSet::allocBuffer()
327 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OResultSet::allocBuffer" );
328 Reference< XResultSetMetaData > xMeta = getMetaData();
329 sal_Int32 nLen = xMeta->getColumnCount();
331 m_aBindVector.reserve(nLen+1);
332 m_aBindVector.push_back(TVoidPtr(0,0)); // the first is reserved for the bookmark
333 m_aRow.resize(nLen+1);
335 for(sal_Int32 i = 1;i<=nLen;++i)
337 sal_Int32 nType = xMeta->getColumnType(i);
338 m_aRow[i].setTypeKind( nType );
340 m_aLengthVector.resize(nLen + 1);
342 // -------------------------------------------------------------------------
343 void OResultSet::releaseBuffer()
345 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OResultSet::releaseBuffer" );
346 unbind(sal_False);
347 m_aLengthVector.clear();
349 // -------------------------------------------------------------------------
350 Any SAL_CALL OResultSet::queryInterface( const Type & rType ) throw(RuntimeException)
352 Any aRet = OPropertySetHelper::queryInterface(rType);
353 return aRet.hasValue() ? aRet : OResultSet_BASE::queryInterface(rType);
355 // -------------------------------------------------------------------------
356 Sequence< Type > SAL_CALL OResultSet::getTypes( ) throw( RuntimeException)
358 OTypeCollection aTypes( ::getCppuType( (const Reference< ::com::sun::star::beans::XMultiPropertySet > *)0 ),
359 ::getCppuType( (const Reference< ::com::sun::star::beans::XFastPropertySet > *)0 ),
360 ::getCppuType( (const Reference< ::com::sun::star::beans::XPropertySet > *)0 ));
362 return ::comphelper::concatSequences(aTypes.getTypes(),OResultSet_BASE::getTypes());
364 // -------------------------------------------------------------------------
366 sal_Int32 SAL_CALL OResultSet::findColumn( const ::rtl::OUString& columnName ) throw(SQLException, RuntimeException)
368 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OResultSet::findColumn" );
369 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
372 ::osl::MutexGuard aGuard( m_aMutex );
374 Reference< XResultSetMetaData > xMeta = getMetaData();
375 sal_Int32 nLen = xMeta->getColumnCount();
376 sal_Int32 i = 1;
377 for(;i<=nLen;++i)
378 if(xMeta->isCaseSensitive(i) ? columnName == xMeta->getColumnName(i) :
379 columnName.equalsIgnoreAsciiCase(xMeta->getColumnName(i)))
380 break;
381 return i;
383 // -------------------------------------------------------------------------
384 Reference< XInputStream > SAL_CALL OResultSet::getBinaryStream( sal_Int32 /*columnIndex*/ ) throw(SQLException, RuntimeException)
386 ::osl::MutexGuard aGuard( m_aMutex );
387 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
390 // TODO use getBytes instead of
391 return NULL;
393 // -------------------------------------------------------------------------
394 Reference< XInputStream > SAL_CALL OResultSet::getCharacterStream( sal_Int32 /*columnIndex*/ ) throw(SQLException, RuntimeException)
396 ::osl::MutexGuard aGuard( m_aMutex );
397 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
400 // TODO use getBytes instead of
401 return NULL;
403 // -----------------------------------------------------------------------------
404 const ORowSetValue& OResultSet::getValue(sal_Int32 _nColumnIndex,SQLSMALLINT _nType,void* _pValue,SQLINTEGER _rSize)
406 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OResultSet::getValue" );
407 ::osl::MutexGuard aGuard( m_aMutex );
408 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
410 if(m_bFetchData)
412 if(_nColumnIndex > m_nLastColumnPos)
413 fillRow(_nColumnIndex);
414 return m_aRow[_nColumnIndex];
416 else
417 OTools::getValue(m_pStatement->getOwnConnection(),m_aStatementHandle,_nColumnIndex,_nType,m_bWasNull,**this,_pValue,_rSize);
419 return m_aEmptyValue;
421 // -------------------------------------------------------------------------
422 sal_Bool SAL_CALL OResultSet::getBoolean( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
424 sal_Int8 nVal(0);
425 const ORowSetValue& aValue = getValue(columnIndex,SQL_C_BIT,&nVal,sizeof nVal);
426 return (&aValue == &m_aEmptyValue) ? (sal_Bool)nVal : (sal_Bool)aValue;
428 // -------------------------------------------------------------------------
430 sal_Int8 SAL_CALL OResultSet::getByte( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
432 sal_Int8 nRet(0);
433 const ORowSetValue& aValue = getValue(columnIndex,SQL_C_TINYINT,&nRet,sizeof nRet);
434 return (&aValue == &m_aEmptyValue) ? nRet : (sal_Int8)aValue;
436 // -------------------------------------------------------------------------
438 Sequence< sal_Int8 > SAL_CALL OResultSet::getBytes( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
440 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OResultSet::getBytes" );
442 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
443 ::osl::MutexGuard aGuard( m_aMutex );
446 if(m_bFetchData)
448 if(columnIndex > m_nLastColumnPos)
449 fillRow(columnIndex);
450 Sequence< sal_Int8 > nRet;
451 switch(m_aRow[columnIndex].getTypeKind())
453 case DataType::BINARY:
454 case DataType::VARBINARY:
455 case DataType::LONGVARBINARY:
456 nRet = m_aRow[columnIndex];
457 break;
458 default:
460 ::rtl::OUString sRet;
461 sRet = m_aRow[columnIndex].getString();
462 nRet = Sequence<sal_Int8>(reinterpret_cast<const sal_Int8*>(sRet.getStr()),sizeof(sal_Unicode)*sRet.getLength());
465 return nRet;
468 ::std::map<sal_Int32,SWORD>::iterator aFind = m_aODBCColumnTypes.find(columnIndex);
469 if ( aFind == m_aODBCColumnTypes.end() )
470 aFind = m_aODBCColumnTypes.insert(::std::map<sal_Int32,SWORD>::value_type(columnIndex,OResultSetMetaData::getColumnODBCType(m_pStatement->getOwnConnection(),m_aStatementHandle,*this,columnIndex))).first;
472 switch(aFind->second)
474 case SQL_WVARCHAR:
475 case SQL_WCHAR:
476 case SQL_WLONGVARCHAR:
477 case SQL_VARCHAR:
478 case SQL_CHAR:
479 case SQL_LONGVARCHAR:
481 ::rtl::OUString aRet = OTools::getStringValue(m_pStatement->getOwnConnection(),m_aStatementHandle,columnIndex,aFind->second,m_bWasNull,**this,m_nTextEncoding);
482 return Sequence<sal_Int8>(reinterpret_cast<const sal_Int8*>(aRet.getStr()),sizeof(sal_Unicode)*aRet.getLength());
484 default:
487 return OTools::getBytesValue(m_pStatement->getOwnConnection(),m_aStatementHandle,columnIndex,SQL_C_BINARY,m_bWasNull,**this);
489 // -------------------------------------------------------------------------
491 Date SAL_CALL OResultSet::getDate( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
493 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OResultSet::getDate" );
494 DATE_STRUCT aDate;
495 aDate.day = 0;
496 aDate.month = 0;
497 aDate.year = 0;
499 const ORowSetValue& aValue = getValue( columnIndex,
500 m_pStatement->getOwnConnection()->useOldDateFormat() ? SQL_C_DATE : SQL_C_TYPE_DATE,
501 &aDate,sizeof aDate);
502 return (&aValue == &m_aEmptyValue) ? Date(aDate.day,aDate.month,aDate.year) : (Date)aValue;
504 // -------------------------------------------------------------------------
506 double SAL_CALL OResultSet::getDouble( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
508 double nRet(0);
509 const ORowSetValue& aValue = getValue(columnIndex,SQL_C_DOUBLE,&nRet,sizeof nRet);
510 return (&aValue == &m_aEmptyValue) ? nRet : (double)aValue;
512 // -------------------------------------------------------------------------
514 float SAL_CALL OResultSet::getFloat( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
516 float nRet(0);
517 const ORowSetValue& aValue = getValue(columnIndex,SQL_C_FLOAT,&nRet,sizeof nRet);
518 return (&aValue == &m_aEmptyValue) ? nRet : (float)aValue;
520 // -------------------------------------------------------------------------
522 sal_Int32 SAL_CALL OResultSet::getInt( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
524 sal_Int32 nRet(0);
525 const ORowSetValue& aValue = getValue(columnIndex,SQL_C_LONG,&nRet,sizeof nRet);
526 return (&aValue == &m_aEmptyValue) ? nRet : (sal_Int32)aValue;
528 // -------------------------------------------------------------------------
530 sal_Int32 SAL_CALL OResultSet::getRow( ) throw(SQLException, RuntimeException)
532 ::osl::MutexGuard aGuard( m_aMutex );
533 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
535 return m_pSkipDeletedSet ? m_pSkipDeletedSet->getMappedPosition(getDriverPos()) : getDriverPos();
537 // -------------------------------------------------------------------------
539 sal_Int64 SAL_CALL OResultSet::getLong( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
541 sal_Int64 nRet(0);
544 const ORowSetValue& aValue = getValue(columnIndex,SQL_C_SBIGINT,&nRet,sizeof nRet);
545 return (&aValue == &m_aEmptyValue) ? nRet : (sal_Int64)aValue;
547 catch(SQLException&)
549 nRet = getString(columnIndex).toInt64();
551 return nRet;
553 // -------------------------------------------------------------------------
555 Reference< XResultSetMetaData > SAL_CALL OResultSet::getMetaData( ) throw(SQLException, RuntimeException)
557 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OResultSet::getMetaData" );
558 ::osl::MutexGuard aGuard( m_aMutex );
559 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
562 if(!m_xMetaData.is())
563 m_xMetaData = new OResultSetMetaData(m_pStatement->getOwnConnection(),m_aStatementHandle);
564 return m_xMetaData;
566 // -------------------------------------------------------------------------
567 Reference< XArray > SAL_CALL OResultSet::getArray( sal_Int32 /*columnIndex*/ ) throw(SQLException, RuntimeException)
569 ::dbtools::throwFunctionNotSupportedException( "XRow::getArray", *this );
570 return NULL;
573 // -------------------------------------------------------------------------
575 Reference< XClob > SAL_CALL OResultSet::getClob( sal_Int32 /*columnIndex*/ ) throw(SQLException, RuntimeException)
577 ::dbtools::throwFunctionNotSupportedException( "XRow::getClob", *this );
578 return NULL;
580 // -------------------------------------------------------------------------
581 Reference< XBlob > SAL_CALL OResultSet::getBlob( sal_Int32 /*columnIndex*/ ) throw(SQLException, RuntimeException)
583 ::dbtools::throwFunctionNotSupportedException( "XRow::getBlob", *this );
584 return NULL;
586 // -------------------------------------------------------------------------
588 Reference< XRef > SAL_CALL OResultSet::getRef( sal_Int32 /*columnIndex*/ ) throw(SQLException, RuntimeException)
590 ::dbtools::throwFunctionNotSupportedException( "XRow::getRef", *this );
591 return NULL;
593 // -------------------------------------------------------------------------
595 Any SAL_CALL OResultSet::getObject( sal_Int32 columnIndex, const Reference< ::com::sun::star::container::XNameAccess >& /*typeMap*/ ) throw(SQLException, RuntimeException)
597 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OResultSet::getObject" );
598 ::osl::MutexGuard aGuard( m_aMutex );
599 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
601 fillRow(columnIndex);
602 return m_aRow[columnIndex].makeAny();
604 // -------------------------------------------------------------------------
606 sal_Int16 SAL_CALL OResultSet::getShort( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
608 sal_Int16 nRet(0);
609 const ORowSetValue& aValue = getValue(columnIndex,SQL_C_SHORT,&nRet,sizeof nRet);
610 return (&aValue == &m_aEmptyValue) ? nRet : (sal_Int16)aValue;
612 // -------------------------------------------------------------------------
615 ::rtl::OUString SAL_CALL OResultSet::getString( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
617 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OResultSet::getString" );
618 ::osl::MutexGuard aGuard( m_aMutex );
620 ::rtl::OUString nRet;
621 if ( m_bFetchData )
622 nRet = getValue(columnIndex,0,NULL,0);
623 else
625 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
626 ::std::map<sal_Int32,SWORD>::iterator aFind = m_aODBCColumnTypes.find(columnIndex);
627 if ( aFind == m_aODBCColumnTypes.end() )
628 aFind = m_aODBCColumnTypes.insert(::std::map<sal_Int32,SWORD>::value_type(columnIndex,OResultSetMetaData::getColumnODBCType(m_pStatement->getOwnConnection(),m_aStatementHandle,*this,columnIndex))).first;
629 nRet = OTools::getStringValue(m_pStatement->getOwnConnection(),m_aStatementHandle,columnIndex,aFind->second,m_bWasNull,**this,m_nTextEncoding);
631 return nRet;
633 // -------------------------------------------------------------------------
635 Time SAL_CALL OResultSet::getTime( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
637 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OResultSet::getTime" );
638 TIME_STRUCT aTime={0,0,0};
639 const ORowSetValue& aValue = getValue(columnIndex,
640 m_pStatement->getOwnConnection()->useOldDateFormat() ? SQL_C_TIME : SQL_C_TYPE_TIME,
641 &aTime,sizeof aTime);
642 return (&aValue == &m_aEmptyValue) ? Time(0,aTime.second,aTime.minute,aTime.hour) : (Time)aValue;
644 // -------------------------------------------------------------------------
647 DateTime SAL_CALL OResultSet::getTimestamp( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
649 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OResultSet::getTimestamp" );
650 TIMESTAMP_STRUCT aTime={0,0,0,0,0,0,0};
651 const ORowSetValue& aValue = getValue(columnIndex,
652 m_pStatement->getOwnConnection()->useOldDateFormat() ? SQL_C_TIMESTAMP : SQL_C_TYPE_TIMESTAMP,
653 &aTime,sizeof aTime);
654 return (&aValue == &m_aEmptyValue)
656 DateTime(static_cast<sal_uInt16>(aTime.fraction*1000),aTime.second,aTime.minute,aTime.hour,aTime.day,aTime.month,aTime.year)
658 (DateTime)aValue;
660 // -------------------------------------------------------------------------
662 sal_Bool SAL_CALL OResultSet::isBeforeFirst( ) throw(SQLException, RuntimeException)
664 ::osl::MutexGuard aGuard( m_aMutex );
665 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
666 return m_nRowPos == 0;
668 // -------------------------------------------------------------------------
669 sal_Bool SAL_CALL OResultSet::isAfterLast( ) throw(SQLException, RuntimeException)
671 ::osl::MutexGuard aGuard( m_aMutex );
672 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
674 return m_nRowPos != 0 && m_nCurrentFetchState == SQL_NO_DATA;
676 // -------------------------------------------------------------------------
677 sal_Bool SAL_CALL OResultSet::isFirst( ) throw(SQLException, RuntimeException)
679 ::osl::MutexGuard aGuard( m_aMutex );
680 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
682 return m_nRowPos == 1;
684 // -------------------------------------------------------------------------
685 sal_Bool SAL_CALL OResultSet::isLast( ) throw(SQLException, RuntimeException)
687 ::osl::MutexGuard aGuard( m_aMutex );
688 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
691 return m_bEOF && m_nCurrentFetchState != SQL_NO_DATA;
693 // -------------------------------------------------------------------------
694 void SAL_CALL OResultSet::beforeFirst( ) throw(SQLException, RuntimeException)
696 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OResultSet::beforeFirst" );
697 ::osl::MutexGuard aGuard( m_aMutex );
698 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
701 if(first())
702 previous();
703 m_nCurrentFetchState = SQL_SUCCESS;
705 // -------------------------------------------------------------------------
706 void SAL_CALL OResultSet::afterLast( ) throw(SQLException, RuntimeException)
708 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OResultSet::afterLast" );
709 ::osl::MutexGuard aGuard( m_aMutex );
710 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
712 if(last())
713 next();
714 m_bEOF = sal_True;
716 // -------------------------------------------------------------------------
718 void SAL_CALL OResultSet::close( ) throw(SQLException, RuntimeException)
721 ::osl::MutexGuard aGuard( m_aMutex );
722 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
725 dispose();
727 // -------------------------------------------------------------------------
729 sal_Bool SAL_CALL OResultSet::first( ) throw(SQLException, RuntimeException)
731 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OResultSet::first" );
732 return moveImpl(IResultSetHelper::FIRST,0,sal_True);
734 // -------------------------------------------------------------------------
736 sal_Bool SAL_CALL OResultSet::last( ) throw(SQLException, RuntimeException)
738 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OResultSet::last" );
739 return moveImpl(IResultSetHelper::LAST,0,sal_True);
741 // -------------------------------------------------------------------------
742 sal_Bool SAL_CALL OResultSet::absolute( sal_Int32 row ) throw(SQLException, RuntimeException)
744 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OResultSet::absolute" );
745 return moveImpl(IResultSetHelper::ABSOLUTE,row,sal_True);
747 // -------------------------------------------------------------------------
748 sal_Bool SAL_CALL OResultSet::relative( sal_Int32 row ) throw(SQLException, RuntimeException)
750 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OResultSet::relative" );
751 return moveImpl(IResultSetHelper::RELATIVE,row,sal_True);
753 // -------------------------------------------------------------------------
754 sal_Bool SAL_CALL OResultSet::previous( ) throw(SQLException, RuntimeException)
756 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OResultSet::previous" );
757 return moveImpl(IResultSetHelper::PRIOR,0,sal_True);
759 // -------------------------------------------------------------------------
760 Reference< XInterface > SAL_CALL OResultSet::getStatement( ) throw(SQLException, RuntimeException)
762 ::osl::MutexGuard aGuard( m_aMutex );
763 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
764 return m_xStatement;
766 // -------------------------------------------------------------------------
768 sal_Bool SAL_CALL OResultSet::rowDeleted() throw(SQLException, RuntimeException)
770 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OResultSet::rowDeleted" );
771 ::osl::MutexGuard aGuard( m_aMutex );
772 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
774 sal_Bool bRet = m_bRowDeleted;
775 m_bRowDeleted = sal_False;
777 return bRet;
779 // -------------------------------------------------------------------------
780 sal_Bool SAL_CALL OResultSet::rowInserted( ) throw(SQLException, RuntimeException)
782 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OResultSet::rowInserted" );
783 ::osl::MutexGuard aGuard( m_aMutex );
784 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
786 sal_Bool bInserted = m_bRowInserted;
787 m_bRowInserted = sal_False;
789 return bInserted;
791 // -------------------------------------------------------------------------
792 sal_Bool SAL_CALL OResultSet::rowUpdated( ) throw(SQLException, RuntimeException)
794 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OResultSet::rowUpdated" );
795 ::osl::MutexGuard aGuard( m_aMutex );
796 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
799 return m_pRowStatusArray[0] == SQL_ROW_UPDATED;
801 // -------------------------------------------------------------------------
803 sal_Bool SAL_CALL OResultSet::next( ) throw(SQLException, RuntimeException)
805 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OResultSet::next" );
806 return moveImpl(IResultSetHelper::NEXT,1,sal_True);
808 // -------------------------------------------------------------------------
810 sal_Bool SAL_CALL OResultSet::wasNull( ) throw(SQLException, RuntimeException)
812 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OResultSet::wasNull" );
813 ::osl::MutexGuard aGuard( m_aMutex );
814 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
817 return m_bFetchData ? m_aRow[m_nLastColumnPos].isNull() : m_bWasNull;
819 // -------------------------------------------------------------------------
821 void SAL_CALL OResultSet::cancel( ) throw(RuntimeException)
823 ::osl::MutexGuard aGuard( m_aMutex );
824 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
827 OTools::ThrowException(m_pStatement->getOwnConnection(),N3SQLCancel(m_aStatementHandle),m_aStatementHandle,SQL_HANDLE_STMT,*this);
829 // -------------------------------------------------------------------------
830 void SAL_CALL OResultSet::clearWarnings( ) throw(SQLException, RuntimeException)
833 // -------------------------------------------------------------------------
834 Any SAL_CALL OResultSet::getWarnings( ) throw(SQLException, RuntimeException)
836 return Any();
838 // -------------------------------------------------------------------------
839 void SAL_CALL OResultSet::insertRow( ) throw(SQLException, RuntimeException)
841 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OResultSet::insertRow" );
842 ::osl::MutexGuard aGuard( m_aMutex );
843 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
846 SQLLEN nMaxLen = 20;
847 SQLLEN nRealLen = 0;
848 Sequence<sal_Int8> aBookmark(nMaxLen);
850 SQLRETURN nRet = N3SQLBindCol(m_aStatementHandle,
852 SQL_C_VARBOOKMARK,
853 aBookmark.getArray(),
854 nMaxLen,
855 &nRealLen
857 // Sequence<sal_Int8> aRealBookmark(nMaxLen);
859 sal_Bool bPositionByBookmark = ( NULL != getOdbcFunction( ODBC3SQLBulkOperations ) );
860 if ( bPositionByBookmark )
862 nRet = N3SQLBulkOperations( m_aStatementHandle, SQL_ADD );
863 fillNeededData( nRet );
865 else
867 if(isBeforeFirst())
868 next(); // must be done
869 nRet = N3SQLSetPos( m_aStatementHandle, 1, SQL_ADD, SQL_LOCK_NO_CHANGE );
870 fillNeededData( nRet );
874 OTools::ThrowException(m_pStatement->getOwnConnection(),nRet,m_aStatementHandle,SQL_HANDLE_STMT,*this);
876 catch(SQLException e)
878 nRet = unbind();
879 throw;
883 if ( bPositionByBookmark )
885 nRet = N3SQLSetStmtAttr(m_aStatementHandle,SQL_ATTR_FETCH_BOOKMARK_PTR,aBookmark.getArray(),SQL_IS_POINTER); // SQL_LEN_BINARY_ATTR(aBookmark.getLength())
887 nRet = N3SQLFetchScroll(m_aStatementHandle,SQL_FETCH_BOOKMARK,0);
889 else
890 nRet = N3SQLFetchScroll(m_aStatementHandle,SQL_FETCH_RELATIVE,0); // OJ 06.03.2004
891 // sometimes we got an error but we are not interested in anymore #106047# OJ
892 // OTools::ThrowException(m_pStatement->getOwnConnection(),nRet,m_aStatementHandle,SQL_HANDLE_STMT,*this);
893 nRet = unbind();
894 OTools::ThrowException(m_pStatement->getOwnConnection(),nRet,m_aStatementHandle,SQL_HANDLE_STMT,*this);
896 if(m_pSkipDeletedSet)
898 aBookmark.realloc(nRealLen);
899 if(moveToBookmark(makeAny(aBookmark)))
901 sal_Int32 nRowPos = getDriverPos();
902 if ( -1 == m_nRowPos )
904 nRowPos = m_aPosToBookmarks.size() + 1;
906 if ( nRowPos == m_nRowPos )
907 ++nRowPos;
908 m_nRowPos = nRowPos;
909 m_pSkipDeletedSet->insertNewPosition(nRowPos);
910 m_aPosToBookmarks[aBookmark] = nRowPos;
913 m_bRowInserted = sal_True;
916 // -------------------------------------------------------------------------
917 void SAL_CALL OResultSet::updateRow( ) throw(SQLException, RuntimeException)
919 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OResultSet::updateRow" );
920 ::osl::MutexGuard aGuard( m_aMutex );
921 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
923 SQLRETURN nRet;
925 sal_Bool bPositionByBookmark = ( NULL != getOdbcFunction( ODBC3SQLBulkOperations ) );
926 if ( bPositionByBookmark )
928 SQLLEN nRealLen = 0;
929 nRet = N3SQLBindCol(m_aStatementHandle,
931 SQL_C_VARBOOKMARK,
932 m_aBookmark.getArray(),
933 m_aBookmark.getLength(),
934 &nRealLen
936 fillNeededData(nRet = N3SQLBulkOperations(m_aStatementHandle, SQL_UPDATE_BY_BOOKMARK));
938 else
939 fillNeededData(nRet = N3SQLSetPos(m_aStatementHandle,1,SQL_UPDATE,SQL_LOCK_NO_CHANGE));
940 OTools::ThrowException(m_pStatement->getOwnConnection(),nRet,m_aStatementHandle,SQL_HANDLE_STMT,*this);
941 // now unbind all columns so we can fetch all columns again with SQLGetData
942 nRet = unbind();
943 OSL_ENSURE(nRet == SQL_SUCCESS,"Could not unbind the columns!");
945 // -------------------------------------------------------------------------
946 void SAL_CALL OResultSet::deleteRow( ) throw(SQLException, RuntimeException)
948 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OResultSet::deleteRow" );
949 SQLRETURN nRet = SQL_SUCCESS;
950 sal_Int32 nPos = getDriverPos();
951 nRet = N3SQLSetPos(m_aStatementHandle,1,SQL_DELETE,SQL_LOCK_NO_CHANGE);
952 OTools::ThrowException(m_pStatement->getOwnConnection(),nRet,m_aStatementHandle,SQL_HANDLE_STMT,*this);
954 m_bRowDeleted = ( m_pRowStatusArray[0] == SQL_ROW_DELETED );
955 if ( m_bRowDeleted )
957 TBookmarkPosMap::iterator aIter = m_aPosToBookmarks.begin();
958 TBookmarkPosMap::iterator aEnd = m_aPosToBookmarks.end();
959 for (; aIter != aEnd; ++aIter)
961 if ( aIter->second == nPos )
963 m_aPosToBookmarks.erase(aIter);
964 break;
968 if ( m_pSkipDeletedSet )
969 m_pSkipDeletedSet->deletePosition(nPos);
971 // -------------------------------------------------------------------------
973 void SAL_CALL OResultSet::cancelRowUpdates( ) throw(SQLException, RuntimeException)
976 // -------------------------------------------------------------------------
978 void SAL_CALL OResultSet::moveToInsertRow( ) throw(SQLException, RuntimeException)
980 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OResultSet::moveToInsertRow" );
981 ::osl::MutexGuard aGuard( m_aMutex );
982 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
985 m_nLastColumnPos = 0;
986 // first unbound all columns
987 OSL_VERIFY_EQUALS( unbind(), SQL_SUCCESS, "Could not unbind columns!" );
988 // SQLRETURN nRet = N3SQLSetStmtAttr(m_aStatementHandle,SQL_ATTR_ROW_ARRAY_SIZE ,(SQLPOINTER)1,SQL_IS_INTEGER);
989 m_bInserting = sal_True;
991 // -------------------------------------------------------------------------
993 void SAL_CALL OResultSet::moveToCurrentRow( ) throw(SQLException, RuntimeException)
995 m_nLastColumnPos = 0;
997 // -------------------------------------------------------------------------
998 void OResultSet::updateValue(sal_Int32 columnIndex,SQLSMALLINT _nType,void* _pValue) throw(SQLException, RuntimeException)
1000 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OResultSet::updateValue" );
1001 ::osl::MutexGuard aGuard( m_aMutex );
1002 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
1004 m_aBindVector.push_back(allocBindColumn(OTools::MapOdbcType2Jdbc(_nType),columnIndex));
1005 void* pData = reinterpret_cast<void*>(m_aBindVector.rbegin()->first);
1006 OSL_ENSURE(pData != NULL,"Data for update is NULL!");
1007 OTools::bindValue( m_pStatement->getOwnConnection(),
1008 m_aStatementHandle,
1009 columnIndex,
1010 _nType,
1012 _pValue,
1013 pData,
1014 &m_aLengthVector[columnIndex],
1015 **this,
1016 m_nTextEncoding,
1017 m_pStatement->getOwnConnection()->useOldDateFormat());
1019 // -----------------------------------------------------------------------------
1020 void SAL_CALL OResultSet::updateNull( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
1022 ::osl::MutexGuard aGuard( m_aMutex );
1023 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
1025 m_aBindVector.push_back(allocBindColumn(DataType::CHAR,columnIndex));
1026 void* pData = reinterpret_cast<void*>(m_aBindVector.rbegin()->first);
1027 OTools::bindValue(m_pStatement->getOwnConnection(),m_aStatementHandle,columnIndex,SQL_CHAR,0,(sal_Int8*)NULL,pData,&m_aLengthVector[columnIndex],**this,m_nTextEncoding,m_pStatement->getOwnConnection()->useOldDateFormat());
1029 // -------------------------------------------------------------------------
1031 void SAL_CALL OResultSet::updateBoolean( sal_Int32 columnIndex, sal_Bool x ) throw(SQLException, RuntimeException)
1033 updateValue(columnIndex,SQL_BIT,&x);
1035 // -------------------------------------------------------------------------
1036 void SAL_CALL OResultSet::updateByte( sal_Int32 columnIndex, sal_Int8 x ) throw(SQLException, RuntimeException)
1038 updateValue(columnIndex,SQL_CHAR,&x);
1040 // -------------------------------------------------------------------------
1042 void SAL_CALL OResultSet::updateShort( sal_Int32 columnIndex, sal_Int16 x ) throw(SQLException, RuntimeException)
1044 updateValue(columnIndex,SQL_TINYINT,&x);
1046 // -------------------------------------------------------------------------
1047 void SAL_CALL OResultSet::updateInt( sal_Int32 columnIndex, sal_Int32 x ) throw(SQLException, RuntimeException)
1049 updateValue(columnIndex,SQL_INTEGER,&x);
1051 // -------------------------------------------------------------------------
1052 void SAL_CALL OResultSet::updateLong( sal_Int32 /*columnIndex*/, sal_Int64 /*x*/ ) throw(SQLException, RuntimeException)
1054 ::dbtools::throwFunctionNotSupportedException( "XRowUpdate::updateLong", *this );
1056 // -----------------------------------------------------------------------
1057 void SAL_CALL OResultSet::updateFloat( sal_Int32 columnIndex, float x ) throw(SQLException, RuntimeException)
1059 updateValue(columnIndex,SQL_REAL,&x);
1061 // -------------------------------------------------------------------------
1063 void SAL_CALL OResultSet::updateDouble( sal_Int32 columnIndex, double x ) throw(SQLException, RuntimeException)
1065 updateValue(columnIndex,SQL_DOUBLE,&x);
1067 // -------------------------------------------------------------------------
1068 void SAL_CALL OResultSet::updateString( sal_Int32 columnIndex, const ::rtl::OUString& x ) throw(SQLException, RuntimeException)
1070 sal_Int32 nType = m_aRow[columnIndex].getTypeKind();
1071 SQLSMALLINT nOdbcType = static_cast<SQLSMALLINT>(OTools::jdbcTypeToOdbc(nType));
1072 m_aRow[columnIndex] = x;
1073 m_aRow[columnIndex].setTypeKind(nType); // OJ: otherwise longvarchar will be recognized by fillNeededData
1074 updateValue(columnIndex,nOdbcType,(void*)&x);
1076 // -------------------------------------------------------------------------
1077 void SAL_CALL OResultSet::updateBytes( sal_Int32 columnIndex, const Sequence< sal_Int8 >& x ) throw(SQLException, RuntimeException)
1079 sal_Int32 nType = m_aRow[columnIndex].getTypeKind();
1080 SQLSMALLINT nOdbcType = static_cast<SQLSMALLINT>(OTools::jdbcTypeToOdbc(nType));
1081 m_aRow[columnIndex] = x;
1082 m_aRow[columnIndex].setTypeKind(nType); // OJ: otherwise longvarbinary will be recognized by fillNeededData
1083 updateValue(columnIndex,nOdbcType,(void*)&x);
1085 // -------------------------------------------------------------------------
1086 void SAL_CALL OResultSet::updateDate( sal_Int32 columnIndex, const Date& x ) throw(SQLException, RuntimeException)
1088 DATE_STRUCT aVal = OTools::DateToOdbcDate(x);
1089 updateValue(columnIndex,SQL_DATE,&aVal);
1091 // -------------------------------------------------------------------------
1093 void SAL_CALL OResultSet::updateTime( sal_Int32 columnIndex, const Time& x ) throw(SQLException, RuntimeException)
1095 TIME_STRUCT aVal = OTools::TimeToOdbcTime(x);
1096 updateValue(columnIndex,SQL_TIME,&aVal);
1098 // -------------------------------------------------------------------------
1100 void SAL_CALL OResultSet::updateTimestamp( sal_Int32 columnIndex, const DateTime& x ) throw(SQLException, RuntimeException)
1102 TIMESTAMP_STRUCT aVal = OTools::DateTimeToTimestamp(x);
1103 updateValue(columnIndex,SQL_TIMESTAMP,&aVal);
1105 // -------------------------------------------------------------------------
1107 void SAL_CALL OResultSet::updateBinaryStream( sal_Int32 columnIndex, const Reference< XInputStream >& x, sal_Int32 length ) throw(SQLException, RuntimeException)
1109 if(!x.is())
1110 ::dbtools::throwFunctionSequenceException(*this);
1112 Sequence<sal_Int8> aSeq;
1113 x->readBytes(aSeq,length);
1114 updateBytes(columnIndex,aSeq);
1116 // -------------------------------------------------------------------------
1117 void SAL_CALL OResultSet::updateCharacterStream( sal_Int32 columnIndex, const Reference< XInputStream >& x, sal_Int32 length ) throw(SQLException, RuntimeException)
1119 updateBinaryStream(columnIndex,x,length);
1121 // -------------------------------------------------------------------------
1122 void SAL_CALL OResultSet::refreshRow( ) throw(SQLException, RuntimeException)
1124 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OResultSet::refreshRow" );
1125 ::osl::MutexGuard aGuard( m_aMutex );
1126 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
1129 // SQLRETURN nRet = N3SQLSetPos(m_aStatementHandle,1,SQL_REFRESH,SQL_LOCK_NO_CHANGE);
1130 m_nCurrentFetchState = N3SQLFetchScroll(m_aStatementHandle,SQL_FETCH_RELATIVE,0);
1131 OTools::ThrowException(m_pStatement->getOwnConnection(),m_nCurrentFetchState,m_aStatementHandle,SQL_HANDLE_STMT,*this);
1133 // -------------------------------------------------------------------------
1134 void SAL_CALL OResultSet::updateObject( sal_Int32 columnIndex, const Any& x ) throw(SQLException, RuntimeException)
1136 if (!::dbtools::implUpdateObject(this, columnIndex, x))
1137 throw SQLException();
1139 // -------------------------------------------------------------------------
1141 void SAL_CALL OResultSet::updateNumericObject( sal_Int32 columnIndex, const Any& x, sal_Int32 /*scale*/ ) throw(SQLException, RuntimeException)
1143 if (!::dbtools::implUpdateObject(this, columnIndex, x))
1144 throw SQLException();
1146 // -------------------------------------------------------------------------
1147 // XRowLocate
1148 Any SAL_CALL OResultSet::getBookmark( ) throw( SQLException, RuntimeException)
1150 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OResultSet::getBookmark" );
1151 ::osl::MutexGuard aGuard( m_aMutex );
1152 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
1154 TBookmarkPosMap::iterator aFind = ::std::find_if(m_aPosToBookmarks.begin(),m_aPosToBookmarks.end(),
1155 ::std::compose1(::std::bind2nd(::std::equal_to<sal_Int32>(),m_nRowPos),::std::select2nd<TBookmarkPosMap::value_type>()));
1157 if ( aFind == m_aPosToBookmarks.end() )
1159 if ( m_nUseBookmarks == ODBC_SQL_NOT_DEFINED )
1161 RTL_LOGFILE_CONTEXT_TRACE( aLogger, "SQLGetStmtAttr" );
1162 m_nUseBookmarks = SQL_UB_OFF;
1163 SQLRETURN nRet = N3SQLGetStmtAttr(m_aStatementHandle,SQL_ATTR_USE_BOOKMARKS,&m_nUseBookmarks,SQL_IS_UINTEGER,NULL);
1164 OSL_UNUSED( nRet );
1166 if(m_nUseBookmarks == SQL_UB_OFF)
1167 throw SQLException();
1169 m_aBookmark = OTools::getBytesValue(m_pStatement->getOwnConnection(),m_aStatementHandle,0,SQL_C_VARBOOKMARK,m_bWasNull,**this);
1170 m_aPosToBookmarks[m_aBookmark] = m_nRowPos;
1171 OSL_ENSURE(m_aBookmark.getLength(),"Invalid bookmark from length 0!");
1173 else
1174 m_aBookmark = aFind->first;
1175 return makeAny(m_aBookmark);
1177 // -------------------------------------------------------------------------
1178 sal_Bool SAL_CALL OResultSet::moveToBookmark( const Any& bookmark ) throw( SQLException, RuntimeException)
1180 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OResultSet::moveToBookmark" );
1181 ::osl::MutexGuard aGuard( m_aMutex );
1182 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
1184 m_nLastColumnPos = 0;
1185 bookmark >>= m_aBookmark;
1186 OSL_ENSURE(m_aBookmark.getLength(),"Invalid bookmark from length 0!");
1187 if(m_aBookmark.getLength())
1189 SQLRETURN nReturn = N3SQLSetStmtAttr(m_aStatementHandle,SQL_ATTR_FETCH_BOOKMARK_PTR,m_aBookmark.getArray(),SQL_IS_POINTER); // SQL_LEN_BINARY_ATTR(aBookmark.getLength())
1190 OSL_UNUSED( nReturn );
1192 if ( SQL_INVALID_HANDLE != nReturn && SQL_ERROR != nReturn )
1194 m_nCurrentFetchState = N3SQLFetchScroll(m_aStatementHandle,SQL_FETCH_BOOKMARK,0);
1195 OTools::ThrowException(m_pStatement->getOwnConnection(),m_nCurrentFetchState,m_aStatementHandle,SQL_HANDLE_STMT,*this);
1196 TBookmarkPosMap::iterator aFind = m_aPosToBookmarks.find(m_aBookmark);
1197 if(aFind != m_aPosToBookmarks.end())
1198 m_nRowPos = aFind->second;
1199 else
1200 m_nRowPos = -1;
1201 return m_nCurrentFetchState == SQL_SUCCESS || m_nCurrentFetchState == SQL_SUCCESS_WITH_INFO;
1204 return sal_False;
1206 // -------------------------------------------------------------------------
1207 sal_Bool SAL_CALL OResultSet::moveRelativeToBookmark( const Any& bookmark, sal_Int32 rows ) throw( SQLException, RuntimeException)
1209 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OResultSet::moveRelativeToBookmark" );
1210 ::osl::MutexGuard aGuard( m_aMutex );
1211 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
1214 m_nLastColumnPos = 0;
1215 bookmark >>= m_aBookmark;
1216 SQLRETURN nReturn = N3SQLSetStmtAttr(m_aStatementHandle,SQL_ATTR_FETCH_BOOKMARK_PTR,m_aBookmark.getArray(),SQL_IS_POINTER);
1217 OSL_UNUSED( nReturn );
1219 m_nCurrentFetchState = N3SQLFetchScroll(m_aStatementHandle,SQL_FETCH_BOOKMARK,rows);
1220 OTools::ThrowException(m_pStatement->getOwnConnection(),m_nCurrentFetchState,m_aStatementHandle,SQL_HANDLE_STMT,*this);
1221 return m_nCurrentFetchState == SQL_SUCCESS || m_nCurrentFetchState == SQL_SUCCESS_WITH_INFO;
1223 // -------------------------------------------------------------------------
1224 sal_Int32 SAL_CALL OResultSet::compareBookmarks( const Any& lhs, const Any& rhs ) throw( SQLException, RuntimeException)
1226 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OResultSet::compareBookmarks" );
1227 ::osl::MutexGuard aGuard( m_aMutex );
1228 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
1230 return (lhs == rhs) ? CompareBookmark::EQUAL : CompareBookmark::NOT_EQUAL;
1232 // -------------------------------------------------------------------------
1233 sal_Bool SAL_CALL OResultSet::hasOrderedBookmarks( ) throw( SQLException, RuntimeException)
1235 return sal_False;
1237 // -------------------------------------------------------------------------
1238 sal_Int32 SAL_CALL OResultSet::hashBookmark( const Any& /*bookmark*/ ) throw( SQLException, RuntimeException)
1240 ::dbtools::throwFunctionNotSupportedException( "XRowLocate::hashBookmark", *this );
1241 return 0;
1243 // -------------------------------------------------------------------------
1244 // XDeleteRows
1245 Sequence< sal_Int32 > SAL_CALL OResultSet::deleteRows( const Sequence< Any >& rows ) throw( SQLException, RuntimeException)
1247 Sequence< sal_Int32 > aRet(rows.getLength());
1248 sal_Int32 *pRet = aRet.getArray();
1250 const Any *pBegin = rows.getConstArray();
1251 const Any *pEnd = pBegin + rows.getLength();
1253 for(;pBegin != pEnd;++pBegin,++pRet)
1257 if(moveToBookmark(*pBegin))
1259 deleteRow();
1260 *pRet = 1;
1263 catch(SQLException&)
1265 *pRet = 0;
1268 return aRet;
1270 //------------------------------------------------------------------------------
1271 sal_Int32 OResultSet::getResultSetConcurrency() const
1273 sal_uInt32 nValue = 0;
1274 SQLRETURN nReturn = N3SQLGetStmtAttr(m_aStatementHandle,SQL_ATTR_CONCURRENCY,&nValue,SQL_IS_UINTEGER,0);
1275 OSL_UNUSED( nReturn );
1276 if(SQL_CONCUR_READ_ONLY == nValue)
1277 nValue = ResultSetConcurrency::READ_ONLY;
1278 else
1279 nValue = ResultSetConcurrency::UPDATABLE;
1281 return nValue;
1283 //------------------------------------------------------------------------------
1284 sal_Int32 OResultSet::getResultSetType() const
1286 sal_uInt32 nValue = 0;
1287 N3SQLGetStmtAttr(m_aStatementHandle,SQL_ATTR_CURSOR_SENSITIVITY,&nValue,SQL_IS_UINTEGER,0);
1288 if(SQL_SENSITIVE == nValue)
1289 nValue = ResultSetType::SCROLL_SENSITIVE;
1290 else if(SQL_INSENSITIVE == nValue)
1291 nValue = ResultSetType::SCROLL_INSENSITIVE;
1292 else
1294 SQLINTEGER nCurType = 0;
1295 N3SQLGetStmtAttr(m_aStatementHandle,SQL_ATTR_CURSOR_TYPE,&nCurType,SQL_IS_UINTEGER,0);
1296 if(SQL_CURSOR_KEYSET_DRIVEN == nCurType)
1297 nValue = ResultSetType::SCROLL_SENSITIVE;
1298 else if(SQL_CURSOR_STATIC == nCurType)
1299 nValue = ResultSetType::SCROLL_INSENSITIVE;
1300 else if(SQL_CURSOR_FORWARD_ONLY == nCurType)
1301 nValue = ResultSetType::FORWARD_ONLY;
1302 else if(SQL_CURSOR_DYNAMIC == nCurType)
1303 nValue = ResultSetType::SCROLL_SENSITIVE;
1305 return nValue;
1307 //------------------------------------------------------------------------------
1308 sal_Int32 OResultSet::getFetchDirection() const
1310 return FetchDirection::FORWARD;
1312 //------------------------------------------------------------------------------
1313 sal_Int32 OResultSet::getFetchSize() const
1315 sal_uInt32 nValue = 0;
1316 N3SQLGetStmtAttr(m_aStatementHandle,SQL_ATTR_ROW_ARRAY_SIZE,&nValue,SQL_IS_UINTEGER,0);
1317 return nValue;
1319 //------------------------------------------------------------------------------
1320 ::rtl::OUString OResultSet::getCursorName() const
1322 SQLCHAR pName[258];
1323 SQLSMALLINT nRealLen = 0;
1324 N3SQLGetCursorName(m_aStatementHandle,(SQLCHAR*)pName,256,&nRealLen);
1325 return ::rtl::OUString::createFromAscii((const char*)pName);
1327 // -------------------------------------------------------------------------
1328 sal_Bool OResultSet::isBookmarkable() const
1330 if(!m_aConnectionHandle)
1331 return sal_False;
1333 sal_uInt32 nValue = 0;
1334 N3SQLGetStmtAttr(m_aStatementHandle,SQL_ATTR_CURSOR_TYPE,&nValue,SQL_IS_UINTEGER,0);
1336 sal_Int32 nAttr = 0;
1339 switch(nValue)
1341 case SQL_CURSOR_FORWARD_ONLY:
1342 return sal_False;
1343 case SQL_CURSOR_STATIC:
1344 OTools::GetInfo(m_pStatement->getOwnConnection(),m_aConnectionHandle,SQL_STATIC_CURSOR_ATTRIBUTES1,nAttr,NULL);
1345 break;
1346 case SQL_CURSOR_KEYSET_DRIVEN:
1347 OTools::GetInfo(m_pStatement->getOwnConnection(),m_aConnectionHandle,SQL_KEYSET_CURSOR_ATTRIBUTES1,nAttr,NULL);
1348 break;
1349 case SQL_CURSOR_DYNAMIC:
1350 OTools::GetInfo(m_pStatement->getOwnConnection(),m_aConnectionHandle,SQL_DYNAMIC_CURSOR_ATTRIBUTES1,nAttr,NULL);
1351 break;
1354 catch(Exception&)
1356 return sal_False;
1359 if ( m_nUseBookmarks == ODBC_SQL_NOT_DEFINED )
1361 m_nUseBookmarks = SQL_UB_OFF;
1362 SQLRETURN nRet = N3SQLGetStmtAttr(m_aStatementHandle,SQL_ATTR_USE_BOOKMARKS,&m_nUseBookmarks,SQL_IS_UINTEGER,NULL);
1363 OSL_UNUSED( nRet );
1366 return (m_nUseBookmarks != SQL_UB_OFF) && (nAttr & SQL_CA1_BOOKMARK) == SQL_CA1_BOOKMARK;
1368 //------------------------------------------------------------------------------
1369 void OResultSet::setFetchDirection(sal_Int32 _par0)
1371 N3SQLSetStmtAttr(m_aStatementHandle,SQL_ATTR_CURSOR_TYPE,(SQLPOINTER)_par0,SQL_IS_UINTEGER);
1373 //------------------------------------------------------------------------------
1374 void OResultSet::setFetchSize(sal_Int32 _par0)
1376 N3SQLSetStmtAttr(m_aStatementHandle,SQL_ATTR_ROW_ARRAY_SIZE,(SQLPOINTER)_par0,SQL_IS_UINTEGER);
1377 delete m_pRowStatusArray;
1378 m_pRowStatusArray = new SQLUSMALLINT[_par0];
1379 N3SQLSetStmtAttr(m_aStatementHandle,SQL_ATTR_ROW_STATUS_PTR,m_pRowStatusArray,SQL_IS_POINTER);
1381 // -------------------------------------------------------------------------
1382 IPropertyArrayHelper* OResultSet::createArrayHelper( ) const
1384 Sequence< Property > aProps(6);
1385 Property* pProperties = aProps.getArray();
1386 sal_Int32 nPos = 0;
1387 DECL_PROP1IMPL(CURSORNAME, ::rtl::OUString) PropertyAttribute::READONLY);
1388 DECL_PROP0(FETCHDIRECTION, sal_Int32);
1389 DECL_PROP0(FETCHSIZE, sal_Int32);
1390 DECL_BOOL_PROP1IMPL(ISBOOKMARKABLE) PropertyAttribute::READONLY);
1391 DECL_PROP1IMPL(RESULTSETCONCURRENCY,sal_Int32) PropertyAttribute::READONLY);
1392 DECL_PROP1IMPL(RESULTSETTYPE, sal_Int32) PropertyAttribute::READONLY);
1394 return new OPropertyArrayHelper(aProps);
1396 // -------------------------------------------------------------------------
1397 IPropertyArrayHelper & OResultSet::getInfoHelper()
1399 return *const_cast<OResultSet*>(this)->getArrayHelper();
1401 // -------------------------------------------------------------------------
1402 sal_Bool OResultSet::convertFastPropertyValue(
1403 Any & rConvertedValue,
1404 Any & rOldValue,
1405 sal_Int32 nHandle,
1406 const Any& rValue )
1407 throw (::com::sun::star::lang::IllegalArgumentException)
1409 switch(nHandle)
1411 case PROPERTY_ID_ISBOOKMARKABLE:
1412 case PROPERTY_ID_CURSORNAME:
1413 case PROPERTY_ID_RESULTSETCONCURRENCY:
1414 case PROPERTY_ID_RESULTSETTYPE:
1415 throw ::com::sun::star::lang::IllegalArgumentException();
1416 case PROPERTY_ID_FETCHDIRECTION:
1417 return ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, getFetchDirection());
1418 case PROPERTY_ID_FETCHSIZE:
1419 return ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, getFetchSize());
1420 default:
1423 return sal_False;
1425 // -------------------------------------------------------------------------
1426 void OResultSet::setFastPropertyValue_NoBroadcast(
1427 sal_Int32 nHandle,
1428 const Any& rValue
1430 throw (Exception)
1432 switch(nHandle)
1434 case PROPERTY_ID_ISBOOKMARKABLE:
1435 case PROPERTY_ID_CURSORNAME:
1436 case PROPERTY_ID_RESULTSETCONCURRENCY:
1437 case PROPERTY_ID_RESULTSETTYPE:
1438 throw Exception();
1439 case PROPERTY_ID_FETCHDIRECTION:
1440 setFetchDirection(getINT32(rValue));
1441 break;
1442 case PROPERTY_ID_FETCHSIZE:
1443 setFetchSize(getINT32(rValue));
1444 break;
1445 default:
1449 // -------------------------------------------------------------------------
1450 void OResultSet::getFastPropertyValue(
1451 Any& rValue,
1452 sal_Int32 nHandle
1453 ) const
1455 switch(nHandle)
1457 case PROPERTY_ID_ISBOOKMARKABLE:
1458 rValue = bool2any(isBookmarkable());
1459 break;
1460 case PROPERTY_ID_CURSORNAME:
1461 rValue <<= getCursorName();
1462 break;
1463 case PROPERTY_ID_RESULTSETCONCURRENCY:
1464 rValue <<= getResultSetConcurrency();
1465 break;
1466 case PROPERTY_ID_RESULTSETTYPE:
1467 rValue <<= getResultSetType();
1468 break;
1469 case PROPERTY_ID_FETCHDIRECTION:
1470 rValue <<= getFetchDirection();
1471 break;
1472 case PROPERTY_ID_FETCHSIZE:
1473 rValue <<= getFetchSize();
1474 break;
1477 // -------------------------------------------------------------------------
1478 void OResultSet::fillRow(sal_Int32 _nToColumn)
1480 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OResultSet::fillRow" );
1481 if((sal_Int32)m_aRow.size() <= _nToColumn)
1483 m_aRow.resize(_nToColumn+1);
1484 m_aRow[_nToColumn].setBound(sal_True);
1486 m_bFetchData = sal_False;
1488 sal_Int32 nColumn = m_nLastColumnPos + 1;
1489 TDataRow::iterator pColumn = m_aRow.begin() + nColumn;
1490 TDataRow::iterator pColumnEnd = m_aRow.begin() + _nToColumn + 1;
1492 for (; pColumn < pColumnEnd; ++nColumn, ++pColumn)
1494 const sal_Int32 nType = pColumn->getTypeKind();
1495 switch (nType)
1497 case DataType::CHAR:
1498 case DataType::VARCHAR:
1499 case DataType::DECIMAL:
1500 case DataType::NUMERIC:
1501 case DataType::LONGVARCHAR:
1503 ::std::map<sal_Int32,SWORD>::iterator aFind = m_aODBCColumnTypes.find(nColumn);
1504 if ( aFind == m_aODBCColumnTypes.end() )
1505 aFind = m_aODBCColumnTypes.insert(::std::map<sal_Int32,SWORD>::value_type(nColumn,OResultSetMetaData::getColumnODBCType(m_pStatement->getOwnConnection(),m_aStatementHandle,*this,nColumn))).first;
1506 *pColumn = OTools::getStringValue(m_pStatement->getOwnConnection(),m_aStatementHandle,nColumn,aFind->second,m_bWasNull,**this,m_nTextEncoding);
1508 break;
1509 case DataType::BIGINT:
1510 *pColumn = getLong(nColumn);
1511 break;
1512 case DataType::REAL:
1513 case DataType::DOUBLE:
1514 *pColumn = getDouble(nColumn);
1515 break;
1516 case DataType::LONGVARBINARY:
1517 *pColumn = getBytes(nColumn);
1518 break;
1519 case DataType::DATE:
1520 *pColumn = getDate(nColumn);
1521 break;
1522 case DataType::TIME:
1523 *pColumn = getTime(nColumn);
1524 break;
1525 case DataType::TIMESTAMP:
1526 *pColumn = getTimestamp(nColumn);
1527 break;
1528 case DataType::BIT:
1529 *pColumn = getBoolean(nColumn);
1530 break;
1531 case DataType::TINYINT:
1532 *pColumn = getByte(nColumn);
1533 break;
1534 case DataType::SMALLINT:
1535 *pColumn = getShort(nColumn);
1536 break;
1537 case DataType::INTEGER:
1538 *pColumn = getInt(nColumn);
1539 break;
1540 case DataType::FLOAT:
1541 *pColumn = getFloat(nColumn);
1542 break;
1543 case DataType::BINARY:
1544 case DataType::VARBINARY:
1545 *pColumn = getBytes(nColumn);
1546 break;
1549 if ( m_bWasNull )
1550 pColumn->setNull();
1551 if(nType != pColumn->getTypeKind())
1553 pColumn->setTypeKind(nType);
1556 m_nLastColumnPos = _nToColumn;
1557 m_bFetchData = sal_True;
1559 // -----------------------------------------------------------------------------
1560 void SAL_CALL OResultSet::acquire() throw()
1562 OResultSet_BASE::acquire();
1564 // -----------------------------------------------------------------------------
1565 void SAL_CALL OResultSet::release() throw()
1567 OResultSet_BASE::release();
1569 // -----------------------------------------------------------------------------
1570 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL OResultSet::getPropertySetInfo( ) throw(::com::sun::star::uno::RuntimeException)
1572 return ::cppu::OPropertySetHelper::createPropertySetInfo(getInfoHelper());
1574 // -----------------------------------------------------------------------------
1575 sal_Bool OResultSet::move(IResultSetHelper::Movement _eCursorPosition, sal_Int32 _nOffset, sal_Bool /*_bRetrieveData*/)
1577 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OResultSet::move" );
1578 SQLSMALLINT nFetchOrientation = SQL_FETCH_NEXT;
1579 switch(_eCursorPosition)
1581 case IResultSetHelper::NEXT:
1582 nFetchOrientation = SQL_FETCH_NEXT;
1583 break;
1584 case IResultSetHelper::PRIOR:
1585 nFetchOrientation = SQL_FETCH_PRIOR;
1586 break;
1587 case IResultSetHelper::FIRST:
1588 nFetchOrientation = SQL_FETCH_FIRST;
1589 break;
1590 case IResultSetHelper::LAST:
1591 nFetchOrientation = SQL_FETCH_LAST;
1592 break;
1593 case IResultSetHelper::RELATIVE:
1594 nFetchOrientation = SQL_FETCH_RELATIVE;
1595 break;
1596 case IResultSetHelper::ABSOLUTE:
1597 nFetchOrientation = SQL_FETCH_ABSOLUTE;
1598 break;
1599 case IResultSetHelper::BOOKMARK: // special case here because we are only called with position numbers
1601 TBookmarkPosMap::iterator aIter = m_aPosToBookmarks.begin();
1602 TBookmarkPosMap::iterator aEnd = m_aPosToBookmarks.end();
1603 for (; aIter != aEnd; ++aIter)
1605 if ( aIter->second == _nOffset )
1606 return moveToBookmark(makeAny(aIter->first));
1608 OSL_ENSURE(0,"Bookmark not found!");
1610 return sal_False;
1613 m_bEOF = sal_False;
1614 m_nLastColumnPos = 0;
1616 SQLRETURN nOldFetchStatus = m_nCurrentFetchState;
1617 if ( !m_bUseFetchScroll && _eCursorPosition == IResultSetHelper::NEXT )
1618 m_nCurrentFetchState = N3SQLFetch(m_aStatementHandle);
1619 else
1620 m_nCurrentFetchState = N3SQLFetchScroll(m_aStatementHandle,nFetchOrientation,_nOffset);
1622 OSL_TRACE( __FILE__": OSkipDeletedSet::OResultSet::move(%d,%d), FetchState = %d",nFetchOrientation,_nOffset,m_nCurrentFetchState);
1623 OTools::ThrowException(m_pStatement->getOwnConnection(),m_nCurrentFetchState,m_aStatementHandle,SQL_HANDLE_STMT,*this);
1625 const bool bSuccess = m_nCurrentFetchState == SQL_SUCCESS || m_nCurrentFetchState == SQL_SUCCESS_WITH_INFO;
1626 if ( bSuccess )
1628 switch(_eCursorPosition)
1630 case IResultSetHelper::NEXT:
1631 ++m_nRowPos;
1632 break;
1633 case IResultSetHelper::PRIOR:
1634 --m_nRowPos;
1635 break;
1636 case IResultSetHelper::FIRST:
1637 m_nRowPos = 1;
1638 break;
1639 case IResultSetHelper::LAST:
1640 m_bEOF = sal_True;
1641 break;
1642 case IResultSetHelper::RELATIVE:
1643 m_nRowPos += _nOffset;
1644 break;
1645 case IResultSetHelper::ABSOLUTE:
1646 case IResultSetHelper::BOOKMARK: // special case here because we are only called with position numbers
1647 m_nRowPos = _nOffset;
1648 break;
1649 } // switch(_eCursorPosition)
1650 if ( m_nUseBookmarks == ODBC_SQL_NOT_DEFINED )
1652 RTL_LOGFILE_CONTEXT_TRACE( aLogger, "SQLGetStmtAttr" );
1653 m_nUseBookmarks = SQL_UB_OFF;
1654 SQLRETURN nRet = N3SQLGetStmtAttr(m_aStatementHandle,SQL_ATTR_USE_BOOKMARKS,&m_nUseBookmarks,SQL_IS_UINTEGER,NULL);
1655 OSL_UNUSED( nRet );
1657 if ( m_nUseBookmarks != SQL_UB_OFF )
1659 RTL_LOGFILE_CONTEXT_TRACE( aLogger, "OTools::getBytesValue" );
1660 m_aBookmark = OTools::getBytesValue(m_pStatement->getOwnConnection(),m_aStatementHandle,0,SQL_C_VARBOOKMARK,m_bWasNull,**this);
1661 m_aPosToBookmarks[m_aBookmark] = m_nRowPos;
1662 OSL_ENSURE(m_aBookmark.getLength(),"Invalid bookmark from length 0!");
1665 else if ( IResultSetHelper::PRIOR == _eCursorPosition && m_nCurrentFetchState == SQL_NO_DATA )
1666 m_nRowPos = 0;
1667 else if(IResultSetHelper::NEXT == _eCursorPosition && m_nCurrentFetchState == SQL_NO_DATA && nOldFetchStatus != SQL_NO_DATA)
1668 ++m_nRowPos;
1670 return bSuccess;
1672 // -----------------------------------------------------------------------------
1673 sal_Int32 OResultSet::getDriverPos() const
1675 sal_Int32 nValue = 0;
1676 SQLRETURN nRet = N3SQLGetStmtAttr(m_aStatementHandle,SQL_ATTR_ROW_NUMBER,&nValue,SQL_IS_UINTEGER,0);
1677 OSL_UNUSED( nRet );
1678 OSL_TRACE( __FILE__": OResultSet::getDriverPos() = Ret = %d, RowNum = %d, RowPos = %d",nRet,nValue , m_nRowPos);
1679 return nValue ? nValue : m_nRowPos;
1681 // -----------------------------------------------------------------------------
1682 sal_Bool OResultSet::deletedVisible() const
1684 return sal_False;
1686 // -----------------------------------------------------------------------------
1687 sal_Bool OResultSet::isRowDeleted() const
1689 return m_pRowStatusArray[0] == SQL_ROW_DELETED;
1691 // -----------------------------------------------------------------------------
1692 sal_Bool OResultSet::moveImpl(IResultSetHelper::Movement _eCursorPosition, sal_Int32 _nOffset, sal_Bool _bRetrieveData)
1694 ::osl::MutexGuard aGuard( m_aMutex );
1695 checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
1696 return (m_pSkipDeletedSet != NULL)
1697 ? m_pSkipDeletedSet->skipDeleted(_eCursorPosition,_nOffset,_bRetrieveData)
1698 : move(_eCursorPosition,_nOffset,_bRetrieveData);
1700 // -----------------------------------------------------------------------------
1701 void OResultSet::fillNeededData(SQLRETURN _nRet)
1703 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OResultSet::fillNeededData" );
1704 SQLRETURN nRet = _nRet;
1705 if( nRet == SQL_NEED_DATA)
1707 void* pColumnIndex = 0;
1708 nRet = N3SQLParamData(m_aStatementHandle,&pColumnIndex);
1712 if (nRet != SQL_SUCCESS && nRet != SQL_SUCCESS_WITH_INFO && nRet != SQL_NEED_DATA)
1713 break;
1715 sal_IntPtr nColumnIndex ( reinterpret_cast<sal_IntPtr>(pColumnIndex));
1716 Sequence< sal_Int8 > aSeq;
1717 switch(m_aRow[nColumnIndex].getTypeKind())
1719 case DataType::BINARY:
1720 case DataType::VARBINARY:
1721 case DataType::LONGVARBINARY:
1722 aSeq = m_aRow[nColumnIndex];
1723 N3SQLPutData (m_aStatementHandle, aSeq.getArray(), aSeq.getLength());
1724 break;
1725 case SQL_WLONGVARCHAR:
1727 ::rtl::OUString sRet;
1728 sRet = m_aRow[nColumnIndex].getString();
1729 nRet = N3SQLPutData (m_aStatementHandle, (SQLPOINTER)sRet.getStr(), sizeof(sal_Unicode)*sRet.getLength());
1730 break;
1732 case DataType::LONGVARCHAR:
1734 ::rtl::OUString sRet;
1735 sRet = m_aRow[nColumnIndex].getString();
1736 ::rtl::OString aString(::rtl::OUStringToOString(sRet,m_nTextEncoding));
1737 nRet = N3SQLPutData (m_aStatementHandle, (SQLPOINTER)aString.getStr(), aString.getLength());
1738 break;
1740 default:
1741 OSL_ENSURE(0,"Not supported at the moment!");
1743 nRet = N3SQLParamData(m_aStatementHandle,&pColumnIndex);
1745 while (nRet == SQL_NEED_DATA);