Version 4.0.0.1, tag libreoffice-4.0.0.1
[LibreOffice.git] / dbaccess / source / core / api / RowSet.cxx
blob50b9aa3226401d48b6278794d36aa5a93023fc1f
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 <string.h>
21 #include "RowSet.hxx"
22 #include "dbastrings.hrc"
23 #include "sdbcoretools.hxx"
24 #include "SingleSelectQueryComposer.hxx"
25 #include "module_dba.hxx"
26 #include "CRowSetColumn.hxx"
27 #include "CRowSetDataColumn.hxx"
28 #include "RowSetCache.hxx"
29 #include "core_resource.hrc"
30 #include "core_resource.hxx"
31 #include "tablecontainer.hxx"
33 #include <com/sun/star/beans/PropertyAttribute.hpp>
34 #include <com/sun/star/container/XChild.hpp>
35 #include <com/sun/star/lang/DisposedException.hpp>
36 #include <com/sun/star/sdb/CommandType.hpp>
37 #include <com/sun/star/sdb/DatabaseContext.hpp>
38 #include <com/sun/star/sdb/ErrorCondition.hpp>
39 #include <com/sun/star/sdb/RowChangeAction.hpp>
40 #include <com/sun/star/sdb/RowSetVetoException.hpp>
41 #include <com/sun/star/sdb/XCompletedConnection.hpp>
42 #include <com/sun/star/sdb/XParametersSupplier.hpp>
43 #include <com/sun/star/sdb/XQueriesSupplier.hpp>
44 #include <com/sun/star/sdbc/FetchDirection.hpp>
45 #include <com/sun/star/sdbc/ResultSetConcurrency.hpp>
46 #include <com/sun/star/sdbc/XDataSource.hpp>
47 #include <com/sun/star/sdbc/XDriverAccess.hpp>
48 #include <com/sun/star/sdbcx/CompareBookmark.hpp>
49 #include <com/sun/star/sdbcx/Privilege.hpp>
50 #include <com/sun/star/sdbcx/XDataDefinitionSupplier.hpp>
51 #include <com/sun/star/uno/XNamingService.hpp>
52 #include <com/sun/star/util/XNumberFormatsSupplier.hpp>
54 #include <comphelper/componentcontext.hxx>
55 #include <comphelper/extract.hxx>
56 #include <comphelper/interaction.hxx>
57 #include <comphelper/property.hxx>
58 #include <comphelper/seqstream.hxx>
59 #include <comphelper/sequence.hxx>
60 #include <comphelper/types.hxx>
61 #include <comphelper/uno3.hxx>
62 #include <connectivity/BlobHelper.hxx>
63 #include <connectivity/dbconversion.hxx>
64 #include <connectivity/dbexception.hxx>
65 #include <connectivity/dbtools.hxx>
66 #include <cppuhelper/exc_hlp.hxx>
67 #include <cppuhelper/interfacecontainer.h>
68 #include <cppuhelper/typeprovider.hxx>
69 #include <rtl/logfile.hxx>
70 #include <unotools/syslocale.hxx>
71 #include <tools/debug.hxx>
72 #include <tools/diagnose_ex.h>
73 #include <unotools/configmgr.hxx>
75 using namespace utl;
76 using namespace dbaccess;
77 using namespace connectivity;
78 using namespace comphelper;
79 using namespace dbtools;
80 using namespace ::com::sun::star;
81 using namespace ::com::sun::star::uno;
82 using namespace ::com::sun::star::beans;
83 using namespace ::com::sun::star::sdbc;
84 using namespace ::com::sun::star::sdb;
85 using namespace ::com::sun::star::sdbcx;
86 using namespace ::com::sun::star::container;
87 using namespace ::com::sun::star::lang;
88 using namespace ::com::sun::star::task;
89 using namespace ::com::sun::star::util;
90 using namespace ::cppu;
91 using namespace ::osl;
93 extern "C" void SAL_CALL createRegistryInfo_ORowSet()
95 static ::dba::OAutoRegistration< ORowSet > aAutoRegistration;
98 #define NOTIFY_LISTERNERS_CHECK(_rListeners,T,method) \
99 Sequence< Reference< XInterface > > aListenerSeq = _rListeners.getElements(); \
101 const Reference< XInterface >* pxIntBegin = aListenerSeq.getConstArray(); \
102 const Reference< XInterface >* pxInt = pxIntBegin + aListenerSeq.getLength(); \
104 _rGuard.clear(); \
105 sal_Bool bCheck = sal_True; \
106 while( pxInt > pxIntBegin && bCheck ) \
108 try \
110 while( pxInt > pxIntBegin && bCheck ) \
112 --pxInt; \
113 bCheck = static_cast< T* >( pxInt->get() )->method(aEvt); \
116 catch( RuntimeException& ) \
120 _rGuard.reset();
123 namespace dbaccess
126 Reference< XInterface > ORowSet_CreateInstance(const Reference< XMultiServiceFactory >& _rxFactory)
128 return *(new ORowSet(_rxFactory));
131 ORowSet::ORowSet( const Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxORB )
132 :ORowSet_BASE1(m_aMutex)
133 ,ORowSetBase( _rxORB, ORowSet_BASE1::rBHelper, &m_aMutex )
134 ,m_pParameters( NULL )
135 ,m_aRowsetListeners(*m_pMutex)
136 ,m_aApproveListeners(*m_pMutex)
137 ,m_aRowsChangeListener(*m_pMutex)
138 ,m_pTables(NULL)
139 ,m_nFetchDirection(FetchDirection::FORWARD)
140 ,m_nFetchSize(50)
141 ,m_nMaxFieldSize(0)
142 ,m_nMaxRows(0)
143 ,m_nQueryTimeOut(0)
144 ,m_nCommandType(CommandType::COMMAND)
145 ,m_nTransactionIsolation(0)
146 ,m_nPrivileges(0)
147 ,m_nInAppend(0)
148 ,m_bUseEscapeProcessing(sal_True)
149 ,m_bApplyFilter(sal_False)
150 ,m_bCommandFacetsDirty( sal_True )
151 ,m_bModified(sal_False)
152 ,m_bRebuildConnOnExecute(sal_False)
153 ,m_bIsBookmarkable(sal_True)
154 ,m_bNew(sal_False)
155 ,m_bCanUpdateInsertedRows(sal_True)
156 ,m_bOwnConnection(sal_False)
157 ,m_bPropChangeNotifyEnabled(sal_True)
159 m_nResultSetType = ResultSetType::SCROLL_SENSITIVE;
160 m_nResultSetConcurrency = ResultSetConcurrency::UPDATABLE;
161 m_pMySelf = this;
162 m_aActiveConnection <<= m_xActiveConnection;
164 sal_Int32 nRBT = PropertyAttribute::READONLY | PropertyAttribute::BOUND | PropertyAttribute::TRANSIENT;
165 sal_Int32 nRT = PropertyAttribute::READONLY | PropertyAttribute::TRANSIENT;
166 sal_Int32 nBT = PropertyAttribute::BOUND | PropertyAttribute::TRANSIENT;
168 m_aPrematureParamValues.get().resize( 0 );
170 // sdb.RowSet Properties
171 registerMayBeVoidProperty(PROPERTY_ACTIVE_CONNECTION,PROPERTY_ID_ACTIVE_CONNECTION, PropertyAttribute::MAYBEVOID|PropertyAttribute::TRANSIENT|PropertyAttribute::BOUND, &m_aActiveConnection, ::getCppuType(static_cast< Reference< XConnection >* >(0)));
172 registerProperty(PROPERTY_DATASOURCENAME, PROPERTY_ID_DATASOURCENAME, PropertyAttribute::BOUND, &m_aDataSourceName, ::getCppuType(static_cast< ::rtl::OUString*>(0)));
173 registerProperty(PROPERTY_COMMAND, PROPERTY_ID_COMMAND, PropertyAttribute::BOUND, &m_aCommand, ::getCppuType(static_cast< ::rtl::OUString*>(0)));
174 registerProperty(PROPERTY_COMMAND_TYPE, PROPERTY_ID_COMMAND_TYPE, PropertyAttribute::BOUND, &m_nCommandType, ::getCppuType(static_cast< sal_Int32*>(0)));
175 registerProperty(PROPERTY_ACTIVECOMMAND, PROPERTY_ID_ACTIVECOMMAND, nRBT, &m_aActiveCommand, ::getCppuType(static_cast< ::rtl::OUString*>(0)));
176 registerProperty(PROPERTY_IGNORERESULT, PROPERTY_ID_IGNORERESULT, PropertyAttribute::BOUND, &m_bIgnoreResult, ::getBooleanCppuType());
177 registerProperty(PROPERTY_FILTER, PROPERTY_ID_FILTER, PropertyAttribute::BOUND, &m_aFilter, ::getCppuType(static_cast< ::rtl::OUString*>(0)));
178 registerProperty(PROPERTY_HAVING_CLAUSE, PROPERTY_ID_HAVING_CLAUSE, PropertyAttribute::BOUND, &m_aHavingClause, ::getCppuType(static_cast< ::rtl::OUString*>(0)));
179 registerProperty(PROPERTY_GROUP_BY, PROPERTY_ID_GROUP_BY, PropertyAttribute::BOUND, &m_aGroupBy, ::getCppuType(static_cast< ::rtl::OUString*>(0)));
180 registerProperty(PROPERTY_APPLYFILTER, PROPERTY_ID_APPLYFILTER, PropertyAttribute::BOUND, &m_bApplyFilter, ::getBooleanCppuType());
181 registerProperty(PROPERTY_ORDER, PROPERTY_ID_ORDER, PropertyAttribute::BOUND, &m_aOrder, ::getCppuType(static_cast< ::rtl::OUString*>(0)));
182 registerProperty(PROPERTY_PRIVILEGES, PROPERTY_ID_PRIVILEGES, nRT, &m_nPrivileges, ::getCppuType(static_cast< sal_Int32*>(0)));
183 registerProperty(PROPERTY_ISMODIFIED, PROPERTY_ID_ISMODIFIED, nBT, &m_bModified, ::getBooleanCppuType());
184 registerProperty(PROPERTY_ISNEW, PROPERTY_ID_ISNEW, nRBT, &m_bNew, ::getBooleanCppuType());
185 registerProperty(PROPERTY_SINGLESELECTQUERYCOMPOSER,PROPERTY_ID_SINGLESELECTQUERYCOMPOSER, nRT, &m_xComposer, ::getCppuType(static_cast< Reference< XSingleSelectQueryComposer >* >(0)));
187 // sdbcx.ResultSet Properties
188 registerProperty(PROPERTY_ISBOOKMARKABLE, PROPERTY_ID_ISBOOKMARKABLE, nRT, &m_bIsBookmarkable, ::getBooleanCppuType());
189 registerProperty(PROPERTY_CANUPDATEINSERTEDROWS,PROPERTY_ID_CANUPDATEINSERTEDROWS, nRT, &m_bCanUpdateInsertedRows, ::getBooleanCppuType());
190 // sdbc.ResultSet Properties
191 registerProperty(PROPERTY_RESULTSETCONCURRENCY, PROPERTY_ID_RESULTSETCONCURRENCY, PropertyAttribute::TRANSIENT, &m_nResultSetConcurrency,::getCppuType(static_cast< sal_Int32*>(0)));
192 registerProperty(PROPERTY_RESULTSETTYPE, PROPERTY_ID_RESULTSETTYPE, PropertyAttribute::TRANSIENT, &m_nResultSetType, ::getCppuType(static_cast< sal_Int32*>(0)));
193 registerProperty(PROPERTY_FETCHDIRECTION, PROPERTY_ID_FETCHDIRECTION, PropertyAttribute::TRANSIENT, &m_nFetchDirection, ::getCppuType(static_cast< sal_Int32*>(0)));
194 registerProperty(PROPERTY_FETCHSIZE, PROPERTY_ID_FETCHSIZE, PropertyAttribute::TRANSIENT, &m_nFetchSize, ::getCppuType(static_cast< sal_Int32*>(0)));
196 // sdbc.RowSet Properties
197 registerProperty(PROPERTY_URL, PROPERTY_ID_URL, 0, &m_aURL, ::getCppuType(static_cast< ::rtl::OUString*>(0)));
198 registerProperty(PROPERTY_TRANSACTIONISOLATION, PROPERTY_ID_TRANSACTIONISOLATION, PropertyAttribute::TRANSIENT, &m_nTransactionIsolation,::getCppuType(static_cast< sal_Int32*>(0)));
199 registerMayBeVoidProperty(PROPERTY_TYPEMAP, PROPERTY_ID_TYPEMAP, PropertyAttribute::MAYBEVOID|PropertyAttribute::TRANSIENT, &m_aTypeMap, ::getCppuType(static_cast< Reference< XNameAccess >* >(0)));
200 registerProperty(PROPERTY_ESCAPE_PROCESSING,PROPERTY_ID_ESCAPE_PROCESSING, PropertyAttribute::BOUND, &m_bUseEscapeProcessing,::getBooleanCppuType() );
201 registerProperty(PROPERTY_QUERYTIMEOUT, PROPERTY_ID_QUERYTIMEOUT, PropertyAttribute::TRANSIENT, &m_nQueryTimeOut, ::getCppuType(static_cast< sal_Int32*>(0)));
202 registerProperty(PROPERTY_MAXFIELDSIZE, PROPERTY_ID_MAXFIELDSIZE, PropertyAttribute::TRANSIENT, &m_nMaxFieldSize, ::getCppuType(static_cast< sal_Int32*>(0)));
203 registerProperty(PROPERTY_MAXROWS, PROPERTY_ID_MAXROWS, 0, &m_nMaxRows, ::getCppuType(static_cast< sal_Int32*>(0)) );
204 registerProperty(PROPERTY_USER, PROPERTY_ID_USER, PropertyAttribute::TRANSIENT, &m_aUser, ::getCppuType(static_cast< ::rtl::OUString*>(0)));
205 registerProperty(PROPERTY_PASSWORD, PROPERTY_ID_PASSWORD, PropertyAttribute::TRANSIENT, &m_aPassword, ::getCppuType(static_cast< ::rtl::OUString*>(0)));
207 registerProperty(PROPERTY_UPDATE_CATALOGNAME, PROPERTY_ID_UPDATE_CATALOGNAME, PropertyAttribute::BOUND, &m_aUpdateCatalogName, ::getCppuType(static_cast< ::rtl::OUString*>(0)));
208 registerProperty(PROPERTY_UPDATE_SCHEMANAME, PROPERTY_ID_UPDATE_SCHEMANAME, PropertyAttribute::BOUND, &m_aUpdateSchemaName, ::getCppuType(static_cast< ::rtl::OUString*>(0)));
209 registerProperty(PROPERTY_UPDATE_TABLENAME, PROPERTY_ID_UPDATE_TABLENAME, PropertyAttribute::BOUND, &m_aUpdateTableName, ::getCppuType(static_cast< ::rtl::OUString*>(0)));
211 // ???
212 registerProperty(PROPERTY_CHANGE_NOTIFICATION_ENABLED, PROPERTY_ID_PROPCHANGE_NOTIFY, PropertyAttribute::BOUND, &m_bPropChangeNotifyEnabled, ::getBooleanCppuType());
215 ORowSet::~ORowSet()
217 if ( !m_rBHelper.bDisposed && !m_rBHelper.bInDispose )
219 OSL_FAIL("Please check who doesn't dispose this component!");
220 osl_atomic_increment( &m_refCount );
221 dispose();
225 void ORowSet::getPropertyDefaultByHandle( sal_Int32 _nHandle, Any& _rDefault ) const
227 switch( _nHandle )
229 case PROPERTY_ID_COMMAND_TYPE:
230 _rDefault <<= static_cast<sal_Int32>(CommandType::COMMAND);
231 break;
232 case PROPERTY_ID_IGNORERESULT:
233 _rDefault <<= sal_False;
234 break;
235 case PROPERTY_ID_APPLYFILTER:
236 _rDefault <<= sal_False;
237 break;
238 case PROPERTY_ID_ISMODIFIED:
239 _rDefault <<= sal_False;
240 break;
241 case PROPERTY_ID_ISBOOKMARKABLE:
242 _rDefault <<= sal_True;
243 break;
244 case PROPERTY_ID_CANUPDATEINSERTEDROWS:
245 _rDefault <<= sal_True;
246 break;
247 case PROPERTY_ID_RESULTSETTYPE:
248 _rDefault <<= ResultSetType::SCROLL_INSENSITIVE;
249 break;
250 case PROPERTY_ID_RESULTSETCONCURRENCY:
251 _rDefault <<= ResultSetConcurrency::UPDATABLE;
252 break;
253 case PROPERTY_ID_FETCHDIRECTION:
254 _rDefault <<= FetchDirection::FORWARD;
255 break;
256 case PROPERTY_ID_FETCHSIZE:
257 _rDefault <<= static_cast<sal_Int32>(1);
258 break;
259 case PROPERTY_ID_ESCAPE_PROCESSING:
260 _rDefault <<= sal_True;
261 break;
262 case PROPERTY_ID_MAXROWS:
263 _rDefault <<= sal_Int32( 0 );
264 break;
265 case PROPERTY_ID_FILTER:
266 case PROPERTY_ID_HAVING_CLAUSE:
267 case PROPERTY_ID_GROUP_BY:
268 case PROPERTY_ID_ORDER:
269 case PROPERTY_ID_UPDATE_CATALOGNAME:
270 case PROPERTY_ID_UPDATE_SCHEMANAME:
271 case PROPERTY_ID_UPDATE_TABLENAME:
272 _rDefault <<= ::rtl::OUString();
273 break;
277 // typedef ::comphelper::OPropertyArrayUsageHelper<ORowSet> ORowSet_Prop;
278 void SAL_CALL ORowSet::setFastPropertyValue_NoBroadcast(sal_Int32 nHandle,const Any& rValue) throw (Exception)
280 switch(nHandle)
282 case PROPERTY_ID_ISMODIFIED:
283 m_bModified = cppu::any2bool(rValue);
284 break;
285 case PROPERTY_ID_FETCHDIRECTION:
286 if( m_nResultSetType == ResultSetType::FORWARD_ONLY)
287 throw Exception(); // else run through
288 default:
289 OPropertyStateContainer::setFastPropertyValue_NoBroadcast(nHandle,rValue);
292 if ( ( nHandle == PROPERTY_ID_ACTIVE_CONNECTION )
293 || ( nHandle == PROPERTY_ID_DATASOURCENAME )
294 || ( nHandle == PROPERTY_ID_COMMAND )
295 || ( nHandle == PROPERTY_ID_COMMAND_TYPE )
296 || ( nHandle == PROPERTY_ID_IGNORERESULT )
297 || ( nHandle == PROPERTY_ID_FILTER )
298 || ( nHandle == PROPERTY_ID_HAVING_CLAUSE )
299 || ( nHandle == PROPERTY_ID_GROUP_BY )
300 || ( nHandle == PROPERTY_ID_APPLYFILTER )
301 || ( nHandle == PROPERTY_ID_ORDER )
302 || ( nHandle == PROPERTY_ID_URL )
303 || ( nHandle == PROPERTY_ID_USER )
306 m_bCommandFacetsDirty = sal_True;
310 switch(nHandle)
312 case PROPERTY_ID_ACTIVE_CONNECTION:
313 // the new connection
315 Reference< XConnection > xNewConnection(m_aActiveConnection,UNO_QUERY);
316 setActiveConnection(xNewConnection, sal_False);
319 m_bOwnConnection = sal_False;
320 m_bRebuildConnOnExecute = sal_False;
321 break;
323 case PROPERTY_ID_DATASOURCENAME:
324 if(!m_xStatement.is())
326 Reference< XConnection > xNewConn;
327 Any aNewConn;
328 aNewConn <<= xNewConn;
329 setFastPropertyValue(PROPERTY_ID_ACTIVE_CONNECTION, aNewConn);
331 else
332 m_bRebuildConnOnExecute = sal_True;
333 break;
334 case PROPERTY_ID_FETCHSIZE:
335 if(m_pCache)
337 m_pCache->setFetchSize(m_nFetchSize);
338 fireRowcount();
340 break;
341 case PROPERTY_ID_URL:
342 // is the connection-to-be-built determined by the url (which is the case if m_aDataSourceName is empty) ?
343 if (m_aDataSourceName.isEmpty())
345 // are we active at the moment ?
346 if (m_xStatement.is())
347 // yes -> the next execute needs to rebuild our connection because of this new property
348 m_bRebuildConnOnExecute = sal_True;
349 else
350 { // no -> drop our active connection (if we have one) as it doesn't correspond to this new property value anymore
351 Reference< XConnection > xNewConn;
352 Any aNewConn;
353 aNewConn <<= xNewConn;
354 setFastPropertyValue(PROPERTY_ID_ACTIVE_CONNECTION, aNewConn);
357 m_bOwnConnection = sal_True;
358 break;
359 case PROPERTY_ID_TYPEMAP:
360 ::cppu::extractInterface(m_xTypeMap,m_aTypeMap);
361 break;
362 case PROPERTY_ID_PROPCHANGE_NOTIFY:
363 m_bPropChangeNotifyEnabled = ::cppu::any2bool(rValue);
364 break;
365 default:
366 break;
370 void SAL_CALL ORowSet::getFastPropertyValue(Any& rValue,sal_Int32 nHandle) const
372 if(m_pCache)
374 switch(nHandle)
376 case PROPERTY_ID_ISMODIFIED:
377 rValue.setValue(&m_bModified,::getCppuBooleanType());
378 break;
379 case PROPERTY_ID_ISNEW:
380 rValue.setValue(&m_bNew,::getCppuBooleanType());
381 break;
382 case PROPERTY_ID_PRIVILEGES:
383 rValue <<= m_pCache->m_nPrivileges;
384 break;
385 case PROPERTY_ID_ACTIVE_CONNECTION:
386 rValue <<= m_xActiveConnection;
387 break;
388 case PROPERTY_ID_TYPEMAP:
389 rValue <<= m_xTypeMap;
390 break;
391 default:
392 ORowSetBase::getFastPropertyValue(rValue,nHandle);
395 else
397 switch(nHandle)
399 case PROPERTY_ID_ACTIVE_CONNECTION:
400 rValue <<= m_xActiveConnection;
401 break;
402 case PROPERTY_ID_TYPEMAP:
403 rValue <<= m_xTypeMap;
404 break;
405 case PROPERTY_ID_PROPCHANGE_NOTIFY:
406 rValue <<= m_bPropChangeNotifyEnabled;
407 break;
408 default:
409 ORowSetBase::getFastPropertyValue(rValue,nHandle);
414 // com::sun::star::XTypeProvider
415 Sequence< Type > SAL_CALL ORowSet::getTypes() throw (RuntimeException)
417 OTypeCollection aTypes(::getCppuType( (const Reference< XPropertySet > *)0 ),
418 ::getCppuType( (const Reference< XFastPropertySet > *)0 ),
419 ::getCppuType( (const Reference< XMultiPropertySet > *)0 ),
420 ::comphelper::concatSequences(ORowSet_BASE1::getTypes(),ORowSetBase::getTypes()));
421 return aTypes.getTypes();
424 Sequence< sal_Int8 > SAL_CALL ORowSet::getImplementationId() throw (RuntimeException)
426 static OImplementationId * pId = 0;
427 if (! pId)
429 MutexGuard aGuard( Mutex::getGlobalMutex() );
430 if (! pId)
432 static OImplementationId aId;
433 pId = &aId;
436 return pId->getImplementationId();
439 // com::sun::star::XInterface
440 Any SAL_CALL ORowSet::queryInterface( const Type & rType ) throw (RuntimeException)
442 return ORowSet_BASE1::queryInterface( rType);
445 void SAL_CALL ORowSet::acquire() throw()
447 ORowSet_BASE1::acquire();
450 void SAL_CALL ORowSet::release() throw()
452 ORowSet_BASE1::release();
455 // com::sun::star::XUnoTunnel
456 sal_Int64 SAL_CALL ORowSet::getSomething( const Sequence< sal_Int8 >& rId ) throw(RuntimeException)
458 if (rId.getLength() == 16 && 0 == memcmp(getImplementationId().getConstArray(), rId.getConstArray(), 16 ) )
459 return reinterpret_cast<sal_Int64>(this);
461 return 0;
464 // com::sun::star::XAggregation
465 Any SAL_CALL ORowSet::queryAggregation( const Type& rType ) throw(RuntimeException)
467 Any aRet(ORowSetBase::queryInterface(rType));
468 if (!aRet.hasValue())
469 aRet = ORowSet_BASE1::queryAggregation(rType);
470 return aRet;
473 rtl::OUString ORowSet::getImplementationName_static( ) throw(RuntimeException)
475 return rtl::OUString("com.sun.star.comp.dba.ORowSet");
478 // ::com::sun::star::XServiceInfo
479 ::rtl::OUString SAL_CALL ORowSet::getImplementationName( ) throw(RuntimeException)
481 return getImplementationName_static();
484 sal_Bool SAL_CALL ORowSet::supportsService( const ::rtl::OUString& _rServiceName ) throw(RuntimeException)
486 return ::comphelper::findValue(getSupportedServiceNames(), _rServiceName, sal_True).getLength() != 0;
489 Sequence< ::rtl::OUString > ORowSet::getSupportedServiceNames_static( ) throw (RuntimeException)
491 Sequence< rtl::OUString > aSNS( 5 );
492 aSNS[0] = SERVICE_SDBC_RESULTSET;
493 aSNS[1] = SERVICE_SDBC_ROWSET;
494 aSNS[2] = SERVICE_SDBCX_RESULTSET;
495 aSNS[3] = SERVICE_SDB_RESULTSET;
496 aSNS[4] = SERVICE_SDB_ROWSET;
497 return aSNS;
500 Sequence< ::rtl::OUString > SAL_CALL ORowSet::getSupportedServiceNames( ) throw(RuntimeException)
502 return getSupportedServiceNames_static();
505 Reference< XInterface > ORowSet::Create(const Reference< XComponentContext >& _rxContext)
507 ::comphelper::ComponentContext aContext( _rxContext );
508 return ORowSet_CreateInstance( aContext.getLegacyServiceFactory() );
511 // OComponentHelper
512 void SAL_CALL ORowSet::disposing()
514 OPropertyStateContainer::disposing();
516 MutexGuard aGuard(m_aMutex);
517 EventObject aDisposeEvent;
518 aDisposeEvent.Source = static_cast< XComponent* >(this);
519 m_aRowsetListeners.disposeAndClear( aDisposeEvent );
520 m_aApproveListeners.disposeAndClear( aDisposeEvent );
521 m_aRowsChangeListener.disposeAndClear( aDisposeEvent );
523 freeResources( true );
525 // remove myself as dispose listener
526 Reference< XComponent > xComponent(m_xActiveConnection, UNO_QUERY);
527 if (xComponent.is())
529 Reference<XEventListener> xEvt;
530 query_aggregation(this,xEvt);
531 xComponent->removeEventListener(xEvt);
534 m_aActiveConnection = Any(); // the any conatains a reference too
535 if(m_bOwnConnection)
536 ::comphelper::disposeComponent(m_xActiveConnection);
537 m_xActiveConnection = NULL;
540 ORowSetBase::disposing();
543 void ORowSet::freeResources( bool _bComplete )
545 MutexGuard aGuard(m_aMutex);
547 // free all clones
548 connectivity::OWeakRefArray::iterator aEnd = m_aClones.end();
549 for (connectivity::OWeakRefArray::iterator i = m_aClones.begin(); aEnd != i; ++i)
551 Reference< XComponent > xComp(i->get(), UNO_QUERY);
552 if (xComp.is())
553 xComp->dispose();
555 m_aClones.clear();
557 if ( _bComplete )
559 // the columns must be disposed before the querycomposer is disposed because
560 // their owner can be the composer
561 TDataColumns().swap(m_aDataColumns);// clear and resize capacity
562 ::std::vector<bool>().swap(m_aReadOnlyDataColumns);
564 m_xColumns = NULL;
565 if ( m_pColumns )
566 m_pColumns->disposing();
567 // dispose the composer to avoid that everbody knows that the querycomposer is eol
568 try { ::comphelper::disposeComponent( m_xComposer ); }
569 catch(Exception&)
571 DBG_UNHANDLED_EXCEPTION();
572 m_xComposer = NULL;
575 // let our warnings container forget the reference to the (possibly disposed) old result set
576 m_aWarnings.setExternalWarnings( NULL );
578 DELETEZ(m_pCache);
580 impl_resetTables_nothrow();
582 m_xStatement = NULL;
583 m_xTypeMap = NULL;
585 m_aBookmark = Any();
586 m_bBeforeFirst = sal_True;
587 m_bAfterLast = sal_False;
588 m_bNew = sal_False;
589 m_bModified = sal_False;
590 m_bIsInsertRow = sal_False;
591 m_bLastKnownRowCountFinal = sal_False;
592 m_nLastKnownRowCount = 0;
593 if ( m_aOldRow.is() )
594 m_aOldRow->clearRow();
596 impl_disposeParametersContainer_nothrow();
598 m_bCommandFacetsDirty = sal_True;
602 void ORowSet::setActiveConnection( Reference< XConnection >& _rxNewConn, sal_Bool _bFireEvent )
604 if (_rxNewConn.get() == m_xActiveConnection.get())
605 // nothing to do
606 return;
608 // remove the event listener for the old connection
609 Reference< XComponent > xComponent(m_xActiveConnection, UNO_QUERY);
610 if (xComponent.is())
612 Reference<XEventListener> xListener;
613 query_aggregation(this, xListener);
614 xComponent->removeEventListener(xListener);
617 // if we owned the connection, remember it for later disposing
618 if(m_bOwnConnection)
619 m_xOldConnection = m_xActiveConnection;
621 // for firing the PropertyChangeEvent
622 sal_Int32 nHandle = PROPERTY_ID_ACTIVE_CONNECTION;
623 Any aOldConnection; aOldConnection <<= m_xActiveConnection;
624 Any aNewConnection; aNewConnection <<= _rxNewConn;
626 // set the new connection
627 m_xActiveConnection = _rxNewConn;
628 if (m_xActiveConnection.is())
629 m_aActiveConnection <<= m_xActiveConnection;
630 else
631 m_aActiveConnection.clear();
633 // fire the event
634 if (_bFireEvent)
635 fire(&nHandle, &aNewConnection, &aOldConnection, 1, sal_False);
637 // register as event listener for the new connection
638 xComponent.set(m_xActiveConnection,UNO_QUERY);
639 if (xComponent.is())
641 Reference<XEventListener> xListener;
642 query_aggregation(this, xListener);
643 xComponent->addEventListener(xListener);
647 // ::com::sun::star::XEventListener
648 void SAL_CALL ORowSet::disposing( const ::com::sun::star::lang::EventObject& Source ) throw(RuntimeException)
650 // close rowset because the connection is going to be deleted (someone told me :-)
651 Reference<XConnection> xCon(Source.Source,UNO_QUERY);
652 if(m_xActiveConnection == xCon)
654 close();
656 MutexGuard aGuard( m_aMutex );
657 Reference< XConnection > xXConnection;
658 setActiveConnection( xXConnection );
663 // XCloseable
664 void SAL_CALL ORowSet::close( ) throw(SQLException, RuntimeException)
667 MutexGuard aGuard( m_aMutex );
668 ::connectivity::checkDisposed(ORowSet_BASE1::rBHelper.bDisposed);
670 // additionals things to set
671 freeResources( true );
674 // comphelper::OPropertyArrayUsageHelper
675 ::cppu::IPropertyArrayHelper* ORowSet::createArrayHelper( ) const
677 Sequence< Property > aProps;
678 describeProperties(aProps);
679 return new ::cppu::OPropertyArrayHelper(aProps);
682 // cppu::OPropertySetHelper
683 ::cppu::IPropertyArrayHelper& SAL_CALL ORowSet::getInfoHelper()
685 typedef ::comphelper::OPropertyArrayUsageHelper<ORowSet> ORowSet_PROP;
686 return *ORowSet_PROP::getArrayHelper();
689 void ORowSet::updateValue(sal_Int32 columnIndex,const ORowSetValue& x)
691 ::connectivity::checkDisposed(ORowSet_BASE1::rBHelper.bDisposed);
693 ::osl::MutexGuard aGuard( *m_pMutex );
694 checkUpdateConditions(columnIndex);
695 checkUpdateIterator();
697 ORowSetValueVector::Vector& rRow = ((*m_aCurrentRow)->get());
698 ORowSetNotifier aNotify(this,rRow);
699 m_pCache->updateValue(columnIndex,x,rRow,aNotify.getChangedColumns());
700 m_bModified = m_bModified || !aNotify.getChangedColumns().empty();
701 aNotify.firePropertyChange();
704 // XRowUpdate
705 void SAL_CALL ORowSet::updateNull( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
707 ::connectivity::checkDisposed(ORowSet_BASE1::rBHelper.bDisposed);
709 ::osl::MutexGuard aGuard( *m_pMutex );
710 checkUpdateConditions(columnIndex);
711 checkUpdateIterator();
713 ORowSetValueVector::Vector& rRow = ((*m_aCurrentRow)->get());
714 ORowSetNotifier aNotify(this,rRow);
715 m_pCache->updateNull(columnIndex,rRow,aNotify.getChangedColumns());
716 m_bModified = m_bModified || !aNotify.getChangedColumns().empty();
717 aNotify.firePropertyChange();
720 void SAL_CALL ORowSet::updateBoolean( sal_Int32 columnIndex, sal_Bool x ) throw(SQLException, RuntimeException)
722 updateValue(columnIndex,x);
725 void SAL_CALL ORowSet::updateByte( sal_Int32 columnIndex, sal_Int8 x ) throw(SQLException, RuntimeException)
727 updateValue(columnIndex,x);
730 void SAL_CALL ORowSet::updateShort( sal_Int32 columnIndex, sal_Int16 x ) throw(SQLException, RuntimeException)
732 updateValue(columnIndex,x);
735 void SAL_CALL ORowSet::updateInt( sal_Int32 columnIndex, sal_Int32 x ) throw(SQLException, RuntimeException)
737 updateValue(columnIndex,x);
740 void SAL_CALL ORowSet::updateLong( sal_Int32 columnIndex, sal_Int64 x ) throw(SQLException, RuntimeException)
742 updateValue(columnIndex,x);
745 void SAL_CALL ORowSet::updateFloat( sal_Int32 columnIndex, float x ) throw(SQLException, RuntimeException)
747 updateValue(columnIndex,x);
750 void SAL_CALL ORowSet::updateDouble( sal_Int32 columnIndex, double x ) throw(SQLException, RuntimeException)
752 updateValue(columnIndex,x);
755 void SAL_CALL ORowSet::updateString( sal_Int32 columnIndex, const ::rtl::OUString& x ) throw(SQLException, RuntimeException)
757 updateValue(columnIndex,x);
760 void SAL_CALL ORowSet::updateBytes( sal_Int32 columnIndex, const Sequence< sal_Int8 >& x ) throw(SQLException, RuntimeException)
762 updateValue(columnIndex,x);
765 void SAL_CALL ORowSet::updateDate( sal_Int32 columnIndex, const ::com::sun::star::util::Date& x ) throw(SQLException, RuntimeException)
767 updateValue(columnIndex,x);
770 void SAL_CALL ORowSet::updateTime( sal_Int32 columnIndex, const ::com::sun::star::util::Time& x ) throw(SQLException, RuntimeException)
772 updateValue(columnIndex,x);
775 void SAL_CALL ORowSet::updateTimestamp( sal_Int32 columnIndex, const ::com::sun::star::util::DateTime& x ) throw(SQLException, RuntimeException)
777 updateValue(columnIndex,x);
780 void SAL_CALL ORowSet::updateBinaryStream( sal_Int32 columnIndex, const Reference< ::com::sun::star::io::XInputStream >& x, sal_Int32 length ) throw(SQLException, RuntimeException)
782 ::connectivity::checkDisposed(ORowSet_BASE1::rBHelper.bDisposed);
783 ::osl::MutexGuard aGuard( *m_pMutex );
784 checkUpdateConditions(columnIndex);
785 checkUpdateIterator();
788 Sequence<sal_Int8> aSeq;
789 if(x.is())
790 x->readBytes(aSeq,length);
791 updateValue(columnIndex,aSeq);
795 void SAL_CALL ORowSet::updateCharacterStream( sal_Int32 columnIndex, const Reference< ::com::sun::star::io::XInputStream >& x, sal_Int32 length ) throw(SQLException, RuntimeException)
797 ::connectivity::checkDisposed(ORowSet_BASE1::rBHelper.bDisposed);
798 ::osl::MutexGuard aGuard( *m_pMutex );
799 checkUpdateConditions(columnIndex);
800 checkUpdateIterator();
801 ORowSetValueVector::Vector& rRow = ((*m_aCurrentRow)->get());
802 ORowSetNotifier aNotify(this,rRow);
803 m_pCache->updateCharacterStream(columnIndex,x,length,rRow,aNotify.getChangedColumns());
804 m_bModified = m_bModified || !aNotify.getChangedColumns().empty();
805 aNotify.firePropertyChange();
808 void SAL_CALL ORowSet::updateObject( sal_Int32 columnIndex, const Any& x ) throw(SQLException, RuntimeException)
810 ::connectivity::checkDisposed(ORowSet_BASE1::rBHelper.bDisposed);
811 ::osl::MutexGuard aGuard( *m_pMutex );
812 checkUpdateConditions(columnIndex);
813 checkUpdateIterator();
815 Any aNewValue = x;
817 if ( m_pColumns )
819 Reference<XPropertySet> xColumn(m_pColumns->getByIndex(columnIndex-1),UNO_QUERY);
820 sal_Int32 nColType = 0;
821 xColumn->getPropertyValue(PROPERTY_TYPE) >>= nColType;
822 switch( nColType )
824 case DataType::DATE:
825 case DataType::TIME:
826 case DataType::TIMESTAMP:
828 double nValue = 0;
829 if ( x >>= nValue )
831 if ( DataType::TIMESTAMP == nColType )
832 aNewValue <<= dbtools::DBTypeConversion::toDateTime( nValue );
833 else if ( DataType::DATE == nColType )
834 aNewValue <<= dbtools::DBTypeConversion::toDate( nValue );
835 else
836 aNewValue <<= dbtools::DBTypeConversion::toTime( nValue );
838 break;
843 if (!::dbtools::implUpdateObject(this, columnIndex, aNewValue))
844 { // there is no other updateXXX call which can handle the value in x
845 ORowSetValueVector::Vector& rRow = ((*m_aCurrentRow)->get());
846 ORowSetNotifier aNotify(this,rRow);
847 m_pCache->updateObject(columnIndex,aNewValue,rRow,aNotify.getChangedColumns());
848 m_bModified = m_bModified || !aNotify.getChangedColumns().empty();
849 aNotify.firePropertyChange();
853 void SAL_CALL ORowSet::updateNumericObject( sal_Int32 columnIndex, const Any& x, sal_Int32 scale ) throw(SQLException, RuntimeException)
855 ::connectivity::checkDisposed(ORowSet_BASE1::rBHelper.bDisposed);
856 ::osl::MutexGuard aGuard( *m_pMutex );
857 checkUpdateConditions(columnIndex);
858 checkUpdateIterator();
859 ORowSetValueVector::Vector& rRow = ((*m_aCurrentRow)->get());
860 ORowSetNotifier aNotify(this,rRow);
861 m_pCache->updateNumericObject(columnIndex,x,scale,rRow,aNotify.getChangedColumns());
862 m_bModified = m_bModified || !aNotify.getChangedColumns().empty();
863 aNotify.firePropertyChange();
866 // XResultSetUpdate
867 void SAL_CALL ORowSet::insertRow( ) throw(SQLException, RuntimeException)
869 ::connectivity::checkDisposed(ORowSet_BASE1::rBHelper.bDisposed);
870 // insertRow is not allowd when
871 // standing not on the insert row nor
872 // when the row isn't modified
873 // or the concurency is read only
874 ::osl::ResettableMutexGuard aGuard( *m_pMutex );
876 if(!m_pCache || !m_bNew || !m_bModified || m_nResultSetConcurrency == ResultSetConcurrency::READ_ONLY)
877 throwFunctionSequenceException(*this);
879 // remember old value for fire
880 sal_Bool bOld = m_bNew;
882 ORowSetRow aOldValues;
883 if ( !m_aCurrentRow.isNull() )
884 aOldValues = new ORowSetValueVector( *(*m_aCurrentRow));
885 Sequence<Any> aChangedBookmarks;
886 RowsChangeEvent aEvt(*this,RowChangeAction::INSERT,1,aChangedBookmarks);
887 notifyAllListenersRowBeforeChange(aGuard,aEvt);
889 ::std::vector< Any > aBookmarks;
890 sal_Bool bInserted = m_pCache->insertRow(aBookmarks);
892 // make sure that our row is set to the new inserted row before clearing the insert flags in the cache
893 m_pCache->resetInsertRow(bInserted);
895 // notification order
896 // - column values
897 setCurrentRow( sal_False, sal_True, aOldValues, aGuard ); // we don't move here
899 // read-only flag restored
900 impl_restoreDataColumnsWriteable_throw();
902 // - rowChanged
903 notifyAllListenersRowChanged(aGuard,aEvt);
905 if ( !aBookmarks.empty() )
907 RowsChangeEvent aUpEvt(*this,RowChangeAction::UPDATE,aBookmarks.size(),Sequence<Any>(&(*aBookmarks.begin()),aBookmarks.size()));
908 notifyAllListenersRowChanged(aGuard,aUpEvt);
911 // - IsModified
912 if(!m_bModified)
913 fireProperty(PROPERTY_ID_ISMODIFIED,sal_False,sal_True);
914 OSL_ENSURE( !m_bModified, "ORowSet::insertRow: just updated, but _still_ modified?" );
916 // - IsNew
917 if(m_bNew != bOld)
918 fireProperty(PROPERTY_ID_ISNEW,m_bNew,bOld);
920 // - RowCount/IsRowCountFinal
921 fireRowcount();
924 sal_Int32 SAL_CALL ORowSet::getRow( ) throw(SQLException, RuntimeException)
926 ::osl::MutexGuard aGuard( *m_pMutex );
927 checkCache();
929 // check if we are inserting a row
930 return (m_pCache && isInsertRow()) ? 0 : ORowSetBase::getRow();
933 void SAL_CALL ORowSet::updateRow( ) throw(SQLException, RuntimeException)
935 ::connectivity::checkDisposed(ORowSet_BASE1::rBHelper.bDisposed);
936 // not allowed when standing on insert row
937 ::osl::ResettableMutexGuard aGuard( *m_pMutex );
938 if ( !m_pCache || m_nResultSetConcurrency == ResultSetConcurrency::READ_ONLY || m_bNew || ((m_pCache->m_nPrivileges & Privilege::UPDATE ) != Privilege::UPDATE) )
939 throwFunctionSequenceException(*this);
942 if(m_bModified)
944 ORowSetRow aOldValues;
945 if ( !m_aCurrentRow.isNull() )
946 aOldValues = new ORowSetValueVector( *(*m_aCurrentRow) );
948 Sequence<Any> aChangedBookmarks;
949 RowsChangeEvent aEvt(*this,RowChangeAction::UPDATE,1,aChangedBookmarks);
950 notifyAllListenersRowBeforeChange(aGuard,aEvt);
952 ::std::vector< Any > aBookmarks;
953 m_pCache->updateRow(m_aCurrentRow.operator ->(),aBookmarks);
954 if ( !aBookmarks.empty() )
955 aEvt.Bookmarks = Sequence<Any>(&(*aBookmarks.begin()),aBookmarks.size());
956 aEvt.Rows += aBookmarks.size();
957 m_aBookmark = m_pCache->getBookmark();
958 m_aCurrentRow = m_pCache->m_aMatrixIter;
959 m_bIsInsertRow = sal_False;
960 if ( m_pCache->m_aMatrixIter != m_pCache->getEnd() && (*m_pCache->m_aMatrixIter).is() )
962 if ( m_pCache->isResultSetChanged() )
964 impl_rebuild_throw(aGuard);
966 else
968 m_aOldRow->setRow(new ORowSetValueVector(*(*m_aCurrentRow)));
970 // notification order
971 // - column values
972 ORowSetBase::firePropertyChange(aOldValues);
974 // - rowChanged
975 notifyAllListenersRowChanged(aGuard,aEvt);
977 // - IsModified
978 if(!m_bModified)
979 fireProperty(PROPERTY_ID_ISMODIFIED,sal_False,sal_True);
980 OSL_ENSURE( !m_bModified, "ORowSet::updateRow: just updated, but _still_ modified?" );
982 // - RowCount/IsRowCountFinal
983 fireRowcount();
985 else if ( !m_bAfterLast ) // the update went rong
987 ::dbtools::throwSQLException( DBACORE_RESSTRING( RID_STR_UPDATE_FAILED ), SQL_INVALID_CURSOR_POSITION, *this );
992 void SAL_CALL ORowSet::deleteRow( ) throw(SQLException, RuntimeException)
994 ::connectivity::checkDisposed(ORowSet_BASE1::rBHelper.bDisposed);
996 ::osl::ResettableMutexGuard aGuard( *m_pMutex );
997 checkCache();
999 if ( m_bBeforeFirst || m_bAfterLast )
1000 ::dbtools::throwSQLException( DBACORE_RESSTRING( RID_STR_NO_DELETE_BEFORE_AFTER ), SQL_INVALID_CURSOR_POSITION, *this );
1001 if ( m_bNew )
1002 ::dbtools::throwSQLException( DBACORE_RESSTRING( RID_STR_NO_DELETE_INSERT_ROW ), SQL_INVALID_CURSOR_POSITION, *this );
1003 if ( m_nResultSetConcurrency == ResultSetConcurrency::READ_ONLY )
1004 ::dbtools::throwSQLException( DBACORE_RESSTRING( RID_STR_RESULT_IS_READONLY ), SQL_FUNCTION_SEQUENCE_ERROR, *this );
1005 if ( ( m_pCache->m_nPrivileges & Privilege::DELETE ) != Privilege::DELETE )
1006 ::dbtools::throwSQLException( DBACORE_RESSTRING( RID_STR_NO_DELETE_PRIVILEGE ), SQL_FUNCTION_SEQUENCE_ERROR, *this );
1007 if ( rowDeleted() )
1008 ::dbtools::throwSQLException( DBACORE_RESSTRING( RID_STR_ROW_ALREADY_DELETED ), SQL_FUNCTION_SEQUENCE_ERROR, *this );
1010 // this call position the cache indirect
1011 Any aBookmarkToDelete( m_aBookmark );
1012 positionCache( MOVE_NONE_REFRESH_ONLY );
1013 sal_Int32 nDeletePosition = m_pCache->getRow();
1015 notifyRowSetAndClonesRowDelete( aBookmarkToDelete );
1017 ORowSetRow aOldValues;
1018 if ( m_pCache->m_aMatrixIter != m_pCache->getEnd() && m_pCache->m_aMatrixIter->is() )
1019 aOldValues = new ORowSetValueVector( *(*(m_pCache->m_aMatrixIter)) );
1021 Sequence<Any> aChangedBookmarks;
1022 RowsChangeEvent aEvt(*this,RowChangeAction::DELETE,1,aChangedBookmarks);
1023 notifyAllListenersRowBeforeChange(aGuard,aEvt);
1025 m_pCache->deleteRow();
1026 notifyRowSetAndClonesRowDeleted( aBookmarkToDelete, nDeletePosition );
1028 ORowSetNotifier aNotifier( this );
1029 // this will call cancelRowModification on the cache if necessary
1031 // notification order
1032 // - rowChanged
1033 notifyAllListenersRowChanged(aGuard,aEvt);
1035 // - IsModified
1036 // - IsNew
1037 aNotifier.fire( );
1039 // - RowCount/IsRowCountFinal
1040 fireRowcount();
1043 void ORowSet::implCancelRowUpdates( sal_Bool _bNotifyModified ) SAL_THROW( ( SQLException, RuntimeException ) )
1045 ::connectivity::checkDisposed(ORowSet_BASE1::rBHelper.bDisposed);
1047 ::osl::MutexGuard aGuard( *m_pMutex );
1048 if ( m_bBeforeFirst || m_bAfterLast || rowDeleted() )
1049 return; // nothing to do so return
1051 checkCache();
1052 // cancelRowUpdates is not allowed when:
1053 // - standing on the insert row
1054 // - the concurrency is read only
1055 // - the current row is deleted
1056 if ( m_bNew || m_nResultSetConcurrency == ResultSetConcurrency::READ_ONLY )
1057 throwFunctionSequenceException(*this);
1059 positionCache( MOVE_NONE_REFRESH_ONLY );
1061 ORowSetRow aOldValues;
1062 if ( !m_bModified && _bNotifyModified && !m_aCurrentRow.isNull() )
1063 aOldValues = new ORowSetValueVector( *(*m_aCurrentRow) );
1065 m_pCache->cancelRowUpdates();
1067 m_aBookmark = m_pCache->getBookmark();
1068 m_aCurrentRow = m_pCache->m_aMatrixIter;
1069 m_bIsInsertRow = sal_False;
1070 m_aCurrentRow.setBookmark(m_aBookmark);
1072 // notification order
1073 // IsModified
1074 if( !m_bModified && _bNotifyModified )
1076 // - column values
1077 ORowSetBase::firePropertyChange(aOldValues);
1078 fireProperty(PROPERTY_ID_ISMODIFIED,sal_False,sal_True);
1082 void SAL_CALL ORowSet::cancelRowUpdates( ) throw(SQLException, RuntimeException)
1084 implCancelRowUpdates( sal_True );
1087 void SAL_CALL ORowSet::addRowSetListener( const Reference< XRowSetListener >& listener ) throw(RuntimeException)
1089 ::connectivity::checkDisposed(ORowSet_BASE1::rBHelper.bDisposed);
1091 ::osl::MutexGuard aGuard( m_aColumnsMutex );
1092 if(listener.is())
1093 m_aRowsetListeners.addInterface(listener);
1096 void SAL_CALL ORowSet::removeRowSetListener( const Reference< XRowSetListener >& listener ) throw(RuntimeException)
1098 ::connectivity::checkDisposed(ORowSet_BASE1::rBHelper.bDisposed);
1100 ::osl::MutexGuard aGuard( m_aColumnsMutex );
1101 if(listener.is())
1102 m_aRowsetListeners.removeInterface(listener);
1105 void ORowSet::notifyAllListeners(::osl::ResettableMutexGuard& _rGuard)
1107 EventObject aEvt(*m_pMySelf);
1108 _rGuard.clear();
1109 m_aRowsetListeners.notifyEach( &XRowSetListener::rowSetChanged, aEvt );
1110 _rGuard.reset();
1113 void ORowSet::notifyAllListenersCursorMoved(::osl::ResettableMutexGuard& _rGuard)
1115 EventObject aEvt(*m_pMySelf);
1116 _rGuard.clear();
1117 m_aRowsetListeners.notifyEach( &XRowSetListener::cursorMoved, aEvt );
1118 _rGuard.reset();
1121 void ORowSet::notifyAllListenersRowChanged(::osl::ResettableMutexGuard& _rGuard, const RowsChangeEvent& aEvt)
1123 _rGuard.clear();
1124 m_aRowsetListeners.notifyEach( &XRowSetListener::rowChanged, (EventObject)aEvt );
1125 m_aRowsChangeListener.notifyEach( &XRowsChangeListener::rowsChanged, aEvt );
1126 _rGuard.reset();
1129 sal_Bool ORowSet::notifyAllListenersCursorBeforeMove(::osl::ResettableMutexGuard& _rGuard)
1131 EventObject aEvt(*m_pMySelf);
1132 NOTIFY_LISTERNERS_CHECK(m_aApproveListeners,XRowSetApproveListener,approveCursorMove);
1133 return bCheck;
1136 void ORowSet::notifyAllListenersRowBeforeChange(::osl::ResettableMutexGuard& _rGuard,const RowChangeEvent &aEvt)
1138 NOTIFY_LISTERNERS_CHECK(m_aApproveListeners,XRowSetApproveListener,approveRowChange);
1139 if ( !bCheck )
1140 m_aErrors.raiseTypedException( sdb::ErrorCondition::ROW_SET_OPERATION_VETOED, *this, ::cppu::UnoType< RowSetVetoException >::get() );
1143 void ORowSet::fireRowcount()
1145 sal_Int32 nCurrentRowCount( impl_getRowCount() );
1146 sal_Bool bCurrentRowCountFinal( m_pCache->m_bRowCountFinal );
1148 if ( m_nLastKnownRowCount != nCurrentRowCount )
1150 sal_Int32 nHandle = PROPERTY_ID_ROWCOUNT;
1151 Any aNew,aOld;
1152 aNew <<= nCurrentRowCount; aOld <<= m_nLastKnownRowCount;
1153 fire(&nHandle,&aNew,&aOld,1,sal_False);
1154 m_nLastKnownRowCount = nCurrentRowCount;
1156 if ( !m_bLastKnownRowCountFinal && ( m_bLastKnownRowCountFinal != bCurrentRowCountFinal ) )
1158 sal_Int32 nHandle = PROPERTY_ID_ISROWCOUNTFINAL;
1159 Any aNew,aOld;
1160 aNew <<= bCurrentRowCountFinal;
1161 aOld <<= m_bLastKnownRowCountFinal;
1162 fire(&nHandle,&aNew,&aOld,1,sal_False);
1163 m_bLastKnownRowCountFinal = bCurrentRowCountFinal;
1167 void SAL_CALL ORowSet::moveToInsertRow( ) throw(SQLException, RuntimeException)
1169 ::connectivity::checkDisposed(ORowSet_BASE1::rBHelper.bDisposed);
1171 ::osl::ResettableMutexGuard aGuard( *m_pMutex );
1172 checkPositioningAllowed();
1173 if ( ( m_pCache->m_nPrivileges & Privilege::INSERT ) != Privilege::INSERT )
1174 ::dbtools::throwSQLException( DBACORE_RESSTRING( RID_STR_NO_INSERT_PRIVILEGE ), SQL_GENERAL_ERROR, *this );
1176 if ( notifyAllListenersCursorBeforeMove( aGuard ) )
1178 // remember old value for fire
1179 ORowSetRow aOldValues;
1180 if ( rowDeleted() )
1182 positionCache( MOVE_FORWARD );
1183 m_pCache->next();
1184 setCurrentRow( sal_True, sal_False, aOldValues, aGuard);
1186 else
1187 positionCache( MOVE_NONE_REFRESH_ONLY );
1189 // check before because the resultset could be empty
1190 if ( !m_bBeforeFirst
1191 && !m_bAfterLast
1192 && m_pCache->m_aMatrixIter != m_pCache->getEnd()
1193 && m_pCache->m_aMatrixIter->is()
1195 aOldValues = new ORowSetValueVector( *(*(m_pCache->m_aMatrixIter)) );
1197 const sal_Bool bNewState = m_bNew;
1198 const sal_Bool bModState = m_bModified;
1200 m_pCache->moveToInsertRow();
1201 m_aCurrentRow = m_pCache->m_aInsertRow;
1202 m_bIsInsertRow = sal_True;
1204 // set read-only flag to false
1205 impl_setDataColumnsWriteable_throw();
1207 // notification order
1208 // - column values
1209 ORowSetBase::firePropertyChange(aOldValues);
1211 // - cursorMoved
1212 notifyAllListenersCursorMoved(aGuard);
1214 // - IsModified
1215 if ( bModState != m_bModified )
1216 fireProperty( PROPERTY_ID_ISMODIFIED, m_bModified, bModState );
1218 // - IsNew
1219 if ( bNewState != m_bNew )
1220 fireProperty( PROPERTY_ID_ISNEW, m_bNew, bNewState );
1222 // - RowCount/IsRowCountFinal
1223 fireRowcount();
1227 void ORowSet::impl_setDataColumnsWriteable_throw()
1229 impl_restoreDataColumnsWriteable_throw();
1230 TDataColumns::iterator aIter = m_aDataColumns.begin();
1231 m_aReadOnlyDataColumns.resize(m_aDataColumns.size(),false);
1232 ::std::vector<bool, std::allocator<bool> >::iterator aReadIter = m_aReadOnlyDataColumns.begin();
1233 for(;aIter != m_aDataColumns.end();++aIter,++aReadIter)
1235 sal_Bool bReadOnly = sal_False;
1236 (*aIter)->getPropertyValue(PROPERTY_ISREADONLY) >>= bReadOnly;
1237 *aReadIter = bReadOnly;
1239 (*aIter)->setPropertyValue(PROPERTY_ISREADONLY,makeAny(sal_False));
1243 void ORowSet::impl_restoreDataColumnsWriteable_throw()
1245 assert(m_aDataColumns.size() == m_aReadOnlyDataColumns.size() || m_aReadOnlyDataColumns.size() == 0 );
1246 TDataColumns::iterator aIter = m_aDataColumns.begin();
1247 ::std::vector<bool, std::allocator<bool> >::iterator aReadIter = m_aReadOnlyDataColumns.begin();
1248 for(;aReadIter != m_aReadOnlyDataColumns.end();++aIter,++aReadIter)
1250 (*aIter)->setPropertyValue(PROPERTY_ISREADONLY,makeAny((sal_Bool)*aReadIter ));
1252 m_aReadOnlyDataColumns.clear();
1255 void SAL_CALL ORowSet::moveToCurrentRow( ) throw(SQLException, RuntimeException)
1257 ::connectivity::checkDisposed(ORowSet_BASE1::rBHelper.bDisposed);
1259 ::osl::ResettableMutexGuard aGuard( *m_pMutex );
1260 checkPositioningAllowed();
1262 if ( !m_pCache->m_bNew && !m_bModified )
1263 // nothing to do if we're not on the insertion row, and not modified otherwise
1264 return;
1266 if ( rowDeleted() )
1267 // this would perhaps even justify a RuntimeException ....
1268 // if the current row is deleted, then no write access to this row should be possible. So,
1269 // m_bModified should be true. Also, as soon as somebody calls moveToInsertRow,
1270 // our current row should not be deleted anymore. So, we should not have survived the above
1271 // check "if ( !m_pCache->m_bNew && !m_bModified )"
1272 ::dbtools::throwSQLException( DBACORE_RESSTRING( RID_STR_ROW_ALREADY_DELETED ), SQL_FUNCTION_SEQUENCE_ERROR, *this );
1274 if ( notifyAllListenersCursorBeforeMove( aGuard ) )
1276 positionCache( MOVE_NONE_REFRESH_ONLY );
1278 ORowSetNotifier aNotifier( this );
1280 // notification order
1281 // - cursorMoved
1282 notifyAllListenersCursorMoved(aGuard);
1284 // - IsModified
1285 // - IsNew
1286 aNotifier.fire();
1290 // XRow
1291 sal_Bool SAL_CALL ORowSet::wasNull( ) throw(SQLException, RuntimeException)
1293 ::osl::MutexGuard aGuard( *m_pMutex );
1294 checkCache();
1296 return ( m_pCache && isInsertRow() ) ? ((*m_pCache->m_aInsertRow)->get())[m_nLastColumnIndex].isNull() : ORowSetBase::wasNull();
1299 const ORowSetValue& ORowSet::getInsertValue(sal_Int32 columnIndex)
1301 checkCache();
1303 if ( m_pCache && isInsertRow() )
1304 return ((*m_pCache->m_aInsertRow)->get())[m_nLastColumnIndex = columnIndex];
1306 return getValue(columnIndex);
1309 ::rtl::OUString SAL_CALL ORowSet::getString( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
1311 ::osl::MutexGuard aGuard( *m_pMutex );
1312 return getInsertValue(columnIndex);
1315 sal_Bool SAL_CALL ORowSet::getBoolean( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
1317 ::osl::MutexGuard aGuard( *m_pMutex );
1318 return getInsertValue(columnIndex);
1321 sal_Int8 SAL_CALL ORowSet::getByte( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
1323 ::osl::MutexGuard aGuard( *m_pMutex );
1324 return getInsertValue(columnIndex);
1327 sal_Int16 SAL_CALL ORowSet::getShort( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
1329 ::osl::MutexGuard aGuard( *m_pMutex );
1330 return getInsertValue(columnIndex);
1333 sal_Int32 SAL_CALL ORowSet::getInt( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
1335 ::osl::MutexGuard aGuard( *m_pMutex );
1336 return getInsertValue(columnIndex);
1339 sal_Int64 SAL_CALL ORowSet::getLong( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
1341 ::osl::MutexGuard aGuard( *m_pMutex );
1342 return getInsertValue(columnIndex);
1345 float SAL_CALL ORowSet::getFloat( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
1347 ::osl::MutexGuard aGuard( *m_pMutex );
1348 return getInsertValue(columnIndex);
1351 double SAL_CALL ORowSet::getDouble( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
1353 ::osl::MutexGuard aGuard( *m_pMutex );
1354 return getInsertValue(columnIndex);
1357 Sequence< sal_Int8 > SAL_CALL ORowSet::getBytes( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
1359 ::osl::MutexGuard aGuard( *m_pMutex );
1360 return getInsertValue(columnIndex);
1363 ::com::sun::star::util::Date SAL_CALL ORowSet::getDate( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
1365 ::osl::MutexGuard aGuard( *m_pMutex );
1366 return getInsertValue(columnIndex);
1369 ::com::sun::star::util::Time SAL_CALL ORowSet::getTime( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
1371 ::osl::MutexGuard aGuard( *m_pMutex );
1372 return getInsertValue(columnIndex);
1375 ::com::sun::star::util::DateTime SAL_CALL ORowSet::getTimestamp( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
1377 ::osl::MutexGuard aGuard( *m_pMutex );
1378 return getInsertValue(columnIndex);
1381 Reference< ::com::sun::star::io::XInputStream > SAL_CALL ORowSet::getBinaryStream( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
1383 ::osl::MutexGuard aGuard( *m_pMutex );
1384 if ( m_pCache && isInsertRow() )
1386 checkCache();
1387 return new ::comphelper::SequenceInputStream(((*m_pCache->m_aInsertRow)->get())[m_nLastColumnIndex = columnIndex].getSequence());
1390 return ORowSetBase::getBinaryStream(columnIndex);
1393 Reference< ::com::sun::star::io::XInputStream > SAL_CALL ORowSet::getCharacterStream( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
1395 ::osl::MutexGuard aGuard( *m_pMutex );
1396 if(m_pCache && isInsertRow() )
1398 checkCache();
1399 return new ::comphelper::SequenceInputStream(((*m_pCache->m_aInsertRow)->get())[m_nLastColumnIndex = columnIndex].getSequence());
1402 return ORowSetBase::getCharacterStream(columnIndex);
1405 Any SAL_CALL ORowSet::getObject( sal_Int32 columnIndex, const Reference< XNameAccess >& /*typeMap*/ ) throw(SQLException, RuntimeException)
1407 ::osl::MutexGuard aGuard( *m_pMutex );
1408 return getInsertValue(columnIndex).makeAny();
1411 Reference< XRef > SAL_CALL ORowSet::getRef( sal_Int32 /*columnIndex*/ ) throw(SQLException, RuntimeException)
1413 return Reference< XRef >();
1416 Reference< XBlob > SAL_CALL ORowSet::getBlob( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
1418 if ( m_pCache && isInsertRow() )
1420 checkCache();
1421 return new ::connectivity::BlobHelper(((*m_pCache->m_aInsertRow)->get())[m_nLastColumnIndex = columnIndex].getSequence());
1423 return ORowSetBase::getBlob(columnIndex);
1426 Reference< XClob > SAL_CALL ORowSet::getClob( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
1428 return Reference< XClob >(getInsertValue(columnIndex).makeAny(),UNO_QUERY);
1431 Reference< XArray > SAL_CALL ORowSet::getArray( sal_Int32 /*columnIndex*/ ) throw(SQLException, RuntimeException)
1433 return Reference< XArray >();
1436 void SAL_CALL ORowSet::executeWithCompletion( const Reference< XInteractionHandler >& _rxHandler ) throw(SQLException, RuntimeException)
1438 if (!_rxHandler.is())
1439 execute();
1441 ::connectivity::checkDisposed(ORowSet_BASE1::rBHelper.bDisposed);
1443 // tell everybody that we will change the result set
1444 approveExecution();
1446 ResettableMutexGuard aGuard( m_aMutex );
1450 freeResources( m_bCommandFacetsDirty );
1452 // calc the connection to be used
1453 if (m_xActiveConnection.is() && m_bRebuildConnOnExecute)
1455 // there was a setProperty(ActiveConnection), but a setProperty(DataSource) _after_ that, too
1456 Reference< XConnection > xXConnection;
1457 setActiveConnection( xXConnection );
1459 calcConnection( _rxHandler );
1460 m_bRebuildConnOnExecute = sal_False;
1462 Reference< XSingleSelectQueryComposer > xComposer = getCurrentSettingsComposer( this, m_aContext.getUNOContext() );
1463 Reference<XParametersSupplier> xParameters(xComposer, UNO_QUERY);
1465 Reference<XIndexAccess> xParamsAsIndicies = xParameters.is() ? xParameters->getParameters() : Reference<XIndexAccess>();
1466 const sal_Int32 nParamCount = xParamsAsIndicies.is() ? xParamsAsIndicies->getCount() : 0;
1467 if ( m_aParametersSet.size() < (size_t)nParamCount )
1468 m_aParametersSet.resize( nParamCount ,false);
1470 ::dbtools::askForParameters( xComposer, this, m_xActiveConnection, _rxHandler,m_aParametersSet );
1472 // ensure that only the allowed exceptions leave this block
1473 catch(SQLException&)
1475 throw;
1477 catch(RuntimeException&)
1479 throw;
1481 catch(Exception&)
1483 OSL_FAIL("ORowSet::executeWithCompletion: caught an unexpected exception type while filling in the parameters!");
1486 // we're done with the parameters, now for the real execution
1488 // do the real execute
1489 execute_NoApprove_NoNewConn(aGuard);
1492 Reference< XIndexAccess > SAL_CALL ORowSet::getParameters( ) throw (RuntimeException)
1494 ::osl::MutexGuard aGuard( *m_pMutex );
1495 ::connectivity::checkDisposed(ORowSet_BASE1::rBHelper.bDisposed);
1497 if ( m_bCommandFacetsDirty )
1498 // need to rebuild the parameters, since some property which contributes to the
1499 // complete command, and thus the parameters, changed
1500 impl_disposeParametersContainer_nothrow();
1502 if ( !m_pParameters.get() && !m_aCommand.isEmpty() )
1506 ::rtl::OUString sNotInterestedIn;
1507 impl_initComposer_throw( sNotInterestedIn );
1509 catch( const Exception& )
1511 // silence it
1515 return m_pParameters.get();
1518 void ORowSet::approveExecution() throw (RowSetVetoException, RuntimeException)
1520 ::osl::MutexGuard aGuard( m_aColumnsMutex );
1521 EventObject aEvt(*this);
1523 OInterfaceIteratorHelper aApproveIter( m_aApproveListeners );
1524 while ( aApproveIter.hasMoreElements() )
1526 Reference< XRowSetApproveListener > xListener( static_cast< XRowSetApproveListener* >( aApproveIter.next() ) );
1529 if ( xListener.is() && !xListener->approveRowSetChange( aEvt ) )
1530 throw RowSetVetoException();
1532 catch ( const DisposedException& e )
1534 if ( e.Context == xListener )
1535 aApproveIter.remove();
1537 catch ( const RuntimeException& ) { throw; }
1538 catch ( const RowSetVetoException& ) { throw; }
1539 catch ( const Exception& )
1541 DBG_UNHANDLED_EXCEPTION();
1546 // XRowSet
1547 void SAL_CALL ORowSet::execute( ) throw(SQLException, RuntimeException)
1549 ::connectivity::checkDisposed(ORowSet_BASE1::rBHelper.bDisposed);
1551 // tell everybody that we will change the result set
1552 approveExecution();
1554 ResettableMutexGuard aGuard( m_aMutex );
1555 freeResources( m_bCommandFacetsDirty );
1557 // calc the connection to be used
1558 if (m_xActiveConnection.is() && m_bRebuildConnOnExecute) {
1559 // there was a setProperty(ActiveConnection), but a setProperty(DataSource) _after_ that, too
1560 Reference< XConnection> xXConnection;
1561 setActiveConnection( xXConnection );
1564 calcConnection(NULL);
1565 m_bRebuildConnOnExecute = sal_False;
1567 // do the real execute
1568 execute_NoApprove_NoNewConn(aGuard);
1571 void ORowSet::setStatementResultSetType( const Reference< XPropertySet >& _rxStatement, sal_Int32 _nDesiredResultSetType, sal_Int32 _nDesiredResultSetConcurrency )
1573 OSL_ENSURE( _rxStatement.is(), "ORowSet::setStatementResultSetType: invalid statement - this will crash!" );
1575 sal_Int32 nResultSetType( _nDesiredResultSetType );
1576 sal_Int32 nResultSetConcurrency( _nDesiredResultSetConcurrency );
1578 // there *might* be a data source setting which tells use to be more defensive with those settings
1579 // #i15113#
1580 sal_Bool bRespectDriverRST = sal_False;
1581 Any aSetting;
1582 if ( getDataSourceSetting( ::dbaccess::getDataSource( m_xActiveConnection ), "RespectDriverResultSetType", aSetting ) )
1584 OSL_VERIFY( aSetting >>= bRespectDriverRST );
1587 if ( bRespectDriverRST )
1589 // try type/concurrency settings with decreasing usefullness, and rely on what the connection claims
1590 // to support
1591 Reference< XDatabaseMetaData > xMeta( m_xActiveConnection->getMetaData() );
1593 sal_Int32 nCharacteristics[5][2] =
1594 { { ResultSetType::SCROLL_SENSITIVE, ResultSetConcurrency::UPDATABLE },
1595 { ResultSetType::SCROLL_INSENSITIVE, ResultSetConcurrency::UPDATABLE },
1596 { ResultSetType::SCROLL_SENSITIVE, ResultSetConcurrency::READ_ONLY },
1597 { ResultSetType::SCROLL_INSENSITIVE, ResultSetConcurrency::READ_ONLY },
1598 { ResultSetType::FORWARD_ONLY, ResultSetConcurrency::READ_ONLY }
1600 sal_Int32 i=0;
1601 if ( m_xActiveConnection->getMetaData()->isReadOnly() )
1602 i = 2; // if the database is read-only we only should use read-only concurrency
1604 for ( ; i<5; ++i )
1606 nResultSetType = nCharacteristics[i][0];
1607 nResultSetConcurrency = nCharacteristics[i][1];
1609 // don't try type/concurrency pairs which are more featured than what our caller requested
1610 if ( nResultSetType > _nDesiredResultSetType )
1611 continue;
1612 if ( nResultSetConcurrency > _nDesiredResultSetConcurrency )
1613 continue;
1615 if ( xMeta.is() && xMeta->supportsResultSetConcurrency( nResultSetType, nResultSetConcurrency ) )
1616 break;
1620 _rxStatement->setPropertyValue( PROPERTY_RESULTSETTYPE, makeAny( nResultSetType ) );
1621 _rxStatement->setPropertyValue( PROPERTY_RESULTSETCONCURRENCY, makeAny( nResultSetConcurrency ) );
1624 Reference< XResultSet > ORowSet::impl_prepareAndExecute_throw()
1626 ::rtl::OUString sCommandToExecute;
1627 sal_Bool bUseEscapeProcessing = impl_initComposer_throw( sCommandToExecute );
1629 Reference< XResultSet> xResultSet;
1632 m_xStatement = m_xActiveConnection->prepareStatement( sCommandToExecute );
1633 if ( !m_xStatement.is() )
1635 ::dbtools::throwSQLException( DBACORE_RESSTRING( RID_STR_INTERNAL_ERROR ), SQL_GENERAL_ERROR, *this );
1638 Reference< XPropertySet > xStatementProps( m_xStatement, UNO_QUERY_THROW );
1639 // set the result set type and concurrency
1642 xStatementProps->setPropertyValue( PROPERTY_USEBOOKMARKS, makeAny( sal_True ) );
1643 xStatementProps->setPropertyValue( PROPERTY_MAXROWS, makeAny( m_nMaxRows ) );
1645 setStatementResultSetType( xStatementProps, m_nResultSetType, m_nResultSetConcurrency );
1647 catch ( const Exception& )
1649 // this exception doesn't matter here because when we catch an exception
1650 // then the driver doesn't support this feature
1652 m_aParameterValueForCache.get().resize(1);
1653 Reference< XParameters > xParam( m_xStatement, UNO_QUERY_THROW );
1654 size_t nParamCount( m_pParameters.is() ? m_pParameters->size() : m_aPrematureParamValues.get().size() );
1655 for ( size_t i=1; i<=nParamCount; ++i )
1657 ORowSetValue& rParamValue( getParameterStorage( (sal_Int32)i ) );
1658 ::dbtools::setObjectWithInfo( xParam, i, rParamValue.makeAny(), rParamValue.getTypeKind() );
1659 m_aParameterValueForCache.get().push_back(rParamValue);
1662 xResultSet = m_xStatement->executeQuery();
1664 catch( const SQLException& )
1666 SQLExceptionInfo aError( ::cppu::getCaughtException() );
1667 OSL_ENSURE( aError.isValid(), "ORowSet::impl_prepareAndExecute_throw: caught an SQLException which we cannot analyze!" );
1669 // append information about what we were actually going to execute
1672 String sQuery = bUseEscapeProcessing && m_xComposer.is() ? m_xComposer->getQuery() : m_aActiveCommand;
1673 String sInfo( DBA_RES_PARAM( RID_STR_COMMAND_LEADING_TO_ERROR, "$command$", sQuery ) );
1674 aError.append( SQLExceptionInfo::SQL_CONTEXT, sInfo );
1676 catch( const Exception& ) { DBG_UNHANDLED_EXCEPTION(); }
1678 // propagate
1679 aError.doThrow();
1682 return xResultSet;
1685 void ORowSet::impl_initializeColumnSettings_nothrow( const Reference< XPropertySet >& _rxTemplateColumn, const Reference< XPropertySet >& _rxRowSetColumn )
1687 OSL_ENSURE( _rxTemplateColumn.is() && _rxRowSetColumn.is(),
1688 "ORowSet::impl_initializeColumnSettings_nothrow: this will crash!" );
1690 bool bHaveAnyColumnSetting = false;
1693 Reference< XPropertySetInfo > xInfo( _rxTemplateColumn->getPropertySetInfo(), UNO_QUERY_THROW );
1695 // a number of properties is plain copied
1696 const ::rtl::OUString aPropertyNames[] = {
1697 PROPERTY_ALIGN, PROPERTY_RELATIVEPOSITION, PROPERTY_WIDTH, PROPERTY_HIDDEN, PROPERTY_CONTROLMODEL,
1698 PROPERTY_HELPTEXT, PROPERTY_CONTROLDEFAULT
1700 for ( size_t i=0; i<sizeof( aPropertyNames ) / sizeof( aPropertyNames[0] ); ++i )
1702 if ( xInfo->hasPropertyByName( aPropertyNames[i] ) )
1704 _rxRowSetColumn->setPropertyValue( aPropertyNames[i], _rxTemplateColumn->getPropertyValue( aPropertyNames[i] ) );
1705 bHaveAnyColumnSetting = true;
1709 // the format key is slightly more complex
1710 sal_Int32 nFormatKey = 0;
1711 if( xInfo->hasPropertyByName( PROPERTY_NUMBERFORMAT ) )
1713 _rxTemplateColumn->getPropertyValue( PROPERTY_NUMBERFORMAT ) >>= nFormatKey;
1714 bHaveAnyColumnSetting = true;
1716 if ( !nFormatKey && m_xNumberFormatTypes.is() )
1717 nFormatKey = ::dbtools::getDefaultNumberFormat( _rxTemplateColumn, m_xNumberFormatTypes, SvtSysLocale().GetLanguageTag().getLocale() );
1718 _rxRowSetColumn->setPropertyValue( PROPERTY_NUMBERFORMAT, makeAny( nFormatKey ) );
1720 catch(Exception&)
1722 DBG_UNHANDLED_EXCEPTION();
1723 return;
1726 if ( bHaveAnyColumnSetting )
1727 return;
1729 // the template column could not provide *any* setting. Okay, probably it's a parser column, which
1730 // does not offer those. However, perhaps the template column referes to a table column, which we
1731 // can use as new template column
1734 Reference< XPropertySetInfo > xInfo( _rxTemplateColumn->getPropertySetInfo(), UNO_QUERY_THROW );
1735 if ( !xInfo->hasPropertyByName( PROPERTY_TABLENAME ) )
1736 // no chance
1737 return;
1739 ::rtl::OUString sTableName;
1740 OSL_VERIFY( _rxTemplateColumn->getPropertyValue( PROPERTY_TABLENAME ) >>= sTableName );
1742 Reference< XNameAccess > xTables( impl_getTables_throw(), UNO_QUERY_THROW );
1743 if ( !xTables->hasByName( sTableName ) )
1744 // no chance
1745 return;
1747 Reference< XColumnsSupplier > xTableColSup( xTables->getByName( sTableName ), UNO_QUERY_THROW );
1748 Reference< XNameAccess > xTableCols( xTableColSup->getColumns(), UNO_QUERY_THROW );
1750 ::rtl::OUString sTableColumnName;
1752 // get the "Name" or (preferred) "RealName" property of the column
1753 ::rtl::OUString sNamePropertyName( PROPERTY_NAME );
1754 if ( xInfo->hasPropertyByName( PROPERTY_REALNAME ) )
1755 sNamePropertyName = PROPERTY_REALNAME;
1756 OSL_VERIFY( _rxTemplateColumn->getPropertyValue( sNamePropertyName ) >>= sTableColumnName );
1758 if ( !xTableCols->hasByName( sTableColumnName ) )
1759 return;
1761 Reference< XPropertySet > xTableColumn( xTableCols->getByName( sTableColumnName ), UNO_QUERY_THROW );
1762 impl_initializeColumnSettings_nothrow( xTableColumn, _rxRowSetColumn );
1764 catch( const Exception& )
1766 DBG_UNHANDLED_EXCEPTION();
1770 void ORowSet::execute_NoApprove_NoNewConn(ResettableMutexGuard& _rClearForNotification)
1772 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "frank.schoenheit@sun.com", "ORowSet::execute_NoApprove_NoNewConn" );
1774 // now we can dispose our old connection
1775 ::comphelper::disposeComponent(m_xOldConnection);
1776 m_xOldConnection = NULL;
1778 // do we need a new statement
1779 if ( m_bCommandFacetsDirty )
1781 m_xStatement = NULL;
1782 m_xComposer = NULL;
1784 Reference< XResultSet > xResultSet( impl_prepareAndExecute_throw() );
1786 // let our warnings container forget the reference to the (possibly disposed) old result set
1787 m_aWarnings.setExternalWarnings( NULL );
1788 // clear all current warnings
1789 m_aWarnings.clearWarnings();
1790 // let the warnings container know about the new "external warnings"
1791 m_aWarnings.setExternalWarnings( Reference< XWarningsSupplier >( xResultSet, UNO_QUERY ) );
1793 ::rtl::OUString aComposedUpdateTableName;
1794 if ( !m_aUpdateTableName.isEmpty() )
1795 aComposedUpdateTableName = composeTableName( m_xActiveConnection->getMetaData(), m_aUpdateCatalogName, m_aUpdateSchemaName, m_aUpdateTableName, sal_False, ::dbtools::eInDataManipulation );
1798 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "frank.schoenheit@sun.com", "ORowSet::execute_NoApprove_NoNewConn: creating cache" );
1799 m_pCache = new ORowSetCache( xResultSet, m_xComposer.get(), m_aContext, aComposedUpdateTableName, m_bModified, m_bNew,m_aParameterValueForCache,m_aFilter,m_nMaxRows );
1800 if ( m_nResultSetConcurrency == ResultSetConcurrency::READ_ONLY )
1802 m_nPrivileges = Privilege::SELECT;
1803 m_pCache->m_nPrivileges = Privilege::SELECT;
1805 m_pCache->setFetchSize(m_nFetchSize);
1806 m_aCurrentRow = m_pCache->createIterator(this);
1807 m_bIsInsertRow = sal_False;
1808 m_aOldRow = m_pCache->registerOldRow();
1811 // get the locale
1812 Locale aLocale = SvtSysLocale().GetLanguageTag().getLocale();
1814 // get the numberformatTypes
1815 OSL_ENSURE(m_xActiveConnection.is(),"No ActiveConnection");
1816 Reference< XNumberFormatTypes> xNumberFormatTypes;
1817 Reference< XNumberFormatsSupplier> xNumberFormat = ::dbtools::getNumberFormats(m_xActiveConnection);
1818 if ( xNumberFormat.is() )
1819 m_xNumberFormatTypes.set(xNumberFormat->getNumberFormats(),UNO_QUERY);
1821 ::rtl::Reference< ::connectivity::OSQLColumns> aColumns = new ::connectivity::OSQLColumns();
1822 ::std::vector< ::rtl::OUString> aNames;
1823 ::rtl::OUString aDescription;
1825 const ::std::map<sal_Int32,sal_Int32>& rKeyColumns = m_pCache->getKeyColumns();
1826 if(!m_xColumns.is())
1828 RTL_LOGFILE_CONTEXT_AUTHOR( aColumnCreateLog, "dbaccess", "frank.schoenheit@sun.com", "ORowSet::execute_NoApprove_NoNewConn::creating columns" );
1829 // use the meta data
1830 Reference<XResultSetMetaDataSupplier> xMetaSup(m_xStatement,UNO_QUERY);
1833 Reference<XResultSetMetaData> xMetaData = xMetaSup->getMetaData();
1834 if ( xMetaData.is() )
1836 sal_Int32 nCount = xMetaData->getColumnCount();
1837 m_aDataColumns.reserve(nCount+1);
1838 aColumns->get().reserve(nCount+1);
1839 DECLARE_STL_USTRINGACCESS_MAP(int,StringMap);
1840 StringMap aColumnMap;
1841 for (sal_Int32 i = 0 ; i < nCount; ++i)
1843 // retrieve the name of the column
1844 ::rtl::OUString sName = xMetaData->getColumnName(i + 1);
1845 // check for duplicate entries
1846 if(aColumnMap.find(sName) != aColumnMap.end())
1848 ::rtl::OUString sAlias(sName);
1849 sal_Int32 searchIndex=1;
1850 while(aColumnMap.find(sAlias) != aColumnMap.end())
1852 (sAlias = sName) += ::rtl::OUString::valueOf(searchIndex++);
1854 sName = sAlias;
1856 ORowSetDataColumn* pColumn = new ORowSetDataColumn( getMetaData(),
1857 this,
1858 this,
1859 i+1,
1860 m_xActiveConnection->getMetaData(),
1861 aDescription,
1862 ::rtl::OUString(),
1863 m_aCurrentRow);
1864 aColumnMap.insert(StringMap::value_type(sName,0));
1865 aColumns->get().push_back(pColumn);
1866 pColumn->setName(sName);
1867 aNames.push_back(sName);
1868 m_aDataColumns.push_back(pColumn);
1870 pColumn->setFastPropertyValue_NoBroadcast(PROPERTY_ID_ISREADONLY,makeAny(rKeyColumns.find(i+1) != rKeyColumns.end()));
1874 sal_Int32 nFormatKey = 0;
1875 if(m_xNumberFormatTypes.is())
1876 nFormatKey = ::dbtools::getDefaultNumberFormat(pColumn,m_xNumberFormatTypes,aLocale);
1879 pColumn->setFastPropertyValue_NoBroadcast(PROPERTY_ID_NUMBERFORMAT,makeAny(nFormatKey));
1880 pColumn->setFastPropertyValue_NoBroadcast(PROPERTY_ID_RELATIVEPOSITION,makeAny(sal_Int32(i+1)));
1881 pColumn->setFastPropertyValue_NoBroadcast(PROPERTY_ID_WIDTH,makeAny(sal_Int32(227)));
1882 pColumn->setFastPropertyValue_NoBroadcast(PROPERTY_ID_ALIGN,makeAny((sal_Int32)0));
1883 pColumn->setFastPropertyValue_NoBroadcast(PROPERTY_ID_HIDDEN,::cppu::bool2any(sal_False));
1885 catch(Exception&)
1891 catch (SQLException&)
1895 else
1897 // create the rowset columns
1898 Reference< XResultSetMetaData > xMeta( getMetaData(), UNO_QUERY_THROW );
1899 sal_Int32 nCount = xMeta->getColumnCount();
1900 m_aDataColumns.reserve(nCount+1);
1901 aColumns->get().reserve(nCount+1);
1902 ::std::set< Reference< XPropertySet > > aAllColumns;
1904 for(sal_Int32 i=1; i <= nCount ;++i)
1906 ::rtl::OUString sName = xMeta->getColumnName(i);
1907 ::rtl::OUString sColumnLabel = xMeta->getColumnLabel(i);
1909 // retrieve the column number |i|
1910 Reference<XPropertySet> xColumn;
1912 sal_Bool bReFetchName = sal_False;
1913 if (m_xColumns->hasByName(sColumnLabel))
1914 m_xColumns->getByName(sColumnLabel) >>= xColumn;
1915 if (!xColumn.is() && m_xColumns->hasByName(sName))
1916 m_xColumns->getByName(sName) >>= xColumn;
1918 // check if column already in the list we need another
1919 if ( aAllColumns.find( xColumn ) != aAllColumns.end() )
1921 xColumn = NULL;
1922 bReFetchName = sal_True;
1923 sColumnLabel = ::rtl::OUString();
1925 if(!xColumn.is())
1927 // no column found so we could look at the position i
1928 Reference<XIndexAccess> xIndexAccess(m_xColumns,UNO_QUERY);
1929 if(xIndexAccess.is() && i <= xIndexAccess->getCount())
1931 xIndexAccess->getByIndex(i-1) >>= xColumn;
1933 else
1935 Sequence< ::rtl::OUString> aSeq = m_xColumns->getElementNames();
1936 if( i <= aSeq.getLength())
1938 m_xColumns->getByName(aSeq.getConstArray()[i-1]) >>= xColumn;
1942 if(bReFetchName && xColumn.is())
1943 xColumn->getPropertyValue(PROPERTY_NAME) >>= sName;
1944 aAllColumns.insert( xColumn );
1947 // create a RowSetDataColumn
1949 Reference<XPropertySetInfo> xInfo = xColumn.is() ? xColumn->getPropertySetInfo() : Reference<XPropertySetInfo>();
1950 if(xInfo.is() && xInfo->hasPropertyByName(PROPERTY_DESCRIPTION))
1951 aDescription = comphelper::getString(xColumn->getPropertyValue(PROPERTY_DESCRIPTION));
1953 ::rtl::OUString sParseLabel;
1954 if ( xColumn.is() )
1956 xColumn->getPropertyValue(PROPERTY_LABEL) >>= sParseLabel;
1958 ORowSetDataColumn* pColumn = new ORowSetDataColumn( getMetaData(),
1959 this,
1960 this,
1962 m_xActiveConnection->getMetaData(),
1963 aDescription,
1964 sParseLabel,
1965 m_aCurrentRow);
1966 aColumns->get().push_back(pColumn);
1968 pColumn->setFastPropertyValue_NoBroadcast(PROPERTY_ID_ISREADONLY,makeAny(rKeyColumns.find(i) != rKeyColumns.end()));
1970 if(sColumnLabel.isEmpty())
1972 if(xColumn.is())
1973 xColumn->getPropertyValue(PROPERTY_NAME) >>= sColumnLabel;
1974 else
1975 sColumnLabel = DBACORE_RESSTRING( RID_STR_EXPRESSION1 );
1977 pColumn->setName(sColumnLabel);
1978 aNames.push_back(sColumnLabel);
1979 m_aDataColumns.push_back(pColumn);
1981 if ( xColumn.is() )
1982 impl_initializeColumnSettings_nothrow( xColumn, pColumn );
1986 // now create the columns we need
1987 if(m_pColumns)
1988 m_pColumns->assign(aColumns,aNames);
1989 else
1991 Reference<XDatabaseMetaData> xMeta = m_xActiveConnection->getMetaData();
1992 m_pColumns = new ORowSetDataColumns(xMeta.is() && xMeta->supportsMixedCaseQuotedIdentifiers(),
1993 aColumns,*this,m_aColumnsMutex,aNames);
1996 checkCache();
1997 // notify the rowset listeners
1998 notifyAllListeners(_rClearForNotification);
2001 // XRowSetApproveBroadcaster
2002 void SAL_CALL ORowSet::addRowSetApproveListener( const Reference< XRowSetApproveListener >& listener ) throw(RuntimeException)
2004 ::connectivity::checkDisposed(ORowSet_BASE1::rBHelper.bDisposed);
2006 ::osl::MutexGuard aGuard( m_aColumnsMutex );
2008 m_aApproveListeners.addInterface(listener);
2011 void SAL_CALL ORowSet::removeRowSetApproveListener( const Reference< XRowSetApproveListener >& listener ) throw(RuntimeException)
2013 ::connectivity::checkDisposed(ORowSet_BASE1::rBHelper.bDisposed);
2015 ::osl::MutexGuard aGuard( m_aColumnsMutex );
2017 m_aApproveListeners.removeInterface(listener);
2019 // XRowsChangeBroadcaster
2020 void SAL_CALL ORowSet::addRowsChangeListener( const Reference< XRowsChangeListener >& listener ) throw(RuntimeException)
2022 ::connectivity::checkDisposed(ORowSet_BASE1::rBHelper.bDisposed);
2024 ::osl::MutexGuard aGuard( m_aColumnsMutex );
2026 m_aRowsChangeListener.addInterface(listener);
2029 void SAL_CALL ORowSet::removeRowsChangeListener( const Reference< XRowsChangeListener >& listener ) throw(RuntimeException)
2031 ::connectivity::checkDisposed(ORowSet_BASE1::rBHelper.bDisposed);
2033 ::osl::MutexGuard aGuard( m_aColumnsMutex );
2035 m_aRowsChangeListener.removeInterface(listener);
2038 // XResultSetAccess
2039 Reference< XResultSet > SAL_CALL ORowSet::createResultSet( ) throw(SQLException, RuntimeException)
2041 ::osl::MutexGuard aGuard( m_aColumnsMutex );
2043 if(m_xStatement.is())
2045 ORowSetClone* pClone = new ORowSetClone( m_aContext, *this, m_pMutex );
2046 Reference< XResultSet > xRet(pClone);
2047 m_aClones.push_back(WeakReferenceHelper(xRet));
2048 return xRet;
2050 return Reference< XResultSet >();
2053 // ::com::sun::star::util::XCancellable
2054 void SAL_CALL ORowSet::cancel( ) throw(RuntimeException)
2056 ::connectivity::checkDisposed(ORowSet_BASE1::rBHelper.bDisposed);
2059 // ::com::sun::star::sdbcx::XDeleteRows
2060 Sequence< sal_Int32 > SAL_CALL ORowSet::deleteRows( const Sequence< Any >& rows ) throw(SQLException, RuntimeException)
2062 ::connectivity::checkDisposed(ORowSet_BASE1::rBHelper.bDisposed);
2064 if(!m_pCache || m_nResultSetConcurrency == ResultSetConcurrency::READ_ONLY)
2065 throwFunctionSequenceException(*this);
2067 ::osl::ResettableMutexGuard aGuard( *m_pMutex );
2069 Sequence<Any> aChangedBookmarks;
2070 RowsChangeEvent aEvt(*this,RowChangeAction::DELETE,rows.getLength(),aChangedBookmarks);
2071 // notify the rowset listeners
2072 notifyAllListenersRowBeforeChange(aGuard,aEvt);
2074 Sequence< sal_Int32 > aResults( rows.getLength() );
2075 const Any* row = rows.getConstArray();
2076 const Any* rowEnd = rows.getConstArray() + rows.getLength();
2077 sal_Int32* result = aResults.getArray();
2078 for ( ; row != rowEnd; ++row, ++result )
2080 *result = 0;
2081 if ( !m_pCache->moveToBookmark( *row ) )
2082 continue;
2083 sal_Int32 nDeletePosition = m_pCache->getRow();
2085 // first notify the clones so that they can save their position
2086 notifyRowSetAndClonesRowDelete( *row );
2088 // now delete the row
2089 if ( !m_pCache->deleteRow() )
2090 continue;
2091 *result = 1;
2092 // now notify that we have deleted
2093 notifyRowSetAndClonesRowDeleted( *row, nDeletePosition );
2095 aEvt.Rows = aResults.getLength();
2097 // we have to check if we stand on the insert row and if so we have to reset it
2098 ORowSetNotifier aNotifier( this );
2099 // this will call cancelRowModification on the cache if necessary
2100 // notification order
2101 // - rowChanged
2102 notifyAllListenersRowChanged(aGuard,aEvt);
2104 // - IsModified
2105 // - IsNew
2106 aNotifier.fire();
2108 // - RowCount/IsRowCountFinal
2109 fireRowcount();
2111 return aResults;
2114 void ORowSet::notifyRowSetAndClonesRowDelete( const Any& _rBookmark )
2116 // notify ourself
2117 onDeleteRow( _rBookmark );
2118 // notify the clones
2119 connectivity::OWeakRefArray::iterator aEnd = m_aClones.end();
2120 for (connectivity::OWeakRefArray::iterator i = m_aClones.begin(); aEnd != i; ++i)
2122 Reference< XUnoTunnel > xTunnel(i->get(),UNO_QUERY);
2123 if(xTunnel.is())
2125 ORowSetClone* pClone = reinterpret_cast<ORowSetClone*>(xTunnel->getSomething(ORowSetClone::getUnoTunnelImplementationId()));
2126 if(pClone)
2127 pClone->onDeleteRow( _rBookmark );
2132 void ORowSet::notifyRowSetAndClonesRowDeleted( const Any& _rBookmark, sal_Int32 _nPos )
2134 // notify ourself
2135 onDeletedRow( _rBookmark, _nPos );
2136 // notify the clones
2137 connectivity::OWeakRefArray::iterator aEnd = m_aClones.end();
2138 for (connectivity::OWeakRefArray::iterator i = m_aClones.begin(); aEnd != i; ++i)
2140 Reference< XUnoTunnel > xTunnel(i->get(),UNO_QUERY);
2141 if(xTunnel.is())
2143 ORowSetClone* pClone = reinterpret_cast<ORowSetClone*>(xTunnel->getSomething(ORowSetClone::getUnoTunnelImplementationId()));
2144 if(pClone)
2145 pClone->onDeletedRow( _rBookmark, _nPos );
2150 Reference< XConnection > ORowSet::calcConnection(const Reference< XInteractionHandler >& _rxHandler) throw( SQLException, RuntimeException )
2152 MutexGuard aGuard(m_aMutex);
2153 if (!m_xActiveConnection.is())
2155 Reference< XConnection > xNewConn;
2156 if ( !m_aDataSourceName.isEmpty() )
2158 Reference< XDatabaseContext > xDatabaseContext( DatabaseContext::create(m_aContext.getUNOContext()) );
2161 Reference< XDataSource > xDataSource( xDatabaseContext->getByName( m_aDataSourceName ), UNO_QUERY_THROW );
2163 // try connecting with the interaction handler
2164 Reference< XCompletedConnection > xComplConn( xDataSource, UNO_QUERY );
2165 if ( _rxHandler.is() && xComplConn.is() )
2167 xNewConn = xComplConn->connectWithCompletion( _rxHandler );
2169 else
2171 xNewConn = xDataSource->getConnection( m_aUser, m_aPassword );
2174 catch ( const SQLException& )
2176 throw;
2178 catch ( const Exception& )
2180 Any aError = ::cppu::getCaughtException();
2181 ::rtl::OUString sMessage = ResourceManager::loadString( RID_NO_SUCH_DATA_SOURCE,
2182 "$name$", m_aDataSourceName, "$error$", extractExceptionMessage( m_aContext, aError ) );
2183 ::dbtools::throwGenericSQLException( sMessage, *this );
2186 setActiveConnection(xNewConn);
2187 m_bOwnConnection = sal_True;
2189 return m_xActiveConnection;
2192 Reference< XNameAccess > ORowSet::impl_getTables_throw()
2194 Reference< XNameAccess > xTables;
2196 Reference< XTablesSupplier > xTablesAccess( m_xActiveConnection, UNO_QUERY );
2197 if ( xTablesAccess.is() )
2199 xTables.set( xTablesAccess->getTables(), UNO_QUERY_THROW );
2201 else if ( m_pTables )
2203 xTables = m_pTables;
2205 else
2207 if ( !m_xActiveConnection.is() )
2208 throw SQLException(DBA_RES(RID_STR_CONNECTION_INVALID),*this,SQLSTATE_GENERAL,1000,Any() );
2210 sal_Bool bCase = sal_True;
2213 Reference<XDatabaseMetaData> xMeta = m_xActiveConnection->getMetaData();
2214 bCase = xMeta.is() && xMeta->supportsMixedCaseQuotedIdentifiers();
2216 catch(SQLException&)
2218 DBG_UNHANDLED_EXCEPTION();
2221 m_pTables = new OTableContainer(*this,m_aMutex,m_xActiveConnection,bCase,NULL,NULL,NULL,m_nInAppend);
2222 xTables = m_pTables;
2223 Sequence< ::rtl::OUString> aTableFilter(1);
2224 aTableFilter[0] = ::rtl::OUString("%");
2225 m_pTables->construct(aTableFilter,Sequence< ::rtl::OUString>());
2228 return xTables;
2231 void ORowSet::impl_resetTables_nothrow()
2233 if ( !m_pTables )
2234 return;
2238 m_pTables->dispose();
2240 catch( const Exception& )
2242 DBG_UNHANDLED_EXCEPTION();
2245 DELETEZ( m_pTables );
2248 sal_Bool ORowSet::impl_initComposer_throw( ::rtl::OUString& _out_rCommandToExecute )
2250 sal_Bool bUseEscapeProcessing = impl_buildActiveCommand_throw( );
2251 _out_rCommandToExecute = m_aActiveCommand;
2252 if ( !bUseEscapeProcessing )
2253 return bUseEscapeProcessing;
2255 Reference< XMultiServiceFactory > xFactory( m_xActiveConnection, UNO_QUERY );
2256 if ( xFactory.is() )
2260 ::comphelper::disposeComponent( m_xComposer );
2261 m_xComposer.set( xFactory->createInstance( SERVICE_NAME_SINGLESELECTQUERYCOMPOSER ), UNO_QUERY_THROW );
2263 catch (const Exception& ) { m_xComposer = NULL; }
2265 if ( !m_xComposer.is() )
2266 m_xComposer = new OSingleSelectQueryComposer( impl_getTables_throw(), m_xActiveConnection, m_aContext );
2268 m_xComposer->setCommand( m_aCommand,m_nCommandType );
2269 m_aActiveCommand = m_xComposer->getQuery();
2271 m_xComposer->setFilter( m_bApplyFilter ? m_aFilter : ::rtl::OUString() );
2272 m_xComposer->setHavingClause( m_bApplyFilter ? m_aHavingClause : ::rtl::OUString() );
2274 if ( m_bIgnoreResult )
2275 { // append a "0=1" filter
2276 // don't simply overwrite an existent filter, this would lead to problems if this existent
2277 // filter contains parameters (since a keyset may add parameters itself)
2278 m_xComposer->setElementaryQuery( m_xComposer->getQuery( ) );
2279 m_xComposer->setFilter( ::rtl::OUString("0 = 1" ) );
2282 m_xComposer->setOrder( m_aOrder );
2283 m_xComposer->setGroup( m_aGroupBy );
2285 if ( !m_xColumns.is() )
2287 Reference< XColumnsSupplier > xCols( m_xComposer, UNO_QUERY_THROW );
2288 m_xColumns = xCols->getColumns();
2291 impl_initParametersContainer_nothrow();
2293 _out_rCommandToExecute = m_xComposer->getQueryWithSubstitution();
2295 return bUseEscapeProcessing;
2298 sal_Bool ORowSet::impl_buildActiveCommand_throw()
2300 // create the sql command
2301 // from a table name or get the command out of a query (not a view)
2302 // the last use the command as it is
2303 sal_Bool bDoEscapeProcessing = m_bUseEscapeProcessing;
2305 m_aActiveCommand = ::rtl::OUString();
2306 ::rtl::OUString sCommand;
2308 if ( m_aCommand.isEmpty() )
2309 return bDoEscapeProcessing;
2311 switch (m_nCommandType)
2313 case CommandType::TABLE:
2315 impl_resetTables_nothrow();
2316 if ( bDoEscapeProcessing )
2318 Reference< XNameAccess > xTables( impl_getTables_throw() );
2319 if ( xTables->hasByName(m_aCommand) )
2322 else
2324 String sMessage( DBACORE_RESSTRING( RID_STR_TABLE_DOES_NOT_EXIST ) );
2325 sMessage.SearchAndReplaceAscii( "$table$", m_aCommand );
2326 throwGenericSQLException(sMessage,*this);
2329 else
2331 sCommand = rtl::OUString("SELECT * FROM ");
2332 ::rtl::OUString sCatalog, sSchema, sTable;
2333 ::dbtools::qualifiedNameComponents( m_xActiveConnection->getMetaData(), m_aCommand, sCatalog, sSchema, sTable, ::dbtools::eInDataManipulation );
2334 sCommand += ::dbtools::composeTableNameForSelect( m_xActiveConnection, sCatalog, sSchema, sTable );
2337 break;
2339 case CommandType::QUERY:
2341 Reference< XQueriesSupplier > xQueriesAccess(m_xActiveConnection, UNO_QUERY);
2342 if (xQueriesAccess.is())
2344 Reference< ::com::sun::star::container::XNameAccess > xQueries(xQueriesAccess->getQueries());
2345 if (xQueries->hasByName(m_aCommand))
2347 Reference< XPropertySet > xQuery(xQueries->getByName(m_aCommand),UNO_QUERY);
2348 OSL_ENSURE(xQuery.is(),"ORowSet::impl_buildActiveCommand_throw: Query is NULL!");
2349 if ( xQuery.is() )
2351 xQuery->getPropertyValue(PROPERTY_COMMAND) >>= sCommand;
2352 xQuery->getPropertyValue(PROPERTY_ESCAPE_PROCESSING) >>= bDoEscapeProcessing;
2353 if ( bDoEscapeProcessing != m_bUseEscapeProcessing )
2355 sal_Bool bOldValue = m_bUseEscapeProcessing;
2356 m_bUseEscapeProcessing = bDoEscapeProcessing;
2357 fireProperty(PROPERTY_ID_ESCAPE_PROCESSING,bOldValue,bDoEscapeProcessing);
2360 ::rtl::OUString aCatalog,aSchema,aTable;
2361 xQuery->getPropertyValue(PROPERTY_UPDATE_CATALOGNAME) >>= aCatalog;
2362 xQuery->getPropertyValue(PROPERTY_UPDATE_SCHEMANAME) >>= aSchema;
2363 xQuery->getPropertyValue(PROPERTY_UPDATE_TABLENAME) >>= aTable;
2364 if(!aTable.isEmpty())
2365 m_aUpdateTableName = composeTableName( m_xActiveConnection->getMetaData(), aCatalog, aSchema, aTable, sal_False, ::dbtools::eInDataManipulation );
2368 else
2370 String sMessage( DBACORE_RESSTRING( RID_STR_QUERY_DOES_NOT_EXIST ) );
2371 sMessage.SearchAndReplaceAscii( "$table$", m_aCommand );
2372 throwGenericSQLException(sMessage,*this);
2375 else
2376 throw SQLException(DBA_RES(RID_STR_NO_XQUERIESSUPPLIER),*this,::rtl::OUString(),0,Any());
2378 break;
2380 default:
2381 sCommand = m_aCommand;
2382 break;
2385 m_aActiveCommand = sCommand;
2387 if ( m_aActiveCommand.isEmpty() && !bDoEscapeProcessing )
2388 ::dbtools::throwSQLException( DBACORE_RESSTRING( RID_STR_NO_SQL_COMMAND ), SQL_FUNCTION_SEQUENCE_ERROR, *this );
2390 return bDoEscapeProcessing;
2393 void ORowSet::impl_initParametersContainer_nothrow()
2395 OSL_PRECOND( !m_pParameters.is(), "ORowSet::impl_initParametersContainer_nothrow: already initialized the parameters!" );
2397 m_pParameters = new param::ParameterWrapperContainer( m_xComposer.get() );
2398 // copy the premature parameters into the final ones
2399 size_t nParamCount( ::std::min( m_pParameters->size(), m_aPrematureParamValues.get().size() ) );
2400 for ( size_t i=0; i<nParamCount; ++i )
2402 (*m_pParameters)[i] = m_aPrematureParamValues.get()[i];
2406 void ORowSet::impl_disposeParametersContainer_nothrow()
2408 if ( !m_pParameters.is() )
2409 return;
2411 // copy the actual values to our "premature" ones, to preserve them for later use
2412 size_t nParamCount( m_pParameters->size() );
2413 m_aPrematureParamValues.get().resize( nParamCount );
2414 for ( size_t i=0; i<nParamCount; ++i )
2416 m_aPrematureParamValues.get()[i] = (*m_pParameters)[i];
2419 m_pParameters->dispose();
2420 m_pParameters = NULL;
2423 ORowSetValue& ORowSet::getParameterStorage(sal_Int32 parameterIndex)
2425 ::connectivity::checkDisposed( ORowSet_BASE1::rBHelper.bDisposed );
2426 if ( parameterIndex < 1 )
2427 throwInvalidIndexException( *this );
2429 if ( m_aParametersSet.size() < (size_t)parameterIndex )
2430 m_aParametersSet.resize( parameterIndex ,false);
2431 m_aParametersSet[parameterIndex - 1] = true;
2433 if ( m_aParametersSet.size() < (size_t)parameterIndex )
2434 m_aParametersSet.resize( parameterIndex ,false);
2435 m_aParametersSet[parameterIndex - 1] = true;
2437 if ( m_pParameters.is() )
2439 if ( m_bCommandFacetsDirty )
2440 // need to rebuild the parameters, since some property which contributes to the
2441 // complete command, and thus the parameters, changed
2442 impl_disposeParametersContainer_nothrow();
2443 if ( m_pParameters.is() )
2445 if ( (size_t)parameterIndex > m_pParameters->size() )
2446 throwInvalidIndexException( *this );
2447 return (*m_pParameters)[ parameterIndex - 1 ];
2451 if ( m_aPrematureParamValues.get().size() < (size_t)parameterIndex )
2452 m_aPrematureParamValues.get().resize( parameterIndex );
2453 return m_aPrematureParamValues.get()[ parameterIndex - 1 ];
2456 // XParameters
2457 void SAL_CALL ORowSet::setNull( sal_Int32 parameterIndex, sal_Int32 /*sqlType*/ ) throw(SQLException, RuntimeException)
2459 ::osl::MutexGuard aGuard( m_aColumnsMutex );
2461 getParameterStorage( parameterIndex ).setNull();
2464 void SAL_CALL ORowSet::setObjectNull( sal_Int32 parameterIndex, sal_Int32 sqlType, const ::rtl::OUString& /*typeName*/ ) throw(SQLException, RuntimeException)
2466 setNull( parameterIndex, sqlType );
2469 void ORowSet::setParameter(sal_Int32 parameterIndex, const ORowSetValue& x)
2471 ::osl::MutexGuard aGuard( m_aColumnsMutex );
2473 getParameterStorage( parameterIndex ) = x;
2476 void SAL_CALL ORowSet::setBoolean( sal_Int32 parameterIndex, sal_Bool x ) throw(SQLException, RuntimeException)
2478 setParameter(parameterIndex,x);
2481 void SAL_CALL ORowSet::setByte( sal_Int32 parameterIndex, sal_Int8 x ) throw(SQLException, RuntimeException)
2483 setParameter(parameterIndex,x);
2486 void SAL_CALL ORowSet::setShort( sal_Int32 parameterIndex, sal_Int16 x ) throw(SQLException, RuntimeException)
2488 setParameter(parameterIndex,x);
2491 void SAL_CALL ORowSet::setInt( sal_Int32 parameterIndex, sal_Int32 x ) throw(SQLException, RuntimeException)
2493 setParameter(parameterIndex,x);
2496 void SAL_CALL ORowSet::setLong( sal_Int32 parameterIndex, sal_Int64 x ) throw(SQLException, RuntimeException)
2498 setParameter(parameterIndex,x);
2501 void SAL_CALL ORowSet::setFloat( sal_Int32 parameterIndex, float x ) throw(SQLException, RuntimeException)
2503 setParameter(parameterIndex,x);
2506 void SAL_CALL ORowSet::setDouble( sal_Int32 parameterIndex, double x ) throw(SQLException, RuntimeException)
2508 setParameter(parameterIndex,x);
2511 void SAL_CALL ORowSet::setString( sal_Int32 parameterIndex, const ::rtl::OUString& x ) throw(SQLException, RuntimeException)
2513 setParameter(parameterIndex,x);
2516 void SAL_CALL ORowSet::setBytes( sal_Int32 parameterIndex, const Sequence< sal_Int8 >& x ) throw(SQLException, RuntimeException)
2518 setParameter(parameterIndex,x);
2521 void SAL_CALL ORowSet::setDate( sal_Int32 parameterIndex, const ::com::sun::star::util::Date& x ) throw(SQLException, RuntimeException)
2523 setParameter(parameterIndex,x);
2526 void SAL_CALL ORowSet::setTime( sal_Int32 parameterIndex, const ::com::sun::star::util::Time& x ) throw(SQLException, RuntimeException)
2528 setParameter(parameterIndex,x);
2531 void SAL_CALL ORowSet::setTimestamp( sal_Int32 parameterIndex, const ::com::sun::star::util::DateTime& x ) throw(SQLException, RuntimeException)
2533 setParameter(parameterIndex,x);
2536 void SAL_CALL ORowSet::setBinaryStream( sal_Int32 parameterIndex, const Reference< ::com::sun::star::io::XInputStream >& x, sal_Int32 length ) throw(SQLException, RuntimeException)
2538 ::osl::MutexGuard aGuard( m_aColumnsMutex );
2539 ORowSetValue& rParamValue( getParameterStorage( parameterIndex ) );
2543 Sequence <sal_Int8> aData;
2544 x->readBytes(aData, length);
2545 rParamValue = aData;
2546 x->closeInput();
2548 catch( Exception& )
2550 throw SQLException();
2554 void SAL_CALL ORowSet::setCharacterStream( sal_Int32 parameterIndex, const Reference< ::com::sun::star::io::XInputStream >& x, sal_Int32 length ) throw(SQLException, RuntimeException)
2556 ::osl::MutexGuard aGuard( m_aColumnsMutex );
2557 ORowSetValue& rParamValue( getParameterStorage( parameterIndex ) );
2560 Sequence <sal_Int8> aData;
2561 rtl::OUString aDataStr;
2562 // the data is given as character data and the length defines the character length
2563 sal_Int32 nSize = x->readBytes(aData, length * sizeof(sal_Unicode));
2564 if (nSize / sizeof(sal_Unicode))
2565 aDataStr = rtl::OUString((sal_Unicode*)aData.getConstArray(), nSize / sizeof(sal_Unicode));
2566 rParamValue = aDataStr;
2567 rParamValue.setTypeKind( DataType::LONGVARCHAR );
2568 x->closeInput();
2570 catch( Exception& )
2572 throw SQLException();
2576 void SAL_CALL ORowSet::setObject( sal_Int32 parameterIndex, const Any& x ) throw(SQLException, RuntimeException)
2578 if ( !::dbtools::implSetObject( this, parameterIndex, x ) )
2579 { // there is no other setXXX call which can handle the value in x
2580 throw SQLException();
2584 void SAL_CALL ORowSet::setObjectWithInfo( sal_Int32 parameterIndex, const Any& x, sal_Int32 targetSqlType, sal_Int32 /*scale*/ ) throw(SQLException, RuntimeException)
2586 ::osl::MutexGuard aGuard( m_aColumnsMutex );
2587 ORowSetValue& rParamValue( getParameterStorage( parameterIndex ) );
2588 setObject( parameterIndex, x );
2589 rParamValue.setTypeKind( targetSqlType );
2592 void SAL_CALL ORowSet::setRef( sal_Int32 /*parameterIndex*/, const Reference< XRef >& /*x*/ ) throw(SQLException, RuntimeException)
2594 ::dbtools::throwFeatureNotImplementedException( "XParameters::setRef", *this );
2597 void SAL_CALL ORowSet::setBlob( sal_Int32 /*parameterIndex*/, const Reference< XBlob >& /*x*/ ) throw(SQLException, RuntimeException)
2599 ::dbtools::throwFeatureNotImplementedException( "XParameters::setBlob", *this );
2602 void SAL_CALL ORowSet::setClob( sal_Int32 /*parameterIndex*/, const Reference< XClob >& /*x*/ ) throw(SQLException, RuntimeException)
2604 ::dbtools::throwFeatureNotImplementedException( "XParameters::setClob", *this );
2607 void SAL_CALL ORowSet::setArray( sal_Int32 /*parameterIndex*/, const Reference< XArray >& /*x*/ ) throw(SQLException, RuntimeException)
2609 ::dbtools::throwFeatureNotImplementedException( "XParameters::setArray", *this );
2612 void SAL_CALL ORowSet::clearParameters( ) throw(SQLException, RuntimeException)
2614 ::connectivity::checkDisposed(ORowSet_BASE1::rBHelper.bDisposed);
2616 ::osl::MutexGuard aGuard( m_aColumnsMutex );
2618 size_t nParamCount( m_pParameters.is() ? m_pParameters->size() : m_aPrematureParamValues.get().size() );
2619 for ( size_t i=1; i<=nParamCount; ++i )
2620 getParameterStorage( (sal_Int32)i ).setNull();
2621 m_aParametersSet.clear();
2624 Any SAL_CALL ORowSet::getWarnings( ) throw (SQLException, RuntimeException)
2626 return m_aWarnings.getWarnings();
2629 void SAL_CALL ORowSet::clearWarnings( ) throw (SQLException, RuntimeException)
2631 m_aWarnings.clearWarnings();
2634 void ORowSet::doCancelModification( )
2636 if ( isModification() )
2638 // read-only flag restored
2639 impl_restoreDataColumnsWriteable_throw();
2640 m_pCache->cancelRowModification();
2642 m_bModified = sal_False;
2643 m_bIsInsertRow = sal_False;
2646 sal_Bool ORowSet::isModification( )
2648 return isNew();
2651 sal_Bool ORowSet::isModified( )
2653 return m_bModified;
2656 sal_Bool ORowSet::isNew( )
2658 return m_bNew;
2661 sal_Bool ORowSet::isPropertyChangeNotificationEnabled() const
2663 return m_bPropChangeNotifyEnabled;
2666 void ORowSet::checkUpdateIterator()
2668 if(!m_bIsInsertRow)
2670 m_pCache->setUpdateIterator(m_aCurrentRow);
2671 m_aCurrentRow = m_pCache->m_aInsertRow;
2672 m_bIsInsertRow = sal_True;
2676 void ORowSet::checkUpdateConditions(sal_Int32 columnIndex)
2678 checkCache();
2679 if ( m_nResultSetConcurrency == ResultSetConcurrency::READ_ONLY)
2680 ::dbtools::throwSQLException( DBACORE_RESSTRING( RID_STR_RESULT_IS_READONLY ), SQL_GENERAL_ERROR, *this );
2682 if ( rowDeleted() )
2683 ::dbtools::throwSQLException( DBACORE_RESSTRING( RID_STR_ROW_ALREADY_DELETED ), SQL_INVALID_CURSOR_POSITION, *this );
2685 if ( m_aCurrentRow.isNull() )
2686 ::dbtools::throwSQLException( DBACORE_RESSTRING( RID_STR_INVALID_CURSOR_STATE ), SQL_INVALID_CURSOR_STATE, *this );
2688 if ( columnIndex <= 0 || sal_Int32((*m_aCurrentRow)->get().size()) <= columnIndex )
2689 ::dbtools::throwSQLException( DBACORE_RESSTRING( RID_STR_INVALID_INDEX ), SQL_INVALID_DESCRIPTOR_INDEX, *this );
2692 void SAL_CALL ORowSet::refreshRow( ) throw(SQLException, RuntimeException)
2695 ORowSetNotifier aNotifier( this );
2696 // this will call cancelRowModification on the cache if necessary
2698 // notification order:
2699 if ( m_bModified && m_pCache )
2700 implCancelRowUpdates( sal_False ); // do _not_ notify the IsModify - will do this ourself below
2702 // - column values
2703 ORowSetBase::refreshRow();
2705 // - IsModified
2706 // - IsNew
2707 aNotifier.fire( );
2710 void ORowSet::impl_rebuild_throw(::osl::ResettableMutexGuard& _rGuard)
2712 Reference< XResultSet > xResultSet( m_xStatement->executeQuery() );
2713 m_aWarnings.setExternalWarnings( Reference< XWarningsSupplier >( xResultSet, UNO_QUERY ) );
2714 m_pCache->reset(xResultSet);
2715 notifyAllListeners(_rGuard);
2717 // ***********************************************************
2718 // ORowSetClone
2719 // ***********************************************************
2720 DBG_NAME(ORowSetClone);
2722 ORowSetClone::ORowSetClone( const ::comphelper::ComponentContext& _rContext, ORowSet& rParent, ::osl::Mutex* _pMutex )
2723 :OSubComponent(m_aMutex, rParent)
2724 ,ORowSetBase( _rContext, OComponentHelper::rBHelper, _pMutex )
2725 ,m_pParent(&rParent)
2726 ,m_nFetchDirection(rParent.m_nFetchDirection)
2727 ,m_nFetchSize(rParent.m_nFetchSize)
2728 ,m_bIsBookmarkable(sal_True)
2730 DBG_CTOR(ORowSetClone, NULL);
2732 m_nResultSetType = rParent.m_nResultSetType;
2733 m_nResultSetConcurrency = ResultSetConcurrency::READ_ONLY;
2734 m_pMySelf = this;
2735 m_bClone = sal_True;
2736 m_bBeforeFirst = rParent.m_bBeforeFirst;
2737 m_bAfterLast = rParent.m_bAfterLast;
2738 m_pCache = rParent.m_pCache;
2739 m_aBookmark = rParent.m_aBookmark;
2740 m_aCurrentRow = m_pCache->createIterator(this);
2741 m_xNumberFormatTypes = rParent.m_xNumberFormatTypes;
2743 m_aOldRow = m_pCache->registerOldRow();
2745 ::rtl::Reference< ::connectivity::OSQLColumns> aColumns = new ::connectivity::OSQLColumns();
2746 ::std::vector< ::rtl::OUString> aNames;
2748 ::rtl::OUString aDescription;
2749 Locale aLocale = SvtSysLocale().GetLanguageTag().getLocale();
2751 if ( rParent.m_pColumns )
2753 Sequence< ::rtl::OUString> aSeq = rParent.m_pColumns->getElementNames();
2754 const ::rtl::OUString* pIter = aSeq.getConstArray();
2755 const ::rtl::OUString* pEnd = pIter + aSeq.getLength();
2756 aColumns->get().reserve(aSeq.getLength()+1);
2757 for(sal_Int32 i=1;pIter != pEnd ;++pIter,++i)
2759 Reference<XPropertySet> xColumn;
2760 rParent.m_pColumns->getByName(*pIter) >>= xColumn;
2761 if(xColumn->getPropertySetInfo()->hasPropertyByName(PROPERTY_DESCRIPTION))
2762 aDescription = comphelper::getString(xColumn->getPropertyValue(PROPERTY_DESCRIPTION));
2764 ::rtl::OUString sParseLabel;
2765 xColumn->getPropertyValue(PROPERTY_LABEL) >>= sParseLabel;
2766 ORowSetColumn* pColumn = new ORowSetColumn( rParent.getMetaData(),
2767 this,
2769 rParent.m_xActiveConnection->getMetaData(),
2770 aDescription,
2771 sParseLabel,
2772 m_aCurrentRow);
2773 aColumns->get().push_back(pColumn);
2774 pColumn->setName(*pIter);
2775 aNames.push_back(*pIter);
2776 m_aDataColumns.push_back(pColumn);
2778 pColumn->setFastPropertyValue_NoBroadcast(PROPERTY_ID_ALIGN,xColumn->getPropertyValue(PROPERTY_ALIGN));
2779 sal_Int32 nFormatKey = 0;
2780 xColumn->getPropertyValue(PROPERTY_NUMBERFORMAT) >>= nFormatKey;
2781 if(!nFormatKey && xColumn.is() && m_xNumberFormatTypes.is())
2782 nFormatKey = ::dbtools::getDefaultNumberFormat(xColumn,m_xNumberFormatTypes,aLocale);
2783 pColumn->setFastPropertyValue_NoBroadcast(PROPERTY_ID_NUMBERFORMAT,makeAny(nFormatKey));
2784 pColumn->setFastPropertyValue_NoBroadcast(PROPERTY_ID_RELATIVEPOSITION,xColumn->getPropertyValue(PROPERTY_RELATIVEPOSITION));
2785 pColumn->setFastPropertyValue_NoBroadcast(PROPERTY_ID_WIDTH,xColumn->getPropertyValue(PROPERTY_WIDTH));
2786 pColumn->setFastPropertyValue_NoBroadcast(PROPERTY_ID_HIDDEN,xColumn->getPropertyValue(PROPERTY_HIDDEN));
2787 pColumn->setFastPropertyValue_NoBroadcast(PROPERTY_ID_CONTROLMODEL,xColumn->getPropertyValue(PROPERTY_CONTROLMODEL));
2788 pColumn->setFastPropertyValue_NoBroadcast(PROPERTY_ID_HELPTEXT,xColumn->getPropertyValue(PROPERTY_HELPTEXT));
2789 pColumn->setFastPropertyValue_NoBroadcast(PROPERTY_ID_CONTROLDEFAULT,xColumn->getPropertyValue(PROPERTY_CONTROLDEFAULT));
2793 Reference<XDatabaseMetaData> xMeta = rParent.m_xActiveConnection->getMetaData();
2794 m_pColumns = new ORowSetDataColumns(xMeta.is() && xMeta->supportsMixedCaseQuotedIdentifiers(),
2795 aColumns,*this,m_aMutex,aNames);
2797 sal_Int32 nRT = PropertyAttribute::READONLY | PropertyAttribute::TRANSIENT;
2799 // sdb.RowSet Properties
2800 registerMayBeVoidProperty(PROPERTY_ACTIVE_CONNECTION,PROPERTY_ID_ACTIVE_CONNECTION, PropertyAttribute::MAYBEVOID|PropertyAttribute::READONLY, &rParent.m_aActiveConnection, ::getCppuType(static_cast< Reference< XConnection >* >(0)));
2801 registerProperty(PROPERTY_RESULTSETCONCURRENCY, PROPERTY_ID_RESULTSETCONCURRENCY, PropertyAttribute::READONLY, &m_nResultSetConcurrency,::getCppuType(static_cast< sal_Int32*>(0)));
2802 registerProperty(PROPERTY_RESULTSETTYPE, PROPERTY_ID_RESULTSETTYPE, PropertyAttribute::READONLY, &m_nResultSetType, ::getCppuType(static_cast< sal_Int32*>(0)));
2803 registerProperty(PROPERTY_FETCHDIRECTION, PROPERTY_ID_FETCHDIRECTION, PropertyAttribute::TRANSIENT, &m_nFetchDirection, ::getCppuType(static_cast< sal_Int32*>(0)));
2804 registerProperty(PROPERTY_FETCHSIZE, PROPERTY_ID_FETCHSIZE, PropertyAttribute::TRANSIENT, &m_nFetchSize, ::getCppuType(static_cast< sal_Int32*>(0)));
2805 registerProperty(PROPERTY_ISBOOKMARKABLE, PROPERTY_ID_ISBOOKMARKABLE, nRT, &m_bIsBookmarkable, ::getBooleanCppuType());
2808 ORowSetClone::~ORowSetClone()
2810 DBG_DTOR(ORowSetClone, NULL);
2813 // com::sun::star::XTypeProvider
2814 Sequence< Type > ORowSetClone::getTypes() throw (RuntimeException)
2816 return ::comphelper::concatSequences(OSubComponent::getTypes(),ORowSetBase::getTypes());
2819 // com::sun::star::XInterface
2820 Any ORowSetClone::queryInterface( const Type & rType ) throw (RuntimeException)
2822 Any aRet = ORowSetBase::queryInterface(rType);
2823 if(!aRet.hasValue())
2824 aRet = OSubComponent::queryInterface(rType);
2825 return aRet;
2828 void ORowSetClone::acquire() throw()
2830 OSubComponent::acquire();
2833 void ORowSetClone::release() throw()
2835 OSubComponent::release();
2838 // XServiceInfo
2839 rtl::OUString ORowSetClone::getImplementationName( ) throw(RuntimeException)
2841 return rtl::OUString("com.sun.star.sdb.ORowSetClone");
2844 sal_Bool ORowSetClone::supportsService( const ::rtl::OUString& _rServiceName ) throw (RuntimeException)
2846 return ::comphelper::findValue(getSupportedServiceNames(), _rServiceName, sal_True).getLength() != 0;
2849 Sequence< ::rtl::OUString > ORowSetClone::getSupportedServiceNames( ) throw (RuntimeException)
2851 Sequence< ::rtl::OUString > aSNS( 2 );
2852 aSNS[0] = SERVICE_SDBC_RESULTSET;
2853 aSNS[1] = SERVICE_SDB_RESULTSET;
2854 return aSNS;
2857 // OComponentHelper
2858 void ORowSetClone::disposing()
2860 MutexGuard aGuard( m_aMutex );
2861 ORowSetBase::disposing();
2863 m_pParent = NULL;
2864 m_pMutex = &m_aMutex; // this must be done here because someone could hold a ref to us and try to do something
2865 OSubComponent::disposing();
2868 // XCloseable
2869 void ORowSetClone::close(void) throw( SQLException, RuntimeException )
2872 MutexGuard aGuard( m_aMutex );
2873 if (OComponentHelper::rBHelper.bDisposed)
2874 throw DisposedException();
2876 dispose();
2879 // comphelper::OPropertyArrayUsageHelper
2880 ::cppu::IPropertyArrayHelper* ORowSetClone::createArrayHelper( ) const
2882 Sequence< Property > aProps;
2883 describeProperties(aProps);
2884 return new ::cppu::OPropertyArrayHelper(aProps);
2887 // cppu::OPropertySetHelper
2888 ::cppu::IPropertyArrayHelper& SAL_CALL ORowSetClone::getInfoHelper()
2890 typedef ::comphelper::OPropertyArrayUsageHelper<ORowSetClone> ORowSetClone_PROP;
2891 return *ORowSetClone_PROP::getArrayHelper();
2894 Sequence< sal_Int8 > ORowSetClone::getUnoTunnelImplementationId()
2896 static ::cppu::OImplementationId * pId = 0;
2897 if (! pId)
2899 ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
2900 if (! pId)
2902 static ::cppu::OImplementationId aId;
2903 pId = &aId;
2906 return pId->getImplementationId();
2909 // com::sun::star::XUnoTunnel
2910 sal_Int64 SAL_CALL ORowSetClone::getSomething( const Sequence< sal_Int8 >& rId ) throw(RuntimeException)
2912 if (rId.getLength() == 16 && 0 == memcmp(getUnoTunnelImplementationId().getConstArray(), rId.getConstArray(), 16 ) )
2913 return reinterpret_cast<sal_Int64>(this);
2915 return 0;
2918 void SAL_CALL ORowSetClone::setFastPropertyValue_NoBroadcast(sal_Int32 nHandle,const Any& rValue) throw (Exception)
2920 if ( nHandle == PROPERTY_ID_FETCHSIZE )
2922 if ( m_pParent )
2923 m_pParent->setFastPropertyValue_NoBroadcast( nHandle, rValue );
2926 OPropertyStateContainer::setFastPropertyValue_NoBroadcast(nHandle,rValue);
2929 void ORowSetClone::doCancelModification( )
2933 sal_Bool ORowSetClone::isModification( )
2935 return sal_False;
2938 sal_Bool ORowSetClone::isModified( )
2940 return sal_False;
2943 sal_Bool ORowSetClone::isNew( )
2945 return sal_False;
2948 void SAL_CALL ORowSetClone::execute( ) throw(SQLException, RuntimeException)
2950 throwFunctionNotSupportedException( "RowSetClone::XRowSet::execute", *this );
2953 void SAL_CALL ORowSetClone::addRowSetListener( const Reference< XRowSetListener >& ) throw(RuntimeException)
2955 throwFunctionNotSupportedException( "RowSetClone::XRowSet", *this );
2958 void SAL_CALL ORowSetClone::removeRowSetListener( const Reference< XRowSetListener >& ) throw(RuntimeException)
2960 throwFunctionNotSupportedException( "RowSetClone::XRowSet", *this );
2963 } // dbaccess
2965 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */