1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_connectivity.hxx"
30 #include "ado/AStatement.hxx"
31 #include "ado/AConnection.hxx"
32 #include "ado/AResultSet.hxx"
33 #include <comphelper/property.hxx>
34 #include <comphelper/uno3.hxx>
35 #include <osl/thread.h>
36 #include <cppuhelper/typeprovider.hxx>
37 #include <comphelper/sequence.hxx>
38 #include <com/sun/star/sdbc/ResultSetConcurrency.hpp>
39 #include <com/sun/star/sdbc/ResultSetType.hpp>
40 #include <com/sun/star/sdbc/FetchDirection.hpp>
41 #include "connectivity/dbexception.hxx"
42 #include <comphelper/types.hxx>
43 
44 #undef max
45 
46 #include <algorithm>
47 
48 using namespace ::comphelper;
49 
50 #define CHECK_RETURN(x)													\
51 	if(!x)																\
52 		ADOS::ThrowException(*m_pConnection->getConnection(),*this);
53 
54 
55 
56 using namespace connectivity::ado;
57 
58 //------------------------------------------------------------------------------
59 using namespace com::sun::star::uno;
60 using namespace com::sun::star::lang;
61 using namespace com::sun::star::beans;
62 using namespace com::sun::star::sdbc;
63 using namespace ::std;
64 //------------------------------------------------------------------------------
65 OStatement_Base::OStatement_Base(OConnection* _pConnection ) :	OStatement_BASE(m_aMutex)
66 														,OPropertySetHelper(OStatement_BASE::rBHelper)
67 														,OSubComponent<OStatement_Base, OStatement_BASE>((::cppu::OWeakObject*)_pConnection, this)
68 														,m_pConnection(_pConnection)
69 														,m_nFetchSize(1)
70 														,m_nMaxRows(0)
71 														,m_eLockType(adLockReadOnly)
72 														,m_eCursorType(adOpenForwardOnly)
73 {
74 	osl_incrementInterlockedCount( &m_refCount );
75 
76 	m_Command.Create();
77 	if(m_Command.IsValid())
78 		m_Command.putref_ActiveConnection(m_pConnection->getConnection());
79 	else
80 		ADOS::ThrowException(*m_pConnection->getConnection(),*this);
81 
82 	m_RecordsAffected.setNoArg();
83 	m_Parameters.setNoArg();
84 
85 	m_pConnection->acquire();
86 
87 	osl_decrementInterlockedCount( &m_refCount );
88 }
89 //------------------------------------------------------------------------------
90 void OStatement_Base::disposeResultSet()
91 {
92 	// free the cursor if alive
93 	Reference< XComponent > xComp(m_xResultSet.get(), UNO_QUERY);
94 	if (xComp.is())
95 		xComp->dispose();
96 	m_xResultSet = Reference< XResultSet>();
97 }
98 
99 //------------------------------------------------------------------------------
100 void OStatement_Base::disposing()
101 {
102 	::osl::MutexGuard aGuard(m_aMutex);
103 
104 
105 	disposeResultSet();
106 
107 	if ( m_Command.IsValid() )
108 		m_Command.putref_ActiveConnection( NULL );
109 	m_Command.clear();
110 
111 	if ( m_RecordSet.IsValid() )
112 		m_RecordSet.PutRefDataSource( NULL );
113 	m_RecordSet.clear();
114 
115 	if (m_pConnection)
116 		m_pConnection->release();
117 
118 	dispose_ChildImpl();
119 	OStatement_BASE::disposing();
120 }
121 //-----------------------------------------------------------------------------
122 void SAL_CALL OStatement_Base::release() throw()
123 {
124 	relase_ChildImpl();
125 }
126 //-----------------------------------------------------------------------------
127 Any SAL_CALL OStatement_Base::queryInterface( const Type & rType ) throw(RuntimeException)
128 {
129 	Any aRet = OStatement_BASE::queryInterface(rType);
130 	return aRet.hasValue() ? aRet : OPropertySetHelper::queryInterface(rType);
131 }
132 // -------------------------------------------------------------------------
133 ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL OStatement_Base::getTypes(  ) throw(::com::sun::star::uno::RuntimeException)
134 {
135 	::cppu::OTypeCollection aTypes(	::getCppuType( (const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XMultiPropertySet > *)0 ),
136 									::getCppuType( (const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XFastPropertySet > *)0 ),
137 									::getCppuType( (const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > *)0 ));
138 
139 	return ::comphelper::concatSequences(aTypes.getTypes(),OStatement_BASE::getTypes());
140 }
141 
142 // -------------------------------------------------------------------------
143 
144 void SAL_CALL OStatement_Base::cancel(  ) throw(RuntimeException)
145 {
146 	::osl::MutexGuard aGuard( m_aMutex );
147 	checkDisposed(OStatement_BASE::rBHelper.bDisposed);
148 
149 
150 	CHECK_RETURN(m_Command.Cancel())
151 }
152 // -------------------------------------------------------------------------
153 
154 void SAL_CALL OStatement_Base::close(  ) throw(SQLException, RuntimeException)
155 {
156 	{
157 		::osl::MutexGuard aGuard( m_aMutex );
158 		checkDisposed(OStatement_BASE::rBHelper.bDisposed);
159 
160 	}
161 	dispose();
162 }
163 // -------------------------------------------------------------------------
164 
165 void SAL_CALL OStatement::clearBatch(  ) throw(SQLException, RuntimeException)
166 {
167 
168 }
169 // -------------------------------------------------------------------------
170 
171 void OStatement_Base::reset() throw (SQLException)
172 {
173 	::osl::MutexGuard aGuard( m_aMutex );
174 	checkDisposed(OStatement_BASE::rBHelper.bDisposed);
175 
176 
177 	clearWarnings ();
178 
179 	if (m_xResultSet.get().is())
180 		clearMyResultSet();
181 }
182 //--------------------------------------------------------------------
183 // clearMyResultSet
184 // If a ResultSet was created for this Statement, close it
185 //--------------------------------------------------------------------
186 
187 void OStatement_Base::clearMyResultSet () throw (SQLException)
188 {
189 	::osl::MutexGuard aGuard( m_aMutex );
190 	checkDisposed(OStatement_BASE::rBHelper.bDisposed);
191 
192     try
193     {
194 	    Reference<XCloseable> xCloseable;
195 	    if ( ::comphelper::query_interface( m_xResultSet.get(), xCloseable ) )
196 		    xCloseable->close();
197     }
198     catch( const DisposedException& ) { }
199 
200     m_xResultSet = Reference< XResultSet >();
201 }
202 //--------------------------------------------------------------------
203 sal_Int32 OStatement_Base::getRowCount () throw( SQLException)
204 {
205 	::osl::MutexGuard aGuard( m_aMutex );
206 	checkDisposed(OStatement_BASE::rBHelper.bDisposed);
207 
208 
209 	return m_RecordsAffected;
210 }
211 //--------------------------------------------------------------------
212 // getPrecision
213 // Given a SQL type, return the maximum precision for the column.
214 // Returns -1 if not known
215 //--------------------------------------------------------------------
216 
217 sal_Int32 OStatement_Base::getPrecision ( sal_Int32 sqlType)
218 {
219 	::osl::MutexGuard aGuard( m_aMutex );
220 	checkDisposed(OStatement_BASE::rBHelper.bDisposed);
221 
222 
223 	sal_Int32 prec = -1;
224 	OTypeInfo aInfo;
225 	aInfo.nType = (sal_Int16)sqlType;
226 	if (!m_aTypeInfo.empty())
227 	{
228 		::std::vector<OTypeInfo>::const_iterator aIter = ::std::find(m_aTypeInfo.begin(),m_aTypeInfo.end(),aInfo);
229 		for(;aIter != m_aTypeInfo.end();++aIter)
230 		{
231 			prec = ::std::max(prec,(*aIter).nPrecision);
232 		}
233 	}
234 
235 	return prec;
236 }
237 //--------------------------------------------------------------------
238 // setWarning
239 // Sets the warning
240 //--------------------------------------------------------------------
241 
242 void OStatement_Base::setWarning (const	SQLWarning &ex) throw( SQLException)
243 {
244 	::osl::MutexGuard aGuard( m_aMutex );
245 	checkDisposed(OStatement_BASE::rBHelper.bDisposed);
246 
247 
248 	m_aLastWarning = ex;
249 }
250 // -------------------------------------------------------------------------
251 void OStatement_Base::assignRecordSet( ADORecordset* _pRS )
252 {
253 	WpADORecordset aOldRS( m_RecordSet );
254 	m_RecordSet = WpADORecordset( _pRS );
255 
256 	if ( aOldRS.IsValid() )
257 		aOldRS.PutRefDataSource( NULL );
258 
259 	if ( m_RecordSet.IsValid() )
260 		m_RecordSet.PutRefDataSource( (IDispatch*)m_Command );
261 }
262 // -------------------------------------------------------------------------
263 sal_Bool SAL_CALL OStatement_Base::execute( const ::rtl::OUString& sql ) throw(SQLException, RuntimeException)
264 {
265 	::osl::MutexGuard aGuard( m_aMutex );
266 	checkDisposed(OStatement_BASE::rBHelper.bDisposed);
267 
268 
269 	// Reset the statement handle and warning
270 
271 	reset();
272 
273 	try
274 	{
275 		ADORecordset* pSet = NULL;
276 		CHECK_RETURN(m_Command.put_CommandText(sql))
277 		CHECK_RETURN(m_Command.Execute(m_RecordsAffected,m_Parameters,adCmdText,&pSet))
278 
279 		assignRecordSet( pSet );
280 	}
281 	catch (SQLWarning& ex)
282 	{
283 
284 		// Save pointer to warning and save with ResultSet
285 		// object once it is created.
286 
287 		m_aLastWarning = ex;
288 	}
289 
290 	return m_RecordSet.IsValid();
291 }
292 // -------------------------------------------------------------------------
293 Reference< XResultSet > SAL_CALL OStatement_Base::executeQuery( const ::rtl::OUString& sql ) throw(SQLException, RuntimeException)
294 {
295 	::osl::MutexGuard aGuard( m_aMutex );
296 	checkDisposed(OStatement_BASE::rBHelper.bDisposed);
297 
298 
299 	reset();
300 
301 	m_xResultSet = WeakReference<XResultSet>(NULL);
302 
303 	WpADORecordset aSet;
304 	aSet.Create();
305 	CHECK_RETURN(m_Command.put_CommandText(sql))
306 	OLEVariant aCmd;
307 	aCmd.setIDispatch(m_Command);
308 	OLEVariant aCon;
309 	aCon.setNoArg();
310 	CHECK_RETURN(aSet.put_CacheSize(m_nFetchSize))
311 	CHECK_RETURN(aSet.put_MaxRecords(m_nMaxRows))
312 	CHECK_RETURN(aSet.Open(aCmd,aCon,m_eCursorType,m_eLockType,adOpenUnspecified))
313 
314 
315 	CHECK_RETURN(aSet.get_CacheSize(m_nFetchSize))
316 	CHECK_RETURN(aSet.get_MaxRecords(m_nMaxRows))
317 	CHECK_RETURN(aSet.get_CursorType(m_eCursorType))
318 	CHECK_RETURN(aSet.get_LockType(m_eLockType))
319 
320 	OResultSet* pSet = new OResultSet(aSet,this);
321 	Reference< XResultSet > xRs = pSet;
322 	pSet->construct();
323 
324 	m_xResultSet = WeakReference<XResultSet>(xRs);
325 
326 	return xRs;
327 }
328 // -------------------------------------------------------------------------
329 
330 Reference< XConnection > SAL_CALL OStatement_Base::getConnection(  ) throw(SQLException, RuntimeException)
331 {
332 	::osl::MutexGuard aGuard( m_aMutex );
333 	checkDisposed(OStatement_BASE::rBHelper.bDisposed);
334 
335 
336 	return (Reference< XConnection >)m_pConnection;
337 }
338 // -------------------------------------------------------------------------
339 
340 Any SAL_CALL OStatement::queryInterface( const Type & rType ) throw(RuntimeException)
341 {
342 	Any aRet = ::cppu::queryInterface(rType,static_cast< XBatchExecution*> (this));
343 	return aRet.hasValue() ? aRet : OStatement_Base::queryInterface(rType);
344 }
345 // -------------------------------------------------------------------------
346 
347 void SAL_CALL OStatement::addBatch( const ::rtl::OUString& sql ) throw(SQLException, RuntimeException)
348 {
349 	::osl::MutexGuard aGuard( m_aMutex );
350 	checkDisposed(OStatement_BASE::rBHelper.bDisposed);
351 
352 
353 	m_aBatchList.push_back(sql);
354 }
355 // -------------------------------------------------------------------------
356 Sequence< sal_Int32 > SAL_CALL OStatement::executeBatch(  ) throw(SQLException, RuntimeException)
357 {
358 	::osl::MutexGuard aGuard( m_aMutex );
359 	checkDisposed(OStatement_BASE::rBHelper.bDisposed);
360 
361 
362 	reset();
363 
364 	::rtl::OUString aBatchSql;
365 	sal_Int32 nLen = 0;
366 	for(::std::list< ::rtl::OUString>::const_iterator i=m_aBatchList.begin();i != m_aBatchList.end();++i,++nLen)
367 		aBatchSql = aBatchSql + *i + ::rtl::OUString::createFromAscii(";");
368 
369 
370 	if ( m_RecordSet.IsValid() )
371 		m_RecordSet.PutRefDataSource( NULL );
372 	m_RecordSet.clear();
373 	m_RecordSet.Create();
374 
375 	CHECK_RETURN(m_Command.put_CommandText(aBatchSql))
376 	if ( m_RecordSet.IsValid() )
377 		m_RecordSet.PutRefDataSource((IDispatch*)m_Command);
378 
379 	CHECK_RETURN(m_RecordSet.UpdateBatch(adAffectAll))
380 
381 	ADORecordset* pSet=NULL;
382 	Sequence< sal_Int32 > aRet(nLen);
383 	sal_Int32* pArray = aRet.getArray();
384 	for(sal_Int32 j=0;j<nLen;++j)
385 	{
386 		pSet = NULL;
387 		OLEVariant aRecordsAffected;
388 		if(m_RecordSet.NextRecordset(aRecordsAffected,&pSet) && pSet)
389 		{
390 			assignRecordSet( pSet );
391 
392 			sal_Int32 nValue;
393 			if(m_RecordSet.get_RecordCount(nValue))
394 				pArray[j] = nValue;
395 		}
396 	}
397 	return aRet;
398 }
399 // -------------------------------------------------------------------------
400 
401 
402 sal_Int32 SAL_CALL OStatement_Base::executeUpdate( const ::rtl::OUString& sql ) throw(SQLException, RuntimeException)
403 {
404 	::osl::MutexGuard aGuard( m_aMutex );
405 	checkDisposed(OStatement_BASE::rBHelper.bDisposed);
406 
407 
408 	reset();
409 
410 	try {
411 		ADORecordset* pSet = NULL;
412 		CHECK_RETURN(m_Command.put_CommandText(sql))
413 		CHECK_RETURN(m_Command.Execute(m_RecordsAffected,m_Parameters,adCmdText|adExecuteNoRecords,&pSet))
414 	}
415 	catch (SQLWarning& ex) {
416 
417 		// Save pointer to warning and save with ResultSet
418 		// object once it is created.
419 
420 		m_aLastWarning = ex;
421 	}
422 	if(!m_RecordsAffected.isEmpty() && !m_RecordsAffected.isNull() && m_RecordsAffected.getType() != VT_ERROR)
423 		return m_RecordsAffected;
424 
425 	return 0;
426 }
427 // -------------------------------------------------------------------------
428 
429 Reference< XResultSet > SAL_CALL OStatement_Base::getResultSet(  ) throw(SQLException, RuntimeException)
430 {
431 	::osl::MutexGuard aGuard( m_aMutex );
432 	checkDisposed(OStatement_BASE::rBHelper.bDisposed);
433 
434 
435 	return m_xResultSet;
436 }
437 // -------------------------------------------------------------------------
438 
439 sal_Int32 SAL_CALL OStatement_Base::getUpdateCount(  ) throw(SQLException, RuntimeException)
440 {
441 	::osl::MutexGuard aGuard( m_aMutex );
442 	checkDisposed(OStatement_BASE::rBHelper.bDisposed);
443 
444 
445 	sal_Int32 nRet;
446 	if(m_RecordSet.IsValid() && m_RecordSet.get_RecordCount(nRet))
447 		return nRet;
448 	return -1;
449 }
450 // -------------------------------------------------------------------------
451 
452 sal_Bool SAL_CALL OStatement_Base::getMoreResults(  ) throw(SQLException, RuntimeException)
453 {
454 	::osl::MutexGuard aGuard( m_aMutex );
455 	checkDisposed(OStatement_BASE::rBHelper.bDisposed);
456 
457 
458 	SQLWarning	warning;
459 
460 	// clear previous warnings
461 
462 	clearWarnings ();
463 
464 	// Call SQLMoreResults
465 
466 	try
467 	{
468 		ADORecordset* pSet=NULL;
469 		OLEVariant aRecordsAffected;
470 		if(m_RecordSet.IsValid() && m_RecordSet.NextRecordset(aRecordsAffected,&pSet) && pSet)
471 			assignRecordSet( pSet );
472 	}
473 	catch (SQLWarning &ex)
474 	{
475 
476 		// Save pointer to warning and save with ResultSet
477 		// object once it is created.
478 
479 		warning = ex;
480 	}
481 	return m_RecordSet.IsValid();
482 }
483 // -------------------------------------------------------------------------
484 
485 // -------------------------------------------------------------------------
486 Any SAL_CALL OStatement_Base::getWarnings(  ) throw(SQLException, RuntimeException)
487 {
488 	::osl::MutexGuard aGuard( m_aMutex );
489 	checkDisposed(OStatement_BASE::rBHelper.bDisposed);
490 
491 
492 	return makeAny(m_aLastWarning);
493 }
494 // -------------------------------------------------------------------------
495 
496 // -------------------------------------------------------------------------
497 void SAL_CALL OStatement_Base::clearWarnings(  ) throw(SQLException, RuntimeException)
498 {
499 	::osl::MutexGuard aGuard( m_aMutex );
500 	checkDisposed(OStatement_BASE::rBHelper.bDisposed);
501 
502 
503 	m_aLastWarning = SQLWarning();
504 }
505 // -------------------------------------------------------------------------
506 //------------------------------------------------------------------------------
507 sal_Int32 OStatement_Base::getQueryTimeOut() const  throw(SQLException, RuntimeException)
508 {
509 	return m_Command.get_CommandTimeout();
510 }
511 //------------------------------------------------------------------------------
512 sal_Int32 OStatement_Base::getMaxRows() const throw(SQLException, RuntimeException)
513 {
514 	sal_Int32 nRet=-1;
515 	if(!(m_RecordSet.IsValid() && m_RecordSet.get_MaxRecords(nRet)))
516 		::dbtools::throwFunctionSequenceException(NULL);
517 	return nRet;
518 }
519 //------------------------------------------------------------------------------
520 sal_Int32 OStatement_Base::getResultSetConcurrency() const throw(SQLException, RuntimeException)
521 {
522 	return m_eLockType;
523 	sal_Int32 nValue=0;
524 	switch(m_eLockType)
525 	{
526 		case adLockReadOnly:
527 			nValue = ResultSetConcurrency::READ_ONLY;
528 			break;
529 		default:
530 			nValue = ResultSetConcurrency::UPDATABLE;
531 			break;
532 	}
533 
534 	return nValue;
535 }
536 //------------------------------------------------------------------------------
537 sal_Int32 OStatement_Base::getResultSetType() const throw(SQLException, RuntimeException)
538 {
539 	sal_Int32 nValue=0;
540 	switch(m_eCursorType)
541 	{
542 		case adOpenUnspecified:
543 		case adOpenForwardOnly:
544 			nValue = ResultSetType::FORWARD_ONLY;
545 			break;
546 		case adOpenStatic:
547 		case adOpenKeyset:
548 			nValue = ResultSetType::SCROLL_INSENSITIVE;
549 			break;
550 		case adOpenDynamic:
551 			nValue = ResultSetType::SCROLL_SENSITIVE;
552 			break;
553 	}
554 	return nValue;
555 }
556 //------------------------------------------------------------------------------
557 sal_Int32 OStatement_Base::getFetchDirection() const throw(SQLException, RuntimeException)
558 {
559 	return FetchDirection::FORWARD;
560 }
561 //------------------------------------------------------------------------------
562 sal_Int32 OStatement_Base::getFetchSize() const throw(SQLException, RuntimeException)
563 {
564 	return m_nFetchSize;
565 }
566 //------------------------------------------------------------------------------
567 sal_Int32 OStatement_Base::getMaxFieldSize() const throw(SQLException, RuntimeException)
568 {
569 	return 0;
570 }
571 //------------------------------------------------------------------------------
572 ::rtl::OUString OStatement_Base::getCursorName() const throw(SQLException, RuntimeException)
573 {
574 	return m_Command.GetName();
575 }
576 //------------------------------------------------------------------------------
577 void OStatement_Base::setQueryTimeOut(sal_Int32 seconds) throw(SQLException, RuntimeException)
578 {
579 	::osl::MutexGuard aGuard( m_aMutex );
580 	checkDisposed(OStatement_BASE::rBHelper.bDisposed);
581 
582 
583 	m_Command.put_CommandTimeout(seconds);
584 }
585 //------------------------------------------------------------------------------
586 void OStatement_Base::setMaxRows(sal_Int32 _par0) throw(SQLException, RuntimeException)
587 {
588 	::osl::MutexGuard aGuard( m_aMutex );
589 	checkDisposed(OStatement_BASE::rBHelper.bDisposed);
590 
591 	m_nMaxRows = _par0;
592 }
593 //------------------------------------------------------------------------------
594 void OStatement_Base::setResultSetConcurrency(sal_Int32 _par0) throw(SQLException, RuntimeException)
595 {
596 	::osl::MutexGuard aGuard( m_aMutex );
597 	checkDisposed(OStatement_BASE::rBHelper.bDisposed);
598 
599 	switch(_par0)
600 	{
601 		case ResultSetConcurrency::READ_ONLY:
602 			m_eLockType = adLockReadOnly;
603 			break;
604 		default:
605 			m_eLockType = adLockOptimistic;
606 			break;
607 	}
608 }
609 //------------------------------------------------------------------------------
610 void OStatement_Base::setResultSetType(sal_Int32 _par0) throw(SQLException, RuntimeException)
611 {
612 	::osl::MutexGuard aGuard( m_aMutex );
613 	checkDisposed(OStatement_BASE::rBHelper.bDisposed);
614 
615 
616 	switch(_par0)
617 	{
618 		case ResultSetType::FORWARD_ONLY:
619 			m_eCursorType = adOpenForwardOnly;
620 			break;
621 		case ResultSetType::SCROLL_INSENSITIVE:
622 			m_eCursorType = adOpenKeyset;
623 			break;
624 		case ResultSetType::SCROLL_SENSITIVE:
625 			m_eCursorType = adOpenDynamic;
626 			break;
627 	}
628 }
629 //------------------------------------------------------------------------------
630 void OStatement_Base::setFetchDirection(sal_Int32 /*_par0*/) throw(SQLException, RuntimeException)
631 {
632 	::osl::MutexGuard aGuard( m_aMutex );
633 	checkDisposed(OStatement_BASE::rBHelper.bDisposed);
634     ::dbtools::throwFeatureNotImplementedException( "Statement::FetchDirection", *this );
635 }
636 //------------------------------------------------------------------------------
637 void OStatement_Base::setFetchSize(sal_Int32 _par0) throw(SQLException, RuntimeException)
638 {
639 	::osl::MutexGuard aGuard( m_aMutex );
640 	checkDisposed(OStatement_BASE::rBHelper.bDisposed);
641 
642 
643 	m_nFetchSize = _par0;
644 	//	m_RecordSet.put_CacheSize(_par0);
645 }
646 //------------------------------------------------------------------------------
647 void OStatement_Base::setMaxFieldSize(sal_Int32 /*_par0*/) throw(SQLException, RuntimeException)
648 {
649 	::osl::MutexGuard aGuard( m_aMutex );
650 	checkDisposed(OStatement_BASE::rBHelper.bDisposed);
651     ::dbtools::throwFeatureNotImplementedException( "Statement::MaxFieldSize", *this );
652 }
653 //------------------------------------------------------------------------------
654 void OStatement_Base::setCursorName(const ::rtl::OUString &_par0) throw(SQLException, RuntimeException)
655 {
656 	::osl::MutexGuard aGuard( m_aMutex );
657 	checkDisposed(OStatement_BASE::rBHelper.bDisposed);
658 
659 	m_Command.put_Name(_par0);
660 }
661 
662 // -------------------------------------------------------------------------
663 ::cppu::IPropertyArrayHelper* OStatement_Base::createArrayHelper( ) const
664 {
665 	Sequence< com::sun::star::beans::Property > aProps(10);
666 	com::sun::star::beans::Property* pProperties = aProps.getArray();
667 	sal_Int32 nPos = 0;
668 	DECL_PROP0(CURSORNAME,	::rtl::OUString);
669 	DECL_BOOL_PROP0(ESCAPEPROCESSING);
670 	DECL_PROP0(FETCHDIRECTION,sal_Int32);
671 	DECL_PROP0(FETCHSIZE,	sal_Int32);
672 	DECL_PROP0(MAXFIELDSIZE,sal_Int32);
673 	DECL_PROP0(MAXROWS,		sal_Int32);
674 	DECL_PROP0(QUERYTIMEOUT,sal_Int32);
675 	DECL_PROP0(RESULTSETCONCURRENCY,sal_Int32);
676 	DECL_PROP0(RESULTSETTYPE,sal_Int32);
677 	DECL_BOOL_PROP0(USEBOOKMARKS);
678 
679 
680 	return new ::cppu::OPropertyArrayHelper(aProps);
681 }
682 
683 // -------------------------------------------------------------------------
684 ::cppu::IPropertyArrayHelper & OStatement_Base::getInfoHelper()
685 {
686 	return *const_cast<OStatement_Base*>(this)->getArrayHelper();
687 }
688 // -------------------------------------------------------------------------
689 sal_Bool OStatement_Base::convertFastPropertyValue(
690 							Any & rConvertedValue,
691 							Any & rOldValue,
692 							sal_Int32 nHandle,
693 							const Any& rValue )
694 								throw (::com::sun::star::lang::IllegalArgumentException)
695 {
696 	sal_Bool bModified = sal_False;
697 
698 	sal_Bool bValidAdoRS = m_RecordSet.IsValid();
699 		// some of the properties below, when set, are remembered in a member, and applied in the next execute
700 		// For these properties, the record set does not need to be valid to allow setting them.
701 		// For all others (where the values are forwarded to the ADO RS directly), the recordset must be valid.
702 
703 	try
704 	{
705 		switch(nHandle)
706 		{
707 			case PROPERTY_ID_MAXROWS:
708 				bModified = ::comphelper::tryPropertyValue( rConvertedValue, rOldValue, rValue, bValidAdoRS ? getMaxRows() : m_nMaxRows );
709 				break;
710 
711 			case PROPERTY_ID_RESULTSETTYPE:
712 				bModified = ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, getResultSetType());
713 				break;
714 			case PROPERTY_ID_FETCHSIZE:
715 				bModified = ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, getFetchSize());
716 				break;
717 			case PROPERTY_ID_RESULTSETCONCURRENCY:
718 				bModified = ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, getResultSetConcurrency());
719 				break;
720 			case PROPERTY_ID_QUERYTIMEOUT:
721 				bModified = ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, getQueryTimeOut());
722 				break;
723 			case PROPERTY_ID_MAXFIELDSIZE:
724 				bModified = ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, getMaxFieldSize());
725 				break;
726 			case PROPERTY_ID_CURSORNAME:
727 				bModified = ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, getCursorName());
728 				break;
729 			case PROPERTY_ID_FETCHDIRECTION:
730 				bModified = ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, getFetchDirection());
731 				break;
732 		}
733 	}
734 	catch( const Exception& e )
735 	{
736 		bModified = sal_True;	// will ensure that the property is set
737 		OSL_ENSURE( sal_False, "OStatement_Base::convertFastPropertyValue: caught something strange!" );
738         (void)e;
739 	}
740 	return bModified;
741 }
742 // -------------------------------------------------------------------------
743 void OStatement_Base::setFastPropertyValue_NoBroadcast(sal_Int32 nHandle,const Any& rValue) throw (Exception)
744 {
745 	switch(nHandle)
746 	{
747 		case PROPERTY_ID_QUERYTIMEOUT:
748 			setQueryTimeOut(comphelper::getINT32(rValue));
749 			break;
750 		case PROPERTY_ID_MAXFIELDSIZE:
751 			setMaxFieldSize(comphelper::getINT32(rValue));
752 			break;
753 		case PROPERTY_ID_MAXROWS:
754 			setMaxRows(comphelper::getINT32(rValue));
755 			break;
756 		case PROPERTY_ID_CURSORNAME:
757 			setCursorName(comphelper::getString(rValue));
758 			break;
759 		case PROPERTY_ID_RESULTSETCONCURRENCY:
760 			setResultSetConcurrency(comphelper::getINT32(rValue));
761 			break;
762 		case PROPERTY_ID_RESULTSETTYPE:
763 			setResultSetType(comphelper::getINT32(rValue));
764 			break;
765 		case PROPERTY_ID_FETCHDIRECTION:
766 			setFetchDirection(comphelper::getINT32(rValue));
767 			break;
768 		case PROPERTY_ID_FETCHSIZE:
769 			setFetchSize(comphelper::getINT32(rValue));
770 			break;
771 		case PROPERTY_ID_ESCAPEPROCESSING:
772 			//	return ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, m_bAsLink);
773 		case PROPERTY_ID_USEBOOKMARKS:
774 			//	return ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, m_bAsLink);
775 		default:
776 			;
777 	}
778 }
779 // -------------------------------------------------------------------------
780 void OStatement_Base::getFastPropertyValue(Any& rValue,sal_Int32 nHandle) const
781 {
782 	switch(nHandle)
783 	{
784 		case PROPERTY_ID_QUERYTIMEOUT:
785 			rValue <<= getQueryTimeOut();
786 			break;
787 		case PROPERTY_ID_MAXFIELDSIZE:
788 			rValue <<= getMaxFieldSize();
789 			break;
790 		case PROPERTY_ID_MAXROWS:
791 			rValue <<= getMaxRows();
792 			break;
793 		case PROPERTY_ID_CURSORNAME:
794 			rValue <<= getCursorName();
795 			break;
796 		case PROPERTY_ID_RESULTSETCONCURRENCY:
797 			rValue <<= getResultSetConcurrency();
798 			break;
799 		case PROPERTY_ID_RESULTSETTYPE:
800 			rValue <<= getResultSetType();
801 			break;
802 		case PROPERTY_ID_FETCHDIRECTION:
803 			rValue <<= getFetchDirection();
804 			break;
805 		case PROPERTY_ID_FETCHSIZE:
806 			rValue <<= getFetchSize();
807 			break;
808 		case PROPERTY_ID_ESCAPEPROCESSING:
809             rValue <<= sal_True;
810             break;
811 		case PROPERTY_ID_USEBOOKMARKS:
812 		default:
813 			;
814 	}
815 }
816 // -------------------------------------------------------------------------
817 OStatement::~OStatement()
818 {
819 }
820 IMPLEMENT_SERVICE_INFO(OStatement,"com.sun.star.sdbcx.AStatement","com.sun.star.sdbc.Statement");
821 // -----------------------------------------------------------------------------
822 void SAL_CALL OStatement_Base::acquire() throw()
823 {
824 	OStatement_BASE::acquire();
825 }
826 // -----------------------------------------------------------------------------
827 void SAL_CALL OStatement::acquire() throw()
828 {
829 	OStatement_Base::acquire();
830 }
831 // -----------------------------------------------------------------------------
832 void SAL_CALL OStatement::release() throw()
833 {
834 	OStatement_Base::release();
835 }
836 // -----------------------------------------------------------------------------
837 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL OStatement_Base::getPropertySetInfo(  ) throw(::com::sun::star::uno::RuntimeException)
838 {
839 	return ::cppu::OPropertySetHelper::createPropertySetInfo(getInfoHelper());
840 }
841 // -----------------------------------------------------------------------------
842