Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 :
21 : #include "connectivity/CommonTools.hxx"
22 : #include "diagnose_ex.h"
23 : #include "TConnection.hxx"
24 : #include "connectivity/ParameterCont.hxx"
25 :
26 : #include <com/sun/star/awt/XWindow.hpp>
27 : #include <com/sun/star/beans/PropertyAttribute.hpp>
28 : #include <com/sun/star/container/XChild.hpp>
29 : #include <com/sun/star/form/FormComponentType.hpp>
30 : #include <com/sun/star/io/XInputStream.hpp>
31 : #include <com/sun/star/lang/DisposedException.hpp>
32 : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
33 : #include <com/sun/star/sdb/DatabaseContext.hpp>
34 : #include <com/sun/star/sdb/BooleanComparisonMode.hpp>
35 : #include <com/sun/star/sdb/CommandType.hpp>
36 : #include <com/sun/star/sdb/ErrorMessageDialog.hpp>
37 : #include <com/sun/star/sdb/ParametersRequest.hpp>
38 : #include <com/sun/star/sdb/RowSetVetoException.hpp>
39 : #include <com/sun/star/sdb/SQLContext.hpp>
40 : #include <com/sun/star/sdb/XCompletedConnection.hpp>
41 : #include <com/sun/star/sdb/XInteractionSupplyParameters.hpp>
42 : #include <com/sun/star/sdb/XOfficeDatabaseDocument.hpp>
43 : #include <com/sun/star/sdb/XParametersSupplier.hpp>
44 : #include <com/sun/star/sdb/XQueriesSupplier.hpp>
45 : #include <com/sun/star/sdb/XSingleSelectQueryComposer.hpp>
46 : #include <com/sun/star/sdbc/ConnectionPool.hpp>
47 : #include <com/sun/star/sdbc/DataType.hpp>
48 : #include <com/sun/star/sdbc/XConnection.hpp>
49 : #include <com/sun/star/sdbc/XDataSource.hpp>
50 : #include <com/sun/star/sdbc/XDriverManager.hpp>
51 : #include <com/sun/star/sdbc/XParameters.hpp>
52 : #include <com/sun/star/sdbc/XRow.hpp>
53 : #include <com/sun/star/sdbc/XRowSet.hpp>
54 : #include <com/sun/star/sdbc/XRowUpdate.hpp>
55 : #include <com/sun/star/sdbcx/KeyType.hpp>
56 : #include <com/sun/star/sdbcx/Privilege.hpp>
57 : #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
58 : #include <com/sun/star/sdbcx/XKeysSupplier.hpp>
59 : #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
60 : #include <com/sun/star/task/InteractionHandler.hpp>
61 : #include <com/sun/star/task/XInteractionRequest.hpp>
62 : #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
63 : #include <com/sun/star/uno/XNamingService.hpp>
64 : #include <com/sun/star/util/NumberFormat.hpp>
65 : #include <com/sun/star/util/NumberFormatsSupplier.hpp>
66 : #include <com/sun/star/util/XNumberFormatTypes.hpp>
67 :
68 : #include <comphelper/extract.hxx>
69 : #include <comphelper/interaction.hxx>
70 : #include <comphelper/processfactory.hxx>
71 : #include <comphelper/property.hxx>
72 : #include <connectivity/conncleanup.hxx>
73 : #include <connectivity/dbconversion.hxx>
74 : #include <connectivity/dbexception.hxx>
75 : #include <connectivity/dbtools.hxx>
76 : #include <connectivity/statementcomposer.hxx>
77 : #include <osl/diagnose.h>
78 : #include <rtl/ustrbuf.hxx>
79 : #include <tools/diagnose_ex.h>
80 :
81 : #include "resource/common_res.hrc"
82 : #include "resource/sharedresources.hxx"
83 : #include "connectivity/OSubComponent.hxx"
84 :
85 : #include <algorithm>
86 : #include <iterator>
87 :
88 : using namespace ::comphelper;
89 : using namespace ::com::sun::star::uno;
90 : using namespace ::com::sun::star::io;
91 : using namespace ::com::sun::star::awt;
92 : using namespace ::com::sun::star::ui::dialogs;
93 : using namespace ::com::sun::star::util;
94 : using namespace ::com::sun::star::lang;
95 : using namespace ::com::sun::star::beans;
96 : using namespace ::com::sun::star::container;
97 : using namespace ::com::sun::star::sdb;
98 : using namespace ::com::sun::star::sdbc;
99 : using namespace ::com::sun::star::sdbcx;
100 : using namespace ::com::sun::star::form;
101 : using namespace connectivity;
102 :
103 : //.........................................................................
104 : namespace dbtools
105 : {
106 : //.........................................................................
107 :
108 : using namespace ::com::sun::star::uno;
109 : using namespace ::com::sun::star::beans;
110 : using namespace ::com::sun::star::util;
111 : using namespace ::com::sun::star::lang;
112 : using namespace ::com::sun::star::sdbc;
113 : using namespace ::com::sun::star::task;
114 :
115 : //==============================================================================
116 : //==============================================================================
117 : namespace
118 : {
119 : typedef sal_Bool (SAL_CALL XDatabaseMetaData::*FMetaDataSupport)();
120 : }
121 : //==============================================================================
122 : //==============================================================================
123 442 : sal_Int32 getDefaultNumberFormat(const Reference< XPropertySet >& _xColumn,
124 : const Reference< XNumberFormatTypes >& _xTypes,
125 : const Locale& _rLocale)
126 : {
127 : OSL_ENSURE(_xTypes.is() && _xColumn.is(), "dbtools::getDefaultNumberFormat: invalid arg !");
128 442 : if (!_xTypes.is() || !_xColumn.is())
129 0 : return NumberFormat::UNDEFINED;
130 :
131 442 : sal_Int32 nDataType = 0;
132 442 : sal_Int32 nScale = 0;
133 : try
134 : {
135 : // determine the datatype of the column
136 442 : _xColumn->getPropertyValue("Type") >>= nDataType;
137 :
138 442 : if (DataType::NUMERIC == nDataType || DataType::DECIMAL == nDataType)
139 80 : _xColumn->getPropertyValue("Scale") >>= nScale;
140 : }
141 0 : catch (Exception&)
142 : {
143 0 : return NumberFormat::UNDEFINED;
144 : }
145 : return getDefaultNumberFormat(nDataType,
146 : nScale,
147 884 : ::cppu::any2bool(_xColumn->getPropertyValue("IsCurrency")),
148 : _xTypes,
149 442 : _rLocale);
150 : }
151 :
152 : //------------------------------------------------------------------
153 442 : sal_Int32 getDefaultNumberFormat(sal_Int32 _nDataType,
154 : sal_Int32 _nScale,
155 : sal_Bool _bIsCurrency,
156 : const Reference< XNumberFormatTypes >& _xTypes,
157 : const Locale& _rLocale)
158 : {
159 : OSL_ENSURE(_xTypes.is() , "dbtools::getDefaultNumberFormat: invalid arg !");
160 442 : if (!_xTypes.is())
161 0 : return NumberFormat::UNDEFINED;
162 :
163 442 : sal_Int32 nFormat = 0;
164 442 : sal_Int32 nNumberType = _bIsCurrency ? NumberFormat::CURRENCY : NumberFormat::NUMBER;
165 442 : switch (_nDataType)
166 : {
167 : case DataType::BIT:
168 : case DataType::BOOLEAN:
169 16 : nFormat = _xTypes->getStandardFormat(NumberFormat::LOGICAL, _rLocale);
170 16 : break;
171 : case DataType::TINYINT:
172 : case DataType::SMALLINT:
173 : case DataType::INTEGER:
174 : case DataType::BIGINT:
175 : case DataType::FLOAT:
176 : case DataType::REAL:
177 : case DataType::DOUBLE:
178 : case DataType::NUMERIC:
179 : case DataType::DECIMAL:
180 : {
181 : try
182 : {
183 80 : nFormat = _xTypes->getStandardFormat((sal_Int16)nNumberType, _rLocale);
184 80 : if(_nScale > 0)
185 : {
186 : // generate a new format if necessary
187 80 : Reference< XNumberFormats > xFormats(_xTypes, UNO_QUERY);
188 160 : OUString sNewFormat = xFormats->generateFormat( 0L, _rLocale, sal_False, sal_False, (sal_Int16)_nScale, sal_True);
189 :
190 : // and add it to the formatter if necessary
191 80 : nFormat = xFormats->queryKey(sNewFormat, _rLocale, sal_False);
192 80 : if (nFormat == (sal_Int32)-1)
193 88 : nFormat = xFormats->addNew(sNewFormat, _rLocale);
194 : }
195 : }
196 0 : catch (Exception&)
197 : {
198 0 : nFormat = _xTypes->getStandardFormat((sal_Int16)nNumberType, _rLocale);
199 : }
200 80 : } break;
201 : case DataType::CHAR:
202 : case DataType::VARCHAR:
203 : case DataType::LONGVARCHAR:
204 : case DataType::CLOB:
205 314 : nFormat = _xTypes->getStandardFormat(NumberFormat::TEXT, _rLocale);
206 314 : break;
207 : case DataType::DATE:
208 32 : nFormat = _xTypes->getStandardFormat(NumberFormat::DATE, _rLocale);
209 32 : break;
210 : case DataType::TIME:
211 0 : nFormat = _xTypes->getStandardFormat(NumberFormat::TIME, _rLocale);
212 0 : break;
213 : case DataType::TIMESTAMP:
214 0 : nFormat = _xTypes->getStandardFormat(NumberFormat::DATETIME, _rLocale);
215 0 : break;
216 : case DataType::BINARY:
217 : case DataType::VARBINARY:
218 : case DataType::LONGVARBINARY:
219 : case DataType::SQLNULL:
220 : case DataType::OTHER:
221 : case DataType::OBJECT:
222 : case DataType::DISTINCT:
223 : case DataType::STRUCT:
224 : case DataType::ARRAY:
225 : case DataType::BLOB:
226 : case DataType::REF:
227 : default:
228 0 : nFormat = _xTypes->getStandardFormat(NumberFormat::UNDEFINED, _rLocale);
229 : //nFormat = NumberFormat::UNDEFINED;
230 : }
231 442 : return nFormat;
232 : }
233 :
234 : //==============================================================================
235 : //------------------------------------------------------------------------------
236 46 : Reference< XConnection> findConnection(const Reference< XInterface >& xParent)
237 : {
238 46 : Reference< XConnection> xConnection(xParent, UNO_QUERY);
239 46 : if (!xConnection.is())
240 : {
241 46 : Reference< XChild> xChild(xParent, UNO_QUERY);
242 46 : if (xChild.is())
243 34 : xConnection = findConnection(xChild->getParent());
244 : }
245 46 : return xConnection;
246 : }
247 :
248 : //------------------------------------------------------------------------------
249 37 : Reference< XDataSource> getDataSource_allowException(
250 : const OUString& _rsTitleOrPath,
251 : const Reference< XComponentContext >& _rxContext )
252 : {
253 37 : ENSURE_OR_RETURN( !_rsTitleOrPath.isEmpty(), "getDataSource_allowException: invalid arg !", NULL );
254 :
255 37 : Reference< XDatabaseContext> xDatabaseContext = DatabaseContext::create(_rxContext);
256 :
257 37 : return Reference< XDataSource >( xDatabaseContext->getByName( _rsTitleOrPath ), UNO_QUERY );
258 : }
259 :
260 : //------------------------------------------------------------------------------
261 26 : Reference< XDataSource > getDataSource(
262 : const OUString& _rsTitleOrPath,
263 : const Reference< XComponentContext >& _rxContext )
264 : {
265 26 : Reference< XDataSource > xDS;
266 : try
267 : {
268 26 : xDS = getDataSource_allowException( _rsTitleOrPath, _rxContext );
269 : }
270 0 : catch( const Exception& )
271 : {
272 : DBG_UNHANDLED_EXCEPTION();
273 : }
274 :
275 26 : return xDS;
276 : }
277 :
278 : //------------------------------------------------------------------------------
279 11 : Reference< XConnection > getConnection_allowException(
280 : const OUString& _rsTitleOrPath,
281 : const OUString& _rsUser,
282 : const OUString& _rsPwd,
283 : const Reference< XComponentContext>& _rxContext)
284 : {
285 11 : Reference< XDataSource> xDataSource( getDataSource_allowException(_rsTitleOrPath, _rxContext) );
286 11 : Reference<XConnection> xConnection;
287 11 : if (xDataSource.is())
288 : {
289 : // do it with interaction handler
290 11 : if(_rsUser.isEmpty() || _rsPwd.isEmpty())
291 : {
292 11 : Reference<XPropertySet> xProp(xDataSource,UNO_QUERY);
293 22 : OUString sPwd, sUser;
294 11 : sal_Bool bPwdReq = sal_False;
295 : try
296 : {
297 11 : xProp->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_PASSWORD)) >>= sPwd;
298 11 : bPwdReq = ::cppu::any2bool(xProp->getPropertyValue("IsPasswordRequired"));
299 11 : xProp->getPropertyValue("User") >>= sUser;
300 : }
301 0 : catch(Exception&)
302 : {
303 : OSL_FAIL("dbtools::getConnection: error while retrieving data source properties!");
304 : }
305 11 : if(bPwdReq && sPwd.isEmpty())
306 : { // password required, but empty -> connect using an interaction handler
307 0 : Reference<XCompletedConnection> xConnectionCompletion(xProp, UNO_QUERY);
308 0 : if (xConnectionCompletion.is())
309 : { // instantiate the default SDB interaction handler
310 : Reference< XInteractionHandler > xHandler(
311 0 : InteractionHandler::createWithParent(_rxContext, 0), UNO_QUERY );
312 0 : xConnection = xConnectionCompletion->connectWithCompletion(xHandler);
313 0 : }
314 : }
315 : else
316 22 : xConnection = xDataSource->getConnection(sUser, sPwd);
317 : }
318 11 : if(!xConnection.is()) // try to get one if not already have one, just to make sure
319 0 : xConnection = xDataSource->getConnection(_rsUser, _rsPwd);
320 : }
321 11 : return xConnection;
322 : }
323 :
324 : //------------------------------------------------------------------------------
325 0 : Reference< XConnection> getConnection_withFeedback(const OUString& _rDataSourceName,
326 : const OUString& _rUser, const OUString& _rPwd, const Reference< XComponentContext>& _rxContext)
327 : SAL_THROW ( (SQLException) )
328 : {
329 0 : Reference< XConnection > xReturn;
330 : try
331 : {
332 0 : xReturn = getConnection_allowException(_rDataSourceName, _rUser, _rPwd, _rxContext);
333 : }
334 0 : catch(SQLException&)
335 : {
336 : // allowed to pass
337 0 : throw;
338 : }
339 0 : catch(Exception&)
340 : {
341 : OSL_FAIL("::dbtools::getConnection_withFeedback: unexpected (non-SQL) exception caught!");
342 : }
343 0 : return xReturn;
344 : }
345 :
346 : //------------------------------------------------------------------------------
347 107 : Reference< XConnection> getConnection(const Reference< XRowSet>& _rxRowSet) throw (RuntimeException)
348 : {
349 107 : Reference< XConnection> xReturn;
350 214 : Reference< XPropertySet> xRowSetProps(_rxRowSet, UNO_QUERY);
351 107 : if (xRowSetProps.is())
352 107 : xRowSetProps->getPropertyValue("ActiveConnection") >>= xReturn;
353 214 : return xReturn;
354 : }
355 :
356 : //------------------------------------------------------------------------------
357 : // helper function which allows to implement both the connectRowset and the ensureRowSetConnection semantics
358 : // if connectRowset (which is deprecated) is removed, this function and one of its parameters are
359 : // not needed anymore, the whole implementation can be moved into ensureRowSetConnection then)
360 29 : SharedConnection lcl_connectRowSet(const Reference< XRowSet>& _rxRowSet, const Reference< XComponentContext >& _rxContext,
361 : bool _bSetAsActiveConnection, bool _bAttachAutoDisposer )
362 : SAL_THROW ( ( SQLException, WrappedTargetException, RuntimeException ) )
363 : {
364 29 : SharedConnection xConnection;
365 :
366 : do
367 : {
368 29 : Reference< XPropertySet> xRowSetProps(_rxRowSet, UNO_QUERY);
369 29 : if ( !xRowSetProps.is() )
370 0 : break;
371 :
372 : // 1. already connected?
373 : Reference< XConnection > xExistingConn(
374 29 : xRowSetProps->getPropertyValue("ActiveConnection"),
375 41 : UNO_QUERY );
376 :
377 104 : if ( xExistingConn.is()
378 : // 2. embedded in a database?
379 12 : || isEmbeddedInDatabase( _rxRowSet, xExistingConn )
380 : // 3. is there a connection in the parent hierarchy?
381 111 : || ( xExistingConn = findConnection( _rxRowSet ) ).is()
382 : )
383 : {
384 17 : if ( _bSetAsActiveConnection )
385 : {
386 17 : xRowSetProps->setPropertyValue("ActiveConnection", makeAny( xExistingConn ) );
387 : // no auto disposer needed, since we did not create the connection
388 : }
389 :
390 17 : xConnection.reset( xExistingConn, SharedConnection::NoTakeOwnership );
391 17 : break;
392 : }
393 :
394 : // build a connection with it's current settings (4. data source name, or 5. URL)
395 :
396 24 : const OUString sUserProp( "User" );
397 24 : OUString sDataSourceName;
398 12 : xRowSetProps->getPropertyValue("DataSourceName") >>= sDataSourceName;
399 24 : OUString sURL;
400 12 : xRowSetProps->getPropertyValue("URL") >>= sURL;
401 :
402 24 : Reference< XConnection > xPureConnection;
403 12 : if (!sDataSourceName.isEmpty())
404 : { // the row set's data source property is set
405 : // -> try to connect, get user and pwd setting for that
406 22 : OUString sUser, sPwd;
407 :
408 11 : if (hasProperty(sUserProp, xRowSetProps))
409 11 : xRowSetProps->getPropertyValue(sUserProp) >>= sUser;
410 11 : if (hasProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_PASSWORD), xRowSetProps))
411 11 : xRowSetProps->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_PASSWORD)) >>= sPwd;
412 :
413 22 : xPureConnection = getConnection_allowException( sDataSourceName, sUser, sPwd, _rxContext );
414 : }
415 1 : else if (!sURL.isEmpty())
416 : { // the row set has no data source, but a connection url set
417 : // -> try to connection with that url
418 0 : Reference< XConnectionPool > xDriverManager;
419 : try {
420 0 : xDriverManager = ConnectionPool::create( _rxContext );
421 0 : } catch( const Exception& ) { }
422 0 : if (xDriverManager.is())
423 : {
424 0 : OUString sUser, sPwd;
425 0 : if (hasProperty(sUserProp, xRowSetProps))
426 0 : xRowSetProps->getPropertyValue(sUserProp) >>= sUser;
427 0 : if (hasProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_PASSWORD), xRowSetProps))
428 0 : xRowSetProps->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_PASSWORD)) >>= sPwd;
429 0 : if (!sUser.isEmpty())
430 : { // use user and pwd together with the url
431 0 : Sequence< PropertyValue> aInfo(2);
432 0 : aInfo.getArray()[0].Name = "user";
433 0 : aInfo.getArray()[0].Value <<= sUser;
434 0 : aInfo.getArray()[1].Name = "password";
435 0 : aInfo.getArray()[1].Value <<= sPwd;
436 0 : xPureConnection = xDriverManager->getConnectionWithInfo( sURL, aInfo );
437 : }
438 : else
439 : // just use the url
440 0 : xPureConnection = xDriverManager->getConnection( sURL );
441 0 : }
442 : }
443 : xConnection.reset(
444 : xPureConnection,
445 : _bAttachAutoDisposer ? SharedConnection::NoTakeOwnership : SharedConnection::TakeOwnership
446 : /* take ownership if and only if we're *not* going to auto-dispose the connection */
447 12 : );
448 :
449 : // now if we created a connection, forward it to the row set
450 12 : if ( xConnection.is() && _bSetAsActiveConnection )
451 : {
452 : try
453 : {
454 11 : if ( _bAttachAutoDisposer )
455 : {
456 11 : OAutoConnectionDisposer* pAutoDispose = new OAutoConnectionDisposer( _rxRowSet, xConnection );
457 11 : Reference< XPropertyChangeListener > xEnsureDelete(pAutoDispose);
458 : }
459 : else
460 0 : xRowSetProps->setPropertyValue(
461 : OUString( "ActiveConnection" ),
462 0 : makeAny( xConnection.getTyped() )
463 0 : );
464 : }
465 0 : catch(Exception&)
466 : {
467 : OSL_FAIL("EXception when we set the new active connection!");
468 : }
469 12 : }
470 : }
471 : while ( false );
472 :
473 29 : return xConnection;
474 : }
475 :
476 : //------------------------------------------------------------------------------
477 29 : Reference< XConnection> connectRowset(const Reference< XRowSet>& _rxRowSet, const Reference< XComponentContext >& _rxContext,
478 : sal_Bool _bSetAsActiveConnection ) SAL_THROW ( ( SQLException, WrappedTargetException, RuntimeException ) )
479 : {
480 29 : SharedConnection xConnection = lcl_connectRowSet( _rxRowSet, _rxContext, _bSetAsActiveConnection, true );
481 29 : return xConnection.getTyped();
482 : }
483 :
484 : //------------------------------------------------------------------------------
485 0 : SharedConnection ensureRowSetConnection(const Reference< XRowSet>& _rxRowSet, const Reference< XComponentContext>& _rxContext,
486 : bool _bUseAutoConnectionDisposer ) SAL_THROW ( ( SQLException, WrappedTargetException, RuntimeException ) )
487 : {
488 0 : return lcl_connectRowSet( _rxRowSet, _rxContext, true, _bUseAutoConnectionDisposer );
489 : }
490 :
491 : //------------------------------------------------------------------------------
492 0 : Reference< XNameAccess> getTableFields(const Reference< XConnection>& _rxConn,const OUString& _rName)
493 : {
494 0 : Reference< XComponent > xDummy;
495 0 : return getFieldsByCommandDescriptor( _rxConn, CommandType::TABLE, _rName, xDummy );
496 : }
497 : //------------------------------------------------------------------------------
498 0 : Reference< XNameAccess> getPrimaryKeyColumns_throw(const Any& i_aTable)
499 : {
500 0 : const Reference< XPropertySet > xTable(i_aTable,UNO_QUERY_THROW);
501 0 : return getPrimaryKeyColumns_throw(xTable);
502 : }
503 : //------------------------------------------------------------------------------
504 0 : Reference< XNameAccess> getPrimaryKeyColumns_throw(const Reference< XPropertySet >& i_xTable)
505 : {
506 0 : Reference<XNameAccess> xKeyColumns;
507 0 : const Reference<XKeysSupplier> xKeySup(i_xTable,UNO_QUERY);
508 0 : if ( xKeySup.is() )
509 : {
510 0 : const Reference<XIndexAccess> xKeys = xKeySup->getKeys();
511 0 : if ( xKeys.is() )
512 : {
513 0 : ::dbtools::OPropertyMap& rPropMap = OMetaConnection::getPropMap();
514 0 : const OUString sPropName = rPropMap.getNameByIndex(PROPERTY_ID_TYPE);
515 0 : Reference<XPropertySet> xProp;
516 0 : const sal_Int32 nCount = xKeys->getCount();
517 0 : for(sal_Int32 i = 0;i< nCount;++i)
518 : {
519 0 : xProp.set(xKeys->getByIndex(i),UNO_QUERY_THROW);
520 0 : if ( xProp.is() )
521 : {
522 0 : sal_Int32 nKeyType = 0;
523 0 : xProp->getPropertyValue(sPropName) >>= nKeyType;
524 0 : if(KeyType::PRIMARY == nKeyType)
525 : {
526 0 : const Reference<XColumnsSupplier> xKeyColsSup(xProp,UNO_QUERY_THROW);
527 0 : xKeyColumns = xKeyColsSup->getColumns();
528 0 : break;
529 : }
530 : }
531 0 : }
532 0 : }
533 : }
534 :
535 0 : return xKeyColumns;
536 : }
537 :
538 : //------------------------------------------------------------------------------
539 : namespace
540 : {
541 : enum FieldLookupState
542 : {
543 : HANDLE_TABLE, HANDLE_QUERY, HANDLE_SQL, RETRIEVE_OBJECT, RETRIEVE_COLUMNS, DONE, FAILED
544 : };
545 : }
546 :
547 : //------------------------------------------------------------------------------
548 0 : Reference< XNameAccess > getFieldsByCommandDescriptor( const Reference< XConnection >& _rxConnection,
549 : const sal_Int32 _nCommandType, const OUString& _rCommand,
550 : Reference< XComponent >& _rxKeepFieldsAlive, SQLExceptionInfo* _pErrorInfo ) SAL_THROW( ( ) )
551 : {
552 : OSL_PRECOND( _rxConnection.is(), "::dbtools::getFieldsByCommandDescriptor: invalid connection!" );
553 : OSL_PRECOND( ( CommandType::TABLE == _nCommandType ) || ( CommandType::QUERY == _nCommandType ) || ( CommandType::COMMAND == _nCommandType ),
554 : "::dbtools::getFieldsByCommandDescriptor: invalid command type!" );
555 : OSL_PRECOND( !_rCommand.isEmpty(), "::dbtools::getFieldsByCommandDescriptor: invalid command (empty)!" );
556 :
557 0 : Reference< XNameAccess > xFields;
558 :
559 : // reset the error
560 0 : if ( _pErrorInfo )
561 0 : *_pErrorInfo = SQLExceptionInfo();
562 : // reset the ownership holder
563 0 : _rxKeepFieldsAlive.clear();
564 :
565 : // go for the fields
566 : try
567 : {
568 : // some kind of state machine to ease the sharing of code
569 0 : FieldLookupState eState = FAILED;
570 0 : switch ( _nCommandType )
571 : {
572 : case CommandType::TABLE:
573 0 : eState = HANDLE_TABLE;
574 0 : break;
575 : case CommandType::QUERY:
576 0 : eState = HANDLE_QUERY;
577 0 : break;
578 : case CommandType::COMMAND:
579 0 : eState = HANDLE_SQL;
580 0 : break;
581 : }
582 :
583 : // needed in various states:
584 0 : Reference< XNameAccess > xObjectCollection;
585 0 : Reference< XColumnsSupplier > xSupplyColumns;
586 :
587 : // go!
588 0 : while ( ( DONE != eState ) && ( FAILED != eState ) )
589 : {
590 0 : switch ( eState )
591 : {
592 : case HANDLE_TABLE:
593 : {
594 : // initial state for handling the tables
595 :
596 : // get the table objects
597 0 : Reference< XTablesSupplier > xSupplyTables( _rxConnection, UNO_QUERY );
598 0 : if ( xSupplyTables.is() )
599 0 : xObjectCollection = xSupplyTables->getTables();
600 : // if something went wrong 'til here, then this will be handled in the next state
601 :
602 : // next state: get the object
603 0 : eState = RETRIEVE_OBJECT;
604 : }
605 0 : break;
606 :
607 : case HANDLE_QUERY:
608 : {
609 : // initial state for handling the tables
610 :
611 : // get the table objects
612 0 : Reference< XQueriesSupplier > xSupplyQueries( _rxConnection, UNO_QUERY );
613 0 : if ( xSupplyQueries.is() )
614 0 : xObjectCollection = xSupplyQueries->getQueries();
615 : // if something went wrong 'til here, then this will be handled in the next state
616 :
617 : // next state: get the object
618 0 : eState = RETRIEVE_OBJECT;
619 : }
620 0 : break;
621 :
622 : case RETRIEVE_OBJECT:
623 : // here we should have an object (aka query or table) collection, and are going
624 : // to retrieve the desired object
625 :
626 : // next state: default to FAILED
627 0 : eState = FAILED;
628 :
629 : OSL_ENSURE( xObjectCollection.is(), "::dbtools::getFieldsByCommandDescriptor: invalid connection (no sdb.Connection, or no Tables-/QueriesSupplier)!");
630 0 : if ( xObjectCollection.is() )
631 : {
632 0 : if ( xObjectCollection.is() && xObjectCollection->hasByName( _rCommand ) )
633 : {
634 0 : xObjectCollection->getByName( _rCommand ) >>= xSupplyColumns;
635 : // (xSupplyColumns being NULL will be handled in the next state)
636 :
637 : // next: go for the columns
638 0 : eState = RETRIEVE_COLUMNS;
639 : }
640 : }
641 0 : break;
642 :
643 : case RETRIEVE_COLUMNS:
644 : OSL_ENSURE( xSupplyColumns.is(), "::dbtools::getFieldsByCommandDescriptor: could not retrieve the columns supplier!" );
645 :
646 : // next state: default to FAILED
647 0 : eState = FAILED;
648 :
649 0 : if ( xSupplyColumns.is() )
650 : {
651 0 : xFields = xSupplyColumns->getColumns();
652 : // that's it
653 0 : eState = DONE;
654 : }
655 0 : break;
656 :
657 : case HANDLE_SQL:
658 : {
659 0 : OUString sStatementToExecute( _rCommand );
660 :
661 : // well, the main problem here is to handle statements which contain a parameter
662 : // If we would simply execute a parametrized statement, then this will fail because
663 : // we cannot supply any parameter values.
664 : // Thus, we try to analyze the statement, and to append a WHERE 0=1 filter criterion
665 : // This should cause every driver to not really execute the statement, but to return
666 : // an empty result set with the proper structure. We then can use this result set
667 : // to retrieve the columns.
668 :
669 : try
670 : {
671 0 : Reference< XMultiServiceFactory > xComposerFac( _rxConnection, UNO_QUERY );
672 :
673 0 : if ( xComposerFac.is() )
674 : {
675 0 : Reference< XSingleSelectQueryComposer > xComposer(xComposerFac->createInstance("com.sun.star.sdb.SingleSelectQueryComposer"),UNO_QUERY);
676 0 : if ( xComposer.is() )
677 : {
678 0 : xComposer->setQuery( sStatementToExecute );
679 :
680 : // Now set the filter to a dummy restriction which will result in an empty
681 : // result set.
682 0 : xComposer->setFilter( OUString( "0=1" ) );
683 0 : sStatementToExecute = xComposer->getQuery( );
684 0 : }
685 0 : }
686 : }
687 0 : catch( const Exception& )
688 : {
689 : // silent this error, this was just a try. If we're here, we did not change sStatementToExecute,
690 : // so it will still be _rCommand, which then will be executed without being touched
691 : }
692 :
693 : // now execute
694 0 : Reference< XPreparedStatement > xStatement = _rxConnection->prepareStatement( sStatementToExecute );
695 : // transfer ownership of this temporary object to the caller
696 0 : _rxKeepFieldsAlive = _rxKeepFieldsAlive.query( xStatement );
697 :
698 : // set the "MaxRows" to 0. This is just in case our attempt to append a 0=1 filter
699 : // failed - in this case, the MaxRows restriction should at least ensure that there
700 : // is no data returned (which would be potentially expensive)
701 0 : Reference< XPropertySet > xStatementProps( xStatement,UNO_QUERY );
702 : try
703 : {
704 0 : if ( xStatementProps.is() )
705 0 : xStatementProps->setPropertyValue(
706 : OUString( "MaxRows" ),
707 : makeAny( sal_Int32( 0 ) )
708 0 : );
709 : }
710 0 : catch( const Exception& )
711 : {
712 : OSL_FAIL( "::dbtools::getFieldsByCommandDescriptor: could not set the MaxRows!" );
713 : // oh damn. Not much of a chance to recover, we will no retrieve the complete
714 : // full blown result set
715 : }
716 :
717 0 : xSupplyColumns = xSupplyColumns.query( xStatement->executeQuery() );
718 : // this should have given us a result set which does not contain any data, but
719 : // the structural information we need
720 :
721 : // so the next state is to get the columns
722 0 : eState = RETRIEVE_COLUMNS;
723 : }
724 0 : break;
725 :
726 : default:
727 : OSL_FAIL( "::dbtools::getFieldsByCommandDescriptor: oops! unhandled state here!" );
728 0 : eState = FAILED;
729 : }
730 0 : }
731 : }
732 0 : catch( const SQLContext& e ) { if ( _pErrorInfo ) *_pErrorInfo = SQLExceptionInfo( e ); }
733 0 : catch( const SQLWarning& e ) { if ( _pErrorInfo ) *_pErrorInfo = SQLExceptionInfo( e ); }
734 0 : catch( const SQLException& e ) { if ( _pErrorInfo ) *_pErrorInfo = SQLExceptionInfo( e ); }
735 0 : catch( const Exception& )
736 : {
737 : OSL_FAIL( "::dbtools::getFieldsByCommandDescriptor: caught an exception while retrieving the fields!" );
738 : }
739 :
740 0 : return xFields;
741 : }
742 :
743 : //------------------------------------------------------------------------------
744 0 : Sequence< OUString > getFieldNamesByCommandDescriptor( const Reference< XConnection >& _rxConnection,
745 : const sal_Int32 _nCommandType, const OUString& _rCommand,
746 : SQLExceptionInfo* _pErrorInfo ) SAL_THROW( ( ) )
747 : {
748 : // get the container for the fields
749 0 : Reference< XComponent > xKeepFieldsAlive;
750 0 : Reference< XNameAccess > xFieldContainer = getFieldsByCommandDescriptor( _rxConnection, _nCommandType, _rCommand, xKeepFieldsAlive, _pErrorInfo );
751 :
752 : // get the names of the fields
753 0 : Sequence< OUString > aNames;
754 0 : if ( xFieldContainer.is() )
755 0 : aNames = xFieldContainer->getElementNames();
756 :
757 : // clean up any temporary objects which have been created
758 0 : disposeComponent( xKeepFieldsAlive );
759 :
760 : // outta here
761 0 : return aNames;
762 : }
763 :
764 : //------------------------------------------------------------------------------
765 0 : SQLContext prependContextInfo(const SQLException& _rException, const Reference< XInterface >& _rxContext, const OUString& _rContextDescription, const OUString& _rContextDetails)
766 : {
767 0 : return SQLContext( _rContextDescription, _rxContext, OUString(), 0, makeAny( _rException ), _rContextDetails );
768 : }
769 : //------------------------------------------------------------------------------
770 0 : SQLException prependErrorInfo( const SQLException& _rChainedException, const Reference< XInterface >& _rxContext,
771 : const OUString& _rAdditionalError, const StandardSQLState _eSQLState, const sal_Int32 _nErrorCode )
772 : {
773 : return SQLException( _rAdditionalError, _rxContext,
774 : _eSQLState == SQL_ERROR_UNSPECIFIED ? OUString() : getStandardSQLState( _eSQLState ),
775 0 : _nErrorCode, makeAny( _rChainedException ) );
776 : }
777 :
778 : //--------------------------------------------------------------------------
779 : namespace
780 : {
781 : struct NameComponentSupport
782 : {
783 : const bool bCatalogs;
784 : const bool bSchemas;
785 :
786 : NameComponentSupport( )
787 : :bCatalogs( true )
788 : ,bSchemas( true )
789 : {
790 : }
791 :
792 464 : NameComponentSupport( const bool _bCatalogs, const bool _bSchemas )
793 : :bCatalogs( _bCatalogs )
794 464 : ,bSchemas( _bSchemas )
795 : {
796 464 : }
797 : };
798 :
799 464 : NameComponentSupport lcl_getNameComponentSupport( const Reference< XDatabaseMetaData >& _rxMetaData, EComposeRule _eComposeRule )
800 : {
801 : OSL_PRECOND( _rxMetaData.is(), "lcl_getNameComponentSupport: invalid meta data!" );
802 :
803 464 : FMetaDataSupport pCatalogCall = &XDatabaseMetaData::supportsCatalogsInDataManipulation;
804 464 : FMetaDataSupport pSchemaCall = &XDatabaseMetaData::supportsSchemasInDataManipulation;
805 464 : bool bIgnoreMetaData = false;
806 :
807 464 : switch ( _eComposeRule )
808 : {
809 : case eInTableDefinitions:
810 0 : pCatalogCall = &XDatabaseMetaData::supportsCatalogsInTableDefinitions;
811 0 : pSchemaCall = &XDatabaseMetaData::supportsSchemasInTableDefinitions;
812 0 : break;
813 : case eInIndexDefinitions:
814 0 : pCatalogCall = &XDatabaseMetaData::supportsCatalogsInIndexDefinitions;
815 0 : pSchemaCall = &XDatabaseMetaData::supportsSchemasInIndexDefinitions;
816 0 : break;
817 : case eInProcedureCalls:
818 0 : pCatalogCall = &XDatabaseMetaData::supportsCatalogsInProcedureCalls;
819 0 : pSchemaCall = &XDatabaseMetaData::supportsSchemasInProcedureCalls;
820 0 : break;
821 : case eInPrivilegeDefinitions:
822 0 : pCatalogCall = &XDatabaseMetaData::supportsCatalogsInPrivilegeDefinitions;
823 0 : pSchemaCall = &XDatabaseMetaData::supportsSchemasInPrivilegeDefinitions;
824 0 : break;
825 : case eComplete:
826 0 : bIgnoreMetaData = true;
827 0 : break;
828 : case eInDataManipulation:
829 : // already properly set above
830 464 : break;
831 : }
832 : return NameComponentSupport(
833 464 : bIgnoreMetaData ? true : (_rxMetaData.get()->*pCatalogCall)(),
834 464 : bIgnoreMetaData ? true : (_rxMetaData.get()->*pSchemaCall)()
835 1392 : );
836 : }
837 : }
838 :
839 : //--------------------------------------------------------------------------
840 239 : static OUString impl_doComposeTableName( const Reference< XDatabaseMetaData >& _rxMetaData,
841 : const OUString& _rCatalog, const OUString& _rSchema, const OUString& _rName,
842 : sal_Bool _bQuote, EComposeRule _eComposeRule )
843 : {
844 : OSL_ENSURE(_rxMetaData.is(), "impl_doComposeTableName : invalid meta data !");
845 239 : if ( !_rxMetaData.is() )
846 0 : return OUString();
847 : OSL_ENSURE(!_rName.isEmpty(), "impl_doComposeTableName : at least the name should be non-empty !");
848 :
849 239 : const OUString sQuoteString = _rxMetaData->getIdentifierQuoteString();
850 239 : const NameComponentSupport aNameComps( lcl_getNameComponentSupport( _rxMetaData, _eComposeRule ) );
851 :
852 478 : OUStringBuffer aComposedName;
853 :
854 478 : OUString sCatalogSep;
855 239 : sal_Bool bCatlogAtStart = sal_True;
856 239 : if ( !_rCatalog.isEmpty() && aNameComps.bCatalogs )
857 : {
858 0 : sCatalogSep = _rxMetaData->getCatalogSeparator();
859 0 : bCatlogAtStart = _rxMetaData->isCatalogAtStart();
860 :
861 0 : if ( bCatlogAtStart && !sCatalogSep.isEmpty())
862 : {
863 0 : aComposedName.append( _bQuote ? quoteName( sQuoteString, _rCatalog ) : _rCatalog );
864 0 : aComposedName.append( sCatalogSep );
865 : }
866 : }
867 :
868 239 : if ( !_rSchema.isEmpty() && aNameComps.bSchemas )
869 : {
870 0 : aComposedName.append( _bQuote ? quoteName( sQuoteString, _rSchema ) : _rSchema );
871 0 : aComposedName.appendAscii( "." );
872 : }
873 :
874 239 : aComposedName.append( _bQuote ? quoteName( sQuoteString, _rName ) : _rName );
875 :
876 478 : if ( !_rCatalog.isEmpty()
877 0 : && !bCatlogAtStart
878 0 : && !sCatalogSep.isEmpty()
879 239 : && aNameComps.bCatalogs
880 : )
881 : {
882 0 : aComposedName.append( sCatalogSep );
883 0 : aComposedName.append( _bQuote ? quoteName( sQuoteString, _rCatalog ) : _rCatalog );
884 : }
885 :
886 478 : return aComposedName.makeStringAndClear();
887 : }
888 :
889 : //------------------------------------------------------------------------------
890 0 : OUString quoteTableName(const Reference< XDatabaseMetaData>& _rxMeta
891 : , const OUString& _rName
892 : , EComposeRule _eComposeRule)
893 : {
894 0 : OUString sCatalog, sSchema, sTable;
895 0 : qualifiedNameComponents(_rxMeta,_rName,sCatalog,sSchema,sTable,_eComposeRule);
896 0 : return impl_doComposeTableName( _rxMeta, sCatalog, sSchema, sTable, sal_True, _eComposeRule );
897 : }
898 :
899 : //------------------------------------------------------------------------------
900 225 : void qualifiedNameComponents(const Reference< XDatabaseMetaData >& _rxConnMetaData, const OUString& _rQualifiedName, OUString& _rCatalog, OUString& _rSchema, OUString& _rName,EComposeRule _eComposeRule)
901 : {
902 : OSL_ENSURE(_rxConnMetaData.is(), "QualifiedNameComponents : invalid meta data!");
903 :
904 225 : NameComponentSupport aNameComps( lcl_getNameComponentSupport( _rxConnMetaData, _eComposeRule ) );
905 :
906 225 : OUString sSeparator = _rxConnMetaData->getCatalogSeparator();
907 :
908 450 : OUString sName(_rQualifiedName);
909 : // do we have catalogs ?
910 225 : if ( aNameComps.bCatalogs )
911 : {
912 0 : if (_rxConnMetaData->isCatalogAtStart())
913 : {
914 : // search for the catalog name at the beginning
915 0 : sal_Int32 nIndex = sName.indexOf(sSeparator);
916 0 : if (-1 != nIndex)
917 : {
918 0 : _rCatalog = sName.copy(0, nIndex);
919 0 : sName = sName.copy(nIndex + 1);
920 : }
921 : }
922 : else
923 : {
924 : // Catalogue name at the end
925 0 : sal_Int32 nIndex = sName.lastIndexOf(sSeparator);
926 0 : if (-1 != nIndex)
927 : {
928 0 : _rCatalog = sName.copy(nIndex + 1);
929 0 : sName = sName.copy(0, nIndex);
930 : }
931 : }
932 : }
933 :
934 225 : if ( aNameComps.bSchemas )
935 : {
936 0 : sal_Int32 nIndex = sName.indexOf((sal_Unicode)'.');
937 : // OSL_ENSURE(-1 != nIndex, "QualifiedNameComponents : no schema separator!");
938 0 : if ( nIndex != -1 )
939 0 : _rSchema = sName.copy(0, nIndex);
940 0 : sName = sName.copy(nIndex + 1);
941 : }
942 :
943 450 : _rName = sName;
944 225 : }
945 :
946 : //------------------------------------------------------------------------------
947 100 : Reference< XNumberFormatsSupplier> getNumberFormats(
948 : const Reference< XConnection>& _rxConn,
949 : sal_Bool _bAlloweDefault,
950 : const Reference< XComponentContext>& _rxContext)
951 : {
952 : // ask the parent of the connection (should be an DatabaseAccess)
953 100 : Reference< XNumberFormatsSupplier> xReturn;
954 200 : Reference< XChild> xConnAsChild(_rxConn, UNO_QUERY);
955 200 : OUString sPropFormatsSupplier( "NumberFormatsSupplier" );
956 100 : if (xConnAsChild.is())
957 : {
958 99 : Reference< XPropertySet> xConnParentProps(xConnAsChild->getParent(), UNO_QUERY);
959 99 : if (xConnParentProps.is() && hasProperty(sPropFormatsSupplier, xConnParentProps))
960 99 : xConnParentProps->getPropertyValue(sPropFormatsSupplier) >>= xReturn;
961 : }
962 1 : else if(_bAlloweDefault && _rxContext.is())
963 : {
964 1 : xReturn = NumberFormatsSupplier::createWithDefaultLocale( _rxContext );
965 : }
966 200 : return xReturn;
967 : }
968 :
969 : //==============================================================================
970 : //------------------------------------------------------------------------------
971 0 : void TransferFormComponentProperties(
972 : const Reference< XPropertySet>& xOldProps,
973 : const Reference< XPropertySet>& xNewProps,
974 : const Locale& _rLocale)
975 : {
976 : try
977 : {
978 : OSL_ENSURE( xOldProps.is() && xNewProps.is(), "TransferFormComponentProperties: invalid source/dest!" );
979 0 : if ( !xOldProps.is() || !xNewProps.is() )
980 0 : return;
981 :
982 : // First we copy all the Props, that are available in source and target and have the same description
983 0 : Reference< XPropertySetInfo> xOldInfo( xOldProps->getPropertySetInfo());
984 0 : Reference< XPropertySetInfo> xNewInfo( xNewProps->getPropertySetInfo());
985 :
986 0 : Sequence< Property> aOldProperties = xOldInfo->getProperties();
987 0 : Sequence< Property> aNewProperties = xNewInfo->getProperties();
988 0 : int nNewLen = aNewProperties.getLength();
989 :
990 0 : Property* pOldProps = aOldProperties.getArray();
991 0 : Property* pNewProps = aNewProperties.getArray();
992 :
993 0 : OUString sPropDefaultControl("DefaultControl");
994 0 : OUString sPropLabelControl("LabelControl");
995 0 : OUString sPropFormatsSupplier("FormatsSupplier");
996 0 : OUString sPropCurrencySymbol("CurrencySymbol");
997 0 : OUString sPropDecimals("Decimals");
998 0 : OUString sPropEffectiveMin("EffectiveMin");
999 0 : OUString sPropEffectiveMax("EffectiveMax");
1000 0 : OUString sPropEffectiveDefault("EffectiveDefault");
1001 0 : OUString sPropDefaultText("DefaultText");
1002 0 : OUString sPropDefaultDate("DefaultDate");
1003 0 : OUString sPropDefaultTime("DefaultTime");
1004 0 : OUString sPropValueMin("ValueMin");
1005 0 : OUString sPropValueMax("ValueMax");
1006 0 : OUString sPropDecimalAccuracy("DecimalAccuracy");
1007 0 : OUString sPropClassId("ClassId");
1008 0 : OUString sFormattedServiceName( "com.sun.star.form.component.FormattedField" );
1009 :
1010 0 : for (sal_Int16 i=0; i<aOldProperties.getLength(); ++i)
1011 : {
1012 0 : if ( (!pOldProps[i].Name.equals(sPropDefaultControl))
1013 0 : && (!pOldProps[i].Name.equals(sPropLabelControl))
1014 : )
1015 : {
1016 : // binary search
1017 : Property* pResult = ::std::lower_bound(
1018 0 : pNewProps, pNewProps + nNewLen, pOldProps[i], ::comphelper::PropertyCompareByName());
1019 :
1020 0 : if ( pResult
1021 0 : && ( pResult != pNewProps + nNewLen && pResult->Name == pOldProps[i].Name )
1022 0 : && ( (pResult->Attributes & PropertyAttribute::READONLY) == 0 )
1023 0 : && ( pResult->Type.equals(pOldProps[i].Type)) )
1024 : { // Attributes match and the property is not read-only
1025 : try
1026 : {
1027 0 : xNewProps->setPropertyValue(pResult->Name, xOldProps->getPropertyValue(pResult->Name));
1028 : }
1029 0 : catch(IllegalArgumentException& e)
1030 : {
1031 : OSL_UNUSED( e );
1032 : #ifdef DBG_UTIL
1033 : OUString sMessage("TransferFormComponentProperties : could not transfer the value for property \"");
1034 : sMessage += pResult->Name;
1035 : sMessage += OUString("\"");
1036 : OSL_FAIL(OUStringToOString(sMessage, RTL_TEXTENCODING_ASCII_US).getStr());
1037 : #endif
1038 : }
1039 : }
1040 : }
1041 : }
1042 :
1043 : // for formatted fields (either old or new) we have some special treatments
1044 0 : Reference< XServiceInfo > xSI( xOldProps, UNO_QUERY );
1045 0 : sal_Bool bOldIsFormatted = xSI.is() && xSI->supportsService( sFormattedServiceName );
1046 0 : xSI = Reference< XServiceInfo >( xNewProps, UNO_QUERY );
1047 0 : sal_Bool bNewIsFormatted = xSI.is() && xSI->supportsService( sFormattedServiceName );
1048 :
1049 0 : if (!bOldIsFormatted && !bNewIsFormatted)
1050 0 : return; // nothing to do
1051 :
1052 0 : if (bOldIsFormatted && bNewIsFormatted)
1053 : // if both fields are formatted we do no conversions
1054 0 : return;
1055 :
1056 0 : if (bOldIsFormatted)
1057 : {
1058 : // get some properties from the selected format and put them in the new Set
1059 0 : Any aFormatKey( xOldProps->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_FORMATKEY)) );
1060 0 : if (aFormatKey.hasValue())
1061 : {
1062 0 : Reference< XNumberFormatsSupplier> xSupplier;
1063 0 : xOldProps->getPropertyValue(sPropFormatsSupplier) >>= xSupplier;
1064 0 : if (xSupplier.is())
1065 : {
1066 0 : Reference< XNumberFormats> xFormats(xSupplier->getNumberFormats());
1067 0 : Reference< XPropertySet> xFormat(xFormats->getByKey(getINT32(aFormatKey)));
1068 0 : if (hasProperty(sPropCurrencySymbol, xFormat))
1069 : {
1070 0 : Any aVal( xFormat->getPropertyValue(sPropCurrencySymbol) );
1071 0 : if (aVal.hasValue() && hasProperty(sPropCurrencySymbol, xNewProps))
1072 : // If the source value hasn't been set then don't copy it, so we don´t overwrite the default value
1073 0 : xNewProps->setPropertyValue(sPropCurrencySymbol, aVal);
1074 : }
1075 0 : if (hasProperty(sPropDecimals, xFormat) && hasProperty(sPropDecimals, xNewProps))
1076 0 : xNewProps->setPropertyValue(sPropDecimals, xFormat->getPropertyValue(sPropDecimals));
1077 0 : }
1078 : }
1079 :
1080 : // a potential Min-Max-Conversion
1081 0 : Any aEffectiveMin( xOldProps->getPropertyValue(sPropEffectiveMin) );
1082 0 : if (aEffectiveMin.hasValue())
1083 : { // Unlike the ValueMin the EffectiveMin can be void
1084 0 : if (hasProperty(sPropValueMin, xNewProps))
1085 : {
1086 : OSL_ENSURE(aEffectiveMin.getValueType().getTypeClass() == TypeClass_DOUBLE,
1087 : "TransferFormComponentProperties : invalid property type !");
1088 0 : xNewProps->setPropertyValue(sPropValueMin, aEffectiveMin);
1089 : }
1090 : }
1091 0 : Any aEffectiveMax( xOldProps->getPropertyValue(sPropEffectiveMax) );
1092 0 : if (aEffectiveMax.hasValue())
1093 : { // analog
1094 0 : if (hasProperty(sPropValueMax, xNewProps))
1095 : {
1096 : OSL_ENSURE(aEffectiveMax.getValueType().getTypeClass() == TypeClass_DOUBLE,
1097 : "TransferFormComponentProperties : invalid property type !");
1098 0 : xNewProps->setPropertyValue(sPropValueMax, aEffectiveMax);
1099 : }
1100 : }
1101 :
1102 : // then we can still convert and copy the default values
1103 0 : Any aEffectiveDefault( xOldProps->getPropertyValue(sPropEffectiveDefault) );
1104 0 : if (aEffectiveDefault.hasValue())
1105 : {
1106 0 : sal_Bool bIsString = aEffectiveDefault.getValueType().getTypeClass() == TypeClass_STRING;
1107 : OSL_ENSURE(bIsString || aEffectiveDefault.getValueType().getTypeClass() == TypeClass_DOUBLE,
1108 : "TransferFormComponentProperties : invalid property type !");
1109 : // The Effective-Properties should always be void or string or double ....
1110 :
1111 0 : if (hasProperty(sPropDefaultDate, xNewProps) && !bIsString)
1112 : { // (to convert a OUString into a date will not always succeed, because it might be bound to a text-column,
1113 : // but we can work with a double)
1114 0 : Date aDate = DBTypeConversion::toDate(getDouble(aEffectiveDefault));
1115 0 : xNewProps->setPropertyValue(sPropDefaultDate, makeAny(aDate));
1116 : }
1117 :
1118 0 : if (hasProperty(sPropDefaultTime, xNewProps) && !bIsString)
1119 : { // Completely analogous to time
1120 0 : Time aTime = DBTypeConversion::toTime(getDouble(aEffectiveDefault));
1121 0 : xNewProps->setPropertyValue(sPropDefaultTime, makeAny(aTime));
1122 : }
1123 :
1124 0 : if (hasProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_DEFAULTVALUE), xNewProps) && !bIsString)
1125 : { // Here we can simply pass the double
1126 0 : xNewProps->setPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_DEFAULTVALUE), aEffectiveDefault);
1127 : }
1128 :
1129 0 : if (hasProperty(sPropDefaultText, xNewProps) && bIsString)
1130 : { // and here the OUString
1131 0 : xNewProps->setPropertyValue(sPropDefaultText, aEffectiveDefault);
1132 : }
1133 :
1134 : // nyi: The translation between doubles and OUString would offer more alternatives
1135 0 : }
1136 : }
1137 :
1138 : // The other direction: the new Control shall be formatted
1139 0 : if (bNewIsFormatted)
1140 : {
1141 : // first the formatting
1142 : // we can't set a Supplier, so the new Set must bring one in
1143 0 : Reference< XNumberFormatsSupplier> xSupplier;
1144 0 : xNewProps->getPropertyValue(sPropFormatsSupplier) >>= xSupplier;
1145 0 : if (xSupplier.is())
1146 : {
1147 0 : Reference< XNumberFormats> xFormats(xSupplier->getNumberFormats());
1148 :
1149 : // Set number of decimals
1150 0 : sal_Int16 nDecimals = 2;
1151 0 : if (hasProperty(sPropDecimalAccuracy, xOldProps))
1152 0 : xOldProps->getPropertyValue(sPropDecimalAccuracy) >>= nDecimals;
1153 :
1154 : // base format (depending on the ClassId of the old Set)
1155 0 : sal_Int32 nBaseKey = 0;
1156 0 : if (hasProperty(sPropClassId, xOldProps))
1157 : {
1158 0 : Reference< XNumberFormatTypes> xTypeList(xFormats, UNO_QUERY);
1159 0 : if (xTypeList.is())
1160 : {
1161 0 : sal_Int16 nClassId = 0;
1162 0 : xOldProps->getPropertyValue(sPropClassId) >>= nClassId;
1163 0 : switch (nClassId)
1164 : {
1165 : case FormComponentType::DATEFIELD :
1166 0 : nBaseKey = xTypeList->getStandardFormat(NumberFormat::DATE, _rLocale);
1167 0 : break;
1168 :
1169 : case FormComponentType::TIMEFIELD :
1170 0 : nBaseKey = xTypeList->getStandardFormat(NumberFormat::TIME, _rLocale);
1171 0 : break;
1172 :
1173 : case FormComponentType::CURRENCYFIELD :
1174 0 : nBaseKey = xTypeList->getStandardFormat(NumberFormat::CURRENCY, _rLocale);
1175 0 : break;
1176 : }
1177 0 : }
1178 : }
1179 :
1180 : // With this we can generate a new format ...
1181 0 : OUString sNewFormat = xFormats->generateFormat(nBaseKey, _rLocale, sal_False, sal_False, nDecimals, 0);
1182 : // No thousands separator, negative numbers are not in red, no leading zeros
1183 :
1184 : // ... and add at FormatsSupplier (if needed)
1185 0 : sal_Int32 nKey = xFormats->queryKey(sNewFormat, _rLocale, sal_False);
1186 0 : if (nKey == (sal_Int32)-1)
1187 : { // not added yet in my formatter ...
1188 0 : nKey = xFormats->addNew(sNewFormat, _rLocale);
1189 : }
1190 :
1191 0 : xNewProps->setPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_FORMATKEY), makeAny((sal_Int32)nKey));
1192 : }
1193 :
1194 : // min-/max-Value
1195 0 : Any aNewMin, aNewMax;
1196 0 : if (hasProperty(sPropValueMin, xOldProps))
1197 0 : aNewMin = xOldProps->getPropertyValue(sPropValueMin);
1198 0 : if (hasProperty(sPropValueMax, xOldProps))
1199 0 : aNewMax = xOldProps->getPropertyValue(sPropValueMax);
1200 0 : xNewProps->setPropertyValue(sPropEffectiveMin, aNewMin);
1201 0 : xNewProps->setPropertyValue(sPropEffectiveMax, aNewMax);
1202 :
1203 : // Default-Value
1204 0 : Any aNewDefault;
1205 0 : if (hasProperty(sPropDefaultDate, xOldProps))
1206 : {
1207 0 : Any aDate( xOldProps->getPropertyValue(sPropDefaultDate) );
1208 0 : if (aDate.hasValue())
1209 0 : aNewDefault <<= DBTypeConversion::toDouble(*(Date*)aDate.getValue());
1210 : }
1211 :
1212 0 : if (hasProperty(sPropDefaultTime, xOldProps))
1213 : {
1214 0 : Any aTime( xOldProps->getPropertyValue(sPropDefaultTime) );
1215 0 : if (aTime.hasValue())
1216 0 : aNewDefault <<= DBTypeConversion::toDouble(*(Time*)aTime.getValue());
1217 : }
1218 :
1219 : // double or OUString will be copied directly
1220 0 : if (hasProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_DEFAULTVALUE), xOldProps))
1221 0 : aNewDefault = xOldProps->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_DEFAULTVALUE));
1222 0 : if (hasProperty(sPropDefaultText, xOldProps))
1223 0 : aNewDefault = xOldProps->getPropertyValue(sPropDefaultText);
1224 :
1225 0 : if (aNewDefault.hasValue())
1226 0 : xNewProps->setPropertyValue(sPropEffectiveDefault, aNewDefault);
1227 0 : }
1228 : }
1229 0 : catch(const Exception&)
1230 : {
1231 : OSL_FAIL( "TransferFormComponentProperties: caught an exception!" );
1232 : }
1233 : }
1234 :
1235 : //------------------------------------------------------------------------------
1236 0 : sal_Bool canInsert(const Reference< XPropertySet>& _rxCursorSet)
1237 : {
1238 0 : return ((_rxCursorSet.is() && (getINT32(_rxCursorSet->getPropertyValue("Privileges")) & Privilege::INSERT) != 0));
1239 : }
1240 :
1241 : //------------------------------------------------------------------------------
1242 0 : sal_Bool canUpdate(const Reference< XPropertySet>& _rxCursorSet)
1243 : {
1244 0 : return ((_rxCursorSet.is() && (getINT32(_rxCursorSet->getPropertyValue("Privileges")) & Privilege::UPDATE) != 0));
1245 : }
1246 :
1247 : //------------------------------------------------------------------------------
1248 0 : sal_Bool canDelete(const Reference< XPropertySet>& _rxCursorSet)
1249 : {
1250 0 : return ((_rxCursorSet.is() && (getINT32(_rxCursorSet->getPropertyValue("Privileges")) & Privilege::DELETE) != 0));
1251 : }
1252 : // -----------------------------------------------------------------------------
1253 968 : Reference< XDataSource> findDataSource(const Reference< XInterface >& _xParent)
1254 : {
1255 968 : Reference< XOfficeDatabaseDocument> xDatabaseDocument(_xParent, UNO_QUERY);
1256 968 : Reference< XDataSource> xDataSource;
1257 968 : if ( xDatabaseDocument.is() )
1258 174 : xDataSource = xDatabaseDocument->getDataSource();
1259 968 : if ( !xDataSource.is() )
1260 794 : xDataSource.set(_xParent, UNO_QUERY);
1261 968 : if (!xDataSource.is())
1262 : {
1263 50 : Reference< XChild> xChild(_xParent, UNO_QUERY);
1264 50 : if ( xChild.is() )
1265 50 : xDataSource = findDataSource(xChild->getParent());
1266 : }
1267 968 : return xDataSource;
1268 : }
1269 :
1270 : //------------------------------------------------------------------------------
1271 17 : Reference< XSingleSelectQueryComposer > getComposedRowSetStatement( const Reference< XPropertySet >& _rxRowSet, const Reference< XComponentContext >& _rxContext )
1272 : SAL_THROW( ( SQLException ) )
1273 : {
1274 17 : Reference< XSingleSelectQueryComposer > xComposer;
1275 : try
1276 : {
1277 17 : Reference< XConnection> xConn = connectRowset( Reference< XRowSet >( _rxRowSet, UNO_QUERY ), _rxContext, sal_True );
1278 17 : if ( xConn.is() ) // implies _rxRowSet.is()
1279 : {
1280 : // build the statement the row set is based on (can't use the ActiveCommand property of the set
1281 : // as this reflects the status after the last execute, not the currently set properties)
1282 :
1283 17 : sal_Int32 nCommandType = CommandType::COMMAND;
1284 17 : OUString sCommand;
1285 17 : sal_Bool bEscapeProcessing = sal_False;
1286 :
1287 17 : OSL_VERIFY( _rxRowSet->getPropertyValue("CommandType") >>= nCommandType );
1288 17 : OSL_VERIFY( _rxRowSet->getPropertyValue("Command") >>= sCommand );
1289 17 : OSL_VERIFY( _rxRowSet->getPropertyValue("EscapeProcessing") >>= bEscapeProcessing );
1290 :
1291 34 : StatementComposer aComposer( xConn, sCommand, nCommandType, bEscapeProcessing );
1292 : // append sort
1293 17 : aComposer.setOrder( getString( _rxRowSet->getPropertyValue("Order") ) );
1294 :
1295 : // append filter
1296 17 : sal_Bool bApplyFilter = sal_True;
1297 17 : _rxRowSet->getPropertyValue("ApplyFilter") >>= bApplyFilter;
1298 17 : if ( bApplyFilter )
1299 11 : aComposer.setFilter( getString( _rxRowSet->getPropertyValue("Filter") ) );
1300 :
1301 17 : aComposer.getQuery();
1302 :
1303 17 : xComposer = aComposer.getComposer();
1304 34 : aComposer.setDisposeComposer( false );
1305 17 : }
1306 : }
1307 0 : catch( const SQLException& )
1308 : {
1309 0 : throw;
1310 : }
1311 0 : catch( const Exception& )
1312 : {
1313 : DBG_UNHANDLED_EXCEPTION();
1314 : }
1315 :
1316 17 : return xComposer;
1317 : }
1318 :
1319 : //------------------------------------------------------------------------------
1320 17 : Reference< XSingleSelectQueryComposer > getCurrentSettingsComposer(
1321 : const Reference< XPropertySet>& _rxRowSetProps,
1322 : const Reference< XComponentContext>& _rxContext)
1323 : {
1324 17 : Reference< XSingleSelectQueryComposer > xReturn;
1325 : try
1326 : {
1327 17 : xReturn = getComposedRowSetStatement( _rxRowSetProps, _rxContext );
1328 : }
1329 0 : catch( const SQLException& )
1330 : {
1331 0 : throw;
1332 : }
1333 0 : catch( const Exception& )
1334 : {
1335 : OSL_FAIL( "::getCurrentSettingsComposer : caught an exception !" );
1336 : }
1337 :
1338 17 : return xReturn;
1339 : }
1340 : //--------------------------------------------------------------------------
1341 214 : OUString composeTableName( const Reference< XDatabaseMetaData >& _rxMetaData,
1342 : const OUString& _rCatalog,
1343 : const OUString& _rSchema,
1344 : const OUString& _rName,
1345 : sal_Bool _bQuote,
1346 : EComposeRule _eComposeRule)
1347 : {
1348 214 : return impl_doComposeTableName( _rxMetaData, _rCatalog, _rSchema, _rName, _bQuote, _eComposeRule );
1349 : }
1350 :
1351 : // -----------------------------------------------------------------------------
1352 25 : OUString composeTableNameForSelect( const Reference< XConnection >& _rxConnection,
1353 : const OUString& _rCatalog, const OUString& _rSchema, const OUString& _rName )
1354 : {
1355 25 : sal_Bool bUseCatalogInSelect = isDataSourcePropertyEnabled( _rxConnection, OUString( "UseCatalogInSelect" ), sal_True );
1356 25 : sal_Bool bUseSchemaInSelect = isDataSourcePropertyEnabled( _rxConnection, OUString( "UseSchemaInSelect" ), sal_True );
1357 :
1358 : return impl_doComposeTableName(
1359 25 : _rxConnection->getMetaData(),
1360 : bUseCatalogInSelect ? _rCatalog : OUString(),
1361 : bUseSchemaInSelect ? _rSchema : OUString(),
1362 : _rName,
1363 : true,
1364 : eInDataManipulation
1365 50 : );
1366 : }
1367 :
1368 : // -----------------------------------------------------------------------------
1369 : namespace
1370 : {
1371 12 : static void lcl_getTableNameComponents( const Reference<XPropertySet>& _xTable,
1372 : OUString& _out_rCatalog, OUString& _out_rSchema, OUString& _out_rName )
1373 : {
1374 12 : ::dbtools::OPropertyMap& rPropMap = OMetaConnection::getPropMap();
1375 12 : Reference< XPropertySetInfo > xInfo;
1376 12 : if (_xTable.is())
1377 12 : xInfo = _xTable->getPropertySetInfo();
1378 36 : if ( xInfo.is()
1379 48 : && xInfo->hasPropertyByName(rPropMap.getNameByIndex(PROPERTY_ID_NAME)) )
1380 : {
1381 48 : if ( xInfo->hasPropertyByName(rPropMap.getNameByIndex(PROPERTY_ID_CATALOGNAME))
1382 48 : && xInfo->hasPropertyByName(rPropMap.getNameByIndex(PROPERTY_ID_SCHEMANAME)) )
1383 : {
1384 12 : _xTable->getPropertyValue(rPropMap.getNameByIndex(PROPERTY_ID_CATALOGNAME)) >>= _out_rCatalog;
1385 12 : _xTable->getPropertyValue(rPropMap.getNameByIndex(PROPERTY_ID_SCHEMANAME)) >>= _out_rSchema;
1386 : }
1387 12 : _xTable->getPropertyValue(rPropMap.getNameByIndex(PROPERTY_ID_NAME)) >>= _out_rName;
1388 : }
1389 : else
1390 12 : OSL_FAIL( "::dbtools::lcl_getTableNameComponents: this is no table object!" );
1391 12 : }
1392 : }
1393 :
1394 : // -----------------------------------------------------------------------------
1395 12 : OUString composeTableNameForSelect( const Reference< XConnection >& _rxConnection, const Reference<XPropertySet>& _xTable )
1396 : {
1397 24 : OUString sCatalog, sSchema, sName;
1398 12 : lcl_getTableNameComponents( _xTable, sCatalog, sSchema, sName );
1399 :
1400 24 : return composeTableNameForSelect( _rxConnection, sCatalog, sSchema, sName );
1401 : }
1402 :
1403 : // -----------------------------------------------------------------------------
1404 0 : OUString composeTableName(const Reference<XDatabaseMetaData>& _xMetaData,
1405 : const Reference<XPropertySet>& _xTable,
1406 : EComposeRule _eComposeRule,
1407 : bool _bSuppressCatalog,
1408 : bool _bSuppressSchema,
1409 : bool _bQuote )
1410 : {
1411 0 : OUString sCatalog, sSchema, sName;
1412 0 : lcl_getTableNameComponents( _xTable, sCatalog, sSchema, sName );
1413 :
1414 : return impl_doComposeTableName(
1415 : _xMetaData,
1416 : _bSuppressCatalog ? OUString() : sCatalog,
1417 : _bSuppressSchema ? OUString() : sSchema,
1418 : sName,
1419 : _bQuote,
1420 : _eComposeRule
1421 0 : );
1422 : }
1423 : // -----------------------------------------------------------------------------
1424 3 : sal_Int32 getSearchColumnFlag( const Reference< XConnection>& _rxConn,sal_Int32 _nDataType)
1425 : {
1426 3 : sal_Int32 nSearchFlag = 0;
1427 3 : Reference<XResultSet> xSet = _rxConn->getMetaData()->getTypeInfo();
1428 3 : if(xSet.is())
1429 : {
1430 3 : Reference<XRow> xRow(xSet,UNO_QUERY);
1431 6 : while(xSet->next())
1432 : {
1433 3 : if(xRow->getInt(2) == _nDataType)
1434 : {
1435 3 : nSearchFlag = xRow->getInt(9);
1436 3 : break;
1437 : }
1438 3 : }
1439 : }
1440 3 : return nSearchFlag;
1441 : }
1442 :
1443 : // -----------------------------------------------------------------------------
1444 0 : OUString createUniqueName( const Sequence< OUString >& _rNames, const OUString& _rBaseName, sal_Bool _bStartWithNumber )
1445 : {
1446 0 : ::std::set< OUString > aUsedNames;
1447 : ::std::copy(
1448 : _rNames.getConstArray(),
1449 0 : _rNames.getConstArray() + _rNames.getLength(),
1450 : ::std::insert_iterator< ::std::set< OUString > >( aUsedNames, aUsedNames.end() )
1451 0 : );
1452 :
1453 0 : OUString sName( _rBaseName );
1454 0 : sal_Int32 nPos = 1;
1455 0 : if ( _bStartWithNumber )
1456 0 : sName += OUString::valueOf( nPos );
1457 :
1458 0 : while ( aUsedNames.find( sName ) != aUsedNames.end() )
1459 : {
1460 0 : sName = _rBaseName;
1461 0 : sName += OUString::valueOf( ++nPos );
1462 : }
1463 0 : return sName;
1464 : }
1465 :
1466 : // -----------------------------------------------------------------------------
1467 0 : OUString createUniqueName(const Reference<XNameAccess>& _rxContainer,const OUString& _rBaseName,sal_Bool _bStartWithNumber)
1468 : {
1469 0 : Sequence< OUString > aElementNames;
1470 :
1471 : OSL_ENSURE( _rxContainer.is(), "createUniqueName: invalid container!" );
1472 0 : if ( _rxContainer.is() )
1473 0 : aElementNames = _rxContainer->getElementNames();
1474 :
1475 0 : return createUniqueName( aElementNames, _rBaseName, _bStartWithNumber );
1476 : }
1477 :
1478 : // -----------------------------------------------------------------------------
1479 0 : void showError(const SQLExceptionInfo& _rInfo,
1480 : const Reference< XWindow>& _xParent,
1481 : const Reference< XComponentContext >& _rxContext)
1482 : {
1483 0 : if (_rInfo.isValid())
1484 : {
1485 : try
1486 : {
1487 0 : Reference< XExecutableDialog > xErrorDialog = ErrorMessageDialog::create( _rxContext, "", _xParent, _rInfo.get() );
1488 0 : xErrorDialog->execute();
1489 : }
1490 0 : catch(const Exception&)
1491 : {
1492 : OSL_FAIL("showError: could not display the error message!");
1493 : }
1494 : }
1495 0 : }
1496 :
1497 : // -------------------------------------------------------------------------
1498 0 : sal_Bool implUpdateObject(const Reference< XRowUpdate >& _rxUpdatedObject,
1499 : const sal_Int32 _nColumnIndex, const Any& _rValue) SAL_THROW ( ( SQLException, RuntimeException ) )
1500 : {
1501 0 : sal_Bool bSuccessfullyReRouted = sal_True;
1502 0 : switch (_rValue.getValueTypeClass())
1503 : {
1504 : case TypeClass_ANY:
1505 : {
1506 0 : Any aInnerValue;
1507 0 : _rValue >>= aInnerValue;
1508 0 : bSuccessfullyReRouted = implUpdateObject(_rxUpdatedObject, _nColumnIndex, aInnerValue);
1509 : }
1510 0 : break;
1511 :
1512 : case TypeClass_VOID:
1513 0 : _rxUpdatedObject->updateNull(_nColumnIndex);
1514 0 : break;
1515 :
1516 : case TypeClass_STRING:
1517 0 : _rxUpdatedObject->updateString(_nColumnIndex, *(OUString*)_rValue.getValue());
1518 0 : break;
1519 :
1520 : case TypeClass_BOOLEAN:
1521 0 : _rxUpdatedObject->updateBoolean(_nColumnIndex, *(sal_Bool *)_rValue.getValue());
1522 0 : break;
1523 :
1524 : case TypeClass_BYTE:
1525 0 : _rxUpdatedObject->updateByte(_nColumnIndex, *(sal_Int8 *)_rValue.getValue());
1526 0 : break;
1527 :
1528 : case TypeClass_UNSIGNED_SHORT:
1529 : case TypeClass_SHORT:
1530 0 : _rxUpdatedObject->updateShort(_nColumnIndex, *(sal_Int16*)_rValue.getValue());
1531 0 : break;
1532 :
1533 : case TypeClass_CHAR:
1534 0 : _rxUpdatedObject->updateString(_nColumnIndex,OUString((sal_Unicode *)_rValue.getValue(),1));
1535 0 : break;
1536 :
1537 : case TypeClass_UNSIGNED_LONG:
1538 : case TypeClass_LONG:
1539 0 : _rxUpdatedObject->updateInt(_nColumnIndex, *(sal_Int32*)_rValue.getValue());
1540 0 : break;
1541 :
1542 : case TypeClass_HYPER:
1543 : {
1544 0 : sal_Int64 nValue = 0;
1545 0 : OSL_VERIFY( _rValue >>= nValue );
1546 0 : _rxUpdatedObject->updateLong( _nColumnIndex, nValue );
1547 : }
1548 0 : break;
1549 :
1550 : case TypeClass_FLOAT:
1551 0 : _rxUpdatedObject->updateFloat(_nColumnIndex, *(float*)_rValue.getValue());
1552 0 : break;
1553 :
1554 : case TypeClass_DOUBLE:
1555 0 : _rxUpdatedObject->updateDouble(_nColumnIndex, *(double*)_rValue.getValue());
1556 0 : break;
1557 :
1558 : case TypeClass_SEQUENCE:
1559 0 : if (_rValue.getValueType() == ::getCppuType((const Sequence< sal_Int8 > *)0))
1560 0 : _rxUpdatedObject->updateBytes(_nColumnIndex, *(Sequence<sal_Int8>*)_rValue.getValue());
1561 : else
1562 0 : bSuccessfullyReRouted = sal_False;
1563 0 : break;
1564 : case TypeClass_STRUCT:
1565 0 : if (_rValue.getValueType() == ::getCppuType((const DateTime*)0))
1566 0 : _rxUpdatedObject->updateTimestamp(_nColumnIndex, *(DateTime*)_rValue.getValue());
1567 0 : else if (_rValue.getValueType() == ::getCppuType((const Date*)0))
1568 0 : _rxUpdatedObject->updateDate(_nColumnIndex, *(Date*)_rValue.getValue());
1569 0 : else if (_rValue.getValueType() == ::getCppuType((const Time*)0))
1570 0 : _rxUpdatedObject->updateTime(_nColumnIndex, *(Time*)_rValue.getValue());
1571 : else
1572 0 : bSuccessfullyReRouted = sal_False;
1573 0 : break;
1574 :
1575 : case TypeClass_INTERFACE:
1576 0 : if (_rValue.getValueType() == ::getCppuType(static_cast<Reference< XInputStream>*>(NULL)))
1577 : {
1578 0 : Reference< XInputStream > xStream;
1579 0 : _rValue >>= xStream;
1580 0 : _rxUpdatedObject->updateBinaryStream(_nColumnIndex, xStream, xStream->available());
1581 0 : break;
1582 : }
1583 : // run through
1584 : default:
1585 0 : bSuccessfullyReRouted = sal_False;
1586 : }
1587 :
1588 0 : return bSuccessfullyReRouted;
1589 : }
1590 : // -------------------------------------------------------------------------
1591 1 : sal_Bool implSetObject( const Reference< XParameters >& _rxParameters,
1592 : const sal_Int32 _nColumnIndex, const Any& _rValue) SAL_THROW ( ( SQLException, RuntimeException ) )
1593 : {
1594 1 : sal_Bool bSuccessfullyReRouted = sal_True;
1595 1 : switch (_rValue.getValueTypeClass())
1596 : {
1597 : case TypeClass_HYPER:
1598 : {
1599 0 : sal_Int64 nValue = 0;
1600 0 : OSL_VERIFY( _rValue >>= nValue );
1601 0 : _rxParameters->setLong( _nColumnIndex, nValue );
1602 : }
1603 0 : break;
1604 :
1605 : case TypeClass_ANY:
1606 : {
1607 0 : Any aInnerValue;
1608 0 : _rValue >>= aInnerValue;
1609 0 : bSuccessfullyReRouted = implSetObject(_rxParameters, _nColumnIndex, aInnerValue);
1610 : }
1611 0 : break;
1612 :
1613 : case TypeClass_VOID:
1614 0 : _rxParameters->setNull(_nColumnIndex,DataType::VARCHAR);
1615 0 : break;
1616 :
1617 : case TypeClass_STRING:
1618 1 : _rxParameters->setString(_nColumnIndex, *(OUString*)_rValue.getValue());
1619 1 : break;
1620 :
1621 : case TypeClass_BOOLEAN:
1622 0 : _rxParameters->setBoolean(_nColumnIndex, *(sal_Bool *)_rValue.getValue());
1623 0 : break;
1624 :
1625 : case TypeClass_BYTE:
1626 0 : _rxParameters->setByte(_nColumnIndex, *(sal_Int8 *)_rValue.getValue());
1627 0 : break;
1628 :
1629 : case TypeClass_UNSIGNED_SHORT:
1630 : case TypeClass_SHORT:
1631 0 : _rxParameters->setShort(_nColumnIndex, *(sal_Int16*)_rValue.getValue());
1632 0 : break;
1633 :
1634 : case TypeClass_CHAR:
1635 0 : _rxParameters->setString(_nColumnIndex, OUString((sal_Unicode *)_rValue.getValue(),1));
1636 0 : break;
1637 :
1638 : case TypeClass_UNSIGNED_LONG:
1639 : case TypeClass_LONG:
1640 0 : _rxParameters->setInt(_nColumnIndex, *(sal_Int32*)_rValue.getValue());
1641 0 : break;
1642 :
1643 : case TypeClass_FLOAT:
1644 0 : _rxParameters->setFloat(_nColumnIndex, *(float*)_rValue.getValue());
1645 0 : break;
1646 :
1647 : case TypeClass_DOUBLE:
1648 0 : _rxParameters->setDouble(_nColumnIndex, *(double*)_rValue.getValue());
1649 0 : break;
1650 :
1651 : case TypeClass_SEQUENCE:
1652 0 : if (_rValue.getValueType() == ::getCppuType((const Sequence< sal_Int8 > *)0))
1653 : {
1654 0 : _rxParameters->setBytes(_nColumnIndex, *(Sequence<sal_Int8>*)_rValue.getValue());
1655 : }
1656 : else
1657 0 : bSuccessfullyReRouted = sal_False;
1658 0 : break;
1659 : case TypeClass_STRUCT:
1660 0 : if (_rValue.getValueType() == ::getCppuType((const DateTime*)0))
1661 0 : _rxParameters->setTimestamp(_nColumnIndex, *(DateTime*)_rValue.getValue());
1662 0 : else if (_rValue.getValueType() == ::getCppuType((const Date*)0))
1663 0 : _rxParameters->setDate(_nColumnIndex, *(Date*)_rValue.getValue());
1664 0 : else if (_rValue.getValueType() == ::getCppuType((const Time*)0))
1665 0 : _rxParameters->setTime(_nColumnIndex, *(Time*)_rValue.getValue());
1666 : else
1667 0 : bSuccessfullyReRouted = sal_False;
1668 0 : break;
1669 :
1670 : case TypeClass_INTERFACE:
1671 0 : if (_rValue.getValueType() == ::getCppuType(static_cast<Reference< XInputStream>*>(NULL)))
1672 : {
1673 0 : Reference< XInputStream > xStream;
1674 0 : _rValue >>= xStream;
1675 0 : _rxParameters->setBinaryStream(_nColumnIndex, xStream, xStream->available());
1676 0 : break;
1677 : }
1678 : // run through
1679 : default:
1680 0 : bSuccessfullyReRouted = sal_False;
1681 :
1682 : }
1683 :
1684 1 : return bSuccessfullyReRouted;
1685 : }
1686 :
1687 : //..................................................................
1688 : namespace
1689 : {
1690 2 : class OParameterWrapper : public ::cppu::WeakImplHelper1< XIndexAccess >
1691 : {
1692 : ::std::vector<bool, std::allocator<bool> > m_aSet;
1693 : Reference<XIndexAccess> m_xSource;
1694 : public:
1695 1 : OParameterWrapper(const ::std::vector<bool, std::allocator<bool> >& _aSet,const Reference<XIndexAccess>& _xSource) : m_aSet(_aSet),m_xSource(_xSource){}
1696 : private:
1697 : // ::com::sun::star::container::XElementAccess
1698 0 : virtual Type SAL_CALL getElementType() throw(RuntimeException)
1699 : {
1700 0 : return m_xSource->getElementType();
1701 : }
1702 0 : virtual sal_Bool SAL_CALL hasElements( ) throw(RuntimeException)
1703 : {
1704 0 : if ( m_aSet.empty() )
1705 0 : return m_xSource->hasElements();
1706 0 : return ::std::count(m_aSet.begin(),m_aSet.end(),false) != 0;
1707 : }
1708 : // ::com::sun::star::container::XIndexAccess
1709 0 : virtual sal_Int32 SAL_CALL getCount( ) throw(RuntimeException)
1710 : {
1711 0 : if ( m_aSet.empty() )
1712 0 : return m_xSource->getCount();
1713 0 : return ::std::count(m_aSet.begin(),m_aSet.end(),false);
1714 : }
1715 1 : virtual Any SAL_CALL getByIndex( sal_Int32 Index ) throw(IndexOutOfBoundsException, WrappedTargetException, RuntimeException)
1716 : {
1717 1 : if ( m_aSet.empty() )
1718 0 : return m_xSource->getByIndex(Index);
1719 1 : if ( m_aSet.size() < (size_t)Index )
1720 0 : throw IndexOutOfBoundsException();
1721 :
1722 1 : ::std::vector<bool, std::allocator<bool> >::iterator aIter = m_aSet.begin();
1723 1 : ::std::vector<bool, std::allocator<bool> >::iterator aEnd = m_aSet.end();
1724 1 : sal_Int32 i = 0;
1725 1 : sal_Int32 nParamPos = -1;
1726 2 : for(; aIter != aEnd && i <= Index; ++aIter)
1727 : {
1728 1 : ++nParamPos;
1729 1 : if ( !*aIter )
1730 : {
1731 1 : ++i;
1732 : }
1733 : }
1734 1 : return m_xSource->getByIndex(nParamPos);
1735 : }
1736 : };
1737 : }
1738 :
1739 : // -----------------------------------------------------------------------------
1740 5 : void askForParameters(const Reference< XSingleSelectQueryComposer >& _xComposer,
1741 : const Reference<XParameters>& _xParameters,
1742 : const Reference< XConnection>& _xConnection,
1743 : const Reference< XInteractionHandler >& _rxHandler,
1744 : const ::std::vector<bool, std::allocator<bool> >& _aParametersSet)
1745 : {
1746 : OSL_ENSURE(_xComposer.is(),"dbtools::askForParameters XSQLQueryComposer is null!");
1747 : OSL_ENSURE(_xParameters.is(),"dbtools::askForParameters XParameters is null!");
1748 : OSL_ENSURE(_xConnection.is(),"dbtools::askForParameters XConnection is null!");
1749 : OSL_ENSURE(_rxHandler.is(),"dbtools::askForParameters XInteractionHandler is null!");
1750 :
1751 : // we have to set this here again because getCurrentSettingsComposer can force a setpropertyvalue
1752 5 : Reference<XParametersSupplier> xParameters = Reference<XParametersSupplier> (_xComposer, UNO_QUERY);
1753 :
1754 10 : Reference<XIndexAccess> xParamsAsIndicies = xParameters.is() ? xParameters->getParameters() : Reference<XIndexAccess>();
1755 5 : sal_Int32 nParamCount = xParamsAsIndicies.is() ? xParamsAsIndicies->getCount() : 0;
1756 10 : ::std::vector<bool, std::allocator<bool> > aNewParameterSet( _aParametersSet );
1757 5 : if ( nParamCount && ::std::count(aNewParameterSet.begin(),aNewParameterSet.end(),true) != nParamCount )
1758 : {
1759 1 : static const OUString PROPERTY_NAME(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME));
1760 1 : aNewParameterSet.resize(nParamCount ,false);
1761 : typedef ::std::map< OUString, ::std::vector<sal_Int32> > TParameterPositions;
1762 1 : TParameterPositions aParameterNames;
1763 2 : for(sal_Int32 i = 0; i < nParamCount; ++i)
1764 : {
1765 1 : Reference<XPropertySet> xParam(xParamsAsIndicies->getByIndex(i),UNO_QUERY);
1766 2 : OUString sName;
1767 1 : xParam->getPropertyValue(PROPERTY_NAME) >>= sName;
1768 :
1769 1 : TParameterPositions::iterator aFind = aParameterNames.find(sName);
1770 1 : if ( aFind != aParameterNames.end() )
1771 0 : aNewParameterSet[i] = true;
1772 1 : aParameterNames[sName].push_back(i+1);
1773 1 : }
1774 : // build an interaction request
1775 : // two continuations (Ok and Cancel)
1776 1 : OInteractionAbort* pAbort = new OInteractionAbort;
1777 1 : OParameterContinuation* pParams = new OParameterContinuation;
1778 : // the request
1779 2 : ParametersRequest aRequest;
1780 2 : Reference<XIndexAccess> xWrappedParameters = new OParameterWrapper(aNewParameterSet,xParamsAsIndicies);
1781 1 : aRequest.Parameters = xWrappedParameters;
1782 1 : aRequest.Connection = _xConnection;
1783 1 : OInteractionRequest* pRequest = new OInteractionRequest(makeAny(aRequest));
1784 2 : Reference< XInteractionRequest > xRequest(pRequest);
1785 : // some knittings
1786 1 : pRequest->addContinuation(pAbort);
1787 1 : pRequest->addContinuation(pParams);
1788 :
1789 : // execute the request
1790 1 : _rxHandler->handle(xRequest);
1791 :
1792 1 : if (!pParams->wasSelected())
1793 : {
1794 : // canceled by the user (i.e. (s)he canceled the dialog)
1795 0 : RowSetVetoException e;
1796 0 : e.ErrorCode = ParameterInteractionCancelled;
1797 0 : throw e;
1798 : }
1799 :
1800 : // now transfer the values from the continuation object to the parameter columns
1801 2 : Sequence< PropertyValue > aFinalValues = pParams->getValues();
1802 1 : const PropertyValue* pFinalValues = aFinalValues.getConstArray();
1803 2 : for (sal_Int32 i=0; i<aFinalValues.getLength(); ++i, ++pFinalValues)
1804 : {
1805 1 : Reference< XPropertySet > xParamColumn(xWrappedParameters->getByIndex(i),UNO_QUERY);
1806 1 : if (xParamColumn.is())
1807 : {
1808 1 : OUString sName;
1809 1 : xParamColumn->getPropertyValue(PROPERTY_NAME) >>= sName;
1810 : OSL_ENSURE(sName.equals(pFinalValues->Name), "::dbaui::askForParameters: inconsistent parameter names!");
1811 :
1812 : // determine the field type and ...
1813 1 : sal_Int32 nParamType = 0;
1814 1 : xParamColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPE)) >>= nParamType;
1815 : // ... the scale of the parameter column
1816 1 : sal_Int32 nScale = 0;
1817 1 : if (hasProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_SCALE), xParamColumn))
1818 1 : xParamColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_SCALE)) >>= nScale;
1819 : // (the index of the parameters is one-based)
1820 1 : TParameterPositions::iterator aFind = aParameterNames.find(pFinalValues->Name);
1821 1 : ::std::vector<sal_Int32>::iterator aIterPos = aFind->second.begin();
1822 1 : ::std::vector<sal_Int32>::iterator aEndPos = aFind->second.end();
1823 2 : for(;aIterPos != aEndPos;++aIterPos)
1824 : {
1825 1 : if ( _aParametersSet.empty() || !_aParametersSet[(*aIterPos)-1] )
1826 : {
1827 1 : _xParameters->setObjectWithInfo(*aIterPos, pFinalValues->Value, nParamType, nScale);
1828 : }
1829 1 : }
1830 : }
1831 2 : }
1832 5 : }
1833 5 : }
1834 : // -----------------------------------------------------------------------------
1835 6 : void setObjectWithInfo(const Reference<XParameters>& _xParams,
1836 : sal_Int32 parameterIndex,
1837 : const Any& x,
1838 : sal_Int32 sqlType,
1839 : sal_Int32 scale) throw(SQLException, RuntimeException)
1840 : {
1841 6 : ORowSetValue aVal;
1842 6 : aVal.fill(x);
1843 6 : setObjectWithInfo(_xParams,parameterIndex,aVal,sqlType,scale);
1844 6 : }
1845 : // -----------------------------------------------------------------------------
1846 6 : void setObjectWithInfo(const Reference<XParameters>& _xParams,
1847 : sal_Int32 parameterIndex,
1848 : const ::connectivity::ORowSetValue& _rValue,
1849 : sal_Int32 sqlType,
1850 : sal_Int32 scale) throw(SQLException, RuntimeException)
1851 : {
1852 6 : if ( _rValue.isNull() )
1853 0 : _xParams->setNull(parameterIndex,sqlType);
1854 : else
1855 : {
1856 6 : switch(sqlType)
1857 : {
1858 : case DataType::DECIMAL:
1859 : case DataType::NUMERIC:
1860 0 : _xParams->setObjectWithInfo(parameterIndex,_rValue.makeAny(),sqlType,scale);
1861 0 : break;
1862 : case DataType::CHAR:
1863 : case DataType::VARCHAR:
1864 : case DataType::LONGVARCHAR:
1865 6 : _xParams->setString(parameterIndex,_rValue);
1866 6 : break;
1867 : case DataType::CLOB:
1868 : {
1869 0 : Any x(_rValue.makeAny());
1870 0 : OUString sValue;
1871 0 : if ( x >>= sValue )
1872 0 : _xParams->setString(parameterIndex,sValue);
1873 : else
1874 : {
1875 0 : Reference< XClob > xClob;
1876 0 : if(x >>= xClob)
1877 0 : _xParams->setClob(parameterIndex,xClob);
1878 : else
1879 : {
1880 0 : Reference< ::com::sun::star::io::XInputStream > xStream;
1881 0 : if(x >>= xStream)
1882 0 : _xParams->setCharacterStream(parameterIndex,xStream,xStream->available());
1883 0 : }
1884 0 : }
1885 : }
1886 0 : break;
1887 : case DataType::BIGINT:
1888 0 : if ( _rValue.isSigned() )
1889 0 : _xParams->setLong(parameterIndex,_rValue);
1890 : else
1891 0 : _xParams->setString(parameterIndex,_rValue);
1892 0 : break;
1893 :
1894 : case DataType::FLOAT:
1895 0 : _xParams->setFloat(parameterIndex,_rValue);
1896 0 : break;
1897 : case DataType::REAL:
1898 : case DataType::DOUBLE:
1899 0 : _xParams->setDouble(parameterIndex,_rValue);
1900 0 : break;
1901 : case DataType::DATE:
1902 0 : _xParams->setDate(parameterIndex,_rValue);
1903 0 : break;
1904 : case DataType::TIME:
1905 0 : _xParams->setTime(parameterIndex,_rValue);
1906 0 : break;
1907 : case DataType::TIMESTAMP:
1908 0 : _xParams->setTimestamp(parameterIndex,_rValue);
1909 0 : break;
1910 : case DataType::BINARY:
1911 : case DataType::VARBINARY:
1912 : case DataType::LONGVARBINARY:
1913 : case DataType::BLOB:
1914 : {
1915 0 : Any x(_rValue.makeAny());
1916 0 : Sequence< sal_Int8> aBytes;
1917 0 : if(x >>= aBytes)
1918 0 : _xParams->setBytes(parameterIndex,aBytes);
1919 : else
1920 : {
1921 0 : Reference< XBlob > xBlob;
1922 0 : if(x >>= xBlob)
1923 0 : _xParams->setBlob(parameterIndex,xBlob);
1924 : else
1925 : {
1926 0 : Reference< XClob > xClob;
1927 0 : if(x >>= xClob)
1928 0 : _xParams->setClob(parameterIndex,xClob);
1929 : else
1930 : {
1931 0 : Reference< ::com::sun::star::io::XInputStream > xBinStream;
1932 0 : if(x >>= xBinStream)
1933 0 : _xParams->setBinaryStream(parameterIndex,xBinStream,xBinStream->available());
1934 0 : }
1935 0 : }
1936 0 : }
1937 : }
1938 0 : break;
1939 : case DataType::BIT:
1940 : case DataType::BOOLEAN:
1941 0 : _xParams->setBoolean(parameterIndex,_rValue);
1942 0 : break;
1943 : case DataType::TINYINT:
1944 0 : if ( _rValue.isSigned() )
1945 0 : _xParams->setByte(parameterIndex,_rValue);
1946 : else
1947 0 : _xParams->setShort(parameterIndex,_rValue);
1948 0 : break;
1949 : case DataType::SMALLINT:
1950 0 : if ( _rValue.isSigned() )
1951 0 : _xParams->setShort(parameterIndex,_rValue);
1952 : else
1953 0 : _xParams->setInt(parameterIndex,_rValue);
1954 0 : break;
1955 : case DataType::INTEGER:
1956 0 : if ( _rValue.isSigned() )
1957 0 : _xParams->setInt(parameterIndex,_rValue);
1958 : else
1959 0 : _xParams->setLong(parameterIndex,_rValue);
1960 0 : break;
1961 : default:
1962 : {
1963 0 : ::connectivity::SharedResources aResources;
1964 : const OUString sError( aResources.getResourceStringWithSubstitution(
1965 : STR_UNKNOWN_PARA_TYPE,
1966 : "$position$", OUString::valueOf(parameterIndex)
1967 0 : ) );
1968 0 : ::dbtools::throwGenericSQLException(sError,NULL);
1969 : }
1970 : }
1971 : }
1972 6 : }
1973 :
1974 : // --------------------------------------------------------------------
1975 0 : void getBoleanComparisonPredicate( const OUString& _rExpression, const sal_Bool _bValue, const sal_Int32 _nBooleanComparisonMode,
1976 : OUStringBuffer& _out_rSQLPredicate )
1977 : {
1978 0 : switch ( _nBooleanComparisonMode )
1979 : {
1980 : case BooleanComparisonMode::IS_LITERAL:
1981 0 : _out_rSQLPredicate.append( _rExpression );
1982 0 : if ( _bValue )
1983 0 : _out_rSQLPredicate.appendAscii( " IS TRUE" );
1984 : else
1985 0 : _out_rSQLPredicate.appendAscii( " IS FALSE" );
1986 0 : break;
1987 :
1988 : case BooleanComparisonMode::EQUAL_LITERAL:
1989 0 : _out_rSQLPredicate.append( _rExpression );
1990 0 : _out_rSQLPredicate.appendAscii( _bValue ? " = TRUE" : " = FALSE" );
1991 0 : break;
1992 :
1993 : case BooleanComparisonMode::ACCESS_COMPAT:
1994 0 : if ( _bValue )
1995 : {
1996 0 : _out_rSQLPredicate.appendAscii( " NOT ( ( " );
1997 0 : _out_rSQLPredicate.append( _rExpression );
1998 0 : _out_rSQLPredicate.appendAscii( " = 0 ) OR ( " );
1999 0 : _out_rSQLPredicate.append( _rExpression );
2000 0 : _out_rSQLPredicate.appendAscii( " IS NULL ) )" );
2001 : }
2002 : else
2003 : {
2004 0 : _out_rSQLPredicate.append( _rExpression );
2005 0 : _out_rSQLPredicate.appendAscii( " = 0" );
2006 : }
2007 0 : break;
2008 :
2009 : case BooleanComparisonMode::EQUAL_INTEGER:
2010 : // fall through
2011 : default:
2012 0 : _out_rSQLPredicate.append( _rExpression );
2013 0 : _out_rSQLPredicate.appendAscii( _bValue ? " = 1" : " = 0" );
2014 0 : break;
2015 : }
2016 0 : }
2017 :
2018 : //.........................................................................
2019 : } // namespace dbtools
2020 : //.........................................................................
2021 :
2022 : //.........................................................................
2023 : namespace connectivity
2024 : {
2025 : //.........................................................................
2026 :
2027 4840 : void release(oslInterlockedCount& _refCount,
2028 : ::cppu::OBroadcastHelper& rBHelper,
2029 : Reference< XInterface >& _xInterface,
2030 : ::com::sun::star::lang::XComponent* _pObject)
2031 : {
2032 4840 : if (osl_atomic_decrement( &_refCount ) == 0)
2033 : {
2034 127 : osl_atomic_increment( &_refCount );
2035 :
2036 127 : if (!rBHelper.bDisposed && !rBHelper.bInDispose)
2037 : {
2038 : // remember the parent
2039 87 : Reference< XInterface > xParent;
2040 : {
2041 87 : ::osl::MutexGuard aGuard( rBHelper.rMutex );
2042 87 : xParent = _xInterface;
2043 87 : _xInterface = NULL;
2044 : }
2045 :
2046 : // First dispose
2047 87 : _pObject->dispose();
2048 :
2049 : // only the alive ref holds the object
2050 : OSL_ASSERT( _refCount == 1 );
2051 :
2052 : // release the parent in the ~
2053 87 : if (xParent.is())
2054 : {
2055 87 : ::osl::MutexGuard aGuard( rBHelper.rMutex );
2056 87 : _xInterface = xParent;
2057 87 : }
2058 :
2059 : // // destroy the object if xHoldAlive decrement the refcount to 0
2060 : // m_pDerivedImplementation->WEAK::release();
2061 : }
2062 : }
2063 : else
2064 4713 : osl_atomic_increment( &_refCount );
2065 4840 : }
2066 :
2067 28118 : void checkDisposed(sal_Bool _bThrow) throw ( DisposedException )
2068 : {
2069 28118 : if (_bThrow)
2070 8 : throw DisposedException();
2071 :
2072 28110 : }
2073 : // -------------------------------------------------------------------------
2074 2657 : OSQLColumns::Vector::const_iterator find( OSQLColumns::Vector::const_iterator __first,
2075 : OSQLColumns::Vector::const_iterator __last,
2076 : const OUString& _rVal,
2077 : const ::comphelper::UStringMixEqual& _rCase)
2078 : {
2079 2657 : OUString sName = OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME);
2080 2657 : return find(__first,__last,sName,_rVal,_rCase);
2081 : }
2082 : // -------------------------------------------------------------------------
2083 0 : OSQLColumns::Vector::const_iterator findRealName( OSQLColumns::Vector::const_iterator __first,
2084 : OSQLColumns::Vector::const_iterator __last,
2085 : const OUString& _rVal,
2086 : const ::comphelper::UStringMixEqual& _rCase)
2087 : {
2088 0 : OUString sRealName = OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_REALNAME);
2089 0 : return find(__first,__last,sRealName,_rVal,_rCase);
2090 : }
2091 : // -------------------------------------------------------------------------
2092 2657 : OSQLColumns::Vector::const_iterator find( OSQLColumns::Vector::const_iterator __first,
2093 : OSQLColumns::Vector::const_iterator __last,
2094 : const OUString& _rProp,
2095 : const OUString& _rVal,
2096 : const ::comphelper::UStringMixEqual& _rCase)
2097 : {
2098 35122 : while (__first != __last && !_rCase(getString((*__first)->getPropertyValue(_rProp)),_rVal))
2099 29808 : ++__first;
2100 2657 : return __first;
2101 : }
2102 :
2103 : // -----------------------------------------------------------------------------
2104 : } //namespace connectivity
2105 : // -----------------------------------------------------------------------------
2106 :
2107 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|