Version 4.0.0.1, tag libreoffice-4.0.0.1
[LibreOffice.git] / dbaccess / source / core / api / statement.cxx
blob014f1752becffd0feda8d2fb675a679a89838d51
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <statement.hxx>
21 #include <resultset.hxx>
22 #include "dbastrings.hrc"
23 #include <com/sun/star/lang/DisposedException.hpp>
24 #include <com/sun/star/sdbc/XDatabaseMetaData.hpp>
25 #include <comphelper/sequence.hxx>
26 #include <cppuhelper/typeprovider.hxx>
27 #include <comphelper/property.hxx>
28 #include <comphelper/types.hxx>
29 #include <tools/debug.hxx>
30 #include <tools/diagnose_ex.h>
31 #include <connectivity/dbexception.hxx>
32 #include <rtl/logfile.hxx>
34 using namespace ::com::sun::star::sdb;
35 using namespace ::com::sun::star::sdbc;
36 using namespace ::com::sun::star::beans;
37 using namespace ::com::sun::star::uno;
38 using namespace ::com::sun::star::lang;
39 using namespace ::cppu;
40 using namespace ::osl;
41 using namespace dbaccess;
42 using namespace dbtools;
44 DBG_NAME(OStatementBase)
46 OStatementBase::OStatementBase(const Reference< XConnection > & _xConn,
47 const Reference< XInterface > & _xStatement)
48 :OSubComponent(m_aMutex, _xConn)
49 ,OPropertySetHelper(OComponentHelper::rBHelper)
50 ,m_bUseBookmarks( sal_False )
51 ,m_bEscapeProcessing( sal_True )
54 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OStatementBase::OStatementBase" );
55 DBG_CTOR(OStatementBase, NULL);
56 OSL_ENSURE(_xStatement.is() ,"Statement is NULL!");
57 m_xAggregateAsSet.set(_xStatement,UNO_QUERY);
58 m_xAggregateAsCancellable = Reference< ::com::sun::star::util::XCancellable > (m_xAggregateAsSet, UNO_QUERY);
61 OStatementBase::~OStatementBase()
63 DBG_DTOR(OStatementBase, NULL);
66 // com::sun::star::lang::XTypeProvider
67 Sequence< Type > OStatementBase::getTypes() throw (RuntimeException)
69 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OStatementBase::getTypes" );
70 OTypeCollection aTypes(::getCppuType( (const Reference< XPropertySet > *)0 ),
71 ::getCppuType( (const Reference< XWarningsSupplier > *)0 ),
72 ::getCppuType( (const Reference< XCloseable > *)0 ),
73 ::getCppuType( (const Reference< XMultipleResults > *)0 ),
74 ::getCppuType( (const Reference< ::com::sun::star::util::XCancellable > *)0 ),
75 OSubComponent::getTypes() );
76 Reference< XGeneratedResultSet > xGRes(m_xAggregateAsSet, UNO_QUERY);
77 if ( xGRes.is() )
78 aTypes = OTypeCollection(::getCppuType( (const Reference< XGeneratedResultSet > *)0 ),aTypes.getTypes());
79 Reference< XPreparedBatchExecution > xPreparedBatchExecution(m_xAggregateAsSet, UNO_QUERY);
80 if ( xPreparedBatchExecution.is() )
81 aTypes = OTypeCollection(::getCppuType( (const Reference< XPreparedBatchExecution > *)0 ),aTypes.getTypes());
83 return aTypes.getTypes();
86 // com::sun::star::uno::XInterface
87 Any OStatementBase::queryInterface( const Type & rType ) throw (RuntimeException)
89 //RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OStatementBase::queryInterface" );
90 Any aIface = OSubComponent::queryInterface( rType );
91 if (!aIface.hasValue())
93 aIface = ::cppu::queryInterface(
94 rType,
95 static_cast< XPropertySet * >( this ),
96 static_cast< XWarningsSupplier * >( this ),
97 static_cast< XCloseable * >( this ),
98 static_cast< XMultipleResults * >( this ),
99 static_cast< ::com::sun::star::util::XCancellable * >( this ));
100 if ( !aIface.hasValue() )
102 Reference< XGeneratedResultSet > xGRes(m_xAggregateAsSet, UNO_QUERY);
103 if ( ::getCppuType( (const Reference< XGeneratedResultSet > *)0 ) == rType && xGRes.is() )
104 aIface = ::cppu::queryInterface(rType,static_cast< XGeneratedResultSet * >( this ));
106 if ( !aIface.hasValue() )
108 Reference< XPreparedBatchExecution > xGRes(m_xAggregateAsSet, UNO_QUERY);
109 if ( ::getCppuType( (const Reference< XPreparedBatchExecution > *)0 ) == rType && xGRes.is() )
110 aIface = ::cppu::queryInterface(rType,static_cast< XPreparedBatchExecution * >( this ));
113 return aIface;
116 void OStatementBase::acquire() throw ()
118 OSubComponent::acquire();
121 void OStatementBase::release() throw ()
123 OSubComponent::release();
126 void OStatementBase::disposeResultSet()
128 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OStatementBase::disposeResultSet" );
129 // free the cursor if alive
130 Reference< XComponent > xComp(m_aResultSet.get(), UNO_QUERY);
131 if (xComp.is())
132 xComp->dispose();
133 m_aResultSet = NULL;
136 // OComponentHelper
137 void OStatementBase::disposing()
139 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OStatementBase::disposing" );
140 OPropertySetHelper::disposing();
142 MutexGuard aGuard(m_aMutex);
144 // free pending results
145 disposeResultSet();
147 // free the original statement
149 MutexGuard aCancelGuard(m_aCancelMutex);
150 m_xAggregateAsCancellable = NULL;
153 if ( m_xAggregateAsSet.is() )
157 Reference< XCloseable > (m_xAggregateAsSet, UNO_QUERY)->close();
159 catch(RuntimeException& )
160 {// don't care for anymore
163 m_xAggregateAsSet = NULL;
165 // free the parent at last
166 OSubComponent::disposing();
169 // XCloseable
170 void OStatementBase::close(void) throw( SQLException, RuntimeException )
172 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OStatementBase::close" );
174 MutexGuard aGuard( m_aMutex );
175 ::connectivity::checkDisposed(OComponentHelper::rBHelper.bDisposed);
177 dispose();
180 // OPropertySetHelper
181 Reference< XPropertySetInfo > OStatementBase::getPropertySetInfo() throw (RuntimeException)
183 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OStatementBase::getPropertySetInfo" );
184 return createPropertySetInfo( getInfoHelper() ) ;
187 // comphelper::OPropertyArrayUsageHelper
188 ::cppu::IPropertyArrayHelper* OStatementBase::createArrayHelper( ) const
190 //RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OStatementBase::createArrayHelper" );
191 BEGIN_PROPERTY_HELPER(10)
192 DECL_PROP0(CURSORNAME, ::rtl::OUString);
193 DECL_PROP0_BOOL(ESCAPE_PROCESSING);
194 DECL_PROP0(FETCHDIRECTION, sal_Int32);
195 DECL_PROP0(FETCHSIZE, sal_Int32);
196 DECL_PROP0(MAXFIELDSIZE, sal_Int32);
197 DECL_PROP0(MAXROWS, sal_Int32);
198 DECL_PROP0(QUERYTIMEOUT, sal_Int32);
199 DECL_PROP0(RESULTSETCONCURRENCY, sal_Int32);
200 DECL_PROP0(RESULTSETTYPE, sal_Int32);
201 DECL_PROP0_BOOL(USEBOOKMARKS);
202 END_PROPERTY_HELPER();
205 // cppu::OPropertySetHelper
206 ::cppu::IPropertyArrayHelper& OStatementBase::getInfoHelper()
208 //RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OStatementBase::getInfoHelper" );
209 return *getArrayHelper();
212 sal_Bool OStatementBase::convertFastPropertyValue( Any & rConvertedValue, Any & rOldValue, sal_Int32 nHandle, const Any& rValue ) throw( IllegalArgumentException )
214 //RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OStatementBase::convertFastPropertyValue" );
215 sal_Bool bModified(sal_False);
216 switch (nHandle)
218 case PROPERTY_ID_USEBOOKMARKS:
219 bModified = ::comphelper::tryPropertyValue( rConvertedValue, rOldValue, rValue, m_bUseBookmarks );
220 break;
222 case PROPERTY_ID_ESCAPE_PROCESSING:
223 bModified = ::comphelper::tryPropertyValue( rConvertedValue, rOldValue, rValue, m_bEscapeProcessing );
224 break;
226 default:
227 if ( m_xAggregateAsSet.is() )
229 // get the property name
230 ::rtl::OUString sPropName;
231 getInfoHelper().fillPropertyMembersByHandle( &sPropName, NULL, nHandle );
233 // now set the value
234 Any aCurrentValue = m_xAggregateAsSet->getPropertyValue( sPropName );
235 if ( aCurrentValue != rValue )
237 rOldValue = aCurrentValue;
238 rConvertedValue = rValue;
239 bModified = sal_True;
242 break;
244 return bModified;
247 void OStatementBase::setFastPropertyValue_NoBroadcast( sal_Int32 nHandle, const Any& rValue ) throw (Exception)
249 //RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OStatementBase::setFastPropertyValue_NoBroadcast" );
250 switch ( nHandle )
252 case PROPERTY_ID_USEBOOKMARKS:
254 m_bUseBookmarks = ::comphelper::getBOOL( rValue );
255 if ( m_xAggregateAsSet.is() && m_xAggregateAsSet->getPropertySetInfo()->hasPropertyByName( PROPERTY_USEBOOKMARKS ) )
256 m_xAggregateAsSet->setPropertyValue( PROPERTY_USEBOOKMARKS, rValue );
258 break;
260 case PROPERTY_ID_ESCAPE_PROCESSING:
261 m_bEscapeProcessing = ::comphelper::getBOOL( rValue );
262 if ( m_xAggregateAsSet.is() )
263 m_xAggregateAsSet->setPropertyValue( PROPERTY_ESCAPE_PROCESSING, rValue );
264 break;
266 default:
267 if ( m_xAggregateAsSet.is() )
269 ::rtl::OUString sPropName;
270 getInfoHelper().fillPropertyMembersByHandle( &sPropName, NULL, nHandle );
271 m_xAggregateAsSet->setPropertyValue( sPropName, rValue );
273 break;
277 void OStatementBase::getFastPropertyValue( Any& rValue, sal_Int32 nHandle ) const
279 //RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OStatementBase::getFastPropertyValue" );
280 switch (nHandle)
282 case PROPERTY_ID_USEBOOKMARKS:
283 rValue <<= m_bUseBookmarks;
284 break;
286 case PROPERTY_ID_ESCAPE_PROCESSING:
287 // don't rely on our aggregate - if it implements this wrong, and always returns
288 // TRUE here, then we would loop in impl_doEscapeProcessing_nothrow
289 rValue <<= m_bEscapeProcessing;
290 break;
292 default:
293 if ( m_xAggregateAsSet.is() )
295 ::rtl::OUString sPropName;
296 const_cast< OStatementBase* >( this )->getInfoHelper().fillPropertyMembersByHandle( &sPropName, NULL, nHandle );
297 rValue = m_xAggregateAsSet->getPropertyValue( sPropName );
299 break;
303 // XWarningsSupplier
304 Any OStatementBase::getWarnings(void) throw( SQLException, RuntimeException )
306 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OStatementBase::getWarnings" );
307 MutexGuard aGuard(m_aMutex);
308 ::connectivity::checkDisposed(OComponentHelper::rBHelper.bDisposed);
310 return Reference< XWarningsSupplier >(m_xAggregateAsSet, UNO_QUERY)->getWarnings();
313 void OStatementBase::clearWarnings(void) throw( SQLException, RuntimeException )
315 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OStatementBase::clearWarnings" );
316 MutexGuard aGuard(m_aMutex);
317 ::connectivity::checkDisposed(OComponentHelper::rBHelper.bDisposed);
319 Reference< XWarningsSupplier >(m_xAggregateAsSet, UNO_QUERY)->clearWarnings();
322 // ::com::sun::star::util::XCancellable
323 void OStatementBase::cancel(void) throw( RuntimeException )
325 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OStatementBase::cancel" );
326 // no blocking as cancel is typically called from a different thread
327 ClearableMutexGuard aCancelGuard(m_aCancelMutex);
328 if (m_xAggregateAsCancellable.is())
329 m_xAggregateAsCancellable->cancel();
330 // else do nothing
333 // XMultipleResults
334 Reference< XResultSet > SAL_CALL OStatementBase::getResultSet( ) throw(SQLException, RuntimeException)
336 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OStatementBase::getResultSet" );
337 MutexGuard aGuard(m_aMutex);
338 ::connectivity::checkDisposed(OComponentHelper::rBHelper.bDisposed);
340 // first check the meta data
341 Reference<XDatabaseMetaData> xMeta = Reference< XConnection > (m_xParent, UNO_QUERY)->getMetaData();
342 if (!xMeta.is() && !xMeta->supportsMultipleResultSets())
343 throwFunctionSequenceException(*this);
345 return Reference< XMultipleResults >(m_xAggregateAsSet, UNO_QUERY)->getResultSet();
348 sal_Int32 SAL_CALL OStatementBase::getUpdateCount( ) throw(SQLException, RuntimeException)
350 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OStatementBase::getUpdateCount" );
351 MutexGuard aGuard(m_aMutex);
352 ::connectivity::checkDisposed(OComponentHelper::rBHelper.bDisposed);
354 // first check the meta data
355 Reference<XDatabaseMetaData> xMeta = Reference< XConnection > (m_xParent, UNO_QUERY)->getMetaData();
356 if (!xMeta.is() && !xMeta->supportsMultipleResultSets())
357 throwFunctionSequenceException(*this);
359 return Reference< XMultipleResults >(m_xAggregateAsSet, UNO_QUERY)->getUpdateCount();
362 sal_Bool SAL_CALL OStatementBase::getMoreResults( ) throw(SQLException, RuntimeException)
364 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OStatementBase::getMoreResults" );
365 MutexGuard aGuard(m_aMutex);
366 ::connectivity::checkDisposed(OComponentHelper::rBHelper.bDisposed);
368 // first check the meta data
369 Reference<XDatabaseMetaData> xMeta = Reference< XConnection > (m_xParent, UNO_QUERY)->getMetaData();
370 if (!xMeta.is() && !xMeta->supportsMultipleResultSets())
371 throwFunctionSequenceException(*this);
372 throwFunctionSequenceException(*this);
374 // free the previous results
375 disposeResultSet();
377 return Reference< XMultipleResults >(m_xAggregateAsSet, UNO_QUERY)->getMoreResults();
380 // XPreparedBatchExecution
381 void SAL_CALL OStatementBase::addBatch( ) throw(SQLException, RuntimeException)
383 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OStatementBase::addBatch" );
384 MutexGuard aGuard(m_aMutex);
385 ::connectivity::checkDisposed(OComponentHelper::rBHelper.bDisposed);
387 // first check the meta data
388 Reference<XDatabaseMetaData> xMeta = Reference< XConnection > (m_xParent, UNO_QUERY)->getMetaData();
389 if (!xMeta.is() && !xMeta->supportsBatchUpdates())
390 throwFunctionSequenceException(*this);
392 Reference< XPreparedBatchExecution >(m_xAggregateAsSet, UNO_QUERY)->addBatch();
395 void SAL_CALL OStatementBase::clearBatch( ) throw(SQLException, RuntimeException)
397 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OStatementBase::clearBatch" );
398 MutexGuard aGuard(m_aMutex);
399 ::connectivity::checkDisposed(OComponentHelper::rBHelper.bDisposed);
401 // first check the meta data
402 Reference<XDatabaseMetaData> xMeta = Reference< XConnection > (m_xParent, UNO_QUERY)->getMetaData();
403 if (!xMeta.is() && !xMeta->supportsBatchUpdates())
404 throwFunctionSequenceException(*this);
406 Reference< XPreparedBatchExecution >(m_xAggregateAsSet, UNO_QUERY)->clearBatch();
409 Sequence< sal_Int32 > SAL_CALL OStatementBase::executeBatch( ) throw(SQLException, RuntimeException)
411 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OStatementBase::executeBatch" );
412 MutexGuard aGuard(m_aMutex);
413 ::connectivity::checkDisposed(OComponentHelper::rBHelper.bDisposed);
415 // first check the meta data
416 Reference<XDatabaseMetaData> xMeta = Reference< XConnection > (m_xParent, UNO_QUERY)->getMetaData();
417 if (!xMeta.is() && !xMeta->supportsBatchUpdates())
418 throwFunctionSequenceException(*this);
420 // free the previous results
421 disposeResultSet();
423 return Reference< XPreparedBatchExecution >(m_xAggregateAsSet, UNO_QUERY)->executeBatch();
426 Reference< XResultSet > SAL_CALL OStatementBase::getGeneratedValues( ) throw (SQLException, RuntimeException)
428 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OStatementBase::getGeneratedValues" );
429 MutexGuard aGuard(m_aMutex);
430 ::connectivity::checkDisposed(OComponentHelper::rBHelper.bDisposed);
431 Reference< XGeneratedResultSet > xGRes(m_xAggregateAsSet, UNO_QUERY);
433 if ( xGRes.is() )
434 return xGRes->getGeneratedValues( );
435 return Reference< XResultSet >();
438 //************************************************************
439 // OStatement
440 //************************************************************
441 OStatement::OStatement( const Reference< XConnection >& _xConn, const Reference< XInterface > & _xStatement )
442 :OStatementBase( _xConn, _xStatement )
443 ,m_bAttemptedComposerCreation( false )
445 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OStatement::OStatement" );
446 m_xAggregateStatement.set( _xStatement, UNO_QUERY_THROW );
449 IMPLEMENT_FORWARD_XINTERFACE2( OStatement, OStatementBase, OStatement_IFACE );
450 IMPLEMENT_FORWARD_XTYPEPROVIDER2( OStatement, OStatementBase, OStatement_IFACE );
452 // XServiceInfo
453 rtl::OUString OStatement::getImplementationName( ) throw(RuntimeException)
455 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OStatement::getImplementationName" );
456 return rtl::OUString("com.sun.star.sdb.OStatement");
459 sal_Bool OStatement::supportsService( const ::rtl::OUString& _rServiceName ) throw (RuntimeException)
461 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OStatement::supportsService" );
462 return ::comphelper::findValue(getSupportedServiceNames(), _rServiceName, sal_True).getLength() != 0;
465 Sequence< ::rtl::OUString > OStatement::getSupportedServiceNames( ) throw (RuntimeException)
467 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OStatement::getSupportedServiceNames" );
468 Sequence< ::rtl::OUString > aSNS( 1 );
469 aSNS.getArray()[0] = SERVICE_SDBC_STATEMENT;
470 return aSNS;
473 // XStatement
474 Reference< XResultSet > OStatement::executeQuery( const rtl::OUString& _rSQL ) throw( SQLException, RuntimeException )
476 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OStatement::executeQuery" );
477 MutexGuard aGuard(m_aMutex);
478 ::connectivity::checkDisposed(OComponentHelper::rBHelper.bDisposed);
480 disposeResultSet();
481 Reference< XResultSet > xResultSet;
483 ::rtl::OUString sSQL( impl_doEscapeProcessing_nothrow( _rSQL ) );
485 Reference< XResultSet > xInnerResultSet = m_xAggregateStatement->executeQuery( sSQL );
486 Reference< XConnection > xConnection( m_xParent, UNO_QUERY_THROW );
488 if ( xInnerResultSet.is() )
490 Reference< XDatabaseMetaData > xMeta = xConnection->getMetaData();
491 sal_Bool bCaseSensitive = xMeta.is() && xMeta->supportsMixedCaseQuotedIdentifiers();
492 xResultSet = new OResultSet( xInnerResultSet, *this, bCaseSensitive );
494 // keep the resultset weak
495 m_aResultSet = xResultSet;
498 return xResultSet;
501 sal_Int32 OStatement::executeUpdate( const rtl::OUString& _rSQL ) throw( SQLException, RuntimeException )
503 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OStatement::executeUpdate" );
504 MutexGuard aGuard(m_aMutex);
505 ::connectivity::checkDisposed(OComponentHelper::rBHelper.bDisposed);
507 disposeResultSet();
509 ::rtl::OUString sSQL( impl_doEscapeProcessing_nothrow( _rSQL ) );
510 return m_xAggregateStatement->executeUpdate( sSQL );
513 sal_Bool OStatement::execute( const rtl::OUString& _rSQL ) throw( SQLException, RuntimeException )
515 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OStatement::execute" );
516 MutexGuard aGuard(m_aMutex);
517 ::connectivity::checkDisposed(OComponentHelper::rBHelper.bDisposed);
519 disposeResultSet();
521 ::rtl::OUString sSQL( impl_doEscapeProcessing_nothrow( _rSQL ) );
522 return m_xAggregateStatement->execute( sSQL );
525 void OStatement::addBatch( const rtl::OUString& _rSQL ) throw( SQLException, RuntimeException )
527 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OStatement::execute" );
528 MutexGuard aGuard(m_aMutex);
529 ::connectivity::checkDisposed(OComponentHelper::rBHelper.bDisposed);
531 // first check the meta data
532 Reference<XDatabaseMetaData> xMeta = Reference< XConnection > (m_xParent, UNO_QUERY)->getMetaData();
533 if (!xMeta.is() && !xMeta->supportsBatchUpdates())
534 throwFunctionSequenceException(*this);
536 ::rtl::OUString sSQL( impl_doEscapeProcessing_nothrow( _rSQL ) );
537 Reference< XBatchExecution >(m_xAggregateAsSet, UNO_QUERY)->addBatch( sSQL );
540 void OStatement::clearBatch( ) throw( SQLException, RuntimeException )
542 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OStatement::execute" );
543 MutexGuard aGuard(m_aMutex);
544 ::connectivity::checkDisposed(OComponentHelper::rBHelper.bDisposed);
545 // first check the meta data
546 Reference<XDatabaseMetaData> xMeta = Reference< XConnection > (m_xParent, UNO_QUERY)->getMetaData();
547 if (!xMeta.is() && !xMeta->supportsBatchUpdates())
548 throwFunctionSequenceException(*this);
550 Reference< XBatchExecution >(m_xAggregateAsSet, UNO_QUERY)->clearBatch();
553 Sequence< sal_Int32 > OStatement::executeBatch( ) throw( SQLException, RuntimeException )
555 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OStatement::execute" );
556 MutexGuard aGuard(m_aMutex);
557 ::connectivity::checkDisposed(OComponentHelper::rBHelper.bDisposed);
558 // first check the meta data
559 Reference<XDatabaseMetaData> xMeta = Reference< XConnection > (m_xParent, UNO_QUERY)->getMetaData();
560 if (!xMeta.is() && !xMeta->supportsBatchUpdates())
561 throwFunctionSequenceException(*this);
562 return Reference< XBatchExecution >(m_xAggregateAsSet, UNO_QUERY)->executeBatch( );
566 Reference< XConnection > OStatement::getConnection(void) throw( SQLException, RuntimeException )
568 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OStatement::getConnection" );
569 return Reference< XConnection >( m_xParent, UNO_QUERY );
572 void SAL_CALL OStatement::disposing()
574 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OStatement::disposing" );
575 OStatementBase::disposing();
576 m_xComposer.clear();
577 m_xAggregateStatement.clear();
580 ::rtl::OUString OStatement::impl_doEscapeProcessing_nothrow( const ::rtl::OUString& _rSQL ) const
582 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OStatement::impl_doEscapeProcessing_nothrow" );
583 if ( !m_bEscapeProcessing )
584 return _rSQL;
587 if ( !impl_ensureComposer_nothrow() )
588 return _rSQL;
590 bool bParseable = false;
591 try { m_xComposer->setQuery( _rSQL ); bParseable = true; }
592 catch( const SQLException& ) { }
594 if ( !bParseable )
595 // if we cannot parse it, silently accept this. The driver is probably able to cope with it then
596 return _rSQL;
598 ::rtl::OUString sLowLevelSQL = m_xComposer->getQueryWithSubstitution();
599 return sLowLevelSQL;
601 catch( const Exception& )
603 DBG_UNHANDLED_EXCEPTION();
606 return _rSQL;
609 bool OStatement::impl_ensureComposer_nothrow() const
611 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OStatement::impl_ensureComposer_nothrow" );
612 if ( m_bAttemptedComposerCreation )
613 return m_xComposer.is();
615 const_cast< OStatement* >( this )->m_bAttemptedComposerCreation = true;
618 Reference< XMultiServiceFactory > xFactory( m_xParent, UNO_QUERY_THROW );
619 const_cast< OStatement* >( this )->m_xComposer.set( xFactory->createInstance( SERVICE_NAME_SINGLESELECTQUERYCOMPOSER ), UNO_QUERY_THROW );
621 catch( const Exception& )
623 DBG_UNHANDLED_EXCEPTION();
626 return m_xComposer.is();
629 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */