xref: /AOO41X/main/connectivity/source/drivers/odbcbase/OStatement.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 
31*cdf0e10cSrcweir #include <stdio.h>
32*cdf0e10cSrcweir #include <osl/diagnose.h>
33*cdf0e10cSrcweir #include "odbc/OStatement.hxx"
34*cdf0e10cSrcweir #include "odbc/OConnection.hxx"
35*cdf0e10cSrcweir #include "odbc/OResultSet.hxx"
36*cdf0e10cSrcweir #include <comphelper/property.hxx>
37*cdf0e10cSrcweir #include "odbc/OTools.hxx"
38*cdf0e10cSrcweir #include <comphelper/uno3.hxx>
39*cdf0e10cSrcweir #include <osl/thread.h>
40*cdf0e10cSrcweir #include <com/sun/star/sdbc/ResultSetConcurrency.hpp>
41*cdf0e10cSrcweir #include <com/sun/star/sdbc/ResultSetType.hpp>
42*cdf0e10cSrcweir #include <com/sun/star/sdbc/FetchDirection.hpp>
43*cdf0e10cSrcweir #include <com/sun/star/lang/DisposedException.hpp>
44*cdf0e10cSrcweir #include <comphelper/sequence.hxx>
45*cdf0e10cSrcweir #include <cppuhelper/typeprovider.hxx>
46*cdf0e10cSrcweir #include <comphelper/extract.hxx>
47*cdf0e10cSrcweir #include <comphelper/types.hxx>
48*cdf0e10cSrcweir #include "diagnose_ex.h"
49*cdf0e10cSrcweir #include <algorithm>
50*cdf0e10cSrcweir #include "resource/common_res.hrc"
51*cdf0e10cSrcweir #include "connectivity/dbexception.hxx"
52*cdf0e10cSrcweir 
53*cdf0e10cSrcweir using namespace ::comphelper;
54*cdf0e10cSrcweir 
55*cdf0e10cSrcweir #define THROW_SQL(x) \
56*cdf0e10cSrcweir 	OTools::ThrowException(m_pConnection,x,m_aStatementHandle,SQL_HANDLE_STMT,*this)
57*cdf0e10cSrcweir 
58*cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 1
59*cdf0e10cSrcweir #define DEBUG_THROW					\
60*cdf0e10cSrcweir 	try									\
61*cdf0e10cSrcweir 	{									\
62*cdf0e10cSrcweir 		THROW_SQL(nRetCode);			\
63*cdf0e10cSrcweir 	}									\
64*cdf0e10cSrcweir 	catch(SQLException&)				\
65*cdf0e10cSrcweir 	{									\
66*cdf0e10cSrcweir 		OSL_ENSURE(0,"Exception in odbc catched"); \
67*cdf0e10cSrcweir 	}
68*cdf0e10cSrcweir #endif
69*cdf0e10cSrcweir 
70*cdf0e10cSrcweir 
71*cdf0e10cSrcweir 
72*cdf0e10cSrcweir using namespace connectivity::odbc;
73*cdf0e10cSrcweir //------------------------------------------------------------------------------
74*cdf0e10cSrcweir using namespace com::sun::star::uno;
75*cdf0e10cSrcweir using namespace com::sun::star::lang;
76*cdf0e10cSrcweir using namespace com::sun::star::beans;
77*cdf0e10cSrcweir using namespace com::sun::star::sdbc;
78*cdf0e10cSrcweir using namespace com::sun::star::sdbcx;
79*cdf0e10cSrcweir using namespace com::sun::star::container;
80*cdf0e10cSrcweir using namespace com::sun::star::io;
81*cdf0e10cSrcweir using namespace com::sun::star::util;
82*cdf0e10cSrcweir //------------------------------------------------------------------------------
83*cdf0e10cSrcweir OStatement_Base::OStatement_Base(OConnection* _pConnection )
84*cdf0e10cSrcweir 	:OStatement_BASE(m_aMutex)
85*cdf0e10cSrcweir 	,OPropertySetHelper(OStatement_BASE::rBHelper)
86*cdf0e10cSrcweir 	,m_pConnection(_pConnection)
87*cdf0e10cSrcweir     ,m_aStatementHandle(SQL_NULL_HANDLE)
88*cdf0e10cSrcweir 	,m_pRowStatusArray(0)
89*cdf0e10cSrcweir     ,rBHelper(OStatement_BASE::rBHelper)
90*cdf0e10cSrcweir {
91*cdf0e10cSrcweir 	osl_incrementInterlockedCount( &m_refCount );
92*cdf0e10cSrcweir 	m_pConnection->acquire();
93*cdf0e10cSrcweir 	m_aStatementHandle = m_pConnection->createStatementHandle();
94*cdf0e10cSrcweir 
95*cdf0e10cSrcweir 	//setMaxFieldSize(0);
96*cdf0e10cSrcweir     // Don't do this. By ODBC spec, "0" is the default for the SQL_ATTR_MAX_LENGTH attribute. We once introduced
97*cdf0e10cSrcweir     // this line since an PostgreSQL ODBC driver had a default other than 0. However, current drivers (at least 8.3
98*cdf0e10cSrcweir     // and later) have a proper default of 0, so there should be no need anymore.
99*cdf0e10cSrcweir     // On the other hand, the NotesSQL driver (IBM's ODBC driver for the Lotus Notes series) wrongly interprets
100*cdf0e10cSrcweir     // "0" as "0", whereas the ODBC spec says it should in fact mean "unlimited".
101*cdf0e10cSrcweir     // So, removing this line seems to be the best option for now.
102*cdf0e10cSrcweir     // If we ever again encounter a ODBC driver which needs this option, then we should introduce a data source
103*cdf0e10cSrcweir     // setting for it, instead of unconditionally doing it.
104*cdf0e10cSrcweir 
105*cdf0e10cSrcweir 	osl_decrementInterlockedCount( &m_refCount );
106*cdf0e10cSrcweir }
107*cdf0e10cSrcweir // -----------------------------------------------------------------------------
108*cdf0e10cSrcweir OStatement_Base::~OStatement_Base()
109*cdf0e10cSrcweir {
110*cdf0e10cSrcweir 	OSL_ENSURE(!m_aStatementHandle,"Sohould ne null here!");
111*cdf0e10cSrcweir }
112*cdf0e10cSrcweir //------------------------------------------------------------------------------
113*cdf0e10cSrcweir void OStatement_Base::disposeResultSet()
114*cdf0e10cSrcweir {
115*cdf0e10cSrcweir 	// free the cursor if alive
116*cdf0e10cSrcweir 	Reference< XComponent > xComp(m_xResultSet.get(), UNO_QUERY);
117*cdf0e10cSrcweir 	if (xComp.is())
118*cdf0e10cSrcweir 		xComp->dispose();
119*cdf0e10cSrcweir 	m_xResultSet = Reference< XResultSet>();
120*cdf0e10cSrcweir }
121*cdf0e10cSrcweir // -----------------------------------------------------------------------------
122*cdf0e10cSrcweir void SAL_CALL OStatement_Base::disposing(void)
123*cdf0e10cSrcweir {
124*cdf0e10cSrcweir 	::osl::MutexGuard aGuard(m_aMutex);
125*cdf0e10cSrcweir 
126*cdf0e10cSrcweir 	disposeResultSet();
127*cdf0e10cSrcweir 	::comphelper::disposeComponent(m_xGeneratedStatement);
128*cdf0e10cSrcweir 
129*cdf0e10cSrcweir 	OSL_ENSURE(m_aStatementHandle,"OStatement_BASE2::disposing: StatementHandle is null!");
130*cdf0e10cSrcweir 	if (m_pConnection)
131*cdf0e10cSrcweir 	{
132*cdf0e10cSrcweir 		m_pConnection->freeStatementHandle(m_aStatementHandle);
133*cdf0e10cSrcweir 		m_pConnection->release();
134*cdf0e10cSrcweir 		m_pConnection = NULL;
135*cdf0e10cSrcweir 	}
136*cdf0e10cSrcweir 	OSL_ENSURE(!m_aStatementHandle,"Sohould ne null here!");
137*cdf0e10cSrcweir 
138*cdf0e10cSrcweir 	OStatement_BASE::disposing();
139*cdf0e10cSrcweir }
140*cdf0e10cSrcweir //------------------------------------------------------------------------------
141*cdf0e10cSrcweir void OStatement_BASE2::disposing()
142*cdf0e10cSrcweir {
143*cdf0e10cSrcweir 	::osl::MutexGuard aGuard(m_aMutex);
144*cdf0e10cSrcweir 
145*cdf0e10cSrcweir 	dispose_ChildImpl();
146*cdf0e10cSrcweir 	OStatement_Base::disposing();
147*cdf0e10cSrcweir }
148*cdf0e10cSrcweir //-----------------------------------------------------------------------------
149*cdf0e10cSrcweir void SAL_CALL OStatement_BASE2::release() throw()
150*cdf0e10cSrcweir {
151*cdf0e10cSrcweir 	relase_ChildImpl();
152*cdf0e10cSrcweir }
153*cdf0e10cSrcweir //-----------------------------------------------------------------------------
154*cdf0e10cSrcweir Any SAL_CALL OStatement_Base::queryInterface( const Type & rType ) throw(RuntimeException)
155*cdf0e10cSrcweir {
156*cdf0e10cSrcweir 	if ( m_pConnection && !m_pConnection->isAutoRetrievingEnabled() && rType == ::getCppuType( (const Reference< XGeneratedResultSet > *)0 ) )
157*cdf0e10cSrcweir 		return Any();
158*cdf0e10cSrcweir 	Any aRet = OStatement_BASE::queryInterface(rType);
159*cdf0e10cSrcweir 	return aRet.hasValue() ? aRet : OPropertySetHelper::queryInterface(rType);
160*cdf0e10cSrcweir }
161*cdf0e10cSrcweir // -------------------------------------------------------------------------
162*cdf0e10cSrcweir Sequence< Type > SAL_CALL OStatement_Base::getTypes(  ) throw(RuntimeException)
163*cdf0e10cSrcweir {
164*cdf0e10cSrcweir 	::cppu::OTypeCollection aTypes(	::getCppuType( (const Reference< XMultiPropertySet > *)0 ),
165*cdf0e10cSrcweir 									::getCppuType( (const Reference< XFastPropertySet > *)0 ),
166*cdf0e10cSrcweir 									::getCppuType( (const Reference< XPropertySet > *)0 ));
167*cdf0e10cSrcweir 	Sequence< Type > aOldTypes = OStatement_BASE::getTypes();
168*cdf0e10cSrcweir 	if ( m_pConnection && !m_pConnection->isAutoRetrievingEnabled() )
169*cdf0e10cSrcweir 	{
170*cdf0e10cSrcweir 		::std::remove(aOldTypes.getArray(),aOldTypes.getArray() + aOldTypes.getLength(),
171*cdf0e10cSrcweir 						::getCppuType( (const Reference< XGeneratedResultSet > *)0 ));
172*cdf0e10cSrcweir 		aOldTypes.realloc(aOldTypes.getLength() - 1);
173*cdf0e10cSrcweir 	}
174*cdf0e10cSrcweir 
175*cdf0e10cSrcweir 	return ::comphelper::concatSequences(aTypes.getTypes(),aOldTypes);
176*cdf0e10cSrcweir }
177*cdf0e10cSrcweir // -------------------------------------------------------------------------
178*cdf0e10cSrcweir Reference< XResultSet > SAL_CALL OStatement_Base::getGeneratedValues(  ) throw (SQLException, RuntimeException)
179*cdf0e10cSrcweir {
180*cdf0e10cSrcweir 	OSL_ENSURE(	m_pConnection && m_pConnection->isAutoRetrievingEnabled(),"Illegal call here. isAutoRetrievingEnabled is false!");
181*cdf0e10cSrcweir 	Reference< XResultSet > xRes;
182*cdf0e10cSrcweir 	if ( m_pConnection )
183*cdf0e10cSrcweir 	{
184*cdf0e10cSrcweir 		::rtl::OUString sStmt = m_pConnection->getTransformedGeneratedStatement(m_sSqlStatement);
185*cdf0e10cSrcweir 		if ( sStmt.getLength() )
186*cdf0e10cSrcweir 		{
187*cdf0e10cSrcweir 			::comphelper::disposeComponent(m_xGeneratedStatement);
188*cdf0e10cSrcweir 			m_xGeneratedStatement = m_pConnection->createStatement();
189*cdf0e10cSrcweir 			xRes = m_xGeneratedStatement->executeQuery(sStmt);
190*cdf0e10cSrcweir 		}
191*cdf0e10cSrcweir 	}
192*cdf0e10cSrcweir 	return xRes;
193*cdf0e10cSrcweir }
194*cdf0e10cSrcweir // -----------------------------------------------------------------------------
195*cdf0e10cSrcweir void SAL_CALL OStatement_Base::cancel(  ) throw(RuntimeException)
196*cdf0e10cSrcweir {
197*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
198*cdf0e10cSrcweir 	checkDisposed(OStatement_BASE::rBHelper.bDisposed);
199*cdf0e10cSrcweir 
200*cdf0e10cSrcweir 	OSL_ENSURE(m_aStatementHandle,"StatementHandle is null!");
201*cdf0e10cSrcweir 	OTools::ThrowException(m_pConnection,N3SQLCancel(m_aStatementHandle),m_aStatementHandle,SQL_HANDLE_STMT,*this);
202*cdf0e10cSrcweir }
203*cdf0e10cSrcweir // -------------------------------------------------------------------------
204*cdf0e10cSrcweir 
205*cdf0e10cSrcweir void SAL_CALL OStatement_Base::close(  ) throw(SQLException, RuntimeException)
206*cdf0e10cSrcweir {
207*cdf0e10cSrcweir 	{
208*cdf0e10cSrcweir 		::osl::MutexGuard aGuard( m_aMutex );
209*cdf0e10cSrcweir 		checkDisposed(OStatement_BASE::rBHelper.bDisposed);
210*cdf0e10cSrcweir 
211*cdf0e10cSrcweir 	}
212*cdf0e10cSrcweir 	dispose();
213*cdf0e10cSrcweir }
214*cdf0e10cSrcweir // -------------------------------------------------------------------------
215*cdf0e10cSrcweir 
216*cdf0e10cSrcweir void SAL_CALL OStatement::clearBatch(  ) throw(SQLException, RuntimeException)
217*cdf0e10cSrcweir {
218*cdf0e10cSrcweir 
219*cdf0e10cSrcweir }
220*cdf0e10cSrcweir // -------------------------------------------------------------------------
221*cdf0e10cSrcweir 
222*cdf0e10cSrcweir void OStatement_Base::reset() throw (SQLException)
223*cdf0e10cSrcweir {
224*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
225*cdf0e10cSrcweir 	checkDisposed(OStatement_BASE::rBHelper.bDisposed);
226*cdf0e10cSrcweir 
227*cdf0e10cSrcweir 
228*cdf0e10cSrcweir 	clearWarnings ();
229*cdf0e10cSrcweir 
230*cdf0e10cSrcweir 	if (m_xResultSet.get().is())
231*cdf0e10cSrcweir 	{
232*cdf0e10cSrcweir 		clearMyResultSet();
233*cdf0e10cSrcweir 	}
234*cdf0e10cSrcweir 	if(m_aStatementHandle)
235*cdf0e10cSrcweir 	{
236*cdf0e10cSrcweir 		THROW_SQL(N3SQLFreeStmt(m_aStatementHandle, SQL_CLOSE));
237*cdf0e10cSrcweir 	}
238*cdf0e10cSrcweir }
239*cdf0e10cSrcweir //--------------------------------------------------------------------
240*cdf0e10cSrcweir // clearMyResultSet
241*cdf0e10cSrcweir // If a ResultSet was created for this Statement, close it
242*cdf0e10cSrcweir //--------------------------------------------------------------------
243*cdf0e10cSrcweir 
244*cdf0e10cSrcweir void OStatement_Base::clearMyResultSet () throw (SQLException)
245*cdf0e10cSrcweir {
246*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
247*cdf0e10cSrcweir 	checkDisposed(OStatement_BASE::rBHelper.bDisposed);
248*cdf0e10cSrcweir 
249*cdf0e10cSrcweir     try
250*cdf0e10cSrcweir     {
251*cdf0e10cSrcweir 	    Reference<XCloseable> xCloseable;
252*cdf0e10cSrcweir 	    if ( ::comphelper::query_interface( m_xResultSet.get(), xCloseable ) )
253*cdf0e10cSrcweir 		    xCloseable->close();
254*cdf0e10cSrcweir     }
255*cdf0e10cSrcweir     catch( const DisposedException& ) { }
256*cdf0e10cSrcweir 
257*cdf0e10cSrcweir     m_xResultSet = Reference< XResultSet >();
258*cdf0e10cSrcweir }
259*cdf0e10cSrcweir //--------------------------------------------------------------------
260*cdf0e10cSrcweir SQLLEN OStatement_Base::getRowCount () throw( SQLException)
261*cdf0e10cSrcweir {
262*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
263*cdf0e10cSrcweir 	checkDisposed(OStatement_BASE::rBHelper.bDisposed);
264*cdf0e10cSrcweir 
265*cdf0e10cSrcweir 
266*cdf0e10cSrcweir 	SQLLEN numRows = 0;
267*cdf0e10cSrcweir 
268*cdf0e10cSrcweir 	try {
269*cdf0e10cSrcweir 		THROW_SQL(N3SQLRowCount(m_aStatementHandle,&numRows));
270*cdf0e10cSrcweir 	}
271*cdf0e10cSrcweir 	catch (SQLException&)
272*cdf0e10cSrcweir 	{
273*cdf0e10cSrcweir 	}
274*cdf0e10cSrcweir 	return numRows;
275*cdf0e10cSrcweir }
276*cdf0e10cSrcweir //--------------------------------------------------------------------
277*cdf0e10cSrcweir // lockIfNecessary
278*cdf0e10cSrcweir // If the given SQL statement contains a 'FOR UPDATE' clause, change
279*cdf0e10cSrcweir // the concurrency to lock so that the row can then be updated.  Returns
280*cdf0e10cSrcweir // true if the concurrency has been changed
281*cdf0e10cSrcweir //--------------------------------------------------------------------
282*cdf0e10cSrcweir 
283*cdf0e10cSrcweir sal_Bool OStatement_Base::lockIfNecessary (const ::rtl::OUString& sql) throw( SQLException)
284*cdf0e10cSrcweir {
285*cdf0e10cSrcweir 	sal_Bool rc = sal_False;
286*cdf0e10cSrcweir 
287*cdf0e10cSrcweir 	// First, convert the statement to upper case
288*cdf0e10cSrcweir 
289*cdf0e10cSrcweir 	::rtl::OUString sqlStatement = sql.toAsciiUpperCase ();
290*cdf0e10cSrcweir 
291*cdf0e10cSrcweir 	// Now, look for the FOR UPDATE keywords.  If there is any extra white
292*cdf0e10cSrcweir 	// space between the FOR and UPDATE, this will fail.
293*cdf0e10cSrcweir 
294*cdf0e10cSrcweir 	sal_Int32 index = sqlStatement.indexOf(::rtl::OUString::createFromAscii(" FOR UPDATE"));
295*cdf0e10cSrcweir 
296*cdf0e10cSrcweir 	// We found it.  Change our concurrency level to ensure that the
297*cdf0e10cSrcweir 	// row can be updated.
298*cdf0e10cSrcweir 
299*cdf0e10cSrcweir 	if (index > 0)
300*cdf0e10cSrcweir 	{
301*cdf0e10cSrcweir 		OSL_ENSURE(m_aStatementHandle,"StatementHandle is null!");
302*cdf0e10cSrcweir 		try
303*cdf0e10cSrcweir 		{
304*cdf0e10cSrcweir 			SQLINTEGER nLock = SQL_CONCUR_LOCK;
305*cdf0e10cSrcweir 			THROW_SQL(N3SQLSetStmtAttr(m_aStatementHandle, SQL_CONCURRENCY,(SQLPOINTER)nLock,SQL_IS_UINTEGER));
306*cdf0e10cSrcweir 		}
307*cdf0e10cSrcweir 		catch (SQLWarning& warn)
308*cdf0e10cSrcweir 		{
309*cdf0e10cSrcweir 			// Catch any warnings and place on the warning stack
310*cdf0e10cSrcweir 			setWarning (warn);
311*cdf0e10cSrcweir 		}
312*cdf0e10cSrcweir 		rc = sal_True;
313*cdf0e10cSrcweir 	}
314*cdf0e10cSrcweir 
315*cdf0e10cSrcweir 	return rc;
316*cdf0e10cSrcweir }
317*cdf0e10cSrcweir //--------------------------------------------------------------------
318*cdf0e10cSrcweir // setWarning
319*cdf0e10cSrcweir // Sets the warning
320*cdf0e10cSrcweir //--------------------------------------------------------------------
321*cdf0e10cSrcweir 
322*cdf0e10cSrcweir void OStatement_Base::setWarning (const	SQLWarning &ex) throw( SQLException)
323*cdf0e10cSrcweir {
324*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
325*cdf0e10cSrcweir 	checkDisposed(OStatement_BASE::rBHelper.bDisposed);
326*cdf0e10cSrcweir 
327*cdf0e10cSrcweir 
328*cdf0e10cSrcweir 	m_aLastWarning = ex;
329*cdf0e10cSrcweir }
330*cdf0e10cSrcweir 
331*cdf0e10cSrcweir //--------------------------------------------------------------------
332*cdf0e10cSrcweir // getColumnCount
333*cdf0e10cSrcweir // Return the number of columns in the ResultSet
334*cdf0e10cSrcweir //--------------------------------------------------------------------
335*cdf0e10cSrcweir 
336*cdf0e10cSrcweir sal_Int32 OStatement_Base::getColumnCount () throw( SQLException)
337*cdf0e10cSrcweir {
338*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
339*cdf0e10cSrcweir 	checkDisposed(OStatement_BASE::rBHelper.bDisposed);
340*cdf0e10cSrcweir 
341*cdf0e10cSrcweir 
342*cdf0e10cSrcweir 	sal_Int16	numCols = 0;
343*cdf0e10cSrcweir 	OSL_ENSURE(m_aStatementHandle,"StatementHandle is null!");
344*cdf0e10cSrcweir 
345*cdf0e10cSrcweir 	try {
346*cdf0e10cSrcweir 		THROW_SQL(N3SQLNumResultCols(m_aStatementHandle,&numCols));
347*cdf0e10cSrcweir 	}
348*cdf0e10cSrcweir 	catch (SQLException&)
349*cdf0e10cSrcweir 	{
350*cdf0e10cSrcweir 	}
351*cdf0e10cSrcweir 	return numCols;
352*cdf0e10cSrcweir }
353*cdf0e10cSrcweir // -------------------------------------------------------------------------
354*cdf0e10cSrcweir 
355*cdf0e10cSrcweir sal_Bool SAL_CALL OStatement_Base::execute( const ::rtl::OUString& sql ) throw(SQLException, RuntimeException)
356*cdf0e10cSrcweir {
357*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
358*cdf0e10cSrcweir 	checkDisposed(OStatement_BASE::rBHelper.bDisposed);
359*cdf0e10cSrcweir 	m_sSqlStatement = sql;
360*cdf0e10cSrcweir 
361*cdf0e10cSrcweir 
362*cdf0e10cSrcweir 	::rtl::OString aSql(::rtl::OUStringToOString(sql,getOwnConnection()->getTextEncoding()));
363*cdf0e10cSrcweir 
364*cdf0e10cSrcweir 	sal_Bool hasResultSet = sal_False;
365*cdf0e10cSrcweir 	SQLWarning aWarning;
366*cdf0e10cSrcweir 
367*cdf0e10cSrcweir 	// Reset the statement handle and warning
368*cdf0e10cSrcweir 
369*cdf0e10cSrcweir 	reset();
370*cdf0e10cSrcweir 
371*cdf0e10cSrcweir 	// Check for a 'FOR UPDATE' statement.  If present, change
372*cdf0e10cSrcweir 	// the concurrency to lock
373*cdf0e10cSrcweir 
374*cdf0e10cSrcweir 	lockIfNecessary (sql);
375*cdf0e10cSrcweir 
376*cdf0e10cSrcweir 	// Call SQLExecDirect
377*cdf0e10cSrcweir 	OSL_ENSURE(m_aStatementHandle,"StatementHandle is null!");
378*cdf0e10cSrcweir 
379*cdf0e10cSrcweir 	try {
380*cdf0e10cSrcweir 		THROW_SQL(N3SQLExecDirect(m_aStatementHandle, (SDB_ODBC_CHAR*)aSql.getStr(),aSql.getLength()));
381*cdf0e10cSrcweir 	}
382*cdf0e10cSrcweir 	catch (SQLWarning& ex) {
383*cdf0e10cSrcweir 
384*cdf0e10cSrcweir 		// Save pointer to warning and save with ResultSet
385*cdf0e10cSrcweir 		// object once it is created.
386*cdf0e10cSrcweir 
387*cdf0e10cSrcweir 		aWarning = ex;
388*cdf0e10cSrcweir 	}
389*cdf0e10cSrcweir 
390*cdf0e10cSrcweir 	// Now determine if there is a result set associated with
391*cdf0e10cSrcweir 	// the SQL statement that was executed.  Get the column
392*cdf0e10cSrcweir 	// count, and if it is not zero, there is a result set.
393*cdf0e10cSrcweir 
394*cdf0e10cSrcweir 	if (getColumnCount () > 0)
395*cdf0e10cSrcweir 	{
396*cdf0e10cSrcweir 		hasResultSet = sal_True;
397*cdf0e10cSrcweir 	}
398*cdf0e10cSrcweir 
399*cdf0e10cSrcweir 	return hasResultSet;
400*cdf0e10cSrcweir }
401*cdf0e10cSrcweir //--------------------------------------------------------------------
402*cdf0e10cSrcweir // getResultSet
403*cdf0e10cSrcweir // getResultSet returns the current result as a ResultSet.  It
404*cdf0e10cSrcweir // returns NULL if the current result is not a ResultSet.
405*cdf0e10cSrcweir //--------------------------------------------------------------------
406*cdf0e10cSrcweir Reference< XResultSet > OStatement_Base::getResultSet (sal_Bool checkCount) throw( SQLException)
407*cdf0e10cSrcweir {
408*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
409*cdf0e10cSrcweir 	checkDisposed(OStatement_BASE::rBHelper.bDisposed);
410*cdf0e10cSrcweir 
411*cdf0e10cSrcweir 
412*cdf0e10cSrcweir 	if (m_xResultSet.get().is())  // if resultset already retrieved,
413*cdf0e10cSrcweir 	{
414*cdf0e10cSrcweir 		// throw exception to avoid sequence error
415*cdf0e10cSrcweir         ::dbtools::throwFunctionSequenceException(*this,Any());
416*cdf0e10cSrcweir 	}
417*cdf0e10cSrcweir 
418*cdf0e10cSrcweir 	OResultSet* pRs = NULL;
419*cdf0e10cSrcweir 	sal_Int32 numCols = 1;
420*cdf0e10cSrcweir 
421*cdf0e10cSrcweir 	// If we already know we have result columns, checkCount
422*cdf0e10cSrcweir 	// is false.  This is an optimization to prevent unneeded
423*cdf0e10cSrcweir 	// calls to getColumnCount
424*cdf0e10cSrcweir 
425*cdf0e10cSrcweir 	if (checkCount)
426*cdf0e10cSrcweir 		numCols = getColumnCount ();
427*cdf0e10cSrcweir 
428*cdf0e10cSrcweir 	// Only return a result set if there are result columns
429*cdf0e10cSrcweir 
430*cdf0e10cSrcweir 	if (numCols > 0)
431*cdf0e10cSrcweir 	{
432*cdf0e10cSrcweir 		OSL_ENSURE(m_aStatementHandle,"StatementHandle is null!");
433*cdf0e10cSrcweir 		pRs = createResulSet();
434*cdf0e10cSrcweir 		pRs->construct();
435*cdf0e10cSrcweir 
436*cdf0e10cSrcweir 		// Save a copy of our last result set
437*cdf0e10cSrcweir 		// Changed to save copy at getResultSet.
438*cdf0e10cSrcweir 		//m_xResultSet = rs;
439*cdf0e10cSrcweir 	}
440*cdf0e10cSrcweir 	else
441*cdf0e10cSrcweir 		clearMyResultSet ();
442*cdf0e10cSrcweir 
443*cdf0e10cSrcweir 	return pRs;
444*cdf0e10cSrcweir }
445*cdf0e10cSrcweir //--------------------------------------------------------------------
446*cdf0e10cSrcweir // getStmtOption
447*cdf0e10cSrcweir // Invoke SQLGetStmtOption with the given option.
448*cdf0e10cSrcweir //--------------------------------------------------------------------
449*cdf0e10cSrcweir 
450*cdf0e10cSrcweir sal_Int32 OStatement_Base::getStmtOption (short fOption) const
451*cdf0e10cSrcweir {
452*cdf0e10cSrcweir 	sal_Int32	result = 0;
453*cdf0e10cSrcweir 	OSL_ENSURE(m_aStatementHandle,"StatementHandle is null!");
454*cdf0e10cSrcweir 	N3SQLGetStmtAttr(m_aStatementHandle, fOption,&result,SQL_IS_INTEGER,NULL);
455*cdf0e10cSrcweir 	return result;
456*cdf0e10cSrcweir }
457*cdf0e10cSrcweir // -------------------------------------------------------------------------
458*cdf0e10cSrcweir 
459*cdf0e10cSrcweir Reference< XResultSet > SAL_CALL OStatement_Base::executeQuery( const ::rtl::OUString& sql ) throw(SQLException, RuntimeException)
460*cdf0e10cSrcweir {
461*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
462*cdf0e10cSrcweir 	checkDisposed(OStatement_BASE::rBHelper.bDisposed);
463*cdf0e10cSrcweir 
464*cdf0e10cSrcweir 
465*cdf0e10cSrcweir 	Reference< XResultSet > xRS = NULL;
466*cdf0e10cSrcweir 
467*cdf0e10cSrcweir 	// Execute the statement.  If execute returns true, a result
468*cdf0e10cSrcweir 	// set exists.
469*cdf0e10cSrcweir 
470*cdf0e10cSrcweir 	if (execute (sql))
471*cdf0e10cSrcweir 	{
472*cdf0e10cSrcweir 		xRS = getResultSet (sal_False);
473*cdf0e10cSrcweir 		m_xResultSet = xRS;
474*cdf0e10cSrcweir 	}
475*cdf0e10cSrcweir 	else
476*cdf0e10cSrcweir 	{
477*cdf0e10cSrcweir 		// No ResultSet was produced.  Raise an exception
478*cdf0e10cSrcweir 		m_pConnection->throwGenericSQLException(STR_NO_RESULTSET,*this);
479*cdf0e10cSrcweir 	}
480*cdf0e10cSrcweir 	return xRS;
481*cdf0e10cSrcweir }
482*cdf0e10cSrcweir // -------------------------------------------------------------------------
483*cdf0e10cSrcweir 
484*cdf0e10cSrcweir Reference< XConnection > SAL_CALL OStatement_Base::getConnection(  ) throw(SQLException, RuntimeException)
485*cdf0e10cSrcweir {
486*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
487*cdf0e10cSrcweir 	checkDisposed(OStatement_BASE::rBHelper.bDisposed);
488*cdf0e10cSrcweir 
489*cdf0e10cSrcweir 	return (Reference< XConnection >)m_pConnection;
490*cdf0e10cSrcweir }
491*cdf0e10cSrcweir // -------------------------------------------------------------------------
492*cdf0e10cSrcweir 
493*cdf0e10cSrcweir Any SAL_CALL OStatement::queryInterface( const Type & rType ) throw(RuntimeException)
494*cdf0e10cSrcweir {
495*cdf0e10cSrcweir 	Any aRet = ::cppu::queryInterface(rType,static_cast< XBatchExecution*> (this));
496*cdf0e10cSrcweir 	return aRet.hasValue() ? aRet : OStatement_Base::queryInterface(rType);
497*cdf0e10cSrcweir }
498*cdf0e10cSrcweir // -------------------------------------------------------------------------
499*cdf0e10cSrcweir 
500*cdf0e10cSrcweir void SAL_CALL OStatement::addBatch( const ::rtl::OUString& sql ) throw(SQLException, RuntimeException)
501*cdf0e10cSrcweir {
502*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
503*cdf0e10cSrcweir 	checkDisposed(OStatement_BASE::rBHelper.bDisposed);
504*cdf0e10cSrcweir 
505*cdf0e10cSrcweir 
506*cdf0e10cSrcweir 	m_aBatchList.push_back(sql);
507*cdf0e10cSrcweir }
508*cdf0e10cSrcweir // -------------------------------------------------------------------------
509*cdf0e10cSrcweir Sequence< sal_Int32 > SAL_CALL OStatement::executeBatch(  ) throw(SQLException, RuntimeException)
510*cdf0e10cSrcweir {
511*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
512*cdf0e10cSrcweir 	checkDisposed(OStatement_BASE::rBHelper.bDisposed);
513*cdf0e10cSrcweir 
514*cdf0e10cSrcweir 
515*cdf0e10cSrcweir 	::rtl::OString aBatchSql;
516*cdf0e10cSrcweir 	sal_Int32 nLen = 0;
517*cdf0e10cSrcweir 	for(::std::list< ::rtl::OUString>::const_iterator i=m_aBatchList.begin();i != m_aBatchList.end();++i,++nLen)
518*cdf0e10cSrcweir 	{
519*cdf0e10cSrcweir 		aBatchSql += ::rtl::OUStringToOString(*i,getOwnConnection()->getTextEncoding());
520*cdf0e10cSrcweir 		aBatchSql += ";";
521*cdf0e10cSrcweir 	}
522*cdf0e10cSrcweir 
523*cdf0e10cSrcweir 	OSL_ENSURE(m_aStatementHandle,"StatementHandle is null!");
524*cdf0e10cSrcweir 	THROW_SQL(N3SQLExecDirect(m_aStatementHandle, (SDB_ODBC_CHAR*)aBatchSql.getStr(),aBatchSql.getLength()));
525*cdf0e10cSrcweir 
526*cdf0e10cSrcweir 	Sequence< sal_Int32 > aRet(nLen);
527*cdf0e10cSrcweir 	sal_Int32* pArray = aRet.getArray();
528*cdf0e10cSrcweir 	for(sal_Int32 j=0;j<nLen;++j)
529*cdf0e10cSrcweir 	{
530*cdf0e10cSrcweir 		SQLRETURN nError = N3SQLMoreResults(m_aStatementHandle);
531*cdf0e10cSrcweir 		if(nError == SQL_SUCCESS)
532*cdf0e10cSrcweir 		{
533*cdf0e10cSrcweir 			SQLLEN nRowCount=0;
534*cdf0e10cSrcweir 			N3SQLRowCount(m_aStatementHandle,&nRowCount);
535*cdf0e10cSrcweir 			pArray[j] = nRowCount;
536*cdf0e10cSrcweir 		}
537*cdf0e10cSrcweir 	}
538*cdf0e10cSrcweir 	return aRet;
539*cdf0e10cSrcweir }
540*cdf0e10cSrcweir // -------------------------------------------------------------------------
541*cdf0e10cSrcweir 
542*cdf0e10cSrcweir 
543*cdf0e10cSrcweir sal_Int32 SAL_CALL OStatement_Base::executeUpdate( const ::rtl::OUString& sql ) throw(SQLException, RuntimeException)
544*cdf0e10cSrcweir {
545*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
546*cdf0e10cSrcweir 	checkDisposed(OStatement_BASE::rBHelper.bDisposed);
547*cdf0e10cSrcweir 
548*cdf0e10cSrcweir 
549*cdf0e10cSrcweir 	sal_Int32 numRows = -1;
550*cdf0e10cSrcweir 
551*cdf0e10cSrcweir 	// Execute the statement.  If execute returns false, a
552*cdf0e10cSrcweir 	// row count exists.
553*cdf0e10cSrcweir 
554*cdf0e10cSrcweir 	if (!execute (sql)) {
555*cdf0e10cSrcweir 		numRows = getUpdateCount();
556*cdf0e10cSrcweir 	}
557*cdf0e10cSrcweir 	else {
558*cdf0e10cSrcweir 
559*cdf0e10cSrcweir 		// No update count was produced (a ResultSet was).  Raise
560*cdf0e10cSrcweir 		// an exception
561*cdf0e10cSrcweir 
562*cdf0e10cSrcweir         ::connectivity::SharedResources aResources;
563*cdf0e10cSrcweir         const ::rtl::OUString sError( aResources.getResourceString(STR_NO_ROWCOUNT));
564*cdf0e10cSrcweir 		throw SQLException (sError,	*this,::rtl::OUString(),0,Any());
565*cdf0e10cSrcweir 	}
566*cdf0e10cSrcweir 	return numRows;
567*cdf0e10cSrcweir 
568*cdf0e10cSrcweir }
569*cdf0e10cSrcweir // -------------------------------------------------------------------------
570*cdf0e10cSrcweir 
571*cdf0e10cSrcweir Reference< XResultSet > SAL_CALL OStatement_Base::getResultSet(  ) throw(SQLException, RuntimeException)
572*cdf0e10cSrcweir {
573*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
574*cdf0e10cSrcweir 	checkDisposed(OStatement_BASE::rBHelper.bDisposed);
575*cdf0e10cSrcweir 
576*cdf0e10cSrcweir 
577*cdf0e10cSrcweir 	m_xResultSet = getResultSet(sal_True);
578*cdf0e10cSrcweir 	return m_xResultSet;
579*cdf0e10cSrcweir }
580*cdf0e10cSrcweir // -------------------------------------------------------------------------
581*cdf0e10cSrcweir 
582*cdf0e10cSrcweir sal_Int32 SAL_CALL OStatement_Base::getUpdateCount(  ) throw(SQLException, RuntimeException)
583*cdf0e10cSrcweir {
584*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
585*cdf0e10cSrcweir 	checkDisposed(OStatement_BASE::rBHelper.bDisposed);
586*cdf0e10cSrcweir 
587*cdf0e10cSrcweir 
588*cdf0e10cSrcweir 	sal_Int32 rowCount = -1;
589*cdf0e10cSrcweir 
590*cdf0e10cSrcweir 	// Only return a row count for SQL statements that did not
591*cdf0e10cSrcweir 	// return a result set.
592*cdf0e10cSrcweir 
593*cdf0e10cSrcweir 	if (getColumnCount () == 0)
594*cdf0e10cSrcweir 		rowCount = getRowCount ();
595*cdf0e10cSrcweir 
596*cdf0e10cSrcweir 	return rowCount;
597*cdf0e10cSrcweir }
598*cdf0e10cSrcweir // -------------------------------------------------------------------------
599*cdf0e10cSrcweir 
600*cdf0e10cSrcweir sal_Bool SAL_CALL OStatement_Base::getMoreResults(  ) throw(SQLException, RuntimeException)
601*cdf0e10cSrcweir {
602*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
603*cdf0e10cSrcweir 	checkDisposed(OStatement_BASE::rBHelper.bDisposed);
604*cdf0e10cSrcweir 
605*cdf0e10cSrcweir 
606*cdf0e10cSrcweir 	SQLWarning	warning;
607*cdf0e10cSrcweir 	sal_Bool hasResultSet = sal_False;
608*cdf0e10cSrcweir 
609*cdf0e10cSrcweir 	// clear previous warnings
610*cdf0e10cSrcweir 
611*cdf0e10cSrcweir 	clearWarnings ();
612*cdf0e10cSrcweir 
613*cdf0e10cSrcweir 	// Call SQLMoreResults
614*cdf0e10cSrcweir 	OSL_ENSURE(m_aStatementHandle,"StatementHandle is null!");
615*cdf0e10cSrcweir 
616*cdf0e10cSrcweir 	try {
617*cdf0e10cSrcweir 		hasResultSet = N3SQLMoreResults(m_aStatementHandle) == SQL_SUCCESS;
618*cdf0e10cSrcweir 	}
619*cdf0e10cSrcweir 	catch (SQLWarning &ex) {
620*cdf0e10cSrcweir 
621*cdf0e10cSrcweir 		// Save pointer to warning and save with ResultSet
622*cdf0e10cSrcweir 		// object once it is created.
623*cdf0e10cSrcweir 
624*cdf0e10cSrcweir 		warning = ex;
625*cdf0e10cSrcweir 	}
626*cdf0e10cSrcweir 
627*cdf0e10cSrcweir 	// There are more results (it may not be a result set, though)
628*cdf0e10cSrcweir 
629*cdf0e10cSrcweir 	if (hasResultSet)
630*cdf0e10cSrcweir 	{
631*cdf0e10cSrcweir 
632*cdf0e10cSrcweir 		// Now determine if there is a result set associated
633*cdf0e10cSrcweir 		// with the SQL statement that was executed.  Get the
634*cdf0e10cSrcweir 		// column count, and if it is zero, there is not a
635*cdf0e10cSrcweir 		// result set.
636*cdf0e10cSrcweir 
637*cdf0e10cSrcweir 		if (getColumnCount () == 0)
638*cdf0e10cSrcweir 			hasResultSet = sal_False;
639*cdf0e10cSrcweir 	}
640*cdf0e10cSrcweir 
641*cdf0e10cSrcweir 	// Set the warning for the statement, if one was generated
642*cdf0e10cSrcweir 
643*cdf0e10cSrcweir 	setWarning (warning);
644*cdf0e10cSrcweir 
645*cdf0e10cSrcweir 	// Return the result set indicator
646*cdf0e10cSrcweir 
647*cdf0e10cSrcweir 	return hasResultSet;
648*cdf0e10cSrcweir }
649*cdf0e10cSrcweir // -------------------------------------------------------------------------
650*cdf0e10cSrcweir 
651*cdf0e10cSrcweir // -------------------------------------------------------------------------
652*cdf0e10cSrcweir Any SAL_CALL OStatement_Base::getWarnings(  ) throw(SQLException, RuntimeException)
653*cdf0e10cSrcweir {
654*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
655*cdf0e10cSrcweir 	checkDisposed(OStatement_BASE::rBHelper.bDisposed);
656*cdf0e10cSrcweir 
657*cdf0e10cSrcweir 
658*cdf0e10cSrcweir 	return makeAny(m_aLastWarning);
659*cdf0e10cSrcweir }
660*cdf0e10cSrcweir // -------------------------------------------------------------------------
661*cdf0e10cSrcweir 
662*cdf0e10cSrcweir // -------------------------------------------------------------------------
663*cdf0e10cSrcweir void SAL_CALL OStatement_Base::clearWarnings(  ) throw(SQLException, RuntimeException)
664*cdf0e10cSrcweir {
665*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
666*cdf0e10cSrcweir 	checkDisposed(OStatement_BASE::rBHelper.bDisposed);
667*cdf0e10cSrcweir 
668*cdf0e10cSrcweir 
669*cdf0e10cSrcweir 	m_aLastWarning = SQLWarning();
670*cdf0e10cSrcweir }
671*cdf0e10cSrcweir // -------------------------------------------------------------------------
672*cdf0e10cSrcweir //------------------------------------------------------------------------------
673*cdf0e10cSrcweir sal_Int32 OStatement_Base::getQueryTimeOut() const
674*cdf0e10cSrcweir {
675*cdf0e10cSrcweir 	return getStmtOption(SQL_ATTR_QUERY_TIMEOUT);
676*cdf0e10cSrcweir }
677*cdf0e10cSrcweir //------------------------------------------------------------------------------
678*cdf0e10cSrcweir sal_Int32 OStatement_Base::getMaxRows() const
679*cdf0e10cSrcweir {
680*cdf0e10cSrcweir 	return getStmtOption(SQL_ATTR_MAX_ROWS);
681*cdf0e10cSrcweir }
682*cdf0e10cSrcweir //------------------------------------------------------------------------------
683*cdf0e10cSrcweir sal_Int32 OStatement_Base::getResultSetConcurrency() const
684*cdf0e10cSrcweir {
685*cdf0e10cSrcweir 	OSL_ENSURE(m_aStatementHandle,"StatementHandle is null!");
686*cdf0e10cSrcweir 	sal_uInt32 nValue;
687*cdf0e10cSrcweir 	SQLRETURN nRetCode = N3SQLGetStmtAttr(m_aStatementHandle,SQL_ATTR_CONCURRENCY,&nValue,SQL_IS_UINTEGER,0);
688*cdf0e10cSrcweir     OSL_UNUSED( nRetCode );
689*cdf0e10cSrcweir 	if(nValue == SQL_CONCUR_READ_ONLY)
690*cdf0e10cSrcweir 		nValue = ResultSetConcurrency::READ_ONLY;
691*cdf0e10cSrcweir 	else
692*cdf0e10cSrcweir 		nValue = ResultSetConcurrency::UPDATABLE;
693*cdf0e10cSrcweir 	return nValue;
694*cdf0e10cSrcweir }
695*cdf0e10cSrcweir //------------------------------------------------------------------------------
696*cdf0e10cSrcweir sal_Int32 OStatement_Base::getResultSetType() const
697*cdf0e10cSrcweir {
698*cdf0e10cSrcweir 	OSL_ENSURE(m_aStatementHandle,"StatementHandle is null!");
699*cdf0e10cSrcweir 	sal_uInt32 nValue = SQL_CURSOR_FORWARD_ONLY;
700*cdf0e10cSrcweir 	SQLRETURN nRetCode = N3SQLGetStmtAttr(m_aStatementHandle,SQL_ATTR_CURSOR_SENSITIVITY,&nValue,SQL_IS_UINTEGER,0);
701*cdf0e10cSrcweir 	nRetCode = N3SQLGetStmtAttr(m_aStatementHandle,SQL_ATTR_CURSOR_TYPE,&nValue,SQL_IS_UINTEGER,0);
702*cdf0e10cSrcweir 	switch(nValue)
703*cdf0e10cSrcweir 	{
704*cdf0e10cSrcweir 		case SQL_CURSOR_FORWARD_ONLY:
705*cdf0e10cSrcweir 			nValue = ResultSetType::FORWARD_ONLY;
706*cdf0e10cSrcweir 			break;
707*cdf0e10cSrcweir 		case SQL_CURSOR_KEYSET_DRIVEN:
708*cdf0e10cSrcweir 		case SQL_CURSOR_STATIC:
709*cdf0e10cSrcweir 			nValue = ResultSetType::SCROLL_INSENSITIVE;
710*cdf0e10cSrcweir 			break;
711*cdf0e10cSrcweir 		case SQL_CURSOR_DYNAMIC:
712*cdf0e10cSrcweir 			nValue = ResultSetType::SCROLL_SENSITIVE;
713*cdf0e10cSrcweir 			break;
714*cdf0e10cSrcweir 	}
715*cdf0e10cSrcweir 
716*cdf0e10cSrcweir 	return nValue;
717*cdf0e10cSrcweir }
718*cdf0e10cSrcweir //------------------------------------------------------------------------------
719*cdf0e10cSrcweir sal_Int32 OStatement_Base::getFetchDirection() const
720*cdf0e10cSrcweir {
721*cdf0e10cSrcweir 	OSL_ENSURE(m_aStatementHandle,"StatementHandle is null!");
722*cdf0e10cSrcweir 	sal_uInt32 nValue = 0;
723*cdf0e10cSrcweir 	SQLRETURN nRetCode = N3SQLGetStmtAttr(m_aStatementHandle,SQL_ATTR_CURSOR_SCROLLABLE,&nValue,SQL_IS_UINTEGER,0);
724*cdf0e10cSrcweir     OSL_UNUSED( nRetCode );
725*cdf0e10cSrcweir 
726*cdf0e10cSrcweir 	switch(nValue)
727*cdf0e10cSrcweir 	{
728*cdf0e10cSrcweir 		case SQL_SCROLLABLE:
729*cdf0e10cSrcweir 			nValue = FetchDirection::REVERSE;
730*cdf0e10cSrcweir 			break;
731*cdf0e10cSrcweir 		default:
732*cdf0e10cSrcweir 			nValue = FetchDirection::FORWARD;
733*cdf0e10cSrcweir 			break;
734*cdf0e10cSrcweir 	}
735*cdf0e10cSrcweir 
736*cdf0e10cSrcweir 	return nValue;
737*cdf0e10cSrcweir }
738*cdf0e10cSrcweir //------------------------------------------------------------------------------
739*cdf0e10cSrcweir sal_Int32 OStatement_Base::getFetchSize() const
740*cdf0e10cSrcweir {
741*cdf0e10cSrcweir 	OSL_ENSURE(m_aStatementHandle,"StatementHandle is null!");
742*cdf0e10cSrcweir 	sal_uInt32 nValue;
743*cdf0e10cSrcweir 	SQLRETURN nRetCode = N3SQLGetStmtAttr(m_aStatementHandle,SQL_ATTR_ROW_ARRAY_SIZE,&nValue,SQL_IS_UINTEGER,0);
744*cdf0e10cSrcweir     OSL_UNUSED( nRetCode );
745*cdf0e10cSrcweir 	return nValue;
746*cdf0e10cSrcweir }
747*cdf0e10cSrcweir //------------------------------------------------------------------------------
748*cdf0e10cSrcweir sal_Int32 OStatement_Base::getMaxFieldSize() const
749*cdf0e10cSrcweir {
750*cdf0e10cSrcweir 	return getStmtOption(SQL_ATTR_MAX_LENGTH);
751*cdf0e10cSrcweir }
752*cdf0e10cSrcweir //------------------------------------------------------------------------------
753*cdf0e10cSrcweir ::rtl::OUString OStatement_Base::getCursorName() const
754*cdf0e10cSrcweir {
755*cdf0e10cSrcweir 	OSL_ENSURE(m_aStatementHandle,"StatementHandle is null!");
756*cdf0e10cSrcweir 	SQLCHAR pName[258];
757*cdf0e10cSrcweir 	SQLSMALLINT nRealLen = 0;
758*cdf0e10cSrcweir 	SQLRETURN nRetCode = N3SQLGetCursorName(m_aStatementHandle,(SQLCHAR*)pName,256,&nRealLen);
759*cdf0e10cSrcweir     OSL_UNUSED( nRetCode );
760*cdf0e10cSrcweir 	return ::rtl::OUString::createFromAscii((const char*)pName);
761*cdf0e10cSrcweir }
762*cdf0e10cSrcweir //------------------------------------------------------------------------------
763*cdf0e10cSrcweir void OStatement_Base::setQueryTimeOut(sal_Int32 seconds)
764*cdf0e10cSrcweir {
765*cdf0e10cSrcweir 	OSL_ENSURE(m_aStatementHandle,"StatementHandle is null!");
766*cdf0e10cSrcweir 	SQLRETURN nRetCode = N3SQLSetStmtAttr(m_aStatementHandle, SQL_ATTR_QUERY_TIMEOUT,(SQLPOINTER)seconds,SQL_IS_UINTEGER);
767*cdf0e10cSrcweir     OSL_UNUSED( nRetCode );
768*cdf0e10cSrcweir }
769*cdf0e10cSrcweir //------------------------------------------------------------------------------
770*cdf0e10cSrcweir void OStatement_Base::setMaxRows(sal_Int32 _par0)
771*cdf0e10cSrcweir {
772*cdf0e10cSrcweir 	OSL_ENSURE(m_aStatementHandle,"StatementHandle is null!");
773*cdf0e10cSrcweir 	SQLRETURN nRetCode = N3SQLSetStmtAttr(m_aStatementHandle, SQL_ATTR_MAX_ROWS, (SQLPOINTER)_par0,SQL_IS_UINTEGER);
774*cdf0e10cSrcweir     OSL_UNUSED( nRetCode );
775*cdf0e10cSrcweir }
776*cdf0e10cSrcweir //------------------------------------------------------------------------------
777*cdf0e10cSrcweir void OStatement_Base::setResultSetConcurrency(sal_Int32 _par0)
778*cdf0e10cSrcweir {
779*cdf0e10cSrcweir 	SQLINTEGER nSet;
780*cdf0e10cSrcweir 	if(_par0 == ResultSetConcurrency::READ_ONLY)
781*cdf0e10cSrcweir 		nSet = SQL_CONCUR_READ_ONLY;
782*cdf0e10cSrcweir 	else
783*cdf0e10cSrcweir 		nSet = SQL_CONCUR_VALUES;
784*cdf0e10cSrcweir 
785*cdf0e10cSrcweir 	OSL_ENSURE(m_aStatementHandle,"StatementHandle is null!");
786*cdf0e10cSrcweir 	N3SQLSetStmtAttr(m_aStatementHandle, SQL_ATTR_CONCURRENCY,(SQLPOINTER)nSet,SQL_IS_UINTEGER);
787*cdf0e10cSrcweir 
788*cdf0e10cSrcweir }
789*cdf0e10cSrcweir //------------------------------------------------------------------------------
790*cdf0e10cSrcweir void OStatement_Base::setResultSetType(sal_Int32 _par0)
791*cdf0e10cSrcweir {
792*cdf0e10cSrcweir 
793*cdf0e10cSrcweir 	OSL_ENSURE(m_aStatementHandle,"StatementHandle is null!");
794*cdf0e10cSrcweir 	SQLRETURN nRetCode = N3SQLSetStmtAttr(m_aStatementHandle, SQL_ATTR_ROW_BIND_TYPE,(SQLPOINTER)SQL_BIND_BY_COLUMN,SQL_IS_UINTEGER);
795*cdf0e10cSrcweir     OSL_UNUSED( nRetCode );
796*cdf0e10cSrcweir 
797*cdf0e10cSrcweir 	sal_Bool bUseBookmark = isUsingBookmarks();
798*cdf0e10cSrcweir     SQLUINTEGER nSet( SQL_UNSPECIFIED );
799*cdf0e10cSrcweir 	switch(_par0)
800*cdf0e10cSrcweir 	{
801*cdf0e10cSrcweir 		case ResultSetType::FORWARD_ONLY:
802*cdf0e10cSrcweir 			nSet = 	SQL_UNSPECIFIED;
803*cdf0e10cSrcweir 			break;
804*cdf0e10cSrcweir 		case ResultSetType::SCROLL_INSENSITIVE:
805*cdf0e10cSrcweir 			nSet = 	SQL_INSENSITIVE;
806*cdf0e10cSrcweir 			N3SQLSetStmtAttr(m_aStatementHandle, SQL_ATTR_CURSOR_TYPE,(SQLPOINTER)SQL_CURSOR_KEYSET_DRIVEN,SQL_IS_UINTEGER);
807*cdf0e10cSrcweir 			break;
808*cdf0e10cSrcweir 		case ResultSetType::SCROLL_SENSITIVE:
809*cdf0e10cSrcweir 			if(bUseBookmark)
810*cdf0e10cSrcweir 			{
811*cdf0e10cSrcweir 				SQLUINTEGER nCurProp = getCursorProperties(SQL_CURSOR_DYNAMIC,sal_True);
812*cdf0e10cSrcweir 				if((nCurProp & SQL_CA1_BOOKMARK) != SQL_CA1_BOOKMARK) // check if bookmark for this type isn't supported
813*cdf0e10cSrcweir 				{ // we have to test the next one
814*cdf0e10cSrcweir 					nCurProp = getCursorProperties(SQL_CURSOR_KEYSET_DRIVEN,sal_True);
815*cdf0e10cSrcweir 					sal_Bool bNotBookmarks = ((nCurProp & SQL_CA1_BOOKMARK) != SQL_CA1_BOOKMARK);
816*cdf0e10cSrcweir 					nCurProp = getCursorProperties(SQL_CURSOR_KEYSET_DRIVEN,sal_False);
817*cdf0e10cSrcweir 					nSet = SQL_CURSOR_KEYSET_DRIVEN;
818*cdf0e10cSrcweir 					if(	bNotBookmarks ||
819*cdf0e10cSrcweir 						((nCurProp & SQL_CA2_SENSITIVITY_DELETIONS) != SQL_CA2_SENSITIVITY_DELETIONS) ||
820*cdf0e10cSrcweir 						((nCurProp & SQL_CA2_SENSITIVITY_ADDITIONS) != SQL_CA2_SENSITIVITY_ADDITIONS))
821*cdf0e10cSrcweir 					{
822*cdf0e10cSrcweir 						// bookmarks for keyset isn't supported so reset bookmark setting
823*cdf0e10cSrcweir 						setUsingBookmarks(sal_False);
824*cdf0e10cSrcweir 						nSet = SQL_CURSOR_DYNAMIC;
825*cdf0e10cSrcweir 					}
826*cdf0e10cSrcweir 				}
827*cdf0e10cSrcweir 				else
828*cdf0e10cSrcweir 					nSet = SQL_CURSOR_DYNAMIC;
829*cdf0e10cSrcweir 			}
830*cdf0e10cSrcweir 			else
831*cdf0e10cSrcweir 				nSet = SQL_CURSOR_DYNAMIC;
832*cdf0e10cSrcweir 			if(N3SQLSetStmtAttr(m_aStatementHandle, SQL_ATTR_CURSOR_TYPE,(SQLPOINTER)nSet,SQL_IS_UINTEGER) != SQL_SUCCESS)
833*cdf0e10cSrcweir 			{
834*cdf0e10cSrcweir 				nSet = SQL_CURSOR_KEYSET_DRIVEN;
835*cdf0e10cSrcweir 				N3SQLSetStmtAttr(m_aStatementHandle, SQL_ATTR_CURSOR_TYPE,(SQLPOINTER)nSet,SQL_IS_UINTEGER);
836*cdf0e10cSrcweir 			}
837*cdf0e10cSrcweir 			nSet = 	SQL_SENSITIVE;
838*cdf0e10cSrcweir 			break;
839*cdf0e10cSrcweir         default:
840*cdf0e10cSrcweir             OSL_ENSURE( false, "OStatement_Base::setResultSetType: invalid result set type!" );
841*cdf0e10cSrcweir             break;
842*cdf0e10cSrcweir 	}
843*cdf0e10cSrcweir 
844*cdf0e10cSrcweir 
845*cdf0e10cSrcweir 	N3SQLSetStmtAttr(m_aStatementHandle, SQL_ATTR_CURSOR_SENSITIVITY,(SQLPOINTER)nSet,SQL_IS_UINTEGER);
846*cdf0e10cSrcweir }
847*cdf0e10cSrcweir //------------------------------------------------------------------------------
848*cdf0e10cSrcweir void OStatement_Base::setEscapeProcessing( const sal_Bool _bEscapeProc )
849*cdf0e10cSrcweir {
850*cdf0e10cSrcweir 	OSL_ENSURE(m_aStatementHandle,"StatementHandle is null!");
851*cdf0e10cSrcweir     SQLUINTEGER nEscapeProc( _bEscapeProc ? SQL_NOSCAN_OFF : SQL_NOSCAN_ON );
852*cdf0e10cSrcweir 	SQLRETURN nRetCode = N3SQLSetStmtAttr( m_aStatementHandle, SQL_ATTR_NOSCAN, (SQLPOINTER)nEscapeProc, SQL_IS_UINTEGER );
853*cdf0e10cSrcweir     (void)nRetCode;
854*cdf0e10cSrcweir }
855*cdf0e10cSrcweir 
856*cdf0e10cSrcweir //------------------------------------------------------------------------------
857*cdf0e10cSrcweir void OStatement_Base::setFetchDirection(sal_Int32 _par0)
858*cdf0e10cSrcweir {
859*cdf0e10cSrcweir 	OSL_ENSURE(m_aStatementHandle,"StatementHandle is null!");
860*cdf0e10cSrcweir 	sal_Int32 nCursType = 0;
861*cdf0e10cSrcweir 	SQLRETURN nRetCode	= SQL_SUCCESS;
862*cdf0e10cSrcweir 	if(_par0 == FetchDirection::FORWARD)
863*cdf0e10cSrcweir 	{
864*cdf0e10cSrcweir 		nCursType = SQL_NONSCROLLABLE;
865*cdf0e10cSrcweir 		nRetCode = N3SQLSetStmtAttr(m_aStatementHandle,SQL_ATTR_CURSOR_SCROLLABLE,(SQLPOINTER)nCursType,SQL_IS_UINTEGER);
866*cdf0e10cSrcweir 	}
867*cdf0e10cSrcweir 	else if(_par0 == FetchDirection::REVERSE)
868*cdf0e10cSrcweir 	{
869*cdf0e10cSrcweir 		nCursType = SQL_SCROLLABLE;
870*cdf0e10cSrcweir 		nRetCode = N3SQLSetStmtAttr(m_aStatementHandle,SQL_ATTR_CURSOR_SCROLLABLE,(SQLPOINTER)nCursType,SQL_IS_UINTEGER);
871*cdf0e10cSrcweir 	}
872*cdf0e10cSrcweir     OSL_UNUSED( nRetCode );
873*cdf0e10cSrcweir }
874*cdf0e10cSrcweir //------------------------------------------------------------------------------
875*cdf0e10cSrcweir void OStatement_Base::setFetchSize(sal_Int32 _par0)
876*cdf0e10cSrcweir {
877*cdf0e10cSrcweir 	OSL_ENSURE(m_aStatementHandle,"StatementHandle is null!");
878*cdf0e10cSrcweir 	OSL_ENSURE(_par0>0,"Illegal fetch size!");
879*cdf0e10cSrcweir 	if ( _par0 > 0 )
880*cdf0e10cSrcweir 	{
881*cdf0e10cSrcweir 
882*cdf0e10cSrcweir 		SQLRETURN nRetCode = N3SQLSetStmtAttr(m_aStatementHandle,SQL_ATTR_ROW_ARRAY_SIZE,(SQLPOINTER)_par0,SQL_IS_UINTEGER);
883*cdf0e10cSrcweir 
884*cdf0e10cSrcweir 		delete m_pRowStatusArray;
885*cdf0e10cSrcweir 		m_pRowStatusArray = new SQLUSMALLINT[_par0];
886*cdf0e10cSrcweir 		nRetCode = N3SQLSetStmtAttr(m_aStatementHandle,SQL_ATTR_ROW_STATUS_PTR,m_pRowStatusArray,SQL_IS_POINTER);
887*cdf0e10cSrcweir 	}
888*cdf0e10cSrcweir }
889*cdf0e10cSrcweir //------------------------------------------------------------------------------
890*cdf0e10cSrcweir void OStatement_Base::setMaxFieldSize(sal_Int32 _par0)
891*cdf0e10cSrcweir {
892*cdf0e10cSrcweir 	OSL_ENSURE(m_aStatementHandle,"StatementHandle is null!");
893*cdf0e10cSrcweir 	N3SQLSetStmtAttr(m_aStatementHandle,SQL_ATTR_MAX_LENGTH,(SQLPOINTER)_par0,SQL_IS_UINTEGER);
894*cdf0e10cSrcweir }
895*cdf0e10cSrcweir //------------------------------------------------------------------------------
896*cdf0e10cSrcweir void OStatement_Base::setCursorName(const ::rtl::OUString &_par0)
897*cdf0e10cSrcweir {
898*cdf0e10cSrcweir 	OSL_ENSURE(m_aStatementHandle,"StatementHandle is null!");
899*cdf0e10cSrcweir 	::rtl::OString aName(::rtl::OUStringToOString(_par0,getOwnConnection()->getTextEncoding()));
900*cdf0e10cSrcweir 	N3SQLSetCursorName(m_aStatementHandle,(SDB_ODBC_CHAR*)aName.getStr(),(SQLSMALLINT)aName.getLength());
901*cdf0e10cSrcweir }
902*cdf0e10cSrcweir // -------------------------------------------------------------------------
903*cdf0e10cSrcweir sal_Bool OStatement_Base::isUsingBookmarks() const
904*cdf0e10cSrcweir {
905*cdf0e10cSrcweir 	OSL_ENSURE(m_aStatementHandle,"StatementHandle is null!");
906*cdf0e10cSrcweir 	sal_uInt32 nValue = SQL_UB_OFF;
907*cdf0e10cSrcweir 	SQLRETURN nRetCode = N3SQLGetStmtAttr(m_aStatementHandle,SQL_ATTR_USE_BOOKMARKS,&nValue,SQL_IS_UINTEGER,NULL);
908*cdf0e10cSrcweir     OSL_UNUSED( nRetCode );
909*cdf0e10cSrcweir 	return nValue != SQL_UB_OFF;
910*cdf0e10cSrcweir }
911*cdf0e10cSrcweir // -------------------------------------------------------------------------
912*cdf0e10cSrcweir sal_Bool OStatement_Base::getEscapeProcessing() const
913*cdf0e10cSrcweir {
914*cdf0e10cSrcweir 	OSL_ENSURE( m_aStatementHandle, "StatementHandle is null!" );
915*cdf0e10cSrcweir 	sal_uInt32 nValue = SQL_NOSCAN_OFF;
916*cdf0e10cSrcweir 	SQLRETURN nRetCode = N3SQLGetStmtAttr( m_aStatementHandle, SQL_ATTR_NOSCAN, &nValue, SQL_IS_UINTEGER, NULL );
917*cdf0e10cSrcweir     (void)nRetCode;
918*cdf0e10cSrcweir 	return nValue == SQL_NOSCAN_OFF;
919*cdf0e10cSrcweir }
920*cdf0e10cSrcweir // -------------------------------------------------------------------------
921*cdf0e10cSrcweir void OStatement_Base::setUsingBookmarks(sal_Bool _bUseBookmark)
922*cdf0e10cSrcweir {
923*cdf0e10cSrcweir 	OSL_ENSURE(m_aStatementHandle,"StatementHandle is null!");
924*cdf0e10cSrcweir 	sal_uInt32 nValue = _bUseBookmark ? SQL_UB_VARIABLE : SQL_UB_OFF;
925*cdf0e10cSrcweir     SQLRETURN nRetCode = N3SQLSetStmtAttr(m_aStatementHandle,SQL_ATTR_USE_BOOKMARKS,(SQLPOINTER)nValue,SQL_IS_UINTEGER);
926*cdf0e10cSrcweir     OSL_UNUSED( nRetCode );
927*cdf0e10cSrcweir }
928*cdf0e10cSrcweir // -------------------------------------------------------------------------
929*cdf0e10cSrcweir ::cppu::IPropertyArrayHelper* OStatement_Base::createArrayHelper( ) const
930*cdf0e10cSrcweir {
931*cdf0e10cSrcweir 	Sequence< Property > aProps(10);
932*cdf0e10cSrcweir 	Property* pProperties = aProps.getArray();
933*cdf0e10cSrcweir 	sal_Int32 nPos = 0;
934*cdf0e10cSrcweir 	DECL_PROP0(CURSORNAME,	::rtl::OUString);
935*cdf0e10cSrcweir 	DECL_BOOL_PROP0(ESCAPEPROCESSING);
936*cdf0e10cSrcweir 	DECL_PROP0(FETCHDIRECTION,sal_Int32);
937*cdf0e10cSrcweir 	DECL_PROP0(FETCHSIZE,	sal_Int32);
938*cdf0e10cSrcweir 	DECL_PROP0(MAXFIELDSIZE,sal_Int32);
939*cdf0e10cSrcweir 	DECL_PROP0(MAXROWS,		sal_Int32);
940*cdf0e10cSrcweir 	DECL_PROP0(QUERYTIMEOUT,sal_Int32);
941*cdf0e10cSrcweir 	DECL_PROP0(RESULTSETCONCURRENCY,sal_Int32);
942*cdf0e10cSrcweir 	DECL_PROP0(RESULTSETTYPE,sal_Int32);
943*cdf0e10cSrcweir 	DECL_BOOL_PROP0(USEBOOKMARKS);
944*cdf0e10cSrcweir 
945*cdf0e10cSrcweir 	return new ::cppu::OPropertyArrayHelper(aProps);
946*cdf0e10cSrcweir }
947*cdf0e10cSrcweir 
948*cdf0e10cSrcweir // -------------------------------------------------------------------------
949*cdf0e10cSrcweir ::cppu::IPropertyArrayHelper & OStatement_Base::getInfoHelper()
950*cdf0e10cSrcweir {
951*cdf0e10cSrcweir 	return *const_cast<OStatement_Base*>(this)->getArrayHelper();
952*cdf0e10cSrcweir }
953*cdf0e10cSrcweir // -------------------------------------------------------------------------
954*cdf0e10cSrcweir sal_Bool OStatement_Base::convertFastPropertyValue(
955*cdf0e10cSrcweir 							Any & rConvertedValue,
956*cdf0e10cSrcweir 							Any & rOldValue,
957*cdf0e10cSrcweir 							sal_Int32 nHandle,
958*cdf0e10cSrcweir 							const Any& rValue )
959*cdf0e10cSrcweir 								throw (::com::sun::star::lang::IllegalArgumentException)
960*cdf0e10cSrcweir {
961*cdf0e10cSrcweir 	sal_Bool bConverted = sal_False;
962*cdf0e10cSrcweir 	try
963*cdf0e10cSrcweir 	{
964*cdf0e10cSrcweir 		switch(nHandle)
965*cdf0e10cSrcweir 		{
966*cdf0e10cSrcweir 			case PROPERTY_ID_QUERYTIMEOUT:
967*cdf0e10cSrcweir 				bConverted = ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, getQueryTimeOut());
968*cdf0e10cSrcweir 				break;
969*cdf0e10cSrcweir 
970*cdf0e10cSrcweir 			case PROPERTY_ID_MAXFIELDSIZE:
971*cdf0e10cSrcweir 				bConverted = ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, getMaxFieldSize());
972*cdf0e10cSrcweir 				break;
973*cdf0e10cSrcweir 
974*cdf0e10cSrcweir 			case PROPERTY_ID_MAXROWS:
975*cdf0e10cSrcweir 				bConverted = ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, getMaxRows());
976*cdf0e10cSrcweir 				break;
977*cdf0e10cSrcweir 
978*cdf0e10cSrcweir 			case PROPERTY_ID_CURSORNAME:
979*cdf0e10cSrcweir 				bConverted = ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, getCursorName());
980*cdf0e10cSrcweir 				break;
981*cdf0e10cSrcweir 
982*cdf0e10cSrcweir 			case PROPERTY_ID_RESULTSETCONCURRENCY:
983*cdf0e10cSrcweir 				bConverted = ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, getResultSetConcurrency());
984*cdf0e10cSrcweir 				break;
985*cdf0e10cSrcweir 
986*cdf0e10cSrcweir 			case PROPERTY_ID_RESULTSETTYPE:
987*cdf0e10cSrcweir 				bConverted = ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, getResultSetType());
988*cdf0e10cSrcweir 				break;
989*cdf0e10cSrcweir 
990*cdf0e10cSrcweir 			case PROPERTY_ID_FETCHDIRECTION:
991*cdf0e10cSrcweir 				bConverted = ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, getFetchDirection());
992*cdf0e10cSrcweir 				break;
993*cdf0e10cSrcweir 
994*cdf0e10cSrcweir 			case PROPERTY_ID_FETCHSIZE:
995*cdf0e10cSrcweir 				bConverted = ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, getFetchSize());
996*cdf0e10cSrcweir 				break;
997*cdf0e10cSrcweir 
998*cdf0e10cSrcweir 			case PROPERTY_ID_USEBOOKMARKS:
999*cdf0e10cSrcweir 				bConverted = ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, isUsingBookmarks());
1000*cdf0e10cSrcweir 				break;
1001*cdf0e10cSrcweir 
1002*cdf0e10cSrcweir 			case PROPERTY_ID_ESCAPEPROCESSING:
1003*cdf0e10cSrcweir 				bConverted = ::comphelper::tryPropertyValue( rConvertedValue, rOldValue, rValue, getEscapeProcessing() );
1004*cdf0e10cSrcweir 				break;
1005*cdf0e10cSrcweir 
1006*cdf0e10cSrcweir 		}
1007*cdf0e10cSrcweir 	}
1008*cdf0e10cSrcweir 	catch(const SQLException&)
1009*cdf0e10cSrcweir 	{
1010*cdf0e10cSrcweir 		//	throw Exception(e.Message,*this);
1011*cdf0e10cSrcweir 	}
1012*cdf0e10cSrcweir 	return bConverted;
1013*cdf0e10cSrcweir }
1014*cdf0e10cSrcweir // -------------------------------------------------------------------------
1015*cdf0e10cSrcweir void OStatement_Base::setFastPropertyValue_NoBroadcast(sal_Int32 nHandle,const Any& rValue) throw (Exception)
1016*cdf0e10cSrcweir {
1017*cdf0e10cSrcweir 	try
1018*cdf0e10cSrcweir 	{
1019*cdf0e10cSrcweir 		switch(nHandle)
1020*cdf0e10cSrcweir 		{
1021*cdf0e10cSrcweir 			case PROPERTY_ID_QUERYTIMEOUT:
1022*cdf0e10cSrcweir 				setQueryTimeOut(comphelper::getINT32(rValue));
1023*cdf0e10cSrcweir 				break;
1024*cdf0e10cSrcweir 			case PROPERTY_ID_MAXFIELDSIZE:
1025*cdf0e10cSrcweir 				setMaxFieldSize(comphelper::getINT32(rValue));
1026*cdf0e10cSrcweir 				break;
1027*cdf0e10cSrcweir 			case PROPERTY_ID_MAXROWS:
1028*cdf0e10cSrcweir 				setMaxRows(comphelper::getINT32(rValue));
1029*cdf0e10cSrcweir 				break;
1030*cdf0e10cSrcweir 			case PROPERTY_ID_CURSORNAME:
1031*cdf0e10cSrcweir 				setCursorName(comphelper::getString(rValue));
1032*cdf0e10cSrcweir 				break;
1033*cdf0e10cSrcweir 			case PROPERTY_ID_RESULTSETCONCURRENCY:
1034*cdf0e10cSrcweir 				setResultSetConcurrency(comphelper::getINT32(rValue));
1035*cdf0e10cSrcweir 				break;
1036*cdf0e10cSrcweir 			case PROPERTY_ID_RESULTSETTYPE:
1037*cdf0e10cSrcweir 				setResultSetType(comphelper::getINT32(rValue));
1038*cdf0e10cSrcweir 				break;
1039*cdf0e10cSrcweir 			case PROPERTY_ID_FETCHDIRECTION:
1040*cdf0e10cSrcweir 				setFetchDirection(comphelper::getINT32(rValue));
1041*cdf0e10cSrcweir 				break;
1042*cdf0e10cSrcweir 			case PROPERTY_ID_FETCHSIZE:
1043*cdf0e10cSrcweir 				setFetchSize(comphelper::getINT32(rValue));
1044*cdf0e10cSrcweir 				break;
1045*cdf0e10cSrcweir 			case PROPERTY_ID_USEBOOKMARKS:
1046*cdf0e10cSrcweir 				setUsingBookmarks(comphelper::getBOOL(rValue));
1047*cdf0e10cSrcweir 				break;
1048*cdf0e10cSrcweir             case PROPERTY_ID_ESCAPEPROCESSING:
1049*cdf0e10cSrcweir                 setEscapeProcessing( ::comphelper::getBOOL( rValue ) );
1050*cdf0e10cSrcweir                 break;
1051*cdf0e10cSrcweir             default:
1052*cdf0e10cSrcweir                 OSL_ENSURE( false, "OStatement_Base::setFastPropertyValue_NoBroadcast: what property?" );
1053*cdf0e10cSrcweir                 break;
1054*cdf0e10cSrcweir 		}
1055*cdf0e10cSrcweir 	}
1056*cdf0e10cSrcweir 	catch(const SQLException& )
1057*cdf0e10cSrcweir 	{
1058*cdf0e10cSrcweir 		//	throw Exception(e.Message,*this);
1059*cdf0e10cSrcweir 	}
1060*cdf0e10cSrcweir }
1061*cdf0e10cSrcweir // -------------------------------------------------------------------------
1062*cdf0e10cSrcweir void OStatement_Base::getFastPropertyValue(Any& rValue,sal_Int32 nHandle) const
1063*cdf0e10cSrcweir {
1064*cdf0e10cSrcweir 	switch(nHandle)
1065*cdf0e10cSrcweir 	{
1066*cdf0e10cSrcweir 		case PROPERTY_ID_QUERYTIMEOUT:
1067*cdf0e10cSrcweir 			rValue <<= getQueryTimeOut();
1068*cdf0e10cSrcweir 			break;
1069*cdf0e10cSrcweir 		case PROPERTY_ID_MAXFIELDSIZE:
1070*cdf0e10cSrcweir 			rValue <<= getMaxFieldSize();
1071*cdf0e10cSrcweir 			break;
1072*cdf0e10cSrcweir 		case PROPERTY_ID_MAXROWS:
1073*cdf0e10cSrcweir 			rValue <<= getMaxRows();
1074*cdf0e10cSrcweir 			break;
1075*cdf0e10cSrcweir 		case PROPERTY_ID_CURSORNAME:
1076*cdf0e10cSrcweir 			rValue <<= getCursorName();
1077*cdf0e10cSrcweir 			break;
1078*cdf0e10cSrcweir 		case PROPERTY_ID_RESULTSETCONCURRENCY:
1079*cdf0e10cSrcweir 			rValue <<= getResultSetConcurrency();
1080*cdf0e10cSrcweir 			break;
1081*cdf0e10cSrcweir 		case PROPERTY_ID_RESULTSETTYPE:
1082*cdf0e10cSrcweir 			rValue <<= getResultSetType();
1083*cdf0e10cSrcweir 			break;
1084*cdf0e10cSrcweir 		case PROPERTY_ID_FETCHDIRECTION:
1085*cdf0e10cSrcweir 			rValue <<= getFetchDirection();
1086*cdf0e10cSrcweir 			break;
1087*cdf0e10cSrcweir 		case PROPERTY_ID_FETCHSIZE:
1088*cdf0e10cSrcweir 			rValue <<= getFetchSize();
1089*cdf0e10cSrcweir 			break;
1090*cdf0e10cSrcweir 		case PROPERTY_ID_USEBOOKMARKS:
1091*cdf0e10cSrcweir 			rValue <<= isUsingBookmarks();
1092*cdf0e10cSrcweir 			break;
1093*cdf0e10cSrcweir         case PROPERTY_ID_ESCAPEPROCESSING:
1094*cdf0e10cSrcweir             rValue <<= getEscapeProcessing();
1095*cdf0e10cSrcweir             break;
1096*cdf0e10cSrcweir         default:
1097*cdf0e10cSrcweir             OSL_ENSURE( false, "OStatement_Base::getFastPropertyValue: what property?" );
1098*cdf0e10cSrcweir             break;
1099*cdf0e10cSrcweir 	}
1100*cdf0e10cSrcweir }
1101*cdf0e10cSrcweir // -------------------------------------------------------------------------
1102*cdf0e10cSrcweir IMPLEMENT_SERVICE_INFO(OStatement,"com.sun.star.sdbcx.OStatement","com.sun.star.sdbc.Statement");
1103*cdf0e10cSrcweir // -----------------------------------------------------------------------------
1104*cdf0e10cSrcweir void SAL_CALL OStatement_Base::acquire() throw()
1105*cdf0e10cSrcweir {
1106*cdf0e10cSrcweir 	OStatement_BASE::acquire();
1107*cdf0e10cSrcweir }
1108*cdf0e10cSrcweir // -----------------------------------------------------------------------------
1109*cdf0e10cSrcweir void SAL_CALL OStatement_Base::release() throw()
1110*cdf0e10cSrcweir {
1111*cdf0e10cSrcweir 	OStatement_BASE::release();
1112*cdf0e10cSrcweir }
1113*cdf0e10cSrcweir // -----------------------------------------------------------------------------
1114*cdf0e10cSrcweir void SAL_CALL OStatement::acquire() throw()
1115*cdf0e10cSrcweir {
1116*cdf0e10cSrcweir 	OStatement_BASE2::acquire();
1117*cdf0e10cSrcweir }
1118*cdf0e10cSrcweir // -----------------------------------------------------------------------------
1119*cdf0e10cSrcweir void SAL_CALL OStatement::release() throw()
1120*cdf0e10cSrcweir {
1121*cdf0e10cSrcweir 	OStatement_BASE2::release();
1122*cdf0e10cSrcweir }
1123*cdf0e10cSrcweir // -----------------------------------------------------------------------------
1124*cdf0e10cSrcweir OResultSet* OStatement_Base::createResulSet()
1125*cdf0e10cSrcweir {
1126*cdf0e10cSrcweir 	return new OResultSet(m_aStatementHandle,this);
1127*cdf0e10cSrcweir }
1128*cdf0e10cSrcweir // -----------------------------------------------------------------------------
1129*cdf0e10cSrcweir Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL OStatement_Base::getPropertySetInfo(  ) throw(RuntimeException)
1130*cdf0e10cSrcweir {
1131*cdf0e10cSrcweir 	return ::cppu::OPropertySetHelper::createPropertySetInfo(getInfoHelper());
1132*cdf0e10cSrcweir }
1133*cdf0e10cSrcweir // -----------------------------------------------------------------------------
1134*cdf0e10cSrcweir SQLUINTEGER OStatement_Base::getCursorProperties(SQLINTEGER _nCursorType,sal_Bool bFirst)
1135*cdf0e10cSrcweir {
1136*cdf0e10cSrcweir 	SQLUINTEGER nValueLen = 0;
1137*cdf0e10cSrcweir 	try
1138*cdf0e10cSrcweir 	{
1139*cdf0e10cSrcweir 		SQLUSMALLINT nAskFor = SQL_FORWARD_ONLY_CURSOR_ATTRIBUTES2;
1140*cdf0e10cSrcweir 		if(SQL_CURSOR_KEYSET_DRIVEN == _nCursorType)
1141*cdf0e10cSrcweir 			nAskFor = bFirst ? SQL_KEYSET_CURSOR_ATTRIBUTES1 : SQL_KEYSET_CURSOR_ATTRIBUTES2;
1142*cdf0e10cSrcweir 		else if(SQL_CURSOR_STATIC  == _nCursorType)
1143*cdf0e10cSrcweir 			nAskFor = bFirst ? SQL_STATIC_CURSOR_ATTRIBUTES1 : SQL_STATIC_CURSOR_ATTRIBUTES2;
1144*cdf0e10cSrcweir 		else if(SQL_CURSOR_FORWARD_ONLY == _nCursorType)
1145*cdf0e10cSrcweir 			nAskFor = bFirst ? SQL_FORWARD_ONLY_CURSOR_ATTRIBUTES1 : SQL_FORWARD_ONLY_CURSOR_ATTRIBUTES2;
1146*cdf0e10cSrcweir 		else if(SQL_CURSOR_DYNAMIC == _nCursorType)
1147*cdf0e10cSrcweir 			nAskFor = bFirst ? SQL_DYNAMIC_CURSOR_ATTRIBUTES1 : SQL_DYNAMIC_CURSOR_ATTRIBUTES2;
1148*cdf0e10cSrcweir 
1149*cdf0e10cSrcweir 
1150*cdf0e10cSrcweir 		OTools::GetInfo(getOwnConnection(),getConnectionHandle(),nAskFor,nValueLen,NULL);
1151*cdf0e10cSrcweir 	}
1152*cdf0e10cSrcweir 	catch(Exception&)
1153*cdf0e10cSrcweir 	{ // we don't want our result destroy here
1154*cdf0e10cSrcweir 		nValueLen = 0;
1155*cdf0e10cSrcweir 	}
1156*cdf0e10cSrcweir 	return nValueLen;
1157*cdf0e10cSrcweir }
1158*cdf0e10cSrcweir // -----------------------------------------------------------------------------
1159