LCOV - code coverage report
Current view: top level - libreoffice/connectivity/source/commontools - dbtools.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 64 886 7.2 %
Date: 2012-12-27 Functions: 10 58 17.2 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10