Bump for 3.6-28
[LibreOffice.git] / connectivity / source / drivers / ado / AStatement.cxx
blob5d00d31106e519a38c09a42f0b633d1d3e720b67
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #include "ado/AStatement.hxx"
30 #include "ado/AConnection.hxx"
31 #include "ado/AResultSet.hxx"
32 #include <comphelper/property.hxx>
33 #include <comphelper/uno3.hxx>
34 #include <osl/thread.h>
35 #include <cppuhelper/typeprovider.hxx>
36 #include <comphelper/sequence.hxx>
37 #include <com/sun/star/sdbc/ResultSetConcurrency.hpp>
38 #include <com/sun/star/sdbc/ResultSetType.hpp>
39 #include <com/sun/star/sdbc/FetchDirection.hpp>
40 #include "connectivity/dbexception.hxx"
41 #include <comphelper/types.hxx>
43 #undef max
45 #include <algorithm>
47 using namespace ::comphelper;
49 #define CHECK_RETURN(x) \
50 if(!x) \
51 ADOS::ThrowException(*m_pConnection->getConnection(),*this);
55 using namespace connectivity::ado;
57 //------------------------------------------------------------------------------
58 using namespace com::sun::star::uno;
59 using namespace com::sun::star::lang;
60 using namespace com::sun::star::beans;
61 using namespace com::sun::star::sdbc;
62 using namespace ::std;
63 //------------------------------------------------------------------------------
64 OStatement_Base::OStatement_Base(OConnection* _pConnection ) : OStatement_BASE(m_aMutex)
65 ,OPropertySetHelper(OStatement_BASE::rBHelper)
66 ,OSubComponent<OStatement_Base, OStatement_BASE>((::cppu::OWeakObject*)_pConnection, this)
67 ,m_pConnection(_pConnection)
68 ,m_nMaxRows(0)
69 ,m_nFetchSize(1)
70 ,m_eLockType(adLockReadOnly)
71 ,m_eCursorType(adOpenForwardOnly)
73 osl_incrementInterlockedCount( &m_refCount );
75 m_Command.Create();
76 if(m_Command.IsValid())
77 m_Command.putref_ActiveConnection(m_pConnection->getConnection());
78 else
79 ADOS::ThrowException(*m_pConnection->getConnection(),*this);
81 m_RecordsAffected.setNoArg();
82 m_Parameters.setNoArg();
84 m_pConnection->acquire();
86 osl_decrementInterlockedCount( &m_refCount );
88 //------------------------------------------------------------------------------
89 void OStatement_Base::disposeResultSet()
91 // free the cursor if alive
92 Reference< XComponent > xComp(m_xResultSet.get(), UNO_QUERY);
93 if (xComp.is())
94 xComp->dispose();
95 m_xResultSet = Reference< XResultSet>();
98 //------------------------------------------------------------------------------
99 void OStatement_Base::disposing()
101 ::osl::MutexGuard aGuard(m_aMutex);
104 disposeResultSet();
106 if ( m_Command.IsValid() )
107 m_Command.putref_ActiveConnection( NULL );
108 m_Command.clear();
110 if ( m_RecordSet.IsValid() )
111 m_RecordSet.PutRefDataSource( NULL );
112 m_RecordSet.clear();
114 if (m_pConnection)
115 m_pConnection->release();
117 dispose_ChildImpl();
118 OStatement_BASE::disposing();
120 //-----------------------------------------------------------------------------
121 void SAL_CALL OStatement_Base::release() throw()
123 relase_ChildImpl();
125 //-----------------------------------------------------------------------------
126 Any SAL_CALL OStatement_Base::queryInterface( const Type & rType ) throw(RuntimeException)
128 Any aRet = OStatement_BASE::queryInterface(rType);
129 return aRet.hasValue() ? aRet : OPropertySetHelper::queryInterface(rType);
131 // -------------------------------------------------------------------------
132 ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL OStatement_Base::getTypes( ) throw(::com::sun::star::uno::RuntimeException)
134 ::cppu::OTypeCollection aTypes( ::getCppuType( (const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XMultiPropertySet > *)0 ),
135 ::getCppuType( (const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XFastPropertySet > *)0 ),
136 ::getCppuType( (const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > *)0 ));
138 return ::comphelper::concatSequences(aTypes.getTypes(),OStatement_BASE::getTypes());
141 // -------------------------------------------------------------------------
143 void SAL_CALL OStatement_Base::cancel( ) throw(RuntimeException)
145 ::osl::MutexGuard aGuard( m_aMutex );
146 checkDisposed(OStatement_BASE::rBHelper.bDisposed);
149 CHECK_RETURN(m_Command.Cancel())
151 // -------------------------------------------------------------------------
153 void SAL_CALL OStatement_Base::close( ) throw(SQLException, RuntimeException)
156 ::osl::MutexGuard aGuard( m_aMutex );
157 checkDisposed(OStatement_BASE::rBHelper.bDisposed);
160 dispose();
162 // -------------------------------------------------------------------------
164 void SAL_CALL OStatement::clearBatch( ) throw(SQLException, RuntimeException)
168 // -------------------------------------------------------------------------
170 void OStatement_Base::reset() throw (SQLException)
172 ::osl::MutexGuard aGuard( m_aMutex );
173 checkDisposed(OStatement_BASE::rBHelper.bDisposed);
176 clearWarnings ();
178 if (m_xResultSet.get().is())
179 clearMyResultSet();
181 //--------------------------------------------------------------------
182 // clearMyResultSet
183 // If a ResultSet was created for this Statement, close it
184 //--------------------------------------------------------------------
186 void OStatement_Base::clearMyResultSet () throw (SQLException)
188 ::osl::MutexGuard aGuard( m_aMutex );
189 checkDisposed(OStatement_BASE::rBHelper.bDisposed);
193 Reference<XCloseable> xCloseable;
194 if ( ::comphelper::query_interface( m_xResultSet.get(), xCloseable ) )
195 xCloseable->close();
197 catch( const DisposedException& ) { }
199 m_xResultSet = Reference< XResultSet >();
201 //--------------------------------------------------------------------
202 sal_Int32 OStatement_Base::getRowCount () throw( SQLException)
204 ::osl::MutexGuard aGuard( m_aMutex );
205 checkDisposed(OStatement_BASE::rBHelper.bDisposed);
208 return m_RecordsAffected;
210 //--------------------------------------------------------------------
211 // getPrecision
212 // Given a SQL type, return the maximum precision for the column.
213 // Returns -1 if not known
214 //--------------------------------------------------------------------
216 sal_Int32 OStatement_Base::getPrecision ( sal_Int32 sqlType)
218 ::osl::MutexGuard aGuard( m_aMutex );
219 checkDisposed(OStatement_BASE::rBHelper.bDisposed);
222 sal_Int32 prec = -1;
223 OTypeInfo aInfo;
224 aInfo.nType = (sal_Int16)sqlType;
225 if (!m_aTypeInfo.empty())
227 ::std::vector<OTypeInfo>::const_iterator aIter = ::std::find(m_aTypeInfo.begin(),m_aTypeInfo.end(),aInfo);
228 for(;aIter != m_aTypeInfo.end();++aIter)
230 prec = ::std::max(prec,(*aIter).nPrecision);
234 return prec;
236 //--------------------------------------------------------------------
237 // setWarning
238 // Sets the warning
239 //--------------------------------------------------------------------
241 void OStatement_Base::setWarning (const SQLWarning &ex) throw( SQLException)
243 ::osl::MutexGuard aGuard( m_aMutex );
244 checkDisposed(OStatement_BASE::rBHelper.bDisposed);
247 m_aLastWarning = ex;
249 // -------------------------------------------------------------------------
250 void OStatement_Base::assignRecordSet( ADORecordset* _pRS )
252 WpADORecordset aOldRS( m_RecordSet );
253 m_RecordSet = WpADORecordset( _pRS );
255 if ( aOldRS.IsValid() )
256 aOldRS.PutRefDataSource( NULL );
258 if ( m_RecordSet.IsValid() )
259 m_RecordSet.PutRefDataSource( (IDispatch*)m_Command );
261 // -------------------------------------------------------------------------
262 sal_Bool SAL_CALL OStatement_Base::execute( const ::rtl::OUString& sql ) throw(SQLException, RuntimeException)
264 ::osl::MutexGuard aGuard( m_aMutex );
265 checkDisposed(OStatement_BASE::rBHelper.bDisposed);
268 // Reset the statement handle and warning
270 reset();
274 ADORecordset* pSet = NULL;
275 CHECK_RETURN(m_Command.put_CommandText(sql))
276 CHECK_RETURN(m_Command.Execute(m_RecordsAffected,m_Parameters,adCmdText,&pSet))
278 assignRecordSet( pSet );
280 catch (SQLWarning& ex)
283 // Save pointer to warning and save with ResultSet
284 // object once it is created.
286 m_aLastWarning = ex;
289 return m_RecordSet.IsValid();
291 // -------------------------------------------------------------------------
292 Reference< XResultSet > SAL_CALL OStatement_Base::executeQuery( const ::rtl::OUString& sql ) throw(SQLException, RuntimeException)
294 ::osl::MutexGuard aGuard( m_aMutex );
295 checkDisposed(OStatement_BASE::rBHelper.bDisposed);
298 reset();
300 m_xResultSet = WeakReference<XResultSet>(NULL);
302 WpADORecordset aSet;
303 aSet.Create();
304 CHECK_RETURN(m_Command.put_CommandText(sql))
305 OLEVariant aCmd;
306 aCmd.setIDispatch(m_Command);
307 OLEVariant aCon;
308 aCon.setNoArg();
309 CHECK_RETURN(aSet.put_CacheSize(m_nFetchSize))
310 CHECK_RETURN(aSet.put_MaxRecords(m_nMaxRows))
311 CHECK_RETURN(aSet.Open(aCmd,aCon,m_eCursorType,m_eLockType,adOpenUnspecified))
314 CHECK_RETURN(aSet.get_CacheSize(m_nFetchSize))
315 CHECK_RETURN(aSet.get_MaxRecords(m_nMaxRows))
316 CHECK_RETURN(aSet.get_CursorType(m_eCursorType))
317 CHECK_RETURN(aSet.get_LockType(m_eLockType))
319 OResultSet* pSet = new OResultSet(aSet,this);
320 Reference< XResultSet > xRs = pSet;
321 pSet->construct();
323 m_xResultSet = WeakReference<XResultSet>(xRs);
325 return xRs;
327 // -------------------------------------------------------------------------
329 Reference< XConnection > SAL_CALL OStatement_Base::getConnection( ) throw(SQLException, RuntimeException)
331 ::osl::MutexGuard aGuard( m_aMutex );
332 checkDisposed(OStatement_BASE::rBHelper.bDisposed);
335 return (Reference< XConnection >)m_pConnection;
337 // -------------------------------------------------------------------------
339 Any SAL_CALL OStatement::queryInterface( const Type & rType ) throw(RuntimeException)
341 Any aRet = ::cppu::queryInterface(rType,static_cast< XBatchExecution*> (this));
342 return aRet.hasValue() ? aRet : OStatement_Base::queryInterface(rType);
344 // -------------------------------------------------------------------------
346 void SAL_CALL OStatement::addBatch( const ::rtl::OUString& sql ) throw(SQLException, RuntimeException)
348 ::osl::MutexGuard aGuard( m_aMutex );
349 checkDisposed(OStatement_BASE::rBHelper.bDisposed);
352 m_aBatchList.push_back(sql);
354 // -------------------------------------------------------------------------
355 Sequence< sal_Int32 > SAL_CALL OStatement::executeBatch( ) throw(SQLException, RuntimeException)
357 ::osl::MutexGuard aGuard( m_aMutex );
358 checkDisposed(OStatement_BASE::rBHelper.bDisposed);
361 reset();
363 ::rtl::OUString aBatchSql;
364 sal_Int32 nLen = 0;
365 for(::std::list< ::rtl::OUString>::const_iterator i=m_aBatchList.begin();i != m_aBatchList.end();++i,++nLen)
366 aBatchSql = aBatchSql + *i + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(";"));
369 if ( m_RecordSet.IsValid() )
370 m_RecordSet.PutRefDataSource( NULL );
371 m_RecordSet.clear();
372 m_RecordSet.Create();
374 CHECK_RETURN(m_Command.put_CommandText(aBatchSql))
375 if ( m_RecordSet.IsValid() )
376 m_RecordSet.PutRefDataSource((IDispatch*)m_Command);
378 CHECK_RETURN(m_RecordSet.UpdateBatch(adAffectAll))
380 ADORecordset* pSet=NULL;
381 Sequence< sal_Int32 > aRet(nLen);
382 sal_Int32* pArray = aRet.getArray();
383 for(sal_Int32 j=0;j<nLen;++j)
385 pSet = NULL;
386 OLEVariant aRecordsAffected;
387 if(m_RecordSet.NextRecordset(aRecordsAffected,&pSet) && pSet)
389 assignRecordSet( pSet );
391 ADO_LONGPTR nValue;
392 if(m_RecordSet.get_RecordCount(nValue))
393 pArray[j] = nValue;
396 return aRet;
398 // -------------------------------------------------------------------------
401 sal_Int32 SAL_CALL OStatement_Base::executeUpdate( const ::rtl::OUString& sql ) throw(SQLException, RuntimeException)
403 ::osl::MutexGuard aGuard( m_aMutex );
404 checkDisposed(OStatement_BASE::rBHelper.bDisposed);
407 reset();
409 try {
410 ADORecordset* pSet = NULL;
411 CHECK_RETURN(m_Command.put_CommandText(sql))
412 CHECK_RETURN(m_Command.Execute(m_RecordsAffected,m_Parameters,adCmdText|adExecuteNoRecords,&pSet))
414 catch (SQLWarning& ex) {
416 // Save pointer to warning and save with ResultSet
417 // object once it is created.
419 m_aLastWarning = ex;
421 if(!m_RecordsAffected.isEmpty() && !m_RecordsAffected.isNull() && m_RecordsAffected.getType() != VT_ERROR)
422 return m_RecordsAffected;
424 return 0;
426 // -------------------------------------------------------------------------
428 Reference< XResultSet > SAL_CALL OStatement_Base::getResultSet( ) throw(SQLException, RuntimeException)
430 ::osl::MutexGuard aGuard( m_aMutex );
431 checkDisposed(OStatement_BASE::rBHelper.bDisposed);
434 return m_xResultSet;
436 // -------------------------------------------------------------------------
438 sal_Int32 SAL_CALL OStatement_Base::getUpdateCount( ) throw(SQLException, RuntimeException)
440 ::osl::MutexGuard aGuard( m_aMutex );
441 checkDisposed(OStatement_BASE::rBHelper.bDisposed);
444 ADO_LONGPTR nRet;
445 if(m_RecordSet.IsValid() && m_RecordSet.get_RecordCount(nRet))
446 return nRet;
447 return -1;
449 // -------------------------------------------------------------------------
451 sal_Bool SAL_CALL OStatement_Base::getMoreResults( ) throw(SQLException, RuntimeException)
453 ::osl::MutexGuard aGuard( m_aMutex );
454 checkDisposed(OStatement_BASE::rBHelper.bDisposed);
457 SQLWarning warning;
459 // clear previous warnings
461 clearWarnings ();
463 // Call SQLMoreResults
467 ADORecordset* pSet=NULL;
468 OLEVariant aRecordsAffected;
469 if(m_RecordSet.IsValid() && m_RecordSet.NextRecordset(aRecordsAffected,&pSet) && pSet)
470 assignRecordSet( pSet );
472 catch (SQLWarning &ex)
475 // Save pointer to warning and save with ResultSet
476 // object once it is created.
478 warning = ex;
480 return m_RecordSet.IsValid();
482 // -------------------------------------------------------------------------
484 // -------------------------------------------------------------------------
485 Any SAL_CALL OStatement_Base::getWarnings( ) throw(SQLException, RuntimeException)
487 ::osl::MutexGuard aGuard( m_aMutex );
488 checkDisposed(OStatement_BASE::rBHelper.bDisposed);
491 return makeAny(m_aLastWarning);
493 // -------------------------------------------------------------------------
495 // -------------------------------------------------------------------------
496 void SAL_CALL OStatement_Base::clearWarnings( ) throw(SQLException, RuntimeException)
498 ::osl::MutexGuard aGuard( m_aMutex );
499 checkDisposed(OStatement_BASE::rBHelper.bDisposed);
502 m_aLastWarning = SQLWarning();
504 // -------------------------------------------------------------------------
505 //------------------------------------------------------------------------------
506 sal_Int32 OStatement_Base::getQueryTimeOut() const throw(SQLException, RuntimeException)
508 return m_Command.get_CommandTimeout();
510 //------------------------------------------------------------------------------
511 sal_Int32 OStatement_Base::getMaxRows() const throw(SQLException, RuntimeException)
513 ADO_LONGPTR nRet=-1;
514 if(!(m_RecordSet.IsValid() && m_RecordSet.get_MaxRecords(nRet)))
515 ::dbtools::throwFunctionSequenceException(NULL);
516 return nRet;
518 //------------------------------------------------------------------------------
519 sal_Int32 OStatement_Base::getResultSetConcurrency() const throw(SQLException, RuntimeException)
521 return m_eLockType;
522 #if 0 // Huh?
523 sal_Int32 nValue=0;
524 switch(m_eLockType)
526 case adLockReadOnly:
527 nValue = ResultSetConcurrency::READ_ONLY;
528 break;
529 default:
530 nValue = ResultSetConcurrency::UPDATABLE;
531 break;
534 return nValue;
535 #endif
537 //------------------------------------------------------------------------------
538 sal_Int32 OStatement_Base::getResultSetType() const throw(SQLException, RuntimeException)
540 sal_Int32 nValue=0;
541 switch(m_eCursorType)
543 case adOpenUnspecified:
544 case adOpenForwardOnly:
545 nValue = ResultSetType::FORWARD_ONLY;
546 break;
547 case adOpenStatic:
548 case adOpenKeyset:
549 nValue = ResultSetType::SCROLL_INSENSITIVE;
550 break;
551 case adOpenDynamic:
552 nValue = ResultSetType::SCROLL_SENSITIVE;
553 break;
555 return nValue;
557 //------------------------------------------------------------------------------
558 sal_Int32 OStatement_Base::getFetchDirection() const throw(SQLException, RuntimeException)
560 return FetchDirection::FORWARD;
562 //------------------------------------------------------------------------------
563 sal_Int32 OStatement_Base::getFetchSize() const throw(SQLException, RuntimeException)
565 return m_nFetchSize;
567 //------------------------------------------------------------------------------
568 sal_Int32 OStatement_Base::getMaxFieldSize() const throw(SQLException, RuntimeException)
570 return 0;
572 //------------------------------------------------------------------------------
573 ::rtl::OUString OStatement_Base::getCursorName() const throw(SQLException, RuntimeException)
575 return m_Command.GetName();
577 //------------------------------------------------------------------------------
578 void OStatement_Base::setQueryTimeOut(sal_Int32 seconds) throw(SQLException, RuntimeException)
580 ::osl::MutexGuard aGuard( m_aMutex );
581 checkDisposed(OStatement_BASE::rBHelper.bDisposed);
584 m_Command.put_CommandTimeout(seconds);
586 //------------------------------------------------------------------------------
587 void OStatement_Base::setMaxRows(sal_Int32 _par0) throw(SQLException, RuntimeException)
589 ::osl::MutexGuard aGuard( m_aMutex );
590 checkDisposed(OStatement_BASE::rBHelper.bDisposed);
592 m_nMaxRows = _par0;
594 //------------------------------------------------------------------------------
595 void OStatement_Base::setResultSetConcurrency(sal_Int32 _par0) throw(SQLException, RuntimeException)
597 ::osl::MutexGuard aGuard( m_aMutex );
598 checkDisposed(OStatement_BASE::rBHelper.bDisposed);
600 switch(_par0)
602 case ResultSetConcurrency::READ_ONLY:
603 m_eLockType = adLockReadOnly;
604 break;
605 default:
606 m_eLockType = adLockOptimistic;
607 break;
610 //------------------------------------------------------------------------------
611 void OStatement_Base::setResultSetType(sal_Int32 _par0) throw(SQLException, RuntimeException)
613 ::osl::MutexGuard aGuard( m_aMutex );
614 checkDisposed(OStatement_BASE::rBHelper.bDisposed);
617 switch(_par0)
619 case ResultSetType::FORWARD_ONLY:
620 m_eCursorType = adOpenForwardOnly;
621 break;
622 case ResultSetType::SCROLL_INSENSITIVE:
623 m_eCursorType = adOpenKeyset;
624 break;
625 case ResultSetType::SCROLL_SENSITIVE:
626 m_eCursorType = adOpenDynamic;
627 break;
630 //------------------------------------------------------------------------------
631 void OStatement_Base::setFetchDirection(sal_Int32 /*_par0*/) throw(SQLException, RuntimeException)
633 ::osl::MutexGuard aGuard( m_aMutex );
634 checkDisposed(OStatement_BASE::rBHelper.bDisposed);
635 ::dbtools::throwFeatureNotImplementedException( "Statement::FetchDirection", *this );
637 //------------------------------------------------------------------------------
638 void OStatement_Base::setFetchSize(sal_Int32 _par0) throw(SQLException, RuntimeException)
640 ::osl::MutexGuard aGuard( m_aMutex );
641 checkDisposed(OStatement_BASE::rBHelper.bDisposed);
644 m_nFetchSize = _par0;
645 // m_RecordSet.put_CacheSize(_par0);
647 //------------------------------------------------------------------------------
648 void OStatement_Base::setMaxFieldSize(sal_Int32 /*_par0*/) throw(SQLException, RuntimeException)
650 ::osl::MutexGuard aGuard( m_aMutex );
651 checkDisposed(OStatement_BASE::rBHelper.bDisposed);
652 ::dbtools::throwFeatureNotImplementedException( "Statement::MaxFieldSize", *this );
654 //------------------------------------------------------------------------------
655 void OStatement_Base::setCursorName(const ::rtl::OUString &_par0) throw(SQLException, RuntimeException)
657 ::osl::MutexGuard aGuard( m_aMutex );
658 checkDisposed(OStatement_BASE::rBHelper.bDisposed);
660 m_Command.put_Name(_par0);
663 // -------------------------------------------------------------------------
664 ::cppu::IPropertyArrayHelper* OStatement_Base::createArrayHelper( ) const
666 Sequence< com::sun::star::beans::Property > aProps(10);
667 com::sun::star::beans::Property* pProperties = aProps.getArray();
668 sal_Int32 nPos = 0;
669 DECL_PROP0(CURSORNAME, ::rtl::OUString);
670 DECL_BOOL_PROP0(ESCAPEPROCESSING);
671 DECL_PROP0(FETCHDIRECTION,sal_Int32);
672 DECL_PROP0(FETCHSIZE, sal_Int32);
673 DECL_PROP0(MAXFIELDSIZE,sal_Int32);
674 DECL_PROP0(MAXROWS, sal_Int32);
675 DECL_PROP0(QUERYTIMEOUT,sal_Int32);
676 DECL_PROP0(RESULTSETCONCURRENCY,sal_Int32);
677 DECL_PROP0(RESULTSETTYPE,sal_Int32);
678 DECL_BOOL_PROP0(USEBOOKMARKS);
681 return new ::cppu::OPropertyArrayHelper(aProps);
684 // -------------------------------------------------------------------------
685 ::cppu::IPropertyArrayHelper & OStatement_Base::getInfoHelper()
687 return *const_cast<OStatement_Base*>(this)->getArrayHelper();
689 // -------------------------------------------------------------------------
690 sal_Bool OStatement_Base::convertFastPropertyValue(
691 Any & rConvertedValue,
692 Any & rOldValue,
693 sal_Int32 nHandle,
694 const Any& rValue )
695 throw (::com::sun::star::lang::IllegalArgumentException)
697 sal_Bool bModified = sal_False;
699 sal_Bool bValidAdoRS = m_RecordSet.IsValid();
700 // some of the properties below, when set, are remembered in a member, and applied in the next execute
701 // For these properties, the record set does not need to be valid to allow setting them.
702 // For all others (where the values are forwarded to the ADO RS directly), the recordset must be valid.
706 switch(nHandle)
708 case PROPERTY_ID_MAXROWS:
709 bModified = ::comphelper::tryPropertyValue( rConvertedValue, rOldValue, rValue, bValidAdoRS ? getMaxRows() : m_nMaxRows );
710 break;
712 case PROPERTY_ID_RESULTSETTYPE:
713 bModified = ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, getResultSetType());
714 break;
715 case PROPERTY_ID_FETCHSIZE:
716 bModified = ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, getFetchSize());
717 break;
718 case PROPERTY_ID_RESULTSETCONCURRENCY:
719 bModified = ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, getResultSetConcurrency());
720 break;
721 case PROPERTY_ID_QUERYTIMEOUT:
722 bModified = ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, getQueryTimeOut());
723 break;
724 case PROPERTY_ID_MAXFIELDSIZE:
725 bModified = ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, getMaxFieldSize());
726 break;
727 case PROPERTY_ID_CURSORNAME:
728 bModified = ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, getCursorName());
729 break;
730 case PROPERTY_ID_FETCHDIRECTION:
731 bModified = ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, getFetchDirection());
732 break;
735 catch( const Exception& e )
737 bModified = sal_True; // will ensure that the property is set
738 OSL_FAIL( "OStatement_Base::convertFastPropertyValue: caught something strange!" );
739 (void)e;
741 return bModified;
743 // -------------------------------------------------------------------------
744 void OStatement_Base::setFastPropertyValue_NoBroadcast(sal_Int32 nHandle,const Any& rValue) throw (Exception)
746 switch(nHandle)
748 case PROPERTY_ID_QUERYTIMEOUT:
749 setQueryTimeOut(comphelper::getINT32(rValue));
750 break;
751 case PROPERTY_ID_MAXFIELDSIZE:
752 setMaxFieldSize(comphelper::getINT32(rValue));
753 break;
754 case PROPERTY_ID_MAXROWS:
755 setMaxRows(comphelper::getINT32(rValue));
756 break;
757 case PROPERTY_ID_CURSORNAME:
758 setCursorName(comphelper::getString(rValue));
759 break;
760 case PROPERTY_ID_RESULTSETCONCURRENCY:
761 setResultSetConcurrency(comphelper::getINT32(rValue));
762 break;
763 case PROPERTY_ID_RESULTSETTYPE:
764 setResultSetType(comphelper::getINT32(rValue));
765 break;
766 case PROPERTY_ID_FETCHDIRECTION:
767 setFetchDirection(comphelper::getINT32(rValue));
768 break;
769 case PROPERTY_ID_FETCHSIZE:
770 setFetchSize(comphelper::getINT32(rValue));
771 break;
772 case PROPERTY_ID_ESCAPEPROCESSING:
773 // return ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, m_bAsLink);
774 case PROPERTY_ID_USEBOOKMARKS:
775 // return ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, m_bAsLink);
776 default:
780 // -------------------------------------------------------------------------
781 void OStatement_Base::getFastPropertyValue(Any& rValue,sal_Int32 nHandle) const
783 switch(nHandle)
785 case PROPERTY_ID_QUERYTIMEOUT:
786 rValue <<= getQueryTimeOut();
787 break;
788 case PROPERTY_ID_MAXFIELDSIZE:
789 rValue <<= getMaxFieldSize();
790 break;
791 case PROPERTY_ID_MAXROWS:
792 rValue <<= getMaxRows();
793 break;
794 case PROPERTY_ID_CURSORNAME:
795 rValue <<= getCursorName();
796 break;
797 case PROPERTY_ID_RESULTSETCONCURRENCY:
798 rValue <<= getResultSetConcurrency();
799 break;
800 case PROPERTY_ID_RESULTSETTYPE:
801 rValue <<= getResultSetType();
802 break;
803 case PROPERTY_ID_FETCHDIRECTION:
804 rValue <<= getFetchDirection();
805 break;
806 case PROPERTY_ID_FETCHSIZE:
807 rValue <<= getFetchSize();
808 break;
809 case PROPERTY_ID_ESCAPEPROCESSING:
810 rValue <<= sal_True;
811 break;
812 case PROPERTY_ID_USEBOOKMARKS:
813 default:
817 // -------------------------------------------------------------------------
818 OStatement::~OStatement()
821 IMPLEMENT_SERVICE_INFO(OStatement,"com.sun.star.sdbcx.AStatement","com.sun.star.sdbc.Statement");
822 // -----------------------------------------------------------------------------
823 void SAL_CALL OStatement_Base::acquire() throw()
825 OStatement_BASE::acquire();
827 // -----------------------------------------------------------------------------
828 void SAL_CALL OStatement::acquire() throw()
830 OStatement_Base::acquire();
832 // -----------------------------------------------------------------------------
833 void SAL_CALL OStatement::release() throw()
835 OStatement_Base::release();
837 // -----------------------------------------------------------------------------
838 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL OStatement_Base::getPropertySetInfo( ) throw(::com::sun::star::uno::RuntimeException)
840 return ::cppu::OPropertySetHelper::createPropertySetInfo(getInfoHelper());
842 // -----------------------------------------------------------------------------
844 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */