update dev300-m58
[ooovba.git] / dbaccess / source / core / api / statement.cxx
blobda5532ea3d9165121bca6b18bbf990d9a6e38d48
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: statement.cxx,v $
10 * $Revision: 1.18 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_dbaccess.hxx"
33 #ifndef _DBA_COREAPI_STATEMENT_HXX_
34 #include <statement.hxx>
35 #endif
36 #ifndef _DBA_COREAPI_RESULTSET_HXX_
37 #include <resultset.hxx>
38 #endif
39 #ifndef DBACCESS_SHARED_DBASTRINGS_HRC
40 #include "dbastrings.hrc"
41 #endif
42 #ifndef _COM_SUN_STAR_LANG_DISPOSEDEXCEPTION_HPP_
43 #include <com/sun/star/lang/DisposedException.hpp>
44 #endif
45 #ifndef _COM_SUN_STAR_SDBC_XDATABASEMETADATA_HPP_
46 #include <com/sun/star/sdbc/XDatabaseMetaData.hpp>
47 #endif
48 #ifndef _COMPHELPER_SEQUENCE_HXX_
49 #include <comphelper/sequence.hxx>
50 #endif
51 #ifndef _CPPUHELPER_TYPEPROVIDER_HXX_
52 #include <cppuhelper/typeprovider.hxx>
53 #endif
54 #ifndef _COMPHELPER_PROPERTY_HXX_
55 #include <comphelper/property.hxx>
56 #endif
57 #ifndef _COMPHELPER_TYPES_HXX_
58 #include <comphelper/types.hxx>
59 #endif
60 #ifndef _TOOLS_DEBUG_HXX //autogen
61 #include <tools/debug.hxx>
62 #endif
63 #ifndef TOOLS_DIAGNOSE_EX_H
64 #include <tools/diagnose_ex.h>
65 #endif
66 #ifndef _DBHELPER_DBEXCEPTION_HXX_
67 #include <connectivity/dbexception.hxx>
68 #endif
69 #include <rtl/logfile.hxx>
71 using namespace ::com::sun::star::sdb;
72 using namespace ::com::sun::star::sdbc;
73 using namespace ::com::sun::star::beans;
74 using namespace ::com::sun::star::uno;
75 using namespace ::com::sun::star::lang;
76 using namespace ::cppu;
77 using namespace ::osl;
78 using namespace dbaccess;
79 using namespace dbtools;
81 DBG_NAME(OStatementBase)
83 //--------------------------------------------------------------------------
84 OStatementBase::OStatementBase(const Reference< XConnection > & _xConn,
85 const Reference< XInterface > & _xStatement)
86 :OSubComponent(m_aMutex, _xConn)
87 ,OPropertySetHelper(OComponentHelper::rBHelper)
88 ,m_bUseBookmarks( sal_False )
89 ,m_bEscapeProcessing( sal_True )
92 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OStatementBase::OStatementBase" );
93 DBG_CTOR(OStatementBase, NULL);
94 OSL_ENSURE(_xStatement.is() ,"Statement is NULL!");
95 m_xAggregateAsSet.set(_xStatement,UNO_QUERY);
96 m_xAggregateAsCancellable = Reference< ::com::sun::star::util::XCancellable > (m_xAggregateAsSet, UNO_QUERY);
99 //--------------------------------------------------------------------------
100 OStatementBase::~OStatementBase()
102 DBG_DTOR(OStatementBase, NULL);
105 // com::sun::star::lang::XTypeProvider
106 //--------------------------------------------------------------------------
107 Sequence< Type > OStatementBase::getTypes() throw (RuntimeException)
109 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OStatementBase::getTypes" );
110 OTypeCollection aTypes(::getCppuType( (const Reference< XPropertySet > *)0 ),
111 ::getCppuType( (const Reference< XWarningsSupplier > *)0 ),
112 ::getCppuType( (const Reference< XCloseable > *)0 ),
113 ::getCppuType( (const Reference< XMultipleResults > *)0 ),
114 ::getCppuType( (const Reference< ::com::sun::star::util::XCancellable > *)0 ),
115 OSubComponent::getTypes() );
116 Reference< XGeneratedResultSet > xGRes(m_xAggregateAsSet, UNO_QUERY);
117 if ( xGRes.is() )
118 aTypes = OTypeCollection(::getCppuType( (const Reference< XGeneratedResultSet > *)0 ),aTypes.getTypes());
119 Reference< XPreparedBatchExecution > xPreparedBatchExecution(m_xAggregateAsSet, UNO_QUERY);
120 if ( xPreparedBatchExecution.is() )
121 aTypes = OTypeCollection(::getCppuType( (const Reference< XPreparedBatchExecution > *)0 ),aTypes.getTypes());
123 return aTypes.getTypes();
126 // com::sun::star::uno::XInterface
127 //--------------------------------------------------------------------------
128 Any OStatementBase::queryInterface( const Type & rType ) throw (RuntimeException)
130 //RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OStatementBase::queryInterface" );
131 Any aIface = OSubComponent::queryInterface( rType );
132 if (!aIface.hasValue())
134 aIface = ::cppu::queryInterface(
135 rType,
136 static_cast< XPropertySet * >( this ),
137 static_cast< XWarningsSupplier * >( this ),
138 static_cast< XCloseable * >( this ),
139 static_cast< XMultipleResults * >( this ),
140 static_cast< ::com::sun::star::util::XCancellable * >( this ));
141 if ( !aIface.hasValue() )
143 Reference< XGeneratedResultSet > xGRes(m_xAggregateAsSet, UNO_QUERY);
144 if ( ::getCppuType( (const Reference< XGeneratedResultSet > *)0 ) == rType && xGRes.is() )
145 aIface = ::cppu::queryInterface(rType,static_cast< XGeneratedResultSet * >( this ));
146 } // if ( !aIface.hasValue() )
147 if ( !aIface.hasValue() )
149 Reference< XPreparedBatchExecution > xGRes(m_xAggregateAsSet, UNO_QUERY);
150 if ( ::getCppuType( (const Reference< XPreparedBatchExecution > *)0 ) == rType && xGRes.is() )
151 aIface = ::cppu::queryInterface(rType,static_cast< XPreparedBatchExecution * >( this ));
154 return aIface;
157 //--------------------------------------------------------------------------
158 void OStatementBase::acquire() throw ()
160 OSubComponent::acquire();
163 //--------------------------------------------------------------------------
164 void OStatementBase::release() throw ()
166 OSubComponent::release();
169 //------------------------------------------------------------------------------
170 void OStatementBase::disposeResultSet()
172 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OStatementBase::disposeResultSet" );
173 // free the cursor if alive
174 Reference< XComponent > xComp(m_aResultSet.get(), UNO_QUERY);
175 if (xComp.is())
176 xComp->dispose();
177 m_aResultSet = NULL;
180 // OComponentHelper
181 //------------------------------------------------------------------------------
182 void OStatementBase::disposing()
184 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OStatementBase::disposing" );
185 OPropertySetHelper::disposing();
187 MutexGuard aGuard(m_aMutex);
189 // free pending results
190 disposeResultSet();
192 // free the original statement
194 MutexGuard aCancelGuard(m_aCancelMutex);
195 m_xAggregateAsCancellable = NULL;
198 if ( m_xAggregateAsSet.is() )
202 Reference< XCloseable > (m_xAggregateAsSet, UNO_QUERY)->close();
204 catch(RuntimeException& )
205 {// don't care for anymore
208 m_xAggregateAsSet = NULL;
210 // free the parent at last
211 OSubComponent::disposing();
214 // XCloseable
215 //------------------------------------------------------------------------------
216 void OStatementBase::close(void) throw( SQLException, RuntimeException )
218 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OStatementBase::close" );
220 MutexGuard aGuard( m_aMutex );
221 ::connectivity::checkDisposed(OComponentHelper::rBHelper.bDisposed);
223 dispose();
226 // OPropertySetHelper
227 //------------------------------------------------------------------------------
228 Reference< XPropertySetInfo > OStatementBase::getPropertySetInfo() throw (RuntimeException)
230 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OStatementBase::getPropertySetInfo" );
231 return createPropertySetInfo( getInfoHelper() ) ;
234 // comphelper::OPropertyArrayUsageHelper
235 //------------------------------------------------------------------------------
236 ::cppu::IPropertyArrayHelper* OStatementBase::createArrayHelper( ) const
238 //RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OStatementBase::createArrayHelper" );
239 BEGIN_PROPERTY_HELPER(10)
240 DECL_PROP0(CURSORNAME, ::rtl::OUString);
241 DECL_PROP0_BOOL(ESCAPE_PROCESSING);
242 DECL_PROP0(FETCHDIRECTION, sal_Int32);
243 DECL_PROP0(FETCHSIZE, sal_Int32);
244 DECL_PROP0(MAXFIELDSIZE, sal_Int32);
245 DECL_PROP0(MAXROWS, sal_Int32);
246 DECL_PROP0(QUERYTIMEOUT, sal_Int32);
247 DECL_PROP0(RESULTSETCONCURRENCY, sal_Int32);
248 DECL_PROP0(RESULTSETTYPE, sal_Int32);
249 DECL_PROP0_BOOL(USEBOOKMARKS);
250 END_PROPERTY_HELPER();
253 // cppu::OPropertySetHelper
254 //------------------------------------------------------------------------------
255 ::cppu::IPropertyArrayHelper& OStatementBase::getInfoHelper()
257 //RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OStatementBase::getInfoHelper" );
258 return *getArrayHelper();
261 //------------------------------------------------------------------------------
262 sal_Bool OStatementBase::convertFastPropertyValue( Any & rConvertedValue, Any & rOldValue, sal_Int32 nHandle, const Any& rValue ) throw( IllegalArgumentException )
264 //RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OStatementBase::convertFastPropertyValue" );
265 sal_Bool bModified(sal_False);
266 switch (nHandle)
268 case PROPERTY_ID_USEBOOKMARKS:
269 bModified = ::comphelper::tryPropertyValue( rConvertedValue, rOldValue, rValue, m_bUseBookmarks );
270 break;
272 case PROPERTY_ID_ESCAPE_PROCESSING:
273 bModified = ::comphelper::tryPropertyValue( rConvertedValue, rOldValue, rValue, m_bEscapeProcessing );
274 break;
276 default:
277 if ( m_xAggregateAsSet.is() )
279 // get the property name
280 ::rtl::OUString sPropName;
281 getInfoHelper().fillPropertyMembersByHandle( &sPropName, NULL, nHandle );
283 // now set the value
284 Any aCurrentValue = m_xAggregateAsSet->getPropertyValue( sPropName );
285 if ( aCurrentValue != rValue )
287 rOldValue = aCurrentValue;
288 rConvertedValue = rValue;
289 bModified = sal_True;
292 break;
294 return bModified;
297 //------------------------------------------------------------------------------
298 void OStatementBase::setFastPropertyValue_NoBroadcast( sal_Int32 nHandle, const Any& rValue ) throw (Exception)
300 //RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OStatementBase::setFastPropertyValue_NoBroadcast" );
301 switch ( nHandle )
303 case PROPERTY_ID_USEBOOKMARKS:
305 m_bUseBookmarks = ::comphelper::getBOOL( rValue );
306 if ( m_xAggregateAsSet.is() && m_xAggregateAsSet->getPropertySetInfo()->hasPropertyByName( PROPERTY_USEBOOKMARKS ) )
307 m_xAggregateAsSet->setPropertyValue( PROPERTY_USEBOOKMARKS, rValue );
309 break;
311 case PROPERTY_ID_ESCAPE_PROCESSING:
312 m_bEscapeProcessing = ::comphelper::getBOOL( rValue );
313 if ( m_xAggregateAsSet.is() )
314 m_xAggregateAsSet->setPropertyValue( PROPERTY_ESCAPE_PROCESSING, rValue );
315 break;
317 default:
318 if ( m_xAggregateAsSet.is() )
320 ::rtl::OUString sPropName;
321 getInfoHelper().fillPropertyMembersByHandle( &sPropName, NULL, nHandle );
322 m_xAggregateAsSet->setPropertyValue( sPropName, rValue );
324 break;
328 //------------------------------------------------------------------------------
329 void OStatementBase::getFastPropertyValue( Any& rValue, sal_Int32 nHandle ) const
331 //RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OStatementBase::getFastPropertyValue" );
332 switch (nHandle)
334 case PROPERTY_ID_USEBOOKMARKS:
335 rValue <<= m_bUseBookmarks;
336 break;
338 case PROPERTY_ID_ESCAPE_PROCESSING:
339 // don't rely on our aggregate - if it implements this wrong, and always returns
340 // TRUE here, then we would loop in impl_doEscapeProcessing_nothrow
341 rValue <<= m_bEscapeProcessing;
342 break;
344 default:
345 if ( m_xAggregateAsSet.is() )
347 ::rtl::OUString sPropName;
348 const_cast< OStatementBase* >( this )->getInfoHelper().fillPropertyMembersByHandle( &sPropName, NULL, nHandle );
349 rValue = m_xAggregateAsSet->getPropertyValue( sPropName );
351 break;
355 // XWarningsSupplier
356 //------------------------------------------------------------------------------
357 Any OStatementBase::getWarnings(void) throw( SQLException, RuntimeException )
359 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OStatementBase::getWarnings" );
360 MutexGuard aGuard(m_aMutex);
361 ::connectivity::checkDisposed(OComponentHelper::rBHelper.bDisposed);
363 return Reference< XWarningsSupplier >(m_xAggregateAsSet, UNO_QUERY)->getWarnings();
366 //------------------------------------------------------------------------------
367 void OStatementBase::clearWarnings(void) throw( SQLException, RuntimeException )
369 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OStatementBase::clearWarnings" );
370 MutexGuard aGuard(m_aMutex);
371 ::connectivity::checkDisposed(OComponentHelper::rBHelper.bDisposed);
373 Reference< XWarningsSupplier >(m_xAggregateAsSet, UNO_QUERY)->clearWarnings();
376 // ::com::sun::star::util::XCancellable
377 //------------------------------------------------------------------------------
378 void OStatementBase::cancel(void) throw( RuntimeException )
380 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OStatementBase::cancel" );
381 // no blocking as cancel is typically called from a different thread
382 ClearableMutexGuard aCancelGuard(m_aCancelMutex);
383 if (m_xAggregateAsCancellable.is())
384 m_xAggregateAsCancellable->cancel();
385 // else do nothing
388 // XMultipleResults
389 //------------------------------------------------------------------------------
390 Reference< XResultSet > SAL_CALL OStatementBase::getResultSet( ) throw(SQLException, RuntimeException)
392 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OStatementBase::getResultSet" );
393 MutexGuard aGuard(m_aMutex);
394 ::connectivity::checkDisposed(OComponentHelper::rBHelper.bDisposed);
396 // first check the meta data
397 Reference<XDatabaseMetaData> xMeta = Reference< XConnection > (m_xParent, UNO_QUERY)->getMetaData();
398 if (!xMeta.is() && !xMeta->supportsMultipleResultSets())
399 throwFunctionSequenceException(*this);
401 return Reference< XMultipleResults >(m_xAggregateAsSet, UNO_QUERY)->getResultSet();
404 //------------------------------------------------------------------------------
405 sal_Int32 SAL_CALL OStatementBase::getUpdateCount( ) throw(SQLException, RuntimeException)
407 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OStatementBase::getUpdateCount" );
408 MutexGuard aGuard(m_aMutex);
409 ::connectivity::checkDisposed(OComponentHelper::rBHelper.bDisposed);
411 // first check the meta data
412 Reference<XDatabaseMetaData> xMeta = Reference< XConnection > (m_xParent, UNO_QUERY)->getMetaData();
413 if (!xMeta.is() && !xMeta->supportsMultipleResultSets())
414 throwFunctionSequenceException(*this);
416 return Reference< XMultipleResults >(m_xAggregateAsSet, UNO_QUERY)->getUpdateCount();
419 //------------------------------------------------------------------------------
420 sal_Bool SAL_CALL OStatementBase::getMoreResults( ) throw(SQLException, RuntimeException)
422 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OStatementBase::getMoreResults" );
423 MutexGuard aGuard(m_aMutex);
424 ::connectivity::checkDisposed(OComponentHelper::rBHelper.bDisposed);
426 // first check the meta data
427 Reference<XDatabaseMetaData> xMeta = Reference< XConnection > (m_xParent, UNO_QUERY)->getMetaData();
428 if (!xMeta.is() && !xMeta->supportsMultipleResultSets())
429 throwFunctionSequenceException(*this);
430 throwFunctionSequenceException(*this);
432 // free the previous results
433 disposeResultSet();
435 return Reference< XMultipleResults >(m_xAggregateAsSet, UNO_QUERY)->getMoreResults();
438 // XPreparedBatchExecution
439 //------------------------------------------------------------------------------
440 void SAL_CALL OStatementBase::addBatch( ) throw(SQLException, RuntimeException)
442 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OStatementBase::addBatch" );
443 MutexGuard aGuard(m_aMutex);
444 ::connectivity::checkDisposed(OComponentHelper::rBHelper.bDisposed);
446 // first check the meta data
447 Reference<XDatabaseMetaData> xMeta = Reference< XConnection > (m_xParent, UNO_QUERY)->getMetaData();
448 if (!xMeta.is() && !xMeta->supportsBatchUpdates())
449 throwFunctionSequenceException(*this);
451 Reference< XPreparedBatchExecution >(m_xAggregateAsSet, UNO_QUERY)->addBatch();
454 //------------------------------------------------------------------------------
455 void SAL_CALL OStatementBase::clearBatch( ) throw(SQLException, RuntimeException)
457 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OStatementBase::clearBatch" );
458 MutexGuard aGuard(m_aMutex);
459 ::connectivity::checkDisposed(OComponentHelper::rBHelper.bDisposed);
461 // first check the meta data
462 Reference<XDatabaseMetaData> xMeta = Reference< XConnection > (m_xParent, UNO_QUERY)->getMetaData();
463 if (!xMeta.is() && !xMeta->supportsBatchUpdates())
464 throwFunctionSequenceException(*this);
466 Reference< XPreparedBatchExecution >(m_xAggregateAsSet, UNO_QUERY)->clearBatch();
469 //------------------------------------------------------------------------------
470 Sequence< sal_Int32 > SAL_CALL OStatementBase::executeBatch( ) throw(SQLException, RuntimeException)
472 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OStatementBase::executeBatch" );
473 MutexGuard aGuard(m_aMutex);
474 ::connectivity::checkDisposed(OComponentHelper::rBHelper.bDisposed);
476 // first check the meta data
477 Reference<XDatabaseMetaData> xMeta = Reference< XConnection > (m_xParent, UNO_QUERY)->getMetaData();
478 if (!xMeta.is() && !xMeta->supportsBatchUpdates())
479 throwFunctionSequenceException(*this);
481 // free the previous results
482 disposeResultSet();
484 return Reference< XPreparedBatchExecution >(m_xAggregateAsSet, UNO_QUERY)->executeBatch();
486 // -----------------------------------------------------------------------------
487 Reference< XResultSet > SAL_CALL OStatementBase::getGeneratedValues( ) throw (SQLException, RuntimeException)
489 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OStatementBase::getGeneratedValues" );
490 MutexGuard aGuard(m_aMutex);
491 ::connectivity::checkDisposed(OComponentHelper::rBHelper.bDisposed);
492 Reference< XGeneratedResultSet > xGRes(m_xAggregateAsSet, UNO_QUERY);
494 if ( xGRes.is() )
495 return xGRes->getGeneratedValues( );
496 return Reference< XResultSet >();
499 //************************************************************
500 // OStatement
501 //************************************************************
502 //------------------------------------------------------------------------------
503 OStatement::OStatement( const Reference< XConnection >& _xConn, const Reference< XInterface > & _xStatement )
504 :OStatementBase( _xConn, _xStatement )
505 ,m_bAttemptedComposerCreation( false )
507 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OStatement::OStatement" );
508 m_xAggregateStatement.set( _xStatement, UNO_QUERY_THROW );
511 //------------------------------------------------------------------------------
512 IMPLEMENT_FORWARD_XINTERFACE2( OStatement, OStatementBase, OStatement_IFACE );
513 IMPLEMENT_FORWARD_XTYPEPROVIDER2( OStatement, OStatementBase, OStatement_IFACE );
515 // XServiceInfo
516 //------------------------------------------------------------------------------
517 rtl::OUString OStatement::getImplementationName( ) throw(RuntimeException)
519 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OStatement::getImplementationName" );
520 return rtl::OUString::createFromAscii("com.sun.star.sdb.OStatement");
523 //------------------------------------------------------------------------------
524 sal_Bool OStatement::supportsService( const ::rtl::OUString& _rServiceName ) throw (RuntimeException)
526 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OStatement::supportsService" );
527 return ::comphelper::findValue(getSupportedServiceNames(), _rServiceName, sal_True).getLength() != 0;
530 //------------------------------------------------------------------------------
531 Sequence< ::rtl::OUString > OStatement::getSupportedServiceNames( ) throw (RuntimeException)
533 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OStatement::getSupportedServiceNames" );
534 Sequence< ::rtl::OUString > aSNS( 1 );
535 aSNS.getArray()[0] = SERVICE_SDBC_STATEMENT;
536 return aSNS;
539 // XStatement
540 //------------------------------------------------------------------------------
541 Reference< XResultSet > OStatement::executeQuery( const rtl::OUString& _rSQL ) throw( SQLException, RuntimeException )
543 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OStatement::executeQuery" );
544 MutexGuard aGuard(m_aMutex);
545 ::connectivity::checkDisposed(OComponentHelper::rBHelper.bDisposed);
547 disposeResultSet();
548 Reference< XResultSet > xResultSet;
550 ::rtl::OUString sSQL( impl_doEscapeProcessing_nothrow( _rSQL ) );
552 Reference< XResultSet > xInnerResultSet = m_xAggregateStatement->executeQuery( sSQL );
553 Reference< XConnection > xConnection( m_xParent, UNO_QUERY_THROW );
555 if ( xInnerResultSet.is() )
557 Reference< XDatabaseMetaData > xMeta = xConnection->getMetaData();
558 sal_Bool bCaseSensitive = xMeta.is() && xMeta->supportsMixedCaseQuotedIdentifiers();
559 xResultSet = new OResultSet( xInnerResultSet, *this, bCaseSensitive );
561 // keep the resultset weak
562 m_aResultSet = xResultSet;
565 return xResultSet;
568 //------------------------------------------------------------------------------
569 sal_Int32 OStatement::executeUpdate( const rtl::OUString& _rSQL ) throw( SQLException, RuntimeException )
571 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OStatement::executeUpdate" );
572 MutexGuard aGuard(m_aMutex);
573 ::connectivity::checkDisposed(OComponentHelper::rBHelper.bDisposed);
575 disposeResultSet();
577 ::rtl::OUString sSQL( impl_doEscapeProcessing_nothrow( _rSQL ) );
578 return m_xAggregateStatement->executeUpdate( sSQL );
581 //------------------------------------------------------------------------------
582 sal_Bool OStatement::execute( const rtl::OUString& _rSQL ) throw( SQLException, RuntimeException )
584 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OStatement::execute" );
585 MutexGuard aGuard(m_aMutex);
586 ::connectivity::checkDisposed(OComponentHelper::rBHelper.bDisposed);
588 disposeResultSet();
590 ::rtl::OUString sSQL( impl_doEscapeProcessing_nothrow( _rSQL ) );
591 return m_xAggregateStatement->execute( sSQL );
593 //------------------------------------------------------------------------------
594 void OStatement::addBatch( const rtl::OUString& _rSQL ) throw( SQLException, RuntimeException )
596 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OStatement::execute" );
597 MutexGuard aGuard(m_aMutex);
598 ::connectivity::checkDisposed(OComponentHelper::rBHelper.bDisposed);
600 // first check the meta data
601 Reference<XDatabaseMetaData> xMeta = Reference< XConnection > (m_xParent, UNO_QUERY)->getMetaData();
602 if (!xMeta.is() && !xMeta->supportsBatchUpdates())
603 throwFunctionSequenceException(*this);
605 ::rtl::OUString sSQL( impl_doEscapeProcessing_nothrow( _rSQL ) );
606 Reference< XBatchExecution >(m_xAggregateAsSet, UNO_QUERY)->addBatch( sSQL );
608 //------------------------------------------------------------------------------
609 void OStatement::clearBatch( ) throw( SQLException, RuntimeException )
611 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OStatement::execute" );
612 MutexGuard aGuard(m_aMutex);
613 ::connectivity::checkDisposed(OComponentHelper::rBHelper.bDisposed);
614 // first check the meta data
615 Reference<XDatabaseMetaData> xMeta = Reference< XConnection > (m_xParent, UNO_QUERY)->getMetaData();
616 if (!xMeta.is() && !xMeta->supportsBatchUpdates())
617 throwFunctionSequenceException(*this);
619 Reference< XBatchExecution >(m_xAggregateAsSet, UNO_QUERY)->clearBatch();
621 //------------------------------------------------------------------------------
622 Sequence< sal_Int32 > OStatement::executeBatch( ) throw( SQLException, RuntimeException )
624 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OStatement::execute" );
625 MutexGuard aGuard(m_aMutex);
626 ::connectivity::checkDisposed(OComponentHelper::rBHelper.bDisposed);
627 // first check the meta data
628 Reference<XDatabaseMetaData> xMeta = Reference< XConnection > (m_xParent, UNO_QUERY)->getMetaData();
629 if (!xMeta.is() && !xMeta->supportsBatchUpdates())
630 throwFunctionSequenceException(*this);
631 return Reference< XBatchExecution >(m_xAggregateAsSet, UNO_QUERY)->executeBatch( );
634 //------------------------------------------------------------------------------
635 Reference< XConnection > OStatement::getConnection(void) throw( SQLException, RuntimeException )
637 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OStatement::getConnection" );
638 return Reference< XConnection >( m_xParent, UNO_QUERY );
641 // -----------------------------------------------------------------------------
642 void SAL_CALL OStatement::disposing()
644 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OStatement::disposing" );
645 OStatementBase::disposing();
646 m_xComposer.clear();
647 m_xAggregateStatement.clear();
650 // -----------------------------------------------------------------------------
651 ::rtl::OUString OStatement::impl_doEscapeProcessing_nothrow( const ::rtl::OUString& _rSQL ) const
653 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OStatement::impl_doEscapeProcessing_nothrow" );
654 if ( !m_bEscapeProcessing )
655 return _rSQL;
658 if ( !impl_ensureComposer_nothrow() )
659 return _rSQL;
661 bool bParseable = false;
662 try { m_xComposer->setQuery( _rSQL ); bParseable = true; }
663 catch( const SQLException& ) { }
665 if ( !bParseable )
666 // if we cannot parse it, silently accept this. The driver is probably able to cope with it then
667 return _rSQL;
669 ::rtl::OUString sLowLevelSQL = m_xComposer->getQueryWithSubstitution();
670 return sLowLevelSQL;
672 catch( const Exception& )
674 DBG_UNHANDLED_EXCEPTION();
677 return _rSQL;
680 // -----------------------------------------------------------------------------
681 bool OStatement::impl_ensureComposer_nothrow() const
683 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OStatement::impl_ensureComposer_nothrow" );
684 if ( m_bAttemptedComposerCreation )
685 return m_xComposer.is();
687 const_cast< OStatement* >( this )->m_bAttemptedComposerCreation = true;
690 Reference< XMultiServiceFactory > xFactory( m_xParent, UNO_QUERY_THROW );
691 const_cast< OStatement* >( this )->m_xComposer.set( xFactory->createInstance( SERVICE_NAME_SINGLESELECTQUERYCOMPOSER ), UNO_QUERY_THROW );
693 catch( const Exception& )
695 DBG_UNHANDLED_EXCEPTION();
698 return m_xComposer.is();