xref: /AOO41X/main/connectivity/source/drivers/odbcbase/OResultSet.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_connectivity.hxx"
30*cdf0e10cSrcweir #include "odbc/OResultSet.hxx"
31*cdf0e10cSrcweir #include "odbc/OTools.hxx"
32*cdf0e10cSrcweir #include "odbc/OResultSetMetaData.hxx"
33*cdf0e10cSrcweir #include <com/sun/star/sdbc/DataType.hpp>
34*cdf0e10cSrcweir #include <com/sun/star/beans/PropertyAttribute.hpp>
35*cdf0e10cSrcweir #include <com/sun/star/sdbcx/CompareBookmark.hpp>
36*cdf0e10cSrcweir #include <com/sun/star/sdbc/ResultSetConcurrency.hpp>
37*cdf0e10cSrcweir #include <com/sun/star/sdbc/FetchDirection.hpp>
38*cdf0e10cSrcweir #include <com/sun/star/sdbc/ResultSetType.hpp>
39*cdf0e10cSrcweir #include <comphelper/property.hxx>
40*cdf0e10cSrcweir #include <comphelper/sequence.hxx>
41*cdf0e10cSrcweir #include <cppuhelper/typeprovider.hxx>
42*cdf0e10cSrcweir #include <comphelper/extract.hxx>
43*cdf0e10cSrcweir #include <com/sun/star/lang/DisposedException.hpp>
44*cdf0e10cSrcweir #include <comphelper/types.hxx>
45*cdf0e10cSrcweir #include "connectivity/dbtools.hxx"
46*cdf0e10cSrcweir #include "connectivity/dbexception.hxx"
47*cdf0e10cSrcweir #include "diagnose_ex.h"
48*cdf0e10cSrcweir #include <rtl/logfile.hxx>
49*cdf0e10cSrcweir 
50*cdf0e10cSrcweir using namespace ::comphelper;
51*cdf0e10cSrcweir using namespace connectivity;
52*cdf0e10cSrcweir using namespace connectivity::odbc;
53*cdf0e10cSrcweir using namespace cppu;
54*cdf0e10cSrcweir using namespace com::sun::star::uno;
55*cdf0e10cSrcweir using namespace com::sun::star::lang;
56*cdf0e10cSrcweir using namespace com::sun::star::beans;
57*cdf0e10cSrcweir using namespace com::sun::star::sdbc;
58*cdf0e10cSrcweir using namespace com::sun::star::sdbcx;
59*cdf0e10cSrcweir using namespace com::sun::star::container;
60*cdf0e10cSrcweir using namespace com::sun::star::io;
61*cdf0e10cSrcweir using namespace com::sun::star::util;
62*cdf0e10cSrcweir 
63*cdf0e10cSrcweir #define ODBC_SQL_NOT_DEFINED    99UL
64*cdf0e10cSrcweir 
65*cdf0e10cSrcweir //------------------------------------------------------------------------------
66*cdf0e10cSrcweir //	IMPLEMENT_SERVICE_INFO(OResultSet,"com.sun.star.sdbcx.OResultSet","com.sun.star.sdbc.ResultSet");
67*cdf0e10cSrcweir ::rtl::OUString SAL_CALL OResultSet::getImplementationName(  ) throw ( RuntimeException)
68*cdf0e10cSrcweir {
69*cdf0e10cSrcweir 	return ::rtl::OUString::createFromAscii("com.sun.star.sdbcx.odbc.ResultSet");
70*cdf0e10cSrcweir }
71*cdf0e10cSrcweir // -------------------------------------------------------------------------
72*cdf0e10cSrcweir  Sequence< ::rtl::OUString > SAL_CALL OResultSet::getSupportedServiceNames(  ) throw( RuntimeException)
73*cdf0e10cSrcweir {
74*cdf0e10cSrcweir 	 Sequence< ::rtl::OUString > aSupported(2);
75*cdf0e10cSrcweir 	aSupported[0] = ::rtl::OUString::createFromAscii("com.sun.star.sdbc.ResultSet");
76*cdf0e10cSrcweir 	aSupported[1] = ::rtl::OUString::createFromAscii("com.sun.star.sdbcx.ResultSet");
77*cdf0e10cSrcweir 	return aSupported;
78*cdf0e10cSrcweir }
79*cdf0e10cSrcweir // -------------------------------------------------------------------------
80*cdf0e10cSrcweir sal_Bool SAL_CALL OResultSet::supportsService( const ::rtl::OUString& _rServiceName ) throw( RuntimeException)
81*cdf0e10cSrcweir {
82*cdf0e10cSrcweir 	Sequence< ::rtl::OUString > aSupported(getSupportedServiceNames());
83*cdf0e10cSrcweir 	const ::rtl::OUString* pSupported = aSupported.getConstArray();
84*cdf0e10cSrcweir 	const ::rtl::OUString* pEnd = pSupported + aSupported.getLength();
85*cdf0e10cSrcweir 	for (;pSupported != pEnd && !pSupported->equals(_rServiceName); ++pSupported)
86*cdf0e10cSrcweir 		;
87*cdf0e10cSrcweir 
88*cdf0e10cSrcweir 	return pSupported != pEnd;
89*cdf0e10cSrcweir }
90*cdf0e10cSrcweir 
91*cdf0e10cSrcweir // -------------------------------------------------------------------------
92*cdf0e10cSrcweir OResultSet::OResultSet(SQLHANDLE _pStatementHandle ,OStatement_Base* pStmt) :	OResultSet_BASE(m_aMutex)
93*cdf0e10cSrcweir 						,OPropertySetHelper(OResultSet_BASE::rBHelper)
94*cdf0e10cSrcweir                         ,m_aStatementHandle(_pStatementHandle)
95*cdf0e10cSrcweir                         ,m_aConnectionHandle(pStmt->getConnectionHandle())
96*cdf0e10cSrcweir                         ,m_pStatement(pStmt)
97*cdf0e10cSrcweir                         ,m_pSkipDeletedSet(NULL)
98*cdf0e10cSrcweir                         ,m_xStatement(*pStmt)
99*cdf0e10cSrcweir                         ,m_xMetaData(NULL)
100*cdf0e10cSrcweir                         ,m_pRowStatusArray( NULL )
101*cdf0e10cSrcweir                         ,m_nTextEncoding(pStmt->getOwnConnection()->getTextEncoding())
102*cdf0e10cSrcweir 						,m_nRowPos(0)
103*cdf0e10cSrcweir                         ,m_nLastColumnPos(0)
104*cdf0e10cSrcweir                         ,m_nUseBookmarks(ODBC_SQL_NOT_DEFINED)
105*cdf0e10cSrcweir                         ,m_nCurrentFetchState(0)
106*cdf0e10cSrcweir                         ,m_bWasNull(sal_True)
107*cdf0e10cSrcweir                         ,m_bEOF(sal_True)
108*cdf0e10cSrcweir 						,m_bLastRecord(sal_False)
109*cdf0e10cSrcweir 						,m_bFreeHandle(sal_False)
110*cdf0e10cSrcweir 						,m_bInserting(sal_False)
111*cdf0e10cSrcweir                         ,m_bFetchData(sal_True)
112*cdf0e10cSrcweir 						,m_bRowInserted(sal_False)
113*cdf0e10cSrcweir 						,m_bRowDeleted(sal_False)
114*cdf0e10cSrcweir 						,m_bUseFetchScroll(sal_False)
115*cdf0e10cSrcweir {
116*cdf0e10cSrcweir 	osl_incrementInterlockedCount( &m_refCount );
117*cdf0e10cSrcweir 	try
118*cdf0e10cSrcweir 	{
119*cdf0e10cSrcweir 		m_pRowStatusArray = new SQLUSMALLINT[1]; // the default value
120*cdf0e10cSrcweir 		N3SQLSetStmtAttr(m_aStatementHandle,SQL_ATTR_ROW_STATUS_PTR,m_pRowStatusArray,SQL_IS_POINTER);
121*cdf0e10cSrcweir 	}
122*cdf0e10cSrcweir 	catch(Exception&)
123*cdf0e10cSrcweir 	{ // we don't want our result destroy here
124*cdf0e10cSrcweir 	}
125*cdf0e10cSrcweir 	SQLINTEGER nCurType = 0;
126*cdf0e10cSrcweir 	try
127*cdf0e10cSrcweir 	{
128*cdf0e10cSrcweir 		N3SQLGetStmtAttr(m_aStatementHandle,SQL_ATTR_CURSOR_TYPE,&nCurType,SQL_IS_UINTEGER,0);
129*cdf0e10cSrcweir 		SQLUINTEGER nValueLen = m_pStatement->getCursorProperties(nCurType,sal_False);
130*cdf0e10cSrcweir 		if( (nValueLen & SQL_CA2_SENSITIVITY_DELETIONS) != SQL_CA2_SENSITIVITY_DELETIONS ||
131*cdf0e10cSrcweir 			(nValueLen & SQL_CA2_CRC_EXACT) != SQL_CA2_CRC_EXACT)
132*cdf0e10cSrcweir 			m_pSkipDeletedSet = new OSkipDeletedSet(this);
133*cdf0e10cSrcweir 	}
134*cdf0e10cSrcweir 	catch(Exception&)
135*cdf0e10cSrcweir 	{ // we don't want our result destroy here
136*cdf0e10cSrcweir 	}
137*cdf0e10cSrcweir 	try
138*cdf0e10cSrcweir 	{
139*cdf0e10cSrcweir 		SQLUINTEGER nValueLen = 0;
140*cdf0e10cSrcweir 		OTools::GetInfo(m_pStatement->getOwnConnection(),m_aConnectionHandle,SQL_GETDATA_EXTENSIONS,nValueLen,NULL);
141*cdf0e10cSrcweir 		m_bFetchData = !((SQL_GD_ANY_ORDER & nValueLen) == SQL_GD_ANY_ORDER && nCurType != SQL_CURSOR_FORWARD_ONLY);
142*cdf0e10cSrcweir 	}
143*cdf0e10cSrcweir 	catch(Exception&)
144*cdf0e10cSrcweir 	{ // we don't want our result destroy here
145*cdf0e10cSrcweir 		m_bFetchData = sal_True;
146*cdf0e10cSrcweir 	}
147*cdf0e10cSrcweir 	try
148*cdf0e10cSrcweir 	{
149*cdf0e10cSrcweir 		if ( getOdbcFunction(ODBC3SQLGetFunctions) )
150*cdf0e10cSrcweir 		{
151*cdf0e10cSrcweir 			SQLUSMALLINT nSupported = 0;
152*cdf0e10cSrcweir 			m_bUseFetchScroll = ( N3SQLGetFunctions(m_aConnectionHandle,SQL_API_SQLFETCHSCROLL,&nSupported) == SQL_SUCCESS && nSupported == 1 );
153*cdf0e10cSrcweir 		}
154*cdf0e10cSrcweir 	}
155*cdf0e10cSrcweir 	catch(Exception&)
156*cdf0e10cSrcweir 	{
157*cdf0e10cSrcweir 		m_bUseFetchScroll = sal_False;
158*cdf0e10cSrcweir 	}
159*cdf0e10cSrcweir 
160*cdf0e10cSrcweir 	osl_decrementInterlockedCount( &m_refCount );
161*cdf0e10cSrcweir }
162*cdf0e10cSrcweir // -------------------------------------------------------------------------
163*cdf0e10cSrcweir OResultSet::~OResultSet()
164*cdf0e10cSrcweir {
165*cdf0e10cSrcweir 	delete [] m_pRowStatusArray;
166*cdf0e10cSrcweir 	delete m_pSkipDeletedSet;
167*cdf0e10cSrcweir }
168*cdf0e10cSrcweir // -----------------------------------------------------------------------------
169*cdf0e10cSrcweir void OResultSet::construct()
170*cdf0e10cSrcweir {
171*cdf0e10cSrcweir 	osl_incrementInterlockedCount( &m_refCount );
172*cdf0e10cSrcweir 	allocBuffer();
173*cdf0e10cSrcweir 	osl_decrementInterlockedCount( &m_refCount );
174*cdf0e10cSrcweir }
175*cdf0e10cSrcweir // -------------------------------------------------------------------------
176*cdf0e10cSrcweir void OResultSet::disposing(void)
177*cdf0e10cSrcweir {
178*cdf0e10cSrcweir 	SQLRETURN nRet = N3SQLCloseCursor(m_aStatementHandle);
179*cdf0e10cSrcweir     OSL_UNUSED( nRet );
180*cdf0e10cSrcweir 	OPropertySetHelper::disposing();
181*cdf0e10cSrcweir 
182*cdf0e10cSrcweir 	::osl::MutexGuard aGuard(m_aMutex);
183*cdf0e10cSrcweir 	if(!m_aBindVector.empty())
184*cdf0e10cSrcweir 		releaseBuffer();
185*cdf0e10cSrcweir 	if(m_bFreeHandle)
186*cdf0e10cSrcweir 		m_pStatement->getOwnConnection()->freeStatementHandle(m_aStatementHandle);
187*cdf0e10cSrcweir 
188*cdf0e10cSrcweir m_xStatement.clear();
189*cdf0e10cSrcweir m_xMetaData.clear();
190*cdf0e10cSrcweir }
191*cdf0e10cSrcweir // -------------------------------------------------------------------------
192*cdf0e10cSrcweir SQLRETURN OResultSet::unbind(sal_Bool _bUnbindHandle)
193*cdf0e10cSrcweir {
194*cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OResultSet::unbind" );
195*cdf0e10cSrcweir 	SQLRETURN nRet = 0;
196*cdf0e10cSrcweir 	if ( _bUnbindHandle )
197*cdf0e10cSrcweir 		nRet = N3SQLFreeStmt(m_aStatementHandle,SQL_UNBIND);
198*cdf0e10cSrcweir 
199*cdf0e10cSrcweir 	if ( m_aBindVector.size() > 1 )
200*cdf0e10cSrcweir 	{
201*cdf0e10cSrcweir 		TVoidVector::iterator pValue = m_aBindVector.begin() + 1;
202*cdf0e10cSrcweir 		TVoidVector::iterator pEnd = m_aBindVector.end();
203*cdf0e10cSrcweir 		for(; pValue != pEnd; ++pValue)
204*cdf0e10cSrcweir 		{
205*cdf0e10cSrcweir 			switch (pValue->second)
206*cdf0e10cSrcweir 			{
207*cdf0e10cSrcweir 				case DataType::CHAR:
208*cdf0e10cSrcweir 				case DataType::VARCHAR:
209*cdf0e10cSrcweir 					delete static_cast< ::rtl::OString* >(reinterpret_cast< void * >(pValue->first));
210*cdf0e10cSrcweir 					break;
211*cdf0e10cSrcweir 				case DataType::BIGINT:
212*cdf0e10cSrcweir 					delete static_cast< sal_Int64* >(reinterpret_cast< void * >(pValue->first));
213*cdf0e10cSrcweir 					break;
214*cdf0e10cSrcweir 				case DataType::DECIMAL:
215*cdf0e10cSrcweir 				case DataType::NUMERIC:
216*cdf0e10cSrcweir 					delete static_cast< ::rtl::OString* >(reinterpret_cast< void * >(pValue->first));
217*cdf0e10cSrcweir 					break;
218*cdf0e10cSrcweir 				case DataType::REAL:
219*cdf0e10cSrcweir 				case DataType::DOUBLE:
220*cdf0e10cSrcweir 					delete static_cast< double* >(reinterpret_cast< void * >(pValue->first));
221*cdf0e10cSrcweir 					break;
222*cdf0e10cSrcweir 				case DataType::LONGVARCHAR:
223*cdf0e10cSrcweir 				case DataType::CLOB:
224*cdf0e10cSrcweir 					delete [] static_cast< char* >(reinterpret_cast< void * >(pValue->first));
225*cdf0e10cSrcweir 					break;
226*cdf0e10cSrcweir 				case DataType::LONGVARBINARY:
227*cdf0e10cSrcweir 				case DataType::BLOB:
228*cdf0e10cSrcweir 					delete [] static_cast< char* >(reinterpret_cast< void * >(pValue->first));
229*cdf0e10cSrcweir 					break;
230*cdf0e10cSrcweir 				case DataType::DATE:
231*cdf0e10cSrcweir 					delete static_cast< DATE_STRUCT* >(reinterpret_cast< void * >(pValue->first));
232*cdf0e10cSrcweir 					break;
233*cdf0e10cSrcweir 				case DataType::TIME:
234*cdf0e10cSrcweir 					delete static_cast< TIME_STRUCT* >(reinterpret_cast< void * >(pValue->first));
235*cdf0e10cSrcweir 					break;
236*cdf0e10cSrcweir 				case DataType::TIMESTAMP:
237*cdf0e10cSrcweir 					delete static_cast< TIMESTAMP_STRUCT* >(reinterpret_cast< void * >(pValue->first));
238*cdf0e10cSrcweir 					break;
239*cdf0e10cSrcweir 				case DataType::BIT:
240*cdf0e10cSrcweir 				case DataType::TINYINT:
241*cdf0e10cSrcweir 					delete static_cast< sal_Int8* >(reinterpret_cast< void * >(pValue->first));
242*cdf0e10cSrcweir 					break;
243*cdf0e10cSrcweir 				case DataType::SMALLINT:
244*cdf0e10cSrcweir 					delete static_cast< sal_Int16* >(reinterpret_cast< void * >(pValue->first));
245*cdf0e10cSrcweir 					break;
246*cdf0e10cSrcweir 				case DataType::INTEGER:
247*cdf0e10cSrcweir 					delete static_cast< sal_Int32* >(reinterpret_cast< void * >(pValue->first));
248*cdf0e10cSrcweir 					break;
249*cdf0e10cSrcweir 				case DataType::FLOAT:
250*cdf0e10cSrcweir 					delete static_cast< float* >(reinterpret_cast< void * >(pValue->first));
251*cdf0e10cSrcweir 					break;
252*cdf0e10cSrcweir 				case DataType::BINARY:
253*cdf0e10cSrcweir 				case DataType::VARBINARY:
254*cdf0e10cSrcweir 					delete static_cast< sal_Int8* >(reinterpret_cast< void * >(pValue->first));
255*cdf0e10cSrcweir 					break;
256*cdf0e10cSrcweir 			}
257*cdf0e10cSrcweir 		}
258*cdf0e10cSrcweir 		m_aBindVector.clear();
259*cdf0e10cSrcweir 		m_aBindVector.push_back(TVoidPtr(0,0)); // the first is reserved for the bookmark
260*cdf0e10cSrcweir 	}
261*cdf0e10cSrcweir 	return nRet;
262*cdf0e10cSrcweir }
263*cdf0e10cSrcweir // -------------------------------------------------------------------------
264*cdf0e10cSrcweir TVoidPtr OResultSet::allocBindColumn(sal_Int32 _nType,sal_Int32 _nColumnIndex)
265*cdf0e10cSrcweir {
266*cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OResultSet::allocBindColumn" );
267*cdf0e10cSrcweir 	TVoidPtr aPair;
268*cdf0e10cSrcweir 	switch (_nType)
269*cdf0e10cSrcweir 	{
270*cdf0e10cSrcweir 		case DataType::CHAR:
271*cdf0e10cSrcweir 		case DataType::VARCHAR:
272*cdf0e10cSrcweir 			aPair = TVoidPtr(reinterpret_cast< sal_Int64 >(new ::rtl::OString()),_nType);
273*cdf0e10cSrcweir 			break;
274*cdf0e10cSrcweir 		case DataType::BIGINT:
275*cdf0e10cSrcweir 			aPair = TVoidPtr(reinterpret_cast< sal_Int64 >(new sal_Int64(0)),_nType);
276*cdf0e10cSrcweir 			break;
277*cdf0e10cSrcweir 		case DataType::DECIMAL:
278*cdf0e10cSrcweir 		case DataType::NUMERIC:
279*cdf0e10cSrcweir 			aPair = TVoidPtr(reinterpret_cast< sal_Int64 >(new ::rtl::OString()),_nType);
280*cdf0e10cSrcweir 			break;
281*cdf0e10cSrcweir 		case DataType::REAL:
282*cdf0e10cSrcweir 		case DataType::DOUBLE:
283*cdf0e10cSrcweir 			aPair = TVoidPtr(reinterpret_cast< sal_Int64 >(new double(0.0)),_nType);
284*cdf0e10cSrcweir 			break;
285*cdf0e10cSrcweir 		case DataType::LONGVARCHAR:
286*cdf0e10cSrcweir 		case DataType::CLOB:
287*cdf0e10cSrcweir 			aPair = TVoidPtr(reinterpret_cast< sal_Int64 >(new char[2]),_nType);  // dient nur zum auffinden
288*cdf0e10cSrcweir 			break;
289*cdf0e10cSrcweir 		case DataType::LONGVARBINARY:
290*cdf0e10cSrcweir 		case DataType::BLOB:
291*cdf0e10cSrcweir 			aPair = TVoidPtr(reinterpret_cast< sal_Int64 >(new char[2]),_nType);  // dient nur zum auffinden
292*cdf0e10cSrcweir 			break;
293*cdf0e10cSrcweir 		case DataType::DATE:
294*cdf0e10cSrcweir 			aPair = TVoidPtr(reinterpret_cast< sal_Int64 >(new DATE_STRUCT),_nType);
295*cdf0e10cSrcweir 			break;
296*cdf0e10cSrcweir 		case DataType::TIME:
297*cdf0e10cSrcweir 			aPair = TVoidPtr(reinterpret_cast< sal_Int64 >(new TIME_STRUCT),_nType);
298*cdf0e10cSrcweir 			break;
299*cdf0e10cSrcweir 		case DataType::TIMESTAMP:
300*cdf0e10cSrcweir 			aPair = TVoidPtr(reinterpret_cast< sal_Int64 >(new TIMESTAMP_STRUCT),_nType);
301*cdf0e10cSrcweir 			break;
302*cdf0e10cSrcweir 		case DataType::BIT:
303*cdf0e10cSrcweir 		case DataType::TINYINT:
304*cdf0e10cSrcweir 			aPair = TVoidPtr(reinterpret_cast< sal_Int64 >(new sal_Int8(0)),_nType);
305*cdf0e10cSrcweir 			break;
306*cdf0e10cSrcweir 		case DataType::SMALLINT:
307*cdf0e10cSrcweir 			aPair = TVoidPtr(reinterpret_cast< sal_Int64 >(new sal_Int16(0)),_nType);
308*cdf0e10cSrcweir 			break;
309*cdf0e10cSrcweir 		case DataType::INTEGER:
310*cdf0e10cSrcweir 			aPair = TVoidPtr(reinterpret_cast< sal_Int64 >(new sal_Int32(0)),_nType);
311*cdf0e10cSrcweir 			break;
312*cdf0e10cSrcweir 		case DataType::FLOAT:
313*cdf0e10cSrcweir 			aPair = TVoidPtr(reinterpret_cast< sal_Int64 >(new float(0)),_nType);
314*cdf0e10cSrcweir 			break;
315*cdf0e10cSrcweir 		case DataType::BINARY:
316*cdf0e10cSrcweir 		case DataType::VARBINARY:
317*cdf0e10cSrcweir 			aPair = TVoidPtr(reinterpret_cast< sal_Int64 >(new sal_Int8[m_aRow[_nColumnIndex].getSequence().getLength()]),_nType);
318*cdf0e10cSrcweir 			break;
319*cdf0e10cSrcweir 		default:
320*cdf0e10cSrcweir 			OSL_ENSURE(0,"Unknown type");
321*cdf0e10cSrcweir 			aPair = TVoidPtr(0,_nType);
322*cdf0e10cSrcweir 	}
323*cdf0e10cSrcweir 	return aPair;
324*cdf0e10cSrcweir }
325*cdf0e10cSrcweir // -------------------------------------------------------------------------
326*cdf0e10cSrcweir void OResultSet::allocBuffer()
327*cdf0e10cSrcweir {
328*cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OResultSet::allocBuffer" );
329*cdf0e10cSrcweir 	Reference< XResultSetMetaData > xMeta = getMetaData();
330*cdf0e10cSrcweir 	sal_Int32 nLen = xMeta->getColumnCount();
331*cdf0e10cSrcweir 
332*cdf0e10cSrcweir 	m_aBindVector.reserve(nLen+1);
333*cdf0e10cSrcweir 	m_aBindVector.push_back(TVoidPtr(0,0)); // the first is reserved for the bookmark
334*cdf0e10cSrcweir 	m_aRow.resize(nLen+1);
335*cdf0e10cSrcweir 
336*cdf0e10cSrcweir 	for(sal_Int32 i = 1;i<=nLen;++i)
337*cdf0e10cSrcweir 	{
338*cdf0e10cSrcweir 		sal_Int32 nType = xMeta->getColumnType(i);
339*cdf0e10cSrcweir 		m_aRow[i].setTypeKind( nType );
340*cdf0e10cSrcweir 	}
341*cdf0e10cSrcweir 	m_aLengthVector.resize(nLen + 1);
342*cdf0e10cSrcweir }
343*cdf0e10cSrcweir // -------------------------------------------------------------------------
344*cdf0e10cSrcweir void OResultSet::releaseBuffer()
345*cdf0e10cSrcweir {
346*cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OResultSet::releaseBuffer" );
347*cdf0e10cSrcweir 	unbind(sal_False);
348*cdf0e10cSrcweir 	m_aLengthVector.clear();
349*cdf0e10cSrcweir }
350*cdf0e10cSrcweir // -------------------------------------------------------------------------
351*cdf0e10cSrcweir Any SAL_CALL OResultSet::queryInterface( const Type & rType ) throw(RuntimeException)
352*cdf0e10cSrcweir {
353*cdf0e10cSrcweir 	Any aRet = OPropertySetHelper::queryInterface(rType);
354*cdf0e10cSrcweir 	return aRet.hasValue() ? aRet : OResultSet_BASE::queryInterface(rType);
355*cdf0e10cSrcweir }
356*cdf0e10cSrcweir // -------------------------------------------------------------------------
357*cdf0e10cSrcweir  Sequence<  Type > SAL_CALL OResultSet::getTypes(  ) throw( RuntimeException)
358*cdf0e10cSrcweir {
359*cdf0e10cSrcweir 	OTypeCollection aTypes(	::getCppuType( (const  Reference< ::com::sun::star::beans::XMultiPropertySet > *)0 ),
360*cdf0e10cSrcweir 												::getCppuType( (const  Reference< ::com::sun::star::beans::XFastPropertySet > *)0 ),
361*cdf0e10cSrcweir 												::getCppuType( (const  Reference< ::com::sun::star::beans::XPropertySet > *)0 ));
362*cdf0e10cSrcweir 
363*cdf0e10cSrcweir 	return ::comphelper::concatSequences(aTypes.getTypes(),OResultSet_BASE::getTypes());
364*cdf0e10cSrcweir }
365*cdf0e10cSrcweir // -------------------------------------------------------------------------
366*cdf0e10cSrcweir 
367*cdf0e10cSrcweir sal_Int32 SAL_CALL OResultSet::findColumn( const ::rtl::OUString& columnName ) throw(SQLException, RuntimeException)
368*cdf0e10cSrcweir {
369*cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OResultSet::findColumn" );
370*cdf0e10cSrcweir 	checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
371*cdf0e10cSrcweir 
372*cdf0e10cSrcweir 
373*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
374*cdf0e10cSrcweir 
375*cdf0e10cSrcweir 	Reference< XResultSetMetaData > xMeta = getMetaData();
376*cdf0e10cSrcweir 	sal_Int32 nLen = xMeta->getColumnCount();
377*cdf0e10cSrcweir 	sal_Int32 i = 1;
378*cdf0e10cSrcweir 	for(;i<=nLen;++i)
379*cdf0e10cSrcweir 		if(xMeta->isCaseSensitive(i) ? columnName == xMeta->getColumnName(i) :
380*cdf0e10cSrcweir 				columnName.equalsIgnoreAsciiCase(xMeta->getColumnName(i)))
381*cdf0e10cSrcweir 			break;
382*cdf0e10cSrcweir 	return i;
383*cdf0e10cSrcweir }
384*cdf0e10cSrcweir // -------------------------------------------------------------------------
385*cdf0e10cSrcweir Reference< XInputStream > SAL_CALL OResultSet::getBinaryStream( sal_Int32 /*columnIndex*/ ) throw(SQLException, RuntimeException)
386*cdf0e10cSrcweir {
387*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
388*cdf0e10cSrcweir 	checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
389*cdf0e10cSrcweir 
390*cdf0e10cSrcweir 
391*cdf0e10cSrcweir 	// TODO use getBytes instead of
392*cdf0e10cSrcweir 	return NULL;
393*cdf0e10cSrcweir }
394*cdf0e10cSrcweir // -------------------------------------------------------------------------
395*cdf0e10cSrcweir Reference< XInputStream > SAL_CALL OResultSet::getCharacterStream( sal_Int32 /*columnIndex*/ ) throw(SQLException, RuntimeException)
396*cdf0e10cSrcweir {
397*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
398*cdf0e10cSrcweir 	checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
399*cdf0e10cSrcweir 
400*cdf0e10cSrcweir 
401*cdf0e10cSrcweir 	// TODO use getBytes instead of
402*cdf0e10cSrcweir 	return NULL;
403*cdf0e10cSrcweir }
404*cdf0e10cSrcweir // -----------------------------------------------------------------------------
405*cdf0e10cSrcweir const ORowSetValue& OResultSet::getValue(sal_Int32 _nColumnIndex,SQLSMALLINT _nType,void* _pValue,SQLINTEGER _rSize)
406*cdf0e10cSrcweir {
407*cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OResultSet::getValue" );
408*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
409*cdf0e10cSrcweir 	checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
410*cdf0e10cSrcweir 
411*cdf0e10cSrcweir 	if(m_bFetchData)
412*cdf0e10cSrcweir 	{
413*cdf0e10cSrcweir 		if(_nColumnIndex > m_nLastColumnPos)
414*cdf0e10cSrcweir 			fillRow(_nColumnIndex);
415*cdf0e10cSrcweir 		return m_aRow[_nColumnIndex];
416*cdf0e10cSrcweir 	}
417*cdf0e10cSrcweir 	else
418*cdf0e10cSrcweir 		OTools::getValue(m_pStatement->getOwnConnection(),m_aStatementHandle,_nColumnIndex,_nType,m_bWasNull,**this,_pValue,_rSize);
419*cdf0e10cSrcweir 
420*cdf0e10cSrcweir 	return m_aEmptyValue;
421*cdf0e10cSrcweir }
422*cdf0e10cSrcweir // -------------------------------------------------------------------------
423*cdf0e10cSrcweir sal_Bool SAL_CALL OResultSet::getBoolean( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
424*cdf0e10cSrcweir {
425*cdf0e10cSrcweir 	sal_Int8 nVal(0);
426*cdf0e10cSrcweir 	const ORowSetValue& aValue = getValue(columnIndex,SQL_C_BIT,&nVal,sizeof nVal);
427*cdf0e10cSrcweir 	return (&aValue == &m_aEmptyValue) ? (sal_Bool)nVal : (sal_Bool)aValue;
428*cdf0e10cSrcweir }
429*cdf0e10cSrcweir // -------------------------------------------------------------------------
430*cdf0e10cSrcweir 
431*cdf0e10cSrcweir sal_Int8 SAL_CALL OResultSet::getByte( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
432*cdf0e10cSrcweir {
433*cdf0e10cSrcweir 	sal_Int8 nRet(0);
434*cdf0e10cSrcweir 	const ORowSetValue& aValue = getValue(columnIndex,SQL_C_TINYINT,&nRet,sizeof nRet);
435*cdf0e10cSrcweir 	return (&aValue == &m_aEmptyValue) ? nRet : (sal_Int8)aValue;
436*cdf0e10cSrcweir }
437*cdf0e10cSrcweir // -------------------------------------------------------------------------
438*cdf0e10cSrcweir 
439*cdf0e10cSrcweir Sequence< sal_Int8 > SAL_CALL OResultSet::getBytes( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
440*cdf0e10cSrcweir {
441*cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OResultSet::getBytes" );
442*cdf0e10cSrcweir 
443*cdf0e10cSrcweir 	checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
444*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
445*cdf0e10cSrcweir 
446*cdf0e10cSrcweir 
447*cdf0e10cSrcweir 	if(m_bFetchData)
448*cdf0e10cSrcweir 	{
449*cdf0e10cSrcweir 		if(columnIndex > m_nLastColumnPos)
450*cdf0e10cSrcweir 			fillRow(columnIndex);
451*cdf0e10cSrcweir 		Sequence< sal_Int8 > nRet;
452*cdf0e10cSrcweir 		switch(m_aRow[columnIndex].getTypeKind())
453*cdf0e10cSrcweir 		{
454*cdf0e10cSrcweir 			case DataType::BINARY:
455*cdf0e10cSrcweir 			case DataType::VARBINARY:
456*cdf0e10cSrcweir 			case DataType::LONGVARBINARY:
457*cdf0e10cSrcweir 				nRet = m_aRow[columnIndex];
458*cdf0e10cSrcweir 				break;
459*cdf0e10cSrcweir 			default:
460*cdf0e10cSrcweir 			{
461*cdf0e10cSrcweir 				::rtl::OUString sRet;
462*cdf0e10cSrcweir 				sRet = m_aRow[columnIndex].getString();
463*cdf0e10cSrcweir 				nRet = Sequence<sal_Int8>(reinterpret_cast<const sal_Int8*>(sRet.getStr()),sizeof(sal_Unicode)*sRet.getLength());
464*cdf0e10cSrcweir 			}
465*cdf0e10cSrcweir 		}
466*cdf0e10cSrcweir 		return nRet;
467*cdf0e10cSrcweir 	}
468*cdf0e10cSrcweir 
469*cdf0e10cSrcweir     const SWORD nColumnType = impl_getColumnType_nothrow(columnIndex);
470*cdf0e10cSrcweir 
471*cdf0e10cSrcweir 	switch(nColumnType)
472*cdf0e10cSrcweir 	{
473*cdf0e10cSrcweir 		case SQL_WVARCHAR:
474*cdf0e10cSrcweir         case SQL_WCHAR:
475*cdf0e10cSrcweir         case SQL_WLONGVARCHAR:
476*cdf0e10cSrcweir         case SQL_VARCHAR:
477*cdf0e10cSrcweir         case SQL_CHAR:
478*cdf0e10cSrcweir         case SQL_LONGVARCHAR:
479*cdf0e10cSrcweir 		{
480*cdf0e10cSrcweir 			::rtl::OUString aRet = OTools::getStringValue(m_pStatement->getOwnConnection(),m_aStatementHandle,columnIndex,nColumnType,m_bWasNull,**this,m_nTextEncoding);
481*cdf0e10cSrcweir 			return Sequence<sal_Int8>(reinterpret_cast<const sal_Int8*>(aRet.getStr()),sizeof(sal_Unicode)*aRet.getLength());
482*cdf0e10cSrcweir 		}
483*cdf0e10cSrcweir         default:
484*cdf0e10cSrcweir             ;
485*cdf0e10cSrcweir 	}
486*cdf0e10cSrcweir 	return OTools::getBytesValue(m_pStatement->getOwnConnection(),m_aStatementHandle,columnIndex,SQL_C_BINARY,m_bWasNull,**this);
487*cdf0e10cSrcweir }
488*cdf0e10cSrcweir // -------------------------------------------------------------------------
489*cdf0e10cSrcweir 
490*cdf0e10cSrcweir Date SAL_CALL OResultSet::getDate( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
491*cdf0e10cSrcweir {
492*cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OResultSet::getDate" );
493*cdf0e10cSrcweir 	DATE_STRUCT aDate;
494*cdf0e10cSrcweir 	aDate.day	= 0;
495*cdf0e10cSrcweir 	aDate.month = 0;
496*cdf0e10cSrcweir 	aDate.year	= 0;
497*cdf0e10cSrcweir 
498*cdf0e10cSrcweir 	const ORowSetValue& aValue = getValue(	columnIndex,
499*cdf0e10cSrcweir 							m_pStatement->getOwnConnection()->useOldDateFormat() ? SQL_C_DATE : SQL_C_TYPE_DATE,
500*cdf0e10cSrcweir 											&aDate,sizeof aDate);
501*cdf0e10cSrcweir 	return (&aValue == &m_aEmptyValue)  ? Date(aDate.day,aDate.month,aDate.year) : (Date)aValue;
502*cdf0e10cSrcweir }
503*cdf0e10cSrcweir // -------------------------------------------------------------------------
504*cdf0e10cSrcweir 
505*cdf0e10cSrcweir double SAL_CALL OResultSet::getDouble( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
506*cdf0e10cSrcweir {
507*cdf0e10cSrcweir 	double nRet(0);
508*cdf0e10cSrcweir 	const ORowSetValue& aValue = getValue(columnIndex,SQL_C_DOUBLE,&nRet,sizeof nRet);
509*cdf0e10cSrcweir 	return (&aValue == &m_aEmptyValue) ? nRet : (double)aValue;
510*cdf0e10cSrcweir }
511*cdf0e10cSrcweir // -------------------------------------------------------------------------
512*cdf0e10cSrcweir 
513*cdf0e10cSrcweir float SAL_CALL OResultSet::getFloat( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
514*cdf0e10cSrcweir {
515*cdf0e10cSrcweir 	float nRet(0);
516*cdf0e10cSrcweir 	const ORowSetValue& aValue = getValue(columnIndex,SQL_C_FLOAT,&nRet,sizeof nRet);
517*cdf0e10cSrcweir 	return (&aValue == &m_aEmptyValue) ? nRet : (float)aValue;
518*cdf0e10cSrcweir }
519*cdf0e10cSrcweir // -------------------------------------------------------------------------
520*cdf0e10cSrcweir 
521*cdf0e10cSrcweir sal_Int32 SAL_CALL OResultSet::getInt( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
522*cdf0e10cSrcweir {
523*cdf0e10cSrcweir 	sal_Int32 nRet(0);
524*cdf0e10cSrcweir 	const ORowSetValue& aValue = getValue(columnIndex,SQL_C_LONG,&nRet,sizeof nRet);
525*cdf0e10cSrcweir 	return (&aValue == &m_aEmptyValue) ? nRet : (sal_Int32)aValue;
526*cdf0e10cSrcweir }
527*cdf0e10cSrcweir // -------------------------------------------------------------------------
528*cdf0e10cSrcweir 
529*cdf0e10cSrcweir sal_Int32 SAL_CALL OResultSet::getRow(  ) throw(SQLException, RuntimeException)
530*cdf0e10cSrcweir {
531*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
532*cdf0e10cSrcweir 	checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
533*cdf0e10cSrcweir 
534*cdf0e10cSrcweir 	return m_pSkipDeletedSet ? m_pSkipDeletedSet->getMappedPosition(getDriverPos()) : getDriverPos();
535*cdf0e10cSrcweir }
536*cdf0e10cSrcweir // -------------------------------------------------------------------------
537*cdf0e10cSrcweir 
538*cdf0e10cSrcweir sal_Int64 SAL_CALL OResultSet::getLong( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
539*cdf0e10cSrcweir {
540*cdf0e10cSrcweir 	sal_Int64 nRet(0);
541*cdf0e10cSrcweir 	try
542*cdf0e10cSrcweir 	{
543*cdf0e10cSrcweir 		const ORowSetValue& aValue = getValue(columnIndex,SQL_C_SBIGINT,&nRet,sizeof nRet);
544*cdf0e10cSrcweir 		return (&aValue == &m_aEmptyValue) ? nRet : (sal_Int64)aValue;
545*cdf0e10cSrcweir 	}
546*cdf0e10cSrcweir 	catch(SQLException&)
547*cdf0e10cSrcweir 	{
548*cdf0e10cSrcweir 		nRet = getString(columnIndex).toInt64();
549*cdf0e10cSrcweir 	}
550*cdf0e10cSrcweir 	return nRet;
551*cdf0e10cSrcweir }
552*cdf0e10cSrcweir // -------------------------------------------------------------------------
553*cdf0e10cSrcweir 
554*cdf0e10cSrcweir Reference< XResultSetMetaData > SAL_CALL OResultSet::getMetaData(  ) throw(SQLException, RuntimeException)
555*cdf0e10cSrcweir {
556*cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OResultSet::getMetaData" );
557*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
558*cdf0e10cSrcweir 	checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
559*cdf0e10cSrcweir 
560*cdf0e10cSrcweir 
561*cdf0e10cSrcweir 	if(!m_xMetaData.is())
562*cdf0e10cSrcweir 		m_xMetaData = new OResultSetMetaData(m_pStatement->getOwnConnection(),m_aStatementHandle);
563*cdf0e10cSrcweir 	return m_xMetaData;
564*cdf0e10cSrcweir }
565*cdf0e10cSrcweir // -------------------------------------------------------------------------
566*cdf0e10cSrcweir Reference< XArray > SAL_CALL OResultSet::getArray( sal_Int32 /*columnIndex*/ ) throw(SQLException, RuntimeException)
567*cdf0e10cSrcweir {
568*cdf0e10cSrcweir     ::dbtools::throwFunctionNotSupportedException( "XRow::getArray", *this );
569*cdf0e10cSrcweir 	return NULL;
570*cdf0e10cSrcweir }
571*cdf0e10cSrcweir 
572*cdf0e10cSrcweir // -------------------------------------------------------------------------
573*cdf0e10cSrcweir 
574*cdf0e10cSrcweir Reference< XClob > SAL_CALL OResultSet::getClob( sal_Int32 /*columnIndex*/ ) throw(SQLException, RuntimeException)
575*cdf0e10cSrcweir {
576*cdf0e10cSrcweir     ::dbtools::throwFunctionNotSupportedException( "XRow::getClob", *this );
577*cdf0e10cSrcweir 	return NULL;
578*cdf0e10cSrcweir }
579*cdf0e10cSrcweir // -------------------------------------------------------------------------
580*cdf0e10cSrcweir Reference< XBlob > SAL_CALL OResultSet::getBlob( sal_Int32 /*columnIndex*/ ) throw(SQLException, RuntimeException)
581*cdf0e10cSrcweir {
582*cdf0e10cSrcweir     ::dbtools::throwFunctionNotSupportedException( "XRow::getBlob", *this );
583*cdf0e10cSrcweir 	return NULL;
584*cdf0e10cSrcweir }
585*cdf0e10cSrcweir // -------------------------------------------------------------------------
586*cdf0e10cSrcweir 
587*cdf0e10cSrcweir Reference< XRef > SAL_CALL OResultSet::getRef( sal_Int32 /*columnIndex*/ ) throw(SQLException, RuntimeException)
588*cdf0e10cSrcweir {
589*cdf0e10cSrcweir     ::dbtools::throwFunctionNotSupportedException( "XRow::getRef", *this );
590*cdf0e10cSrcweir 	return NULL;
591*cdf0e10cSrcweir }
592*cdf0e10cSrcweir // -------------------------------------------------------------------------
593*cdf0e10cSrcweir 
594*cdf0e10cSrcweir Any SAL_CALL OResultSet::getObject( sal_Int32 columnIndex, const Reference< ::com::sun::star::container::XNameAccess >& /*typeMap*/ ) throw(SQLException, RuntimeException)
595*cdf0e10cSrcweir {
596*cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OResultSet::getObject" );
597*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
598*cdf0e10cSrcweir 	checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
599*cdf0e10cSrcweir 
600*cdf0e10cSrcweir 	fillRow(columnIndex);
601*cdf0e10cSrcweir 	return m_aRow[columnIndex].makeAny();
602*cdf0e10cSrcweir }
603*cdf0e10cSrcweir // -------------------------------------------------------------------------
604*cdf0e10cSrcweir 
605*cdf0e10cSrcweir sal_Int16 SAL_CALL OResultSet::getShort( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
606*cdf0e10cSrcweir {
607*cdf0e10cSrcweir 	sal_Int16 nRet(0);
608*cdf0e10cSrcweir 	const ORowSetValue& aValue = getValue(columnIndex,SQL_C_SHORT,&nRet,sizeof nRet);
609*cdf0e10cSrcweir 	return (&aValue == &m_aEmptyValue) ? nRet : (sal_Int16)aValue;
610*cdf0e10cSrcweir }
611*cdf0e10cSrcweir // -------------------------------------------------------------------------
612*cdf0e10cSrcweir 
613*cdf0e10cSrcweir 
614*cdf0e10cSrcweir ::rtl::OUString SAL_CALL OResultSet::getString( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
615*cdf0e10cSrcweir {
616*cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OResultSet::getString" );
617*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
618*cdf0e10cSrcweir 
619*cdf0e10cSrcweir 	::rtl::OUString nRet;
620*cdf0e10cSrcweir 	if ( m_bFetchData )
621*cdf0e10cSrcweir 		nRet = getValue(columnIndex,0,NULL,0);
622*cdf0e10cSrcweir 	else
623*cdf0e10cSrcweir     {
624*cdf0e10cSrcweir         checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
625*cdf0e10cSrcweir         const SWORD nColumnType = impl_getColumnType_nothrow(columnIndex);
626*cdf0e10cSrcweir 		nRet = OTools::getStringValue(m_pStatement->getOwnConnection(),m_aStatementHandle,columnIndex,nColumnType,m_bWasNull,**this,m_nTextEncoding);
627*cdf0e10cSrcweir     }
628*cdf0e10cSrcweir 	return nRet;
629*cdf0e10cSrcweir }
630*cdf0e10cSrcweir // -------------------------------------------------------------------------
631*cdf0e10cSrcweir 
632*cdf0e10cSrcweir Time SAL_CALL OResultSet::getTime( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
633*cdf0e10cSrcweir {
634*cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OResultSet::getTime" );
635*cdf0e10cSrcweir 	TIME_STRUCT aTime={0,0,0};
636*cdf0e10cSrcweir 	const ORowSetValue& aValue = getValue(columnIndex,
637*cdf0e10cSrcweir 		m_pStatement->getOwnConnection()->useOldDateFormat() ? SQL_C_TIME : SQL_C_TYPE_TIME,
638*cdf0e10cSrcweir 		&aTime,sizeof aTime);
639*cdf0e10cSrcweir 	return (&aValue == &m_aEmptyValue) ? Time(0,aTime.second,aTime.minute,aTime.hour) : (Time)aValue;
640*cdf0e10cSrcweir }
641*cdf0e10cSrcweir // -------------------------------------------------------------------------
642*cdf0e10cSrcweir 
643*cdf0e10cSrcweir 
644*cdf0e10cSrcweir DateTime SAL_CALL OResultSet::getTimestamp( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
645*cdf0e10cSrcweir {
646*cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OResultSet::getTimestamp" );
647*cdf0e10cSrcweir 	TIMESTAMP_STRUCT aTime={0,0,0,0,0,0,0};
648*cdf0e10cSrcweir 	const ORowSetValue& aValue = getValue(columnIndex,
649*cdf0e10cSrcweir 		m_pStatement->getOwnConnection()->useOldDateFormat() ? SQL_C_TIMESTAMP : SQL_C_TYPE_TIMESTAMP,
650*cdf0e10cSrcweir 		&aTime,sizeof aTime);
651*cdf0e10cSrcweir 	return (&aValue == &m_aEmptyValue)
652*cdf0e10cSrcweir 			?
653*cdf0e10cSrcweir 			DateTime(static_cast<sal_uInt16>(aTime.fraction*1000),aTime.second,aTime.minute,aTime.hour,aTime.day,aTime.month,aTime.year)
654*cdf0e10cSrcweir 			:
655*cdf0e10cSrcweir 			(DateTime)aValue;
656*cdf0e10cSrcweir }
657*cdf0e10cSrcweir // -------------------------------------------------------------------------
658*cdf0e10cSrcweir 
659*cdf0e10cSrcweir sal_Bool SAL_CALL OResultSet::isBeforeFirst(  ) throw(SQLException, RuntimeException)
660*cdf0e10cSrcweir {
661*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
662*cdf0e10cSrcweir 	checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
663*cdf0e10cSrcweir 	return m_nRowPos == 0;
664*cdf0e10cSrcweir }
665*cdf0e10cSrcweir // -------------------------------------------------------------------------
666*cdf0e10cSrcweir sal_Bool SAL_CALL OResultSet::isAfterLast(  ) throw(SQLException, RuntimeException)
667*cdf0e10cSrcweir {
668*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
669*cdf0e10cSrcweir 	checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
670*cdf0e10cSrcweir 
671*cdf0e10cSrcweir 	return m_nRowPos != 0 && m_nCurrentFetchState == SQL_NO_DATA;
672*cdf0e10cSrcweir }
673*cdf0e10cSrcweir // -------------------------------------------------------------------------
674*cdf0e10cSrcweir sal_Bool SAL_CALL OResultSet::isFirst(  ) throw(SQLException, RuntimeException)
675*cdf0e10cSrcweir {
676*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
677*cdf0e10cSrcweir 	checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
678*cdf0e10cSrcweir 
679*cdf0e10cSrcweir 	return m_nRowPos == 1;
680*cdf0e10cSrcweir }
681*cdf0e10cSrcweir // -------------------------------------------------------------------------
682*cdf0e10cSrcweir sal_Bool SAL_CALL OResultSet::isLast(  ) throw(SQLException, RuntimeException)
683*cdf0e10cSrcweir {
684*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
685*cdf0e10cSrcweir 	checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
686*cdf0e10cSrcweir 
687*cdf0e10cSrcweir 
688*cdf0e10cSrcweir 	return m_bEOF && m_nCurrentFetchState != SQL_NO_DATA;
689*cdf0e10cSrcweir }
690*cdf0e10cSrcweir // -------------------------------------------------------------------------
691*cdf0e10cSrcweir void SAL_CALL OResultSet::beforeFirst(  ) throw(SQLException, RuntimeException)
692*cdf0e10cSrcweir {
693*cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OResultSet::beforeFirst" );
694*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
695*cdf0e10cSrcweir 	checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
696*cdf0e10cSrcweir 
697*cdf0e10cSrcweir 
698*cdf0e10cSrcweir 	if(first())
699*cdf0e10cSrcweir 		previous();
700*cdf0e10cSrcweir 	m_nCurrentFetchState = SQL_SUCCESS;
701*cdf0e10cSrcweir }
702*cdf0e10cSrcweir // -------------------------------------------------------------------------
703*cdf0e10cSrcweir void SAL_CALL OResultSet::afterLast(  ) throw(SQLException, RuntimeException)
704*cdf0e10cSrcweir {
705*cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OResultSet::afterLast" );
706*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
707*cdf0e10cSrcweir 	checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
708*cdf0e10cSrcweir 
709*cdf0e10cSrcweir 	if(last())
710*cdf0e10cSrcweir 		next();
711*cdf0e10cSrcweir 	m_bEOF = sal_True;
712*cdf0e10cSrcweir }
713*cdf0e10cSrcweir // -------------------------------------------------------------------------
714*cdf0e10cSrcweir 
715*cdf0e10cSrcweir void SAL_CALL OResultSet::close(  ) throw(SQLException, RuntimeException)
716*cdf0e10cSrcweir {
717*cdf0e10cSrcweir 	{
718*cdf0e10cSrcweir 		::osl::MutexGuard aGuard( m_aMutex );
719*cdf0e10cSrcweir 		checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
720*cdf0e10cSrcweir 
721*cdf0e10cSrcweir 	}
722*cdf0e10cSrcweir 	dispose();
723*cdf0e10cSrcweir }
724*cdf0e10cSrcweir // -------------------------------------------------------------------------
725*cdf0e10cSrcweir 
726*cdf0e10cSrcweir sal_Bool SAL_CALL OResultSet::first(  ) throw(SQLException, RuntimeException)
727*cdf0e10cSrcweir {
728*cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OResultSet::first" );
729*cdf0e10cSrcweir 	return moveImpl(IResultSetHelper::FIRST,0,sal_True);
730*cdf0e10cSrcweir }
731*cdf0e10cSrcweir // -------------------------------------------------------------------------
732*cdf0e10cSrcweir 
733*cdf0e10cSrcweir sal_Bool SAL_CALL OResultSet::last(  ) throw(SQLException, RuntimeException)
734*cdf0e10cSrcweir {
735*cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OResultSet::last" );
736*cdf0e10cSrcweir 	return moveImpl(IResultSetHelper::LAST,0,sal_True);
737*cdf0e10cSrcweir }
738*cdf0e10cSrcweir // -------------------------------------------------------------------------
739*cdf0e10cSrcweir sal_Bool SAL_CALL OResultSet::absolute( sal_Int32 row ) throw(SQLException, RuntimeException)
740*cdf0e10cSrcweir {
741*cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OResultSet::absolute" );
742*cdf0e10cSrcweir 	return moveImpl(IResultSetHelper::ABSOLUTE,row,sal_True);
743*cdf0e10cSrcweir }
744*cdf0e10cSrcweir // -------------------------------------------------------------------------
745*cdf0e10cSrcweir sal_Bool SAL_CALL OResultSet::relative( sal_Int32 row ) throw(SQLException, RuntimeException)
746*cdf0e10cSrcweir {
747*cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OResultSet::relative" );
748*cdf0e10cSrcweir 	return moveImpl(IResultSetHelper::RELATIVE,row,sal_True);
749*cdf0e10cSrcweir }
750*cdf0e10cSrcweir // -------------------------------------------------------------------------
751*cdf0e10cSrcweir sal_Bool SAL_CALL OResultSet::previous(  ) throw(SQLException, RuntimeException)
752*cdf0e10cSrcweir {
753*cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OResultSet::previous" );
754*cdf0e10cSrcweir 	return moveImpl(IResultSetHelper::PRIOR,0,sal_True);
755*cdf0e10cSrcweir }
756*cdf0e10cSrcweir // -------------------------------------------------------------------------
757*cdf0e10cSrcweir Reference< XInterface > SAL_CALL OResultSet::getStatement(  ) throw(SQLException, RuntimeException)
758*cdf0e10cSrcweir {
759*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
760*cdf0e10cSrcweir 	checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
761*cdf0e10cSrcweir 	return m_xStatement;
762*cdf0e10cSrcweir }
763*cdf0e10cSrcweir // -------------------------------------------------------------------------
764*cdf0e10cSrcweir 
765*cdf0e10cSrcweir sal_Bool SAL_CALL OResultSet::rowDeleted() throw(SQLException, RuntimeException)
766*cdf0e10cSrcweir {
767*cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OResultSet::rowDeleted" );
768*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
769*cdf0e10cSrcweir 	checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
770*cdf0e10cSrcweir 
771*cdf0e10cSrcweir 	sal_Bool bRet = m_bRowDeleted;
772*cdf0e10cSrcweir 	m_bRowDeleted = sal_False;
773*cdf0e10cSrcweir 
774*cdf0e10cSrcweir 	return bRet;
775*cdf0e10cSrcweir }
776*cdf0e10cSrcweir // -------------------------------------------------------------------------
777*cdf0e10cSrcweir sal_Bool SAL_CALL OResultSet::rowInserted(  ) throw(SQLException, RuntimeException)
778*cdf0e10cSrcweir {
779*cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OResultSet::rowInserted" );
780*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
781*cdf0e10cSrcweir 	checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
782*cdf0e10cSrcweir 
783*cdf0e10cSrcweir 	sal_Bool bInserted = m_bRowInserted;
784*cdf0e10cSrcweir 	m_bRowInserted = sal_False;
785*cdf0e10cSrcweir 
786*cdf0e10cSrcweir 	return bInserted;
787*cdf0e10cSrcweir }
788*cdf0e10cSrcweir // -------------------------------------------------------------------------
789*cdf0e10cSrcweir sal_Bool SAL_CALL OResultSet::rowUpdated(  ) throw(SQLException, RuntimeException)
790*cdf0e10cSrcweir {
791*cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OResultSet::rowUpdated" );
792*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
793*cdf0e10cSrcweir 	checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
794*cdf0e10cSrcweir 
795*cdf0e10cSrcweir 
796*cdf0e10cSrcweir 	return m_pRowStatusArray[0] == SQL_ROW_UPDATED;
797*cdf0e10cSrcweir }
798*cdf0e10cSrcweir // -------------------------------------------------------------------------
799*cdf0e10cSrcweir 
800*cdf0e10cSrcweir sal_Bool SAL_CALL OResultSet::next(  ) throw(SQLException, RuntimeException)
801*cdf0e10cSrcweir {
802*cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OResultSet::next" );
803*cdf0e10cSrcweir 	return moveImpl(IResultSetHelper::NEXT,1,sal_True);
804*cdf0e10cSrcweir }
805*cdf0e10cSrcweir // -------------------------------------------------------------------------
806*cdf0e10cSrcweir 
807*cdf0e10cSrcweir sal_Bool SAL_CALL OResultSet::wasNull(  ) throw(SQLException, RuntimeException)
808*cdf0e10cSrcweir {
809*cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OResultSet::wasNull" );
810*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
811*cdf0e10cSrcweir 	checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
812*cdf0e10cSrcweir 
813*cdf0e10cSrcweir 
814*cdf0e10cSrcweir 	return m_bFetchData ? m_aRow[m_nLastColumnPos].isNull() : m_bWasNull;
815*cdf0e10cSrcweir }
816*cdf0e10cSrcweir // -------------------------------------------------------------------------
817*cdf0e10cSrcweir 
818*cdf0e10cSrcweir void SAL_CALL OResultSet::cancel(  ) throw(RuntimeException)
819*cdf0e10cSrcweir {
820*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
821*cdf0e10cSrcweir 	checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
822*cdf0e10cSrcweir 
823*cdf0e10cSrcweir 
824*cdf0e10cSrcweir 	OTools::ThrowException(m_pStatement->getOwnConnection(),N3SQLCancel(m_aStatementHandle),m_aStatementHandle,SQL_HANDLE_STMT,*this);
825*cdf0e10cSrcweir }
826*cdf0e10cSrcweir // -------------------------------------------------------------------------
827*cdf0e10cSrcweir void SAL_CALL OResultSet::clearWarnings(  ) throw(SQLException, RuntimeException)
828*cdf0e10cSrcweir {
829*cdf0e10cSrcweir }
830*cdf0e10cSrcweir // -------------------------------------------------------------------------
831*cdf0e10cSrcweir Any SAL_CALL OResultSet::getWarnings(  ) throw(SQLException, RuntimeException)
832*cdf0e10cSrcweir {
833*cdf0e10cSrcweir 	return Any();
834*cdf0e10cSrcweir }
835*cdf0e10cSrcweir // -------------------------------------------------------------------------
836*cdf0e10cSrcweir void SAL_CALL OResultSet::insertRow(  ) throw(SQLException, RuntimeException)
837*cdf0e10cSrcweir {
838*cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OResultSet::insertRow" );
839*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
840*cdf0e10cSrcweir 	checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
841*cdf0e10cSrcweir 
842*cdf0e10cSrcweir 
843*cdf0e10cSrcweir 	SQLLEN nMaxLen = 20;
844*cdf0e10cSrcweir 	SQLLEN nRealLen = 0;
845*cdf0e10cSrcweir 	Sequence<sal_Int8> aBookmark(nMaxLen);
846*cdf0e10cSrcweir 
847*cdf0e10cSrcweir 	SQLRETURN nRet = N3SQLBindCol(m_aStatementHandle,
848*cdf0e10cSrcweir 								0,
849*cdf0e10cSrcweir 								SQL_C_VARBOOKMARK,
850*cdf0e10cSrcweir 								aBookmark.getArray(),
851*cdf0e10cSrcweir 								nMaxLen,
852*cdf0e10cSrcweir 								&nRealLen
853*cdf0e10cSrcweir 								);
854*cdf0e10cSrcweir 	//	Sequence<sal_Int8> aRealBookmark(nMaxLen);
855*cdf0e10cSrcweir 
856*cdf0e10cSrcweir     sal_Bool bPositionByBookmark = ( NULL != getOdbcFunction( ODBC3SQLBulkOperations ) );
857*cdf0e10cSrcweir 	if ( bPositionByBookmark )
858*cdf0e10cSrcweir 	{
859*cdf0e10cSrcweir         nRet = N3SQLBulkOperations( m_aStatementHandle, SQL_ADD );
860*cdf0e10cSrcweir         fillNeededData( nRet );
861*cdf0e10cSrcweir 	}
862*cdf0e10cSrcweir 	else
863*cdf0e10cSrcweir 	{
864*cdf0e10cSrcweir 		if(isBeforeFirst())
865*cdf0e10cSrcweir 			next(); // must be done
866*cdf0e10cSrcweir         nRet = N3SQLSetPos( m_aStatementHandle, 1, SQL_ADD, SQL_LOCK_NO_CHANGE );
867*cdf0e10cSrcweir         fillNeededData( nRet );
868*cdf0e10cSrcweir 	}
869*cdf0e10cSrcweir 	try
870*cdf0e10cSrcweir 	{
871*cdf0e10cSrcweir 		OTools::ThrowException(m_pStatement->getOwnConnection(),nRet,m_aStatementHandle,SQL_HANDLE_STMT,*this);
872*cdf0e10cSrcweir 	}
873*cdf0e10cSrcweir 	catch(SQLException e)
874*cdf0e10cSrcweir 	{
875*cdf0e10cSrcweir 		nRet = unbind();
876*cdf0e10cSrcweir 		throw;
877*cdf0e10cSrcweir 	}
878*cdf0e10cSrcweir 
879*cdf0e10cSrcweir 
880*cdf0e10cSrcweir 	if ( bPositionByBookmark )
881*cdf0e10cSrcweir 	{
882*cdf0e10cSrcweir 		nRet = N3SQLSetStmtAttr(m_aStatementHandle,SQL_ATTR_FETCH_BOOKMARK_PTR,aBookmark.getArray(),SQL_IS_POINTER); // SQL_LEN_BINARY_ATTR(aBookmark.getLength())
883*cdf0e10cSrcweir 
884*cdf0e10cSrcweir 		nRet = N3SQLFetchScroll(m_aStatementHandle,SQL_FETCH_BOOKMARK,0);
885*cdf0e10cSrcweir 	}
886*cdf0e10cSrcweir 	else
887*cdf0e10cSrcweir 		nRet = N3SQLFetchScroll(m_aStatementHandle,SQL_FETCH_RELATIVE,0); // OJ 06.03.2004
888*cdf0e10cSrcweir 	// sometimes we got an error but we are not interested in anymore #106047# OJ
889*cdf0e10cSrcweir 	//	OTools::ThrowException(m_pStatement->getOwnConnection(),nRet,m_aStatementHandle,SQL_HANDLE_STMT,*this);
890*cdf0e10cSrcweir 	nRet = unbind();
891*cdf0e10cSrcweir 	OTools::ThrowException(m_pStatement->getOwnConnection(),nRet,m_aStatementHandle,SQL_HANDLE_STMT,*this);
892*cdf0e10cSrcweir 
893*cdf0e10cSrcweir 	if(m_pSkipDeletedSet)
894*cdf0e10cSrcweir 	{
895*cdf0e10cSrcweir 		aBookmark.realloc(nRealLen);
896*cdf0e10cSrcweir 		if(moveToBookmark(makeAny(aBookmark)))
897*cdf0e10cSrcweir 		{
898*cdf0e10cSrcweir 			sal_Int32 nRowPos = getDriverPos();
899*cdf0e10cSrcweir 			if ( -1 == m_nRowPos )
900*cdf0e10cSrcweir 			{
901*cdf0e10cSrcweir 				nRowPos = m_aPosToBookmarks.size() + 1;
902*cdf0e10cSrcweir 			}
903*cdf0e10cSrcweir 			if ( nRowPos == m_nRowPos )
904*cdf0e10cSrcweir 				++nRowPos;
905*cdf0e10cSrcweir 			m_nRowPos = nRowPos;
906*cdf0e10cSrcweir 			m_pSkipDeletedSet->insertNewPosition(nRowPos);
907*cdf0e10cSrcweir 			m_aPosToBookmarks[aBookmark] = nRowPos;
908*cdf0e10cSrcweir 		}
909*cdf0e10cSrcweir 	}
910*cdf0e10cSrcweir 	m_bRowInserted = sal_True;
911*cdf0e10cSrcweir 
912*cdf0e10cSrcweir }
913*cdf0e10cSrcweir // -------------------------------------------------------------------------
914*cdf0e10cSrcweir void SAL_CALL OResultSet::updateRow(  ) throw(SQLException, RuntimeException)
915*cdf0e10cSrcweir {
916*cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OResultSet::updateRow" );
917*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
918*cdf0e10cSrcweir 	checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
919*cdf0e10cSrcweir 
920*cdf0e10cSrcweir 	SQLRETURN nRet;
921*cdf0e10cSrcweir 
922*cdf0e10cSrcweir     sal_Bool bPositionByBookmark = ( NULL != getOdbcFunction( ODBC3SQLBulkOperations ) );
923*cdf0e10cSrcweir 	if ( bPositionByBookmark )
924*cdf0e10cSrcweir 	{
925*cdf0e10cSrcweir 		SQLLEN nRealLen = 0;
926*cdf0e10cSrcweir 		nRet = N3SQLBindCol(m_aStatementHandle,
927*cdf0e10cSrcweir 							0,
928*cdf0e10cSrcweir 							SQL_C_VARBOOKMARK,
929*cdf0e10cSrcweir 							m_aBookmark.getArray(),
930*cdf0e10cSrcweir 							m_aBookmark.getLength(),
931*cdf0e10cSrcweir 							&nRealLen
932*cdf0e10cSrcweir 							);
933*cdf0e10cSrcweir 		fillNeededData(nRet = N3SQLBulkOperations(m_aStatementHandle, SQL_UPDATE_BY_BOOKMARK));
934*cdf0e10cSrcweir 	}
935*cdf0e10cSrcweir 	else
936*cdf0e10cSrcweir 		fillNeededData(nRet = N3SQLSetPos(m_aStatementHandle,1,SQL_UPDATE,SQL_LOCK_NO_CHANGE));
937*cdf0e10cSrcweir 	OTools::ThrowException(m_pStatement->getOwnConnection(),nRet,m_aStatementHandle,SQL_HANDLE_STMT,*this);
938*cdf0e10cSrcweir 	// now unbind all columns so we can fetch all columns again with SQLGetData
939*cdf0e10cSrcweir 	nRet = unbind();
940*cdf0e10cSrcweir 	OSL_ENSURE(nRet == SQL_SUCCESS,"Could not unbind the columns!");
941*cdf0e10cSrcweir }
942*cdf0e10cSrcweir // -------------------------------------------------------------------------
943*cdf0e10cSrcweir void SAL_CALL OResultSet::deleteRow(  ) throw(SQLException, RuntimeException)
944*cdf0e10cSrcweir {
945*cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OResultSet::deleteRow" );
946*cdf0e10cSrcweir 	SQLRETURN nRet = SQL_SUCCESS;
947*cdf0e10cSrcweir 	sal_Int32 nPos = getDriverPos();
948*cdf0e10cSrcweir 	nRet = N3SQLSetPos(m_aStatementHandle,1,SQL_DELETE,SQL_LOCK_NO_CHANGE);
949*cdf0e10cSrcweir 	OTools::ThrowException(m_pStatement->getOwnConnection(),nRet,m_aStatementHandle,SQL_HANDLE_STMT,*this);
950*cdf0e10cSrcweir 
951*cdf0e10cSrcweir     m_bRowDeleted = ( m_pRowStatusArray[0] == SQL_ROW_DELETED );
952*cdf0e10cSrcweir     if ( m_bRowDeleted )
953*cdf0e10cSrcweir 	{
954*cdf0e10cSrcweir 		TBookmarkPosMap::iterator aIter = m_aPosToBookmarks.begin();
955*cdf0e10cSrcweir 		TBookmarkPosMap::iterator aEnd = m_aPosToBookmarks.end();
956*cdf0e10cSrcweir 		for (; aIter != aEnd; ++aIter)
957*cdf0e10cSrcweir 		{
958*cdf0e10cSrcweir 			if ( aIter->second == nPos )
959*cdf0e10cSrcweir 			{
960*cdf0e10cSrcweir 				m_aPosToBookmarks.erase(aIter);
961*cdf0e10cSrcweir 				break;
962*cdf0e10cSrcweir 			}
963*cdf0e10cSrcweir 		}
964*cdf0e10cSrcweir 	}
965*cdf0e10cSrcweir 	if ( m_pSkipDeletedSet )
966*cdf0e10cSrcweir 		m_pSkipDeletedSet->deletePosition(nPos);
967*cdf0e10cSrcweir }
968*cdf0e10cSrcweir // -------------------------------------------------------------------------
969*cdf0e10cSrcweir 
970*cdf0e10cSrcweir void SAL_CALL OResultSet::cancelRowUpdates(  ) throw(SQLException, RuntimeException)
971*cdf0e10cSrcweir {
972*cdf0e10cSrcweir }
973*cdf0e10cSrcweir // -------------------------------------------------------------------------
974*cdf0e10cSrcweir 
975*cdf0e10cSrcweir void SAL_CALL OResultSet::moveToInsertRow(  ) throw(SQLException, RuntimeException)
976*cdf0e10cSrcweir {
977*cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OResultSet::moveToInsertRow" );
978*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
979*cdf0e10cSrcweir 	checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
980*cdf0e10cSrcweir 
981*cdf0e10cSrcweir 
982*cdf0e10cSrcweir 	m_nLastColumnPos = 0;
983*cdf0e10cSrcweir 	// first unbound all columns
984*cdf0e10cSrcweir     OSL_VERIFY_EQUALS( unbind(), SQL_SUCCESS, "Could not unbind columns!" );
985*cdf0e10cSrcweir 	//	SQLRETURN nRet = N3SQLSetStmtAttr(m_aStatementHandle,SQL_ATTR_ROW_ARRAY_SIZE ,(SQLPOINTER)1,SQL_IS_INTEGER);
986*cdf0e10cSrcweir 	m_bInserting = sal_True;
987*cdf0e10cSrcweir }
988*cdf0e10cSrcweir // -------------------------------------------------------------------------
989*cdf0e10cSrcweir 
990*cdf0e10cSrcweir void SAL_CALL OResultSet::moveToCurrentRow(  ) throw(SQLException, RuntimeException)
991*cdf0e10cSrcweir {
992*cdf0e10cSrcweir 	m_nLastColumnPos = 0;
993*cdf0e10cSrcweir }
994*cdf0e10cSrcweir // -------------------------------------------------------------------------
995*cdf0e10cSrcweir void OResultSet::updateValue(sal_Int32 columnIndex,SQLSMALLINT _nType,void* _pValue) throw(SQLException, RuntimeException)
996*cdf0e10cSrcweir {
997*cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OResultSet::updateValue" );
998*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
999*cdf0e10cSrcweir 	checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
1000*cdf0e10cSrcweir 
1001*cdf0e10cSrcweir 	m_aBindVector.push_back(allocBindColumn(OTools::MapOdbcType2Jdbc(_nType),columnIndex));
1002*cdf0e10cSrcweir 	void* pData = reinterpret_cast<void*>(m_aBindVector.rbegin()->first);
1003*cdf0e10cSrcweir 	OSL_ENSURE(pData != NULL,"Data for update is NULL!");
1004*cdf0e10cSrcweir 	OTools::bindValue(	m_pStatement->getOwnConnection(),
1005*cdf0e10cSrcweir 						m_aStatementHandle,
1006*cdf0e10cSrcweir 						columnIndex,
1007*cdf0e10cSrcweir 						_nType,
1008*cdf0e10cSrcweir 						0,
1009*cdf0e10cSrcweir 						_pValue,
1010*cdf0e10cSrcweir 						pData,
1011*cdf0e10cSrcweir 						&m_aLengthVector[columnIndex],
1012*cdf0e10cSrcweir 						**this,
1013*cdf0e10cSrcweir 						m_nTextEncoding,
1014*cdf0e10cSrcweir 						m_pStatement->getOwnConnection()->useOldDateFormat());
1015*cdf0e10cSrcweir }
1016*cdf0e10cSrcweir // -----------------------------------------------------------------------------
1017*cdf0e10cSrcweir void SAL_CALL OResultSet::updateNull( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
1018*cdf0e10cSrcweir {
1019*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
1020*cdf0e10cSrcweir 	checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
1021*cdf0e10cSrcweir 
1022*cdf0e10cSrcweir 	m_aBindVector.push_back(allocBindColumn(DataType::CHAR,columnIndex));
1023*cdf0e10cSrcweir 	void* pData = reinterpret_cast<void*>(m_aBindVector.rbegin()->first);
1024*cdf0e10cSrcweir 	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());
1025*cdf0e10cSrcweir }
1026*cdf0e10cSrcweir // -------------------------------------------------------------------------
1027*cdf0e10cSrcweir 
1028*cdf0e10cSrcweir void SAL_CALL OResultSet::updateBoolean( sal_Int32 columnIndex, sal_Bool x ) throw(SQLException, RuntimeException)
1029*cdf0e10cSrcweir {
1030*cdf0e10cSrcweir 	updateValue(columnIndex,SQL_BIT,&x);
1031*cdf0e10cSrcweir }
1032*cdf0e10cSrcweir // -------------------------------------------------------------------------
1033*cdf0e10cSrcweir void SAL_CALL OResultSet::updateByte( sal_Int32 columnIndex, sal_Int8 x ) throw(SQLException, RuntimeException)
1034*cdf0e10cSrcweir {
1035*cdf0e10cSrcweir 	updateValue(columnIndex,SQL_CHAR,&x);
1036*cdf0e10cSrcweir }
1037*cdf0e10cSrcweir // -------------------------------------------------------------------------
1038*cdf0e10cSrcweir 
1039*cdf0e10cSrcweir void SAL_CALL OResultSet::updateShort( sal_Int32 columnIndex, sal_Int16 x ) throw(SQLException, RuntimeException)
1040*cdf0e10cSrcweir {
1041*cdf0e10cSrcweir 	updateValue(columnIndex,SQL_TINYINT,&x);
1042*cdf0e10cSrcweir }
1043*cdf0e10cSrcweir // -------------------------------------------------------------------------
1044*cdf0e10cSrcweir void SAL_CALL OResultSet::updateInt( sal_Int32 columnIndex, sal_Int32 x ) throw(SQLException, RuntimeException)
1045*cdf0e10cSrcweir {
1046*cdf0e10cSrcweir 	updateValue(columnIndex,SQL_INTEGER,&x);
1047*cdf0e10cSrcweir }
1048*cdf0e10cSrcweir // -------------------------------------------------------------------------
1049*cdf0e10cSrcweir void SAL_CALL OResultSet::updateLong( sal_Int32 /*columnIndex*/, sal_Int64 /*x*/ ) throw(SQLException, RuntimeException)
1050*cdf0e10cSrcweir {
1051*cdf0e10cSrcweir     ::dbtools::throwFunctionNotSupportedException( "XRowUpdate::updateLong", *this );
1052*cdf0e10cSrcweir }
1053*cdf0e10cSrcweir // -----------------------------------------------------------------------
1054*cdf0e10cSrcweir void SAL_CALL OResultSet::updateFloat( sal_Int32 columnIndex, float x ) throw(SQLException, RuntimeException)
1055*cdf0e10cSrcweir {
1056*cdf0e10cSrcweir 	updateValue(columnIndex,SQL_REAL,&x);
1057*cdf0e10cSrcweir }
1058*cdf0e10cSrcweir // -------------------------------------------------------------------------
1059*cdf0e10cSrcweir 
1060*cdf0e10cSrcweir void SAL_CALL OResultSet::updateDouble( sal_Int32 columnIndex, double x ) throw(SQLException, RuntimeException)
1061*cdf0e10cSrcweir {
1062*cdf0e10cSrcweir 	updateValue(columnIndex,SQL_DOUBLE,&x);
1063*cdf0e10cSrcweir }
1064*cdf0e10cSrcweir // -------------------------------------------------------------------------
1065*cdf0e10cSrcweir void SAL_CALL OResultSet::updateString( sal_Int32 columnIndex, const ::rtl::OUString& x ) throw(SQLException, RuntimeException)
1066*cdf0e10cSrcweir {
1067*cdf0e10cSrcweir 	sal_Int32 nType = m_aRow[columnIndex].getTypeKind();
1068*cdf0e10cSrcweir 	SQLSMALLINT nOdbcType = static_cast<SQLSMALLINT>(OTools::jdbcTypeToOdbc(nType));
1069*cdf0e10cSrcweir 	m_aRow[columnIndex] = x;
1070*cdf0e10cSrcweir 	m_aRow[columnIndex].setTypeKind(nType); // OJ: otherwise longvarchar will be recognized by fillNeededData
1071*cdf0e10cSrcweir 	updateValue(columnIndex,nOdbcType,(void*)&x);
1072*cdf0e10cSrcweir }
1073*cdf0e10cSrcweir // -------------------------------------------------------------------------
1074*cdf0e10cSrcweir void SAL_CALL OResultSet::updateBytes( sal_Int32 columnIndex, const Sequence< sal_Int8 >& x ) throw(SQLException, RuntimeException)
1075*cdf0e10cSrcweir {
1076*cdf0e10cSrcweir 	sal_Int32 nType = m_aRow[columnIndex].getTypeKind();
1077*cdf0e10cSrcweir 	SQLSMALLINT nOdbcType = static_cast<SQLSMALLINT>(OTools::jdbcTypeToOdbc(nType));
1078*cdf0e10cSrcweir 	m_aRow[columnIndex] = x;
1079*cdf0e10cSrcweir 	m_aRow[columnIndex].setTypeKind(nType); // OJ: otherwise longvarbinary will be recognized by fillNeededData
1080*cdf0e10cSrcweir 	updateValue(columnIndex,nOdbcType,(void*)&x);
1081*cdf0e10cSrcweir }
1082*cdf0e10cSrcweir // -------------------------------------------------------------------------
1083*cdf0e10cSrcweir void SAL_CALL OResultSet::updateDate( sal_Int32 columnIndex, const Date& x ) throw(SQLException, RuntimeException)
1084*cdf0e10cSrcweir {
1085*cdf0e10cSrcweir 	DATE_STRUCT aVal = OTools::DateToOdbcDate(x);
1086*cdf0e10cSrcweir 	updateValue(columnIndex,SQL_DATE,&aVal);
1087*cdf0e10cSrcweir }
1088*cdf0e10cSrcweir // -------------------------------------------------------------------------
1089*cdf0e10cSrcweir 
1090*cdf0e10cSrcweir void SAL_CALL OResultSet::updateTime( sal_Int32 columnIndex, const Time& x ) throw(SQLException, RuntimeException)
1091*cdf0e10cSrcweir {
1092*cdf0e10cSrcweir 	TIME_STRUCT aVal = OTools::TimeToOdbcTime(x);
1093*cdf0e10cSrcweir 	updateValue(columnIndex,SQL_TIME,&aVal);
1094*cdf0e10cSrcweir }
1095*cdf0e10cSrcweir // -------------------------------------------------------------------------
1096*cdf0e10cSrcweir 
1097*cdf0e10cSrcweir void SAL_CALL OResultSet::updateTimestamp( sal_Int32 columnIndex, const DateTime& x ) throw(SQLException, RuntimeException)
1098*cdf0e10cSrcweir {
1099*cdf0e10cSrcweir 	TIMESTAMP_STRUCT aVal = OTools::DateTimeToTimestamp(x);
1100*cdf0e10cSrcweir 	updateValue(columnIndex,SQL_TIMESTAMP,&aVal);
1101*cdf0e10cSrcweir }
1102*cdf0e10cSrcweir // -------------------------------------------------------------------------
1103*cdf0e10cSrcweir 
1104*cdf0e10cSrcweir void SAL_CALL OResultSet::updateBinaryStream( sal_Int32 columnIndex, const Reference< XInputStream >& x, sal_Int32 length ) throw(SQLException, RuntimeException)
1105*cdf0e10cSrcweir {
1106*cdf0e10cSrcweir 	if(!x.is())
1107*cdf0e10cSrcweir 		::dbtools::throwFunctionSequenceException(*this);
1108*cdf0e10cSrcweir 
1109*cdf0e10cSrcweir 	Sequence<sal_Int8> aSeq;
1110*cdf0e10cSrcweir 	x->readBytes(aSeq,length);
1111*cdf0e10cSrcweir 	updateBytes(columnIndex,aSeq);
1112*cdf0e10cSrcweir }
1113*cdf0e10cSrcweir // -------------------------------------------------------------------------
1114*cdf0e10cSrcweir void SAL_CALL OResultSet::updateCharacterStream( sal_Int32 columnIndex, const Reference< XInputStream >& x, sal_Int32 length ) throw(SQLException, RuntimeException)
1115*cdf0e10cSrcweir {
1116*cdf0e10cSrcweir 	updateBinaryStream(columnIndex,x,length);
1117*cdf0e10cSrcweir }
1118*cdf0e10cSrcweir // -------------------------------------------------------------------------
1119*cdf0e10cSrcweir void SAL_CALL OResultSet::refreshRow(  ) throw(SQLException, RuntimeException)
1120*cdf0e10cSrcweir {
1121*cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OResultSet::refreshRow" );
1122*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
1123*cdf0e10cSrcweir 	checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
1124*cdf0e10cSrcweir 
1125*cdf0e10cSrcweir 
1126*cdf0e10cSrcweir 	//	SQLRETURN nRet = N3SQLSetPos(m_aStatementHandle,1,SQL_REFRESH,SQL_LOCK_NO_CHANGE);
1127*cdf0e10cSrcweir 	m_nCurrentFetchState = N3SQLFetchScroll(m_aStatementHandle,SQL_FETCH_RELATIVE,0);
1128*cdf0e10cSrcweir 	OTools::ThrowException(m_pStatement->getOwnConnection(),m_nCurrentFetchState,m_aStatementHandle,SQL_HANDLE_STMT,*this);
1129*cdf0e10cSrcweir }
1130*cdf0e10cSrcweir // -------------------------------------------------------------------------
1131*cdf0e10cSrcweir void SAL_CALL OResultSet::updateObject( sal_Int32 columnIndex, const Any& x ) throw(SQLException, RuntimeException)
1132*cdf0e10cSrcweir {
1133*cdf0e10cSrcweir 	if (!::dbtools::implUpdateObject(this, columnIndex, x))
1134*cdf0e10cSrcweir 		throw SQLException();
1135*cdf0e10cSrcweir }
1136*cdf0e10cSrcweir // -------------------------------------------------------------------------
1137*cdf0e10cSrcweir 
1138*cdf0e10cSrcweir void SAL_CALL OResultSet::updateNumericObject( sal_Int32 columnIndex, const Any& x, sal_Int32 /*scale*/ ) throw(SQLException, RuntimeException)
1139*cdf0e10cSrcweir {
1140*cdf0e10cSrcweir 	if (!::dbtools::implUpdateObject(this, columnIndex, x))
1141*cdf0e10cSrcweir 		throw SQLException();
1142*cdf0e10cSrcweir }
1143*cdf0e10cSrcweir // -------------------------------------------------------------------------
1144*cdf0e10cSrcweir // XRowLocate
1145*cdf0e10cSrcweir Any SAL_CALL OResultSet::getBookmark(  ) throw( SQLException,  RuntimeException)
1146*cdf0e10cSrcweir {
1147*cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OResultSet::getBookmark" );
1148*cdf0e10cSrcweir 	 ::osl::MutexGuard aGuard( m_aMutex );
1149*cdf0e10cSrcweir 	checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
1150*cdf0e10cSrcweir 
1151*cdf0e10cSrcweir 	TBookmarkPosMap::iterator aFind = ::std::find_if(m_aPosToBookmarks.begin(),m_aPosToBookmarks.end(),
1152*cdf0e10cSrcweir 		::std::compose1(::std::bind2nd(::std::equal_to<sal_Int32>(),m_nRowPos),::std::select2nd<TBookmarkPosMap::value_type>()));
1153*cdf0e10cSrcweir 
1154*cdf0e10cSrcweir 	if ( aFind == m_aPosToBookmarks.end() )
1155*cdf0e10cSrcweir 	{
1156*cdf0e10cSrcweir         if ( m_nUseBookmarks == ODBC_SQL_NOT_DEFINED )
1157*cdf0e10cSrcweir         {
1158*cdf0e10cSrcweir             RTL_LOGFILE_CONTEXT_TRACE( aLogger, "SQLGetStmtAttr" );
1159*cdf0e10cSrcweir             m_nUseBookmarks = SQL_UB_OFF;
1160*cdf0e10cSrcweir 		    SQLRETURN nRet = N3SQLGetStmtAttr(m_aStatementHandle,SQL_ATTR_USE_BOOKMARKS,&m_nUseBookmarks,SQL_IS_UINTEGER,NULL);
1161*cdf0e10cSrcweir             OSL_UNUSED( nRet );
1162*cdf0e10cSrcweir         }
1163*cdf0e10cSrcweir 		if(m_nUseBookmarks == SQL_UB_OFF)
1164*cdf0e10cSrcweir 			throw SQLException();
1165*cdf0e10cSrcweir 
1166*cdf0e10cSrcweir 		m_aBookmark = OTools::getBytesValue(m_pStatement->getOwnConnection(),m_aStatementHandle,0,SQL_C_VARBOOKMARK,m_bWasNull,**this);
1167*cdf0e10cSrcweir 		m_aPosToBookmarks[m_aBookmark] = m_nRowPos;
1168*cdf0e10cSrcweir 		OSL_ENSURE(m_aBookmark.getLength(),"Invalid bookmark from length 0!");
1169*cdf0e10cSrcweir 	}
1170*cdf0e10cSrcweir 	else
1171*cdf0e10cSrcweir 		m_aBookmark = aFind->first;
1172*cdf0e10cSrcweir 	return makeAny(m_aBookmark);
1173*cdf0e10cSrcweir }
1174*cdf0e10cSrcweir // -------------------------------------------------------------------------
1175*cdf0e10cSrcweir sal_Bool SAL_CALL OResultSet::moveToBookmark( const  Any& bookmark ) throw( SQLException,  RuntimeException)
1176*cdf0e10cSrcweir {
1177*cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OResultSet::moveToBookmark" );
1178*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
1179*cdf0e10cSrcweir 	checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
1180*cdf0e10cSrcweir 
1181*cdf0e10cSrcweir 	m_nLastColumnPos = 0;
1182*cdf0e10cSrcweir 	bookmark >>= m_aBookmark;
1183*cdf0e10cSrcweir 	OSL_ENSURE(m_aBookmark.getLength(),"Invalid bookmark from length 0!");
1184*cdf0e10cSrcweir 	if(m_aBookmark.getLength())
1185*cdf0e10cSrcweir 	{
1186*cdf0e10cSrcweir 		SQLRETURN nReturn = N3SQLSetStmtAttr(m_aStatementHandle,SQL_ATTR_FETCH_BOOKMARK_PTR,m_aBookmark.getArray(),SQL_IS_POINTER); // SQL_LEN_BINARY_ATTR(aBookmark.getLength())
1187*cdf0e10cSrcweir         OSL_UNUSED( nReturn );
1188*cdf0e10cSrcweir 
1189*cdf0e10cSrcweir         if ( SQL_INVALID_HANDLE != nReturn && SQL_ERROR != nReturn )
1190*cdf0e10cSrcweir         {
1191*cdf0e10cSrcweir 		    m_nCurrentFetchState = N3SQLFetchScroll(m_aStatementHandle,SQL_FETCH_BOOKMARK,0);
1192*cdf0e10cSrcweir 		    OTools::ThrowException(m_pStatement->getOwnConnection(),m_nCurrentFetchState,m_aStatementHandle,SQL_HANDLE_STMT,*this);
1193*cdf0e10cSrcweir 		    TBookmarkPosMap::iterator aFind = m_aPosToBookmarks.find(m_aBookmark);
1194*cdf0e10cSrcweir 		    if(aFind != m_aPosToBookmarks.end())
1195*cdf0e10cSrcweir 			    m_nRowPos = aFind->second;
1196*cdf0e10cSrcweir 		    else
1197*cdf0e10cSrcweir 			    m_nRowPos = -1;
1198*cdf0e10cSrcweir 		    return m_nCurrentFetchState == SQL_SUCCESS || m_nCurrentFetchState == SQL_SUCCESS_WITH_INFO;
1199*cdf0e10cSrcweir         }
1200*cdf0e10cSrcweir 	}
1201*cdf0e10cSrcweir 	return sal_False;
1202*cdf0e10cSrcweir }
1203*cdf0e10cSrcweir // -------------------------------------------------------------------------
1204*cdf0e10cSrcweir sal_Bool SAL_CALL OResultSet::moveRelativeToBookmark( const  Any& bookmark, sal_Int32 rows ) throw( SQLException,  RuntimeException)
1205*cdf0e10cSrcweir {
1206*cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OResultSet::moveRelativeToBookmark" );
1207*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
1208*cdf0e10cSrcweir 	checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
1209*cdf0e10cSrcweir 
1210*cdf0e10cSrcweir 
1211*cdf0e10cSrcweir 	m_nLastColumnPos = 0;
1212*cdf0e10cSrcweir 	bookmark >>= m_aBookmark;
1213*cdf0e10cSrcweir 	SQLRETURN nReturn = N3SQLSetStmtAttr(m_aStatementHandle,SQL_ATTR_FETCH_BOOKMARK_PTR,m_aBookmark.getArray(),SQL_IS_POINTER);
1214*cdf0e10cSrcweir     OSL_UNUSED( nReturn );
1215*cdf0e10cSrcweir 
1216*cdf0e10cSrcweir 	m_nCurrentFetchState = N3SQLFetchScroll(m_aStatementHandle,SQL_FETCH_BOOKMARK,rows);
1217*cdf0e10cSrcweir 	OTools::ThrowException(m_pStatement->getOwnConnection(),m_nCurrentFetchState,m_aStatementHandle,SQL_HANDLE_STMT,*this);
1218*cdf0e10cSrcweir 	return m_nCurrentFetchState == SQL_SUCCESS || m_nCurrentFetchState == SQL_SUCCESS_WITH_INFO;
1219*cdf0e10cSrcweir }
1220*cdf0e10cSrcweir // -------------------------------------------------------------------------
1221*cdf0e10cSrcweir sal_Int32 SAL_CALL OResultSet::compareBookmarks( const Any& lhs, const  Any& rhs ) throw( SQLException,  RuntimeException)
1222*cdf0e10cSrcweir {
1223*cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OResultSet::compareBookmarks" );
1224*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
1225*cdf0e10cSrcweir 	checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
1226*cdf0e10cSrcweir 
1227*cdf0e10cSrcweir 	return (lhs == rhs) ? CompareBookmark::EQUAL : CompareBookmark::NOT_EQUAL;
1228*cdf0e10cSrcweir }
1229*cdf0e10cSrcweir // -------------------------------------------------------------------------
1230*cdf0e10cSrcweir sal_Bool SAL_CALL OResultSet::hasOrderedBookmarks(  ) throw( SQLException,  RuntimeException)
1231*cdf0e10cSrcweir {
1232*cdf0e10cSrcweir 	return sal_False;
1233*cdf0e10cSrcweir }
1234*cdf0e10cSrcweir // -------------------------------------------------------------------------
1235*cdf0e10cSrcweir sal_Int32 SAL_CALL OResultSet::hashBookmark( const  Any& /*bookmark*/ ) throw( SQLException,  RuntimeException)
1236*cdf0e10cSrcweir {
1237*cdf0e10cSrcweir     ::dbtools::throwFunctionNotSupportedException( "XRowLocate::hashBookmark", *this );
1238*cdf0e10cSrcweir     return 0;
1239*cdf0e10cSrcweir }
1240*cdf0e10cSrcweir // -------------------------------------------------------------------------
1241*cdf0e10cSrcweir // XDeleteRows
1242*cdf0e10cSrcweir Sequence< sal_Int32 > SAL_CALL OResultSet::deleteRows( const  Sequence<  Any >& rows ) throw( SQLException,  RuntimeException)
1243*cdf0e10cSrcweir {
1244*cdf0e10cSrcweir 	Sequence< sal_Int32 > aRet(rows.getLength());
1245*cdf0e10cSrcweir 	sal_Int32 *pRet	= aRet.getArray();
1246*cdf0e10cSrcweir 
1247*cdf0e10cSrcweir 	const Any *pBegin	= rows.getConstArray();
1248*cdf0e10cSrcweir 	const Any *pEnd		= pBegin + rows.getLength();
1249*cdf0e10cSrcweir 
1250*cdf0e10cSrcweir 	for(;pBegin != pEnd;++pBegin,++pRet)
1251*cdf0e10cSrcweir 	{
1252*cdf0e10cSrcweir 		try
1253*cdf0e10cSrcweir 		{
1254*cdf0e10cSrcweir 			if(moveToBookmark(*pBegin))
1255*cdf0e10cSrcweir 			{
1256*cdf0e10cSrcweir 				deleteRow();
1257*cdf0e10cSrcweir 				*pRet = 1;
1258*cdf0e10cSrcweir 			}
1259*cdf0e10cSrcweir 		}
1260*cdf0e10cSrcweir 		catch(SQLException&)
1261*cdf0e10cSrcweir 		{
1262*cdf0e10cSrcweir 			*pRet = 0;
1263*cdf0e10cSrcweir 		}
1264*cdf0e10cSrcweir 	}
1265*cdf0e10cSrcweir 	return aRet;
1266*cdf0e10cSrcweir }
1267*cdf0e10cSrcweir //------------------------------------------------------------------------------
1268*cdf0e10cSrcweir sal_Int32 OResultSet::getResultSetConcurrency() const
1269*cdf0e10cSrcweir {
1270*cdf0e10cSrcweir 	sal_uInt32 nValue = 0;
1271*cdf0e10cSrcweir 	SQLRETURN nReturn = N3SQLGetStmtAttr(m_aStatementHandle,SQL_ATTR_CONCURRENCY,&nValue,SQL_IS_UINTEGER,0);
1272*cdf0e10cSrcweir     OSL_UNUSED( nReturn );
1273*cdf0e10cSrcweir 	if(SQL_CONCUR_READ_ONLY == nValue)
1274*cdf0e10cSrcweir 		nValue = ResultSetConcurrency::READ_ONLY;
1275*cdf0e10cSrcweir 	else
1276*cdf0e10cSrcweir 		nValue = ResultSetConcurrency::UPDATABLE;
1277*cdf0e10cSrcweir 
1278*cdf0e10cSrcweir 	return nValue;
1279*cdf0e10cSrcweir }
1280*cdf0e10cSrcweir //------------------------------------------------------------------------------
1281*cdf0e10cSrcweir sal_Int32 OResultSet::getResultSetType() const
1282*cdf0e10cSrcweir {
1283*cdf0e10cSrcweir 	sal_uInt32 nValue = 0;
1284*cdf0e10cSrcweir 	N3SQLGetStmtAttr(m_aStatementHandle,SQL_ATTR_CURSOR_SENSITIVITY,&nValue,SQL_IS_UINTEGER,0);
1285*cdf0e10cSrcweir 	if(SQL_SENSITIVE == nValue)
1286*cdf0e10cSrcweir 		nValue = ResultSetType::SCROLL_SENSITIVE;
1287*cdf0e10cSrcweir 	else if(SQL_INSENSITIVE == nValue)
1288*cdf0e10cSrcweir 		nValue = ResultSetType::SCROLL_INSENSITIVE;
1289*cdf0e10cSrcweir 	else
1290*cdf0e10cSrcweir 	{
1291*cdf0e10cSrcweir 		SQLINTEGER nCurType = 0;
1292*cdf0e10cSrcweir 		N3SQLGetStmtAttr(m_aStatementHandle,SQL_ATTR_CURSOR_TYPE,&nCurType,SQL_IS_UINTEGER,0);
1293*cdf0e10cSrcweir 		if(SQL_CURSOR_KEYSET_DRIVEN == nCurType)
1294*cdf0e10cSrcweir 			nValue = ResultSetType::SCROLL_SENSITIVE;
1295*cdf0e10cSrcweir 		else if(SQL_CURSOR_STATIC  == nCurType)
1296*cdf0e10cSrcweir 			nValue = ResultSetType::SCROLL_INSENSITIVE;
1297*cdf0e10cSrcweir 		else if(SQL_CURSOR_FORWARD_ONLY == nCurType)
1298*cdf0e10cSrcweir 			nValue = ResultSetType::FORWARD_ONLY;
1299*cdf0e10cSrcweir 		else if(SQL_CURSOR_DYNAMIC == nCurType)
1300*cdf0e10cSrcweir 			nValue = ResultSetType::SCROLL_SENSITIVE;
1301*cdf0e10cSrcweir 	}
1302*cdf0e10cSrcweir 	return nValue;
1303*cdf0e10cSrcweir }
1304*cdf0e10cSrcweir //------------------------------------------------------------------------------
1305*cdf0e10cSrcweir sal_Int32 OResultSet::getFetchDirection() const
1306*cdf0e10cSrcweir {
1307*cdf0e10cSrcweir 	return FetchDirection::FORWARD;
1308*cdf0e10cSrcweir }
1309*cdf0e10cSrcweir //------------------------------------------------------------------------------
1310*cdf0e10cSrcweir sal_Int32 OResultSet::getFetchSize() const
1311*cdf0e10cSrcweir {
1312*cdf0e10cSrcweir 	sal_uInt32 nValue = 0;
1313*cdf0e10cSrcweir 	N3SQLGetStmtAttr(m_aStatementHandle,SQL_ATTR_ROW_ARRAY_SIZE,&nValue,SQL_IS_UINTEGER,0);
1314*cdf0e10cSrcweir 	return nValue;
1315*cdf0e10cSrcweir }
1316*cdf0e10cSrcweir //------------------------------------------------------------------------------
1317*cdf0e10cSrcweir ::rtl::OUString OResultSet::getCursorName() const
1318*cdf0e10cSrcweir {
1319*cdf0e10cSrcweir 	SQLCHAR pName[258];
1320*cdf0e10cSrcweir 	SQLSMALLINT nRealLen = 0;
1321*cdf0e10cSrcweir 	N3SQLGetCursorName(m_aStatementHandle,(SQLCHAR*)pName,256,&nRealLen);
1322*cdf0e10cSrcweir 	return ::rtl::OUString::createFromAscii((const char*)pName);
1323*cdf0e10cSrcweir }
1324*cdf0e10cSrcweir // -------------------------------------------------------------------------
1325*cdf0e10cSrcweir sal_Bool  OResultSet::isBookmarkable() const
1326*cdf0e10cSrcweir {
1327*cdf0e10cSrcweir 	if(!m_aConnectionHandle)
1328*cdf0e10cSrcweir 		return sal_False;
1329*cdf0e10cSrcweir 
1330*cdf0e10cSrcweir 	sal_uInt32 nValue = 0;
1331*cdf0e10cSrcweir 	N3SQLGetStmtAttr(m_aStatementHandle,SQL_ATTR_CURSOR_TYPE,&nValue,SQL_IS_UINTEGER,0);
1332*cdf0e10cSrcweir 
1333*cdf0e10cSrcweir 	sal_Int32 nAttr = 0;
1334*cdf0e10cSrcweir 	try
1335*cdf0e10cSrcweir 	{
1336*cdf0e10cSrcweir 		switch(nValue)
1337*cdf0e10cSrcweir 		{
1338*cdf0e10cSrcweir 		case SQL_CURSOR_FORWARD_ONLY:
1339*cdf0e10cSrcweir 			return sal_False;
1340*cdf0e10cSrcweir 		case SQL_CURSOR_STATIC:
1341*cdf0e10cSrcweir 			OTools::GetInfo(m_pStatement->getOwnConnection(),m_aConnectionHandle,SQL_STATIC_CURSOR_ATTRIBUTES1,nAttr,NULL);
1342*cdf0e10cSrcweir 			break;
1343*cdf0e10cSrcweir 		case SQL_CURSOR_KEYSET_DRIVEN:
1344*cdf0e10cSrcweir 			OTools::GetInfo(m_pStatement->getOwnConnection(),m_aConnectionHandle,SQL_KEYSET_CURSOR_ATTRIBUTES1,nAttr,NULL);
1345*cdf0e10cSrcweir 			break;
1346*cdf0e10cSrcweir 		case SQL_CURSOR_DYNAMIC:
1347*cdf0e10cSrcweir 			OTools::GetInfo(m_pStatement->getOwnConnection(),m_aConnectionHandle,SQL_DYNAMIC_CURSOR_ATTRIBUTES1,nAttr,NULL);
1348*cdf0e10cSrcweir 			break;
1349*cdf0e10cSrcweir 		}
1350*cdf0e10cSrcweir 	}
1351*cdf0e10cSrcweir 	catch(Exception&)
1352*cdf0e10cSrcweir 	{
1353*cdf0e10cSrcweir 		return sal_False;
1354*cdf0e10cSrcweir 	}
1355*cdf0e10cSrcweir 
1356*cdf0e10cSrcweir     if ( m_nUseBookmarks == ODBC_SQL_NOT_DEFINED )
1357*cdf0e10cSrcweir     {
1358*cdf0e10cSrcweir         m_nUseBookmarks = SQL_UB_OFF;
1359*cdf0e10cSrcweir 	    SQLRETURN nRet = N3SQLGetStmtAttr(m_aStatementHandle,SQL_ATTR_USE_BOOKMARKS,&m_nUseBookmarks,SQL_IS_UINTEGER,NULL);
1360*cdf0e10cSrcweir         OSL_UNUSED( nRet );
1361*cdf0e10cSrcweir     }
1362*cdf0e10cSrcweir 
1363*cdf0e10cSrcweir 	return (m_nUseBookmarks != SQL_UB_OFF) && (nAttr & SQL_CA1_BOOKMARK) == SQL_CA1_BOOKMARK;
1364*cdf0e10cSrcweir }
1365*cdf0e10cSrcweir //------------------------------------------------------------------------------
1366*cdf0e10cSrcweir void OResultSet::setFetchDirection(sal_Int32 _par0)
1367*cdf0e10cSrcweir {
1368*cdf0e10cSrcweir 	OSL_ENSURE(_par0>0,"Illegal fetch direction!");
1369*cdf0e10cSrcweir 	if ( _par0 > 0 )
1370*cdf0e10cSrcweir 	{
1371*cdf0e10cSrcweir 		N3SQLSetStmtAttr(m_aStatementHandle,SQL_ATTR_CURSOR_TYPE,(SQLPOINTER)_par0,SQL_IS_UINTEGER);
1372*cdf0e10cSrcweir 	}
1373*cdf0e10cSrcweir }
1374*cdf0e10cSrcweir //------------------------------------------------------------------------------
1375*cdf0e10cSrcweir void OResultSet::setFetchSize(sal_Int32 _par0)
1376*cdf0e10cSrcweir {
1377*cdf0e10cSrcweir 	OSL_ENSURE(_par0>0,"Illegal fetch size!");
1378*cdf0e10cSrcweir 	if ( _par0 > 0 )
1379*cdf0e10cSrcweir 	{
1380*cdf0e10cSrcweir 		N3SQLSetStmtAttr(m_aStatementHandle,SQL_ATTR_ROW_ARRAY_SIZE,(SQLPOINTER)_par0,SQL_IS_UINTEGER);
1381*cdf0e10cSrcweir 		delete m_pRowStatusArray;
1382*cdf0e10cSrcweir 
1383*cdf0e10cSrcweir 		m_pRowStatusArray = new SQLUSMALLINT[_par0];
1384*cdf0e10cSrcweir 		N3SQLSetStmtAttr(m_aStatementHandle,SQL_ATTR_ROW_STATUS_PTR,m_pRowStatusArray,SQL_IS_POINTER);
1385*cdf0e10cSrcweir 	}
1386*cdf0e10cSrcweir }
1387*cdf0e10cSrcweir // -------------------------------------------------------------------------
1388*cdf0e10cSrcweir IPropertyArrayHelper* OResultSet::createArrayHelper( ) const
1389*cdf0e10cSrcweir {
1390*cdf0e10cSrcweir 	Sequence< Property > aProps(6);
1391*cdf0e10cSrcweir 	Property* pProperties = aProps.getArray();
1392*cdf0e10cSrcweir 	sal_Int32 nPos = 0;
1393*cdf0e10cSrcweir 	DECL_PROP1IMPL(CURSORNAME,			::rtl::OUString) PropertyAttribute::READONLY);
1394*cdf0e10cSrcweir 	DECL_PROP0(FETCHDIRECTION,			sal_Int32);
1395*cdf0e10cSrcweir 	DECL_PROP0(FETCHSIZE,				sal_Int32);
1396*cdf0e10cSrcweir 	DECL_BOOL_PROP1IMPL(ISBOOKMARKABLE) PropertyAttribute::READONLY);
1397*cdf0e10cSrcweir 	DECL_PROP1IMPL(RESULTSETCONCURRENCY,sal_Int32) PropertyAttribute::READONLY);
1398*cdf0e10cSrcweir 	DECL_PROP1IMPL(RESULTSETTYPE,		sal_Int32) PropertyAttribute::READONLY);
1399*cdf0e10cSrcweir 
1400*cdf0e10cSrcweir 	return new OPropertyArrayHelper(aProps);
1401*cdf0e10cSrcweir }
1402*cdf0e10cSrcweir // -------------------------------------------------------------------------
1403*cdf0e10cSrcweir IPropertyArrayHelper & OResultSet::getInfoHelper()
1404*cdf0e10cSrcweir {
1405*cdf0e10cSrcweir 	return *const_cast<OResultSet*>(this)->getArrayHelper();
1406*cdf0e10cSrcweir }
1407*cdf0e10cSrcweir // -------------------------------------------------------------------------
1408*cdf0e10cSrcweir sal_Bool OResultSet::convertFastPropertyValue(
1409*cdf0e10cSrcweir 							Any & rConvertedValue,
1410*cdf0e10cSrcweir 							Any & rOldValue,
1411*cdf0e10cSrcweir 							sal_Int32 nHandle,
1412*cdf0e10cSrcweir 							const Any& rValue )
1413*cdf0e10cSrcweir 								throw (::com::sun::star::lang::IllegalArgumentException)
1414*cdf0e10cSrcweir {
1415*cdf0e10cSrcweir 	switch(nHandle)
1416*cdf0e10cSrcweir 	{
1417*cdf0e10cSrcweir 		case PROPERTY_ID_ISBOOKMARKABLE:
1418*cdf0e10cSrcweir 		case PROPERTY_ID_CURSORNAME:
1419*cdf0e10cSrcweir 		case PROPERTY_ID_RESULTSETCONCURRENCY:
1420*cdf0e10cSrcweir 		case PROPERTY_ID_RESULTSETTYPE:
1421*cdf0e10cSrcweir 			throw ::com::sun::star::lang::IllegalArgumentException();
1422*cdf0e10cSrcweir 		case PROPERTY_ID_FETCHDIRECTION:
1423*cdf0e10cSrcweir 			return ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, getFetchDirection());
1424*cdf0e10cSrcweir 		case PROPERTY_ID_FETCHSIZE:
1425*cdf0e10cSrcweir 			return ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, getFetchSize());
1426*cdf0e10cSrcweir 		default:
1427*cdf0e10cSrcweir 			;
1428*cdf0e10cSrcweir 	}
1429*cdf0e10cSrcweir 	return sal_False;
1430*cdf0e10cSrcweir }
1431*cdf0e10cSrcweir // -------------------------------------------------------------------------
1432*cdf0e10cSrcweir void OResultSet::setFastPropertyValue_NoBroadcast(
1433*cdf0e10cSrcweir 								sal_Int32 nHandle,
1434*cdf0e10cSrcweir 								const Any& rValue
1435*cdf0e10cSrcweir 												 )
1436*cdf0e10cSrcweir 												 throw (Exception)
1437*cdf0e10cSrcweir {
1438*cdf0e10cSrcweir 	switch(nHandle)
1439*cdf0e10cSrcweir 	{
1440*cdf0e10cSrcweir 		case PROPERTY_ID_ISBOOKMARKABLE:
1441*cdf0e10cSrcweir 		case PROPERTY_ID_CURSORNAME:
1442*cdf0e10cSrcweir 		case PROPERTY_ID_RESULTSETCONCURRENCY:
1443*cdf0e10cSrcweir 		case PROPERTY_ID_RESULTSETTYPE:
1444*cdf0e10cSrcweir 			throw Exception();
1445*cdf0e10cSrcweir 		case PROPERTY_ID_FETCHDIRECTION:
1446*cdf0e10cSrcweir 			setFetchDirection(getINT32(rValue));
1447*cdf0e10cSrcweir 			break;
1448*cdf0e10cSrcweir 		case PROPERTY_ID_FETCHSIZE:
1449*cdf0e10cSrcweir 			setFetchSize(getINT32(rValue));
1450*cdf0e10cSrcweir 			break;
1451*cdf0e10cSrcweir 		default:
1452*cdf0e10cSrcweir 			;
1453*cdf0e10cSrcweir 	}
1454*cdf0e10cSrcweir }
1455*cdf0e10cSrcweir // -------------------------------------------------------------------------
1456*cdf0e10cSrcweir void OResultSet::getFastPropertyValue(
1457*cdf0e10cSrcweir 								Any& rValue,
1458*cdf0e10cSrcweir 								sal_Int32 nHandle
1459*cdf0e10cSrcweir 									 ) const
1460*cdf0e10cSrcweir {
1461*cdf0e10cSrcweir 	switch(nHandle)
1462*cdf0e10cSrcweir 	{
1463*cdf0e10cSrcweir 		case PROPERTY_ID_ISBOOKMARKABLE:
1464*cdf0e10cSrcweir 			rValue = bool2any(isBookmarkable());
1465*cdf0e10cSrcweir 			break;
1466*cdf0e10cSrcweir 		case PROPERTY_ID_CURSORNAME:
1467*cdf0e10cSrcweir 			rValue <<= getCursorName();
1468*cdf0e10cSrcweir 			break;
1469*cdf0e10cSrcweir 		case PROPERTY_ID_RESULTSETCONCURRENCY:
1470*cdf0e10cSrcweir 			rValue <<= getResultSetConcurrency();
1471*cdf0e10cSrcweir 			break;
1472*cdf0e10cSrcweir 		case PROPERTY_ID_RESULTSETTYPE:
1473*cdf0e10cSrcweir 			rValue <<= getResultSetType();
1474*cdf0e10cSrcweir 			break;
1475*cdf0e10cSrcweir 		case PROPERTY_ID_FETCHDIRECTION:
1476*cdf0e10cSrcweir 			rValue <<= getFetchDirection();
1477*cdf0e10cSrcweir 			break;
1478*cdf0e10cSrcweir 		case PROPERTY_ID_FETCHSIZE:
1479*cdf0e10cSrcweir 			rValue <<= getFetchSize();
1480*cdf0e10cSrcweir 			break;
1481*cdf0e10cSrcweir 	}
1482*cdf0e10cSrcweir }
1483*cdf0e10cSrcweir // -------------------------------------------------------------------------
1484*cdf0e10cSrcweir void OResultSet::fillRow(sal_Int32 _nToColumn)
1485*cdf0e10cSrcweir {
1486*cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OResultSet::fillRow" );
1487*cdf0e10cSrcweir 	if((sal_Int32)m_aRow.size() <= _nToColumn)
1488*cdf0e10cSrcweir 	{
1489*cdf0e10cSrcweir 		m_aRow.resize(_nToColumn+1);
1490*cdf0e10cSrcweir 		m_aRow[_nToColumn].setBound(sal_True);
1491*cdf0e10cSrcweir 	}
1492*cdf0e10cSrcweir 	m_bFetchData = sal_False;
1493*cdf0e10cSrcweir 
1494*cdf0e10cSrcweir 	sal_Int32			nColumn		= m_nLastColumnPos + 1;
1495*cdf0e10cSrcweir 	TDataRow::iterator pColumn		= m_aRow.begin() + nColumn;
1496*cdf0e10cSrcweir 	TDataRow::iterator pColumnEnd	= m_aRow.begin() + _nToColumn + 1;
1497*cdf0e10cSrcweir 
1498*cdf0e10cSrcweir 	for (; pColumn < pColumnEnd; ++nColumn, ++pColumn)
1499*cdf0e10cSrcweir 	{
1500*cdf0e10cSrcweir 		const sal_Int32 nType = pColumn->getTypeKind();
1501*cdf0e10cSrcweir 		switch (nType)
1502*cdf0e10cSrcweir 		{
1503*cdf0e10cSrcweir 			case DataType::CHAR:
1504*cdf0e10cSrcweir 			case DataType::VARCHAR:
1505*cdf0e10cSrcweir             case DataType::DECIMAL:
1506*cdf0e10cSrcweir 			case DataType::NUMERIC:
1507*cdf0e10cSrcweir             case DataType::LONGVARCHAR:
1508*cdf0e10cSrcweir 			case DataType::CLOB:
1509*cdf0e10cSrcweir                 {
1510*cdf0e10cSrcweir                     const SWORD nColumnType = impl_getColumnType_nothrow(nColumn);
1511*cdf0e10cSrcweir 		            *pColumn = OTools::getStringValue(m_pStatement->getOwnConnection(),m_aStatementHandle,nColumn,nColumnType,m_bWasNull,**this,m_nTextEncoding);
1512*cdf0e10cSrcweir                 }
1513*cdf0e10cSrcweir 				break;
1514*cdf0e10cSrcweir 			case DataType::BIGINT:
1515*cdf0e10cSrcweir 				*pColumn = getLong(nColumn);
1516*cdf0e10cSrcweir 				break;
1517*cdf0e10cSrcweir 			case DataType::REAL:
1518*cdf0e10cSrcweir 			case DataType::DOUBLE:
1519*cdf0e10cSrcweir 				*pColumn = getDouble(nColumn);
1520*cdf0e10cSrcweir 				break;
1521*cdf0e10cSrcweir 			case DataType::LONGVARBINARY:
1522*cdf0e10cSrcweir 			case DataType::BLOB:
1523*cdf0e10cSrcweir 				*pColumn = getBytes(nColumn);
1524*cdf0e10cSrcweir 				break;
1525*cdf0e10cSrcweir 			case DataType::DATE:
1526*cdf0e10cSrcweir 				*pColumn = getDate(nColumn);
1527*cdf0e10cSrcweir 				break;
1528*cdf0e10cSrcweir 			case DataType::TIME:
1529*cdf0e10cSrcweir 				*pColumn = getTime(nColumn);
1530*cdf0e10cSrcweir 				break;
1531*cdf0e10cSrcweir 			case DataType::TIMESTAMP:
1532*cdf0e10cSrcweir 				*pColumn = getTimestamp(nColumn);
1533*cdf0e10cSrcweir 				break;
1534*cdf0e10cSrcweir 			case DataType::BIT:
1535*cdf0e10cSrcweir 				*pColumn = getBoolean(nColumn);
1536*cdf0e10cSrcweir 				break;
1537*cdf0e10cSrcweir 			case DataType::TINYINT:
1538*cdf0e10cSrcweir 				*pColumn = getByte(nColumn);
1539*cdf0e10cSrcweir 				break;
1540*cdf0e10cSrcweir 			case DataType::SMALLINT:
1541*cdf0e10cSrcweir 				*pColumn = getShort(nColumn);
1542*cdf0e10cSrcweir 				break;
1543*cdf0e10cSrcweir 			case DataType::INTEGER:
1544*cdf0e10cSrcweir 				*pColumn = getInt(nColumn);
1545*cdf0e10cSrcweir 				break;
1546*cdf0e10cSrcweir 			case DataType::FLOAT:
1547*cdf0e10cSrcweir 				*pColumn = getFloat(nColumn);
1548*cdf0e10cSrcweir 				break;
1549*cdf0e10cSrcweir 			case DataType::BINARY:
1550*cdf0e10cSrcweir 			case DataType::VARBINARY:
1551*cdf0e10cSrcweir 				*pColumn = getBytes(nColumn);
1552*cdf0e10cSrcweir 				break;
1553*cdf0e10cSrcweir 		}
1554*cdf0e10cSrcweir 
1555*cdf0e10cSrcweir 		if ( m_bWasNull )
1556*cdf0e10cSrcweir 			pColumn->setNull();
1557*cdf0e10cSrcweir 		if(nType != pColumn->getTypeKind())
1558*cdf0e10cSrcweir 		{
1559*cdf0e10cSrcweir 			pColumn->setTypeKind(nType);
1560*cdf0e10cSrcweir 		}
1561*cdf0e10cSrcweir 	}
1562*cdf0e10cSrcweir 	m_nLastColumnPos = _nToColumn;
1563*cdf0e10cSrcweir 	m_bFetchData = sal_True;
1564*cdf0e10cSrcweir }
1565*cdf0e10cSrcweir // -----------------------------------------------------------------------------
1566*cdf0e10cSrcweir void SAL_CALL OResultSet::acquire() throw()
1567*cdf0e10cSrcweir {
1568*cdf0e10cSrcweir 	OResultSet_BASE::acquire();
1569*cdf0e10cSrcweir }
1570*cdf0e10cSrcweir // -----------------------------------------------------------------------------
1571*cdf0e10cSrcweir void SAL_CALL OResultSet::release() throw()
1572*cdf0e10cSrcweir {
1573*cdf0e10cSrcweir 	OResultSet_BASE::release();
1574*cdf0e10cSrcweir }
1575*cdf0e10cSrcweir // -----------------------------------------------------------------------------
1576*cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL OResultSet::getPropertySetInfo(  ) throw(::com::sun::star::uno::RuntimeException)
1577*cdf0e10cSrcweir {
1578*cdf0e10cSrcweir 	return ::cppu::OPropertySetHelper::createPropertySetInfo(getInfoHelper());
1579*cdf0e10cSrcweir }
1580*cdf0e10cSrcweir // -----------------------------------------------------------------------------
1581*cdf0e10cSrcweir sal_Bool OResultSet::move(IResultSetHelper::Movement _eCursorPosition, sal_Int32 _nOffset, sal_Bool /*_bRetrieveData*/)
1582*cdf0e10cSrcweir {
1583*cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OResultSet::move" );
1584*cdf0e10cSrcweir 	SQLSMALLINT nFetchOrientation = SQL_FETCH_NEXT;
1585*cdf0e10cSrcweir 	switch(_eCursorPosition)
1586*cdf0e10cSrcweir 	{
1587*cdf0e10cSrcweir 		case IResultSetHelper::NEXT:
1588*cdf0e10cSrcweir 			nFetchOrientation = SQL_FETCH_NEXT;
1589*cdf0e10cSrcweir 			break;
1590*cdf0e10cSrcweir 		case IResultSetHelper::PRIOR:
1591*cdf0e10cSrcweir 			nFetchOrientation = SQL_FETCH_PRIOR;
1592*cdf0e10cSrcweir 			break;
1593*cdf0e10cSrcweir 		case IResultSetHelper::FIRST:
1594*cdf0e10cSrcweir 			nFetchOrientation = SQL_FETCH_FIRST;
1595*cdf0e10cSrcweir 			break;
1596*cdf0e10cSrcweir 		case IResultSetHelper::LAST:
1597*cdf0e10cSrcweir 			nFetchOrientation = SQL_FETCH_LAST;
1598*cdf0e10cSrcweir 			break;
1599*cdf0e10cSrcweir 		case IResultSetHelper::RELATIVE:
1600*cdf0e10cSrcweir 			nFetchOrientation = SQL_FETCH_RELATIVE;
1601*cdf0e10cSrcweir 			break;
1602*cdf0e10cSrcweir 		case IResultSetHelper::ABSOLUTE:
1603*cdf0e10cSrcweir 			nFetchOrientation = SQL_FETCH_ABSOLUTE;
1604*cdf0e10cSrcweir 			break;
1605*cdf0e10cSrcweir 		case IResultSetHelper::BOOKMARK: // special case here because we are only called with position numbers
1606*cdf0e10cSrcweir 		{
1607*cdf0e10cSrcweir 			TBookmarkPosMap::iterator aIter = m_aPosToBookmarks.begin();
1608*cdf0e10cSrcweir 			TBookmarkPosMap::iterator aEnd = m_aPosToBookmarks.end();
1609*cdf0e10cSrcweir 			for (; aIter != aEnd; ++aIter)
1610*cdf0e10cSrcweir 			{
1611*cdf0e10cSrcweir 				if ( aIter->second == _nOffset )
1612*cdf0e10cSrcweir 					return moveToBookmark(makeAny(aIter->first));
1613*cdf0e10cSrcweir 			}
1614*cdf0e10cSrcweir 			OSL_ENSURE(0,"Bookmark not found!");
1615*cdf0e10cSrcweir 		}
1616*cdf0e10cSrcweir 		return sal_False;
1617*cdf0e10cSrcweir 	}
1618*cdf0e10cSrcweir 
1619*cdf0e10cSrcweir 	m_bEOF = sal_False;
1620*cdf0e10cSrcweir 	m_nLastColumnPos = 0;
1621*cdf0e10cSrcweir 
1622*cdf0e10cSrcweir 	SQLRETURN nOldFetchStatus = m_nCurrentFetchState;
1623*cdf0e10cSrcweir 	if ( !m_bUseFetchScroll && _eCursorPosition == IResultSetHelper::NEXT )
1624*cdf0e10cSrcweir 		m_nCurrentFetchState = N3SQLFetch(m_aStatementHandle);
1625*cdf0e10cSrcweir 	else
1626*cdf0e10cSrcweir 		m_nCurrentFetchState = N3SQLFetchScroll(m_aStatementHandle,nFetchOrientation,_nOffset);
1627*cdf0e10cSrcweir 
1628*cdf0e10cSrcweir 	OSL_TRACE( __FILE__": OSkipDeletedSet::OResultSet::move(%d,%d), FetchState = %d",nFetchOrientation,_nOffset,m_nCurrentFetchState);
1629*cdf0e10cSrcweir 	OTools::ThrowException(m_pStatement->getOwnConnection(),m_nCurrentFetchState,m_aStatementHandle,SQL_HANDLE_STMT,*this);
1630*cdf0e10cSrcweir 
1631*cdf0e10cSrcweir     const bool bSuccess = m_nCurrentFetchState == SQL_SUCCESS || m_nCurrentFetchState == SQL_SUCCESS_WITH_INFO;
1632*cdf0e10cSrcweir 	if ( bSuccess )
1633*cdf0e10cSrcweir 	{
1634*cdf0e10cSrcweir 		switch(_eCursorPosition)
1635*cdf0e10cSrcweir 		{
1636*cdf0e10cSrcweir 			case IResultSetHelper::NEXT:
1637*cdf0e10cSrcweir 				++m_nRowPos;
1638*cdf0e10cSrcweir 				break;
1639*cdf0e10cSrcweir 			case IResultSetHelper::PRIOR:
1640*cdf0e10cSrcweir 				--m_nRowPos;
1641*cdf0e10cSrcweir 				break;
1642*cdf0e10cSrcweir 			case IResultSetHelper::FIRST:
1643*cdf0e10cSrcweir 				m_nRowPos = 1;
1644*cdf0e10cSrcweir 				break;
1645*cdf0e10cSrcweir 			case IResultSetHelper::LAST:
1646*cdf0e10cSrcweir 				m_bEOF = sal_True;
1647*cdf0e10cSrcweir 				break;
1648*cdf0e10cSrcweir 			case IResultSetHelper::RELATIVE:
1649*cdf0e10cSrcweir 				m_nRowPos += _nOffset;
1650*cdf0e10cSrcweir 				break;
1651*cdf0e10cSrcweir 			case IResultSetHelper::ABSOLUTE:
1652*cdf0e10cSrcweir 			case IResultSetHelper::BOOKMARK: // special case here because we are only called with position numbers
1653*cdf0e10cSrcweir 				m_nRowPos = _nOffset;
1654*cdf0e10cSrcweir 				break;
1655*cdf0e10cSrcweir 		} // switch(_eCursorPosition)
1656*cdf0e10cSrcweir         if ( m_nUseBookmarks == ODBC_SQL_NOT_DEFINED )
1657*cdf0e10cSrcweir         {
1658*cdf0e10cSrcweir             RTL_LOGFILE_CONTEXT_TRACE( aLogger, "SQLGetStmtAttr" );
1659*cdf0e10cSrcweir             m_nUseBookmarks = SQL_UB_OFF;
1660*cdf0e10cSrcweir 		    SQLRETURN nRet = N3SQLGetStmtAttr(m_aStatementHandle,SQL_ATTR_USE_BOOKMARKS,&m_nUseBookmarks,SQL_IS_UINTEGER,NULL);
1661*cdf0e10cSrcweir             OSL_UNUSED( nRet );
1662*cdf0e10cSrcweir         }
1663*cdf0e10cSrcweir 		if ( m_nUseBookmarks != SQL_UB_OFF )
1664*cdf0e10cSrcweir 		{
1665*cdf0e10cSrcweir             RTL_LOGFILE_CONTEXT_TRACE( aLogger, "OTools::getBytesValue" );
1666*cdf0e10cSrcweir 			m_aBookmark = OTools::getBytesValue(m_pStatement->getOwnConnection(),m_aStatementHandle,0,SQL_C_VARBOOKMARK,m_bWasNull,**this);
1667*cdf0e10cSrcweir 			m_aPosToBookmarks[m_aBookmark] = m_nRowPos;
1668*cdf0e10cSrcweir 			OSL_ENSURE(m_aBookmark.getLength(),"Invalid bookmark from length 0!");
1669*cdf0e10cSrcweir 		}
1670*cdf0e10cSrcweir 	}
1671*cdf0e10cSrcweir 	else if ( IResultSetHelper::PRIOR == _eCursorPosition && m_nCurrentFetchState == SQL_NO_DATA )
1672*cdf0e10cSrcweir 		m_nRowPos = 0;
1673*cdf0e10cSrcweir 	else if(IResultSetHelper::NEXT == _eCursorPosition && m_nCurrentFetchState == SQL_NO_DATA && nOldFetchStatus != SQL_NO_DATA)
1674*cdf0e10cSrcweir 		++m_nRowPos;
1675*cdf0e10cSrcweir 
1676*cdf0e10cSrcweir 	return bSuccess;
1677*cdf0e10cSrcweir }
1678*cdf0e10cSrcweir // -----------------------------------------------------------------------------
1679*cdf0e10cSrcweir sal_Int32 OResultSet::getDriverPos() const
1680*cdf0e10cSrcweir {
1681*cdf0e10cSrcweir 	sal_Int32 nValue = 0;
1682*cdf0e10cSrcweir 	SQLRETURN nRet = N3SQLGetStmtAttr(m_aStatementHandle,SQL_ATTR_ROW_NUMBER,&nValue,SQL_IS_UINTEGER,0);
1683*cdf0e10cSrcweir     OSL_UNUSED( nRet );
1684*cdf0e10cSrcweir 	OSL_TRACE( __FILE__": OResultSet::getDriverPos() = Ret = %d, RowNum = %d, RowPos = %d",nRet,nValue , m_nRowPos);
1685*cdf0e10cSrcweir 	return nValue ? nValue : m_nRowPos;
1686*cdf0e10cSrcweir }
1687*cdf0e10cSrcweir // -----------------------------------------------------------------------------
1688*cdf0e10cSrcweir sal_Bool OResultSet::deletedVisible() const
1689*cdf0e10cSrcweir {
1690*cdf0e10cSrcweir 	return sal_False;
1691*cdf0e10cSrcweir }
1692*cdf0e10cSrcweir // -----------------------------------------------------------------------------
1693*cdf0e10cSrcweir sal_Bool OResultSet::isRowDeleted() const
1694*cdf0e10cSrcweir {
1695*cdf0e10cSrcweir 	return m_pRowStatusArray[0] == SQL_ROW_DELETED;
1696*cdf0e10cSrcweir }
1697*cdf0e10cSrcweir // -----------------------------------------------------------------------------
1698*cdf0e10cSrcweir sal_Bool OResultSet::moveImpl(IResultSetHelper::Movement _eCursorPosition, sal_Int32 _nOffset, sal_Bool _bRetrieveData)
1699*cdf0e10cSrcweir {
1700*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
1701*cdf0e10cSrcweir 	checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
1702*cdf0e10cSrcweir 	return (m_pSkipDeletedSet != NULL)
1703*cdf0e10cSrcweir 				?   m_pSkipDeletedSet->skipDeleted(_eCursorPosition,_nOffset,_bRetrieveData)
1704*cdf0e10cSrcweir 				:   move(_eCursorPosition,_nOffset,_bRetrieveData);
1705*cdf0e10cSrcweir }
1706*cdf0e10cSrcweir // -----------------------------------------------------------------------------
1707*cdf0e10cSrcweir void OResultSet::fillNeededData(SQLRETURN _nRet)
1708*cdf0e10cSrcweir {
1709*cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "odbc", "Ocke.Janssen@sun.com", "OResultSet::fillNeededData" );
1710*cdf0e10cSrcweir 	SQLRETURN nRet = _nRet;
1711*cdf0e10cSrcweir 	if( nRet == SQL_NEED_DATA)
1712*cdf0e10cSrcweir 	{
1713*cdf0e10cSrcweir 		void* pColumnIndex = 0;
1714*cdf0e10cSrcweir 		nRet = N3SQLParamData(m_aStatementHandle,&pColumnIndex);
1715*cdf0e10cSrcweir 
1716*cdf0e10cSrcweir 		do
1717*cdf0e10cSrcweir 		{
1718*cdf0e10cSrcweir 			if (nRet != SQL_SUCCESS && nRet != SQL_SUCCESS_WITH_INFO && nRet != SQL_NEED_DATA)
1719*cdf0e10cSrcweir 				break;
1720*cdf0e10cSrcweir 
1721*cdf0e10cSrcweir 			sal_IntPtr nColumnIndex ( reinterpret_cast<sal_IntPtr>(pColumnIndex));
1722*cdf0e10cSrcweir 			Sequence< sal_Int8 > aSeq;
1723*cdf0e10cSrcweir 			switch(m_aRow[nColumnIndex].getTypeKind())
1724*cdf0e10cSrcweir 			{
1725*cdf0e10cSrcweir 				case DataType::BINARY:
1726*cdf0e10cSrcweir 				case DataType::VARBINARY:
1727*cdf0e10cSrcweir 				case DataType::LONGVARBINARY:
1728*cdf0e10cSrcweir 				case DataType::BLOB:
1729*cdf0e10cSrcweir 					aSeq = m_aRow[nColumnIndex];
1730*cdf0e10cSrcweir 					N3SQLPutData (m_aStatementHandle, aSeq.getArray(), aSeq.getLength());
1731*cdf0e10cSrcweir 					break;
1732*cdf0e10cSrcweir 				case SQL_WLONGVARCHAR:
1733*cdf0e10cSrcweir 				{
1734*cdf0e10cSrcweir 					::rtl::OUString sRet;
1735*cdf0e10cSrcweir 					sRet = m_aRow[nColumnIndex].getString();
1736*cdf0e10cSrcweir 					nRet = N3SQLPutData (m_aStatementHandle, (SQLPOINTER)sRet.getStr(), sizeof(sal_Unicode)*sRet.getLength());
1737*cdf0e10cSrcweir 					break;
1738*cdf0e10cSrcweir 				}
1739*cdf0e10cSrcweir 				case DataType::LONGVARCHAR:
1740*cdf0e10cSrcweir 				case DataType::CLOB:
1741*cdf0e10cSrcweir 				{
1742*cdf0e10cSrcweir 					::rtl::OUString sRet;
1743*cdf0e10cSrcweir 					sRet = m_aRow[nColumnIndex].getString();
1744*cdf0e10cSrcweir 					::rtl::OString aString(::rtl::OUStringToOString(sRet,m_nTextEncoding));
1745*cdf0e10cSrcweir 					nRet = N3SQLPutData (m_aStatementHandle, (SQLPOINTER)aString.getStr(), aString.getLength());
1746*cdf0e10cSrcweir 					break;
1747*cdf0e10cSrcweir 				}
1748*cdf0e10cSrcweir 				default:
1749*cdf0e10cSrcweir 					OSL_ENSURE(0,"Not supported at the moment!");
1750*cdf0e10cSrcweir 			}
1751*cdf0e10cSrcweir 			nRet = N3SQLParamData(m_aStatementHandle,&pColumnIndex);
1752*cdf0e10cSrcweir 		}
1753*cdf0e10cSrcweir 		while (nRet == SQL_NEED_DATA);
1754*cdf0e10cSrcweir 	}
1755*cdf0e10cSrcweir }
1756*cdf0e10cSrcweir // -----------------------------------------------------------------------------
1757*cdf0e10cSrcweir SWORD OResultSet::impl_getColumnType_nothrow(sal_Int32 columnIndex)
1758*cdf0e10cSrcweir {
1759*cdf0e10cSrcweir     ::std::map<sal_Int32,SWORD>::iterator aFind = m_aODBCColumnTypes.find(columnIndex);
1760*cdf0e10cSrcweir     if ( aFind == m_aODBCColumnTypes.end() )
1761*cdf0e10cSrcweir         aFind = m_aODBCColumnTypes.insert(::std::map<sal_Int32,SWORD>::value_type(columnIndex,OResultSetMetaData::getColumnODBCType(m_pStatement->getOwnConnection(),m_aStatementHandle,*this,columnIndex))).first;
1762*cdf0e10cSrcweir     return aFind->second;
1763*cdf0e10cSrcweir }
1764*cdf0e10cSrcweir 
1765