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