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