LCOV - code coverage report
Current view: top level - dbaccess/source/ui/uno - copytablewizard.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 9 569 1.6 %
Date: 2012-08-25 Functions: 3 64 4.7 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 5 1586 0.3 %

           Branch data     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                 :            : #include "dbu_reghelper.hxx"
      21                 :            : #include "dbu_resource.hrc"
      22                 :            : #include "dbu_uno.hrc"
      23                 :            : #include "dbustrings.hrc"
      24                 :            : #include "moduledbu.hxx"
      25                 :            : #include "sqlmessage.hxx"
      26                 :            : #include "WCopyTable.hxx"
      27                 :            : 
      28                 :            : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
      29                 :            : #include <com/sun/star/sdb/application/XCopyTableWizard.hpp>
      30                 :            : #include <com/sun/star/sdb/application/CopyTableContinuation.hpp>
      31                 :            : #include <com/sun/star/sdb/application/CopyTableOperation.hpp>
      32                 :            : #include <com/sun/star/ucb/AlreadyInitializedException.hpp>
      33                 :            : #include <com/sun/star/lang/NotInitializedException.hpp>
      34                 :            : #include <com/sun/star/sdbc/XDataSource.hpp>
      35                 :            : #include <com/sun/star/sdbc/DataType.hpp>
      36                 :            : #include <com/sun/star/container/XNameAccess.hpp>
      37                 :            : #include <com/sun/star/container/XChild.hpp>
      38                 :            : #include <com/sun/star/task/XInteractionHandler.hpp>
      39                 :            : #include <com/sun/star/frame/XModel.hpp>
      40                 :            : #include <com/sun/star/sdb/XDocumentDataSource.hpp>
      41                 :            : #include <com/sun/star/sdb/XCompletedConnection.hpp>
      42                 :            : #include <com/sun/star/sdb/CommandType.hpp>
      43                 :            : #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
      44                 :            : #include <com/sun/star/sdb/XQueriesSupplier.hpp>
      45                 :            : #include <com/sun/star/lang/DisposedException.hpp>
      46                 :            : #include <com/sun/star/sdb/XSingleSelectQueryComposer.hpp>
      47                 :            : #include <com/sun/star/sdbc/XParameters.hpp>
      48                 :            : #include <com/sun/star/sdbc/XRow.hpp>
      49                 :            : #include <com/sun/star/sdbc/XBlob.hpp>
      50                 :            : #include <com/sun/star/sdbc/XClob.hpp>
      51                 :            : #include <com/sun/star/sdbcx/XRowLocate.hpp>
      52                 :            : #include <com/sun/star/sdbc/XResultSetMetaDataSupplier.hpp>
      53                 :            : #include <com/sun/star/sdb/SQLContext.hpp>
      54                 :            : #include <com/sun/star/sdbc/XDriverManager.hpp>
      55                 :            : 
      56                 :            : #include <comphelper/componentcontext.hxx>
      57                 :            : #include <comphelper/interaction.hxx>
      58                 :            : #include <comphelper/namedvaluecollection.hxx>
      59                 :            : #include <comphelper/proparrhlp.hxx>
      60                 :            : #include <connectivity/dbexception.hxx>
      61                 :            : #include <connectivity/dbtools.hxx>
      62                 :            : #include <cppuhelper/exc_hlp.hxx>
      63                 :            : #include <cppuhelper/implbase1.hxx>
      64                 :            : #include <rtl/ustrbuf.hxx>
      65                 :            : #include <rtl/logfile.hxx>
      66                 :            : #include <svtools/genericunodialog.hxx>
      67                 :            : #include <tools/diagnose_ex.h>
      68                 :            : #include <unotools/sharedunocomponent.hxx>
      69                 :            : #include <vcl/msgbox.hxx>
      70                 :            : #include <vcl/waitobj.hxx>
      71                 :            : 
      72                 :            : //........................................................................
      73                 :            : namespace dbaui
      74                 :            : {
      75                 :            : //........................................................................
      76                 :            : 
      77                 :            :     /** === begin UNO using === **/
      78                 :            :     using ::com::sun::star::uno::Reference;
      79                 :            :     using ::com::sun::star::uno::XInterface;
      80                 :            :     using ::com::sun::star::uno::UNO_QUERY;
      81                 :            :     using ::com::sun::star::uno::UNO_QUERY_THROW;
      82                 :            :     using ::com::sun::star::uno::UNO_SET_THROW;
      83                 :            :     using ::com::sun::star::uno::Exception;
      84                 :            :     using ::com::sun::star::uno::RuntimeException;
      85                 :            :     using ::com::sun::star::uno::Any;
      86                 :            :     using ::com::sun::star::uno::makeAny;
      87                 :            :     using ::com::sun::star::uno::Sequence;
      88                 :            :     using ::com::sun::star::beans::XPropertySetInfo;
      89                 :            :     using ::com::sun::star::lang::XMultiServiceFactory;
      90                 :            :     using ::com::sun::star::beans::Property;
      91                 :            :     using ::com::sun::star::sdb::application::XCopyTableWizard;
      92                 :            :     using ::com::sun::star::sdb::application::XCopyTableListener;
      93                 :            :     using ::com::sun::star::sdb::application::CopyTableRowEvent;
      94                 :            :     using ::com::sun::star::beans::Optional;
      95                 :            :     using ::com::sun::star::lang::IllegalArgumentException;
      96                 :            :     using ::com::sun::star::ucb::AlreadyInitializedException;
      97                 :            :     using ::com::sun::star::beans::XPropertySet;
      98                 :            :     using ::com::sun::star::lang::NotInitializedException;
      99                 :            :     using ::com::sun::star::lang::XServiceInfo;
     100                 :            :     using ::com::sun::star::sdbc::XConnection;
     101                 :            :     using ::com::sun::star::sdbc::XDataSource;
     102                 :            :     using ::com::sun::star::container::XNameAccess;
     103                 :            :     using ::com::sun::star::container::XChild;
     104                 :            :     using ::com::sun::star::task::XInteractionHandler;
     105                 :            :     using ::com::sun::star::frame::XModel;
     106                 :            :     using ::com::sun::star::sdb::XDocumentDataSource;
     107                 :            :     using ::com::sun::star::sdb::XCompletedConnection;
     108                 :            :     using ::com::sun::star::lang::WrappedTargetException;
     109                 :            :     using ::com::sun::star::sdbcx::XTablesSupplier;
     110                 :            :     using ::com::sun::star::sdb::XQueriesSupplier;
     111                 :            :     using ::com::sun::star::lang::DisposedException;
     112                 :            :     using ::com::sun::star::sdbc::XPreparedStatement;
     113                 :            :     using ::com::sun::star::sdb::XSingleSelectQueryComposer;
     114                 :            :     using ::com::sun::star::sdbc::XDatabaseMetaData;
     115                 :            :     using ::com::sun::star::sdbcx::XColumnsSupplier;
     116                 :            :     using ::com::sun::star::sdbc::XParameters;
     117                 :            :     using ::com::sun::star::sdbc::XResultSet;
     118                 :            :     using ::com::sun::star::sdbc::XRow;
     119                 :            :     using ::com::sun::star::sdbc::XBlob;
     120                 :            :     using ::com::sun::star::sdbc::XClob;
     121                 :            :     using ::com::sun::star::sdbcx::XRowLocate;
     122                 :            :     using ::com::sun::star::sdbc::XResultSetMetaDataSupplier;
     123                 :            :     using ::com::sun::star::sdbc::XResultSetMetaData;
     124                 :            :     using ::com::sun::star::sdbc::SQLException;
     125                 :            :     using ::com::sun::star::sdb::SQLContext;
     126                 :            :     using ::com::sun::star::sdbc::XDriverManager;
     127                 :            :     using ::com::sun::star::beans::PropertyValue;
     128                 :            :     /** === end UNO using === **/
     129                 :            :     namespace CopyTableOperation = ::com::sun::star::sdb::application::CopyTableOperation;
     130                 :            :     namespace CopyTableContinuation = ::com::sun::star::sdb::application::CopyTableContinuation;
     131                 :            :     namespace CommandType = ::com::sun::star::sdb::CommandType;
     132                 :            :     namespace DataType = ::com::sun::star::sdbc::DataType;
     133                 :            : 
     134                 :            :     typedef ::utl::SharedUNOComponent< XConnection >    SharedConnection;
     135                 :            :     typedef Reference< XInteractionHandler >            InteractionHandler;
     136                 :            : 
     137                 :            :     //=========================================================================
     138                 :            :     //= CopyTableWizard
     139                 :            :     //=========================================================================
     140                 :            :     typedef ::svt::OGenericUnoDialog        CopyTableWizard_DialogBase;
     141                 :            :     typedef ::cppu::ImplInheritanceHelper1  <   CopyTableWizard_DialogBase
     142                 :            :                                             ,   XCopyTableWizard
     143                 :            :                                             >   CopyTableWizard_Base;
     144                 :            :     class CopyTableWizard
     145                 :            :             :public CopyTableWizard_Base
     146                 :            :             ,public ::comphelper::OPropertyArrayUsageHelper< CopyTableWizard >
     147                 :            :     {
     148                 :            :     public:
     149                 :            :         // XServiceInfo
     150                 :            :         virtual ::rtl::OUString SAL_CALL getImplementationName() throw(RuntimeException);
     151                 :            :         virtual ::comphelper::StringSequence SAL_CALL getSupportedServiceNames() throw(RuntimeException);
     152                 :            : 
     153                 :            :         // XServiceInfo - static methods
     154                 :            :         static Sequence< ::rtl::OUString >  getSupportedServiceNames_Static(void) throw( RuntimeException );
     155                 :            :         static ::rtl::OUString              getImplementationName_Static(void) throw( RuntimeException );
     156                 :            :         static Reference< XInterface >      Create( const Reference< XMultiServiceFactory >& );
     157                 :            : 
     158                 :            :         // XCopyTableWizard
     159                 :            :         virtual ::sal_Int16 SAL_CALL getOperation() throw (RuntimeException);
     160                 :            :         virtual void SAL_CALL setOperation( ::sal_Int16 _operation ) throw (IllegalArgumentException, RuntimeException);
     161                 :            :         virtual ::rtl::OUString SAL_CALL getDestinationTableName() throw (RuntimeException);
     162                 :            :         virtual void SAL_CALL setDestinationTableName( const ::rtl::OUString& _destinationTableName ) throw (RuntimeException);
     163                 :            :         virtual Optional< ::rtl::OUString > SAL_CALL getCreatePrimaryKey() throw (RuntimeException);
     164                 :            :         virtual void SAL_CALL setCreatePrimaryKey( const Optional< ::rtl::OUString >& _newPrimaryKey ) throw (IllegalArgumentException, RuntimeException);
     165                 :            :         virtual sal_Bool SAL_CALL getUseHeaderLineAsColumnNames() throw (RuntimeException);
     166                 :            :         virtual void SAL_CALL setUseHeaderLineAsColumnNames( sal_Bool _bUseHeaderLineAsColumnNames ) throw (RuntimeException);
     167                 :            :         virtual void SAL_CALL addCopyTableListener( const Reference< XCopyTableListener >& Listener ) throw (RuntimeException);
     168                 :            :         virtual void SAL_CALL removeCopyTableListener( const Reference< XCopyTableListener >& Listener ) throw (RuntimeException);
     169                 :            : 
     170                 :            :         // XCopyTableWizard::XExecutableDialog
     171                 :            :         virtual void SAL_CALL setTitle( const ::rtl::OUString& aTitle ) throw (RuntimeException);
     172                 :            :         virtual ::sal_Int16 SAL_CALL execute(  ) throw (RuntimeException);
     173                 :            : 
     174                 :            :         // XInitialization
     175                 :            :         virtual void SAL_CALL initialize( const Sequence< Any >& aArguments ) throw (Exception, RuntimeException);
     176                 :            : 
     177                 :            :         // XPropertySet
     178                 :            :         virtual Reference< XPropertySetInfo > SAL_CALL getPropertySetInfo() throw(RuntimeException);
     179                 :            :         virtual ::cppu::IPropertyArrayHelper& SAL_CALL getInfoHelper();
     180                 :            : 
     181                 :            :         // OPropertyArrayUsageHelper
     182                 :            :         virtual ::cppu::IPropertyArrayHelper* createArrayHelper( ) const;
     183                 :            : 
     184                 :            :     public:
     185                 :          0 :         ::osl::Mutex&   getMutex() { return m_aMutex; }
     186 [ #  # ][ #  # ]:          0 :         bool            isInitialized() const { return m_xSourceConnection.is() && m_pSourceObject.get() && m_xDestConnection.is(); }
                 [ #  # ]
     187                 :            : 
     188                 :            :     protected:
     189                 :            :         CopyTableWizard( const Reference< XMultiServiceFactory >& _rxORB );
     190                 :            :         ~CopyTableWizard();
     191                 :            : 
     192                 :            :         // OGenericUnoDialog overridables
     193                 :            :         virtual Dialog* createDialog( Window* _pParent );
     194                 :            :         virtual void executedDialog( sal_Int16 _nExecutionResult );
     195                 :            : 
     196                 :            :     private:
     197                 :            :         /// ensures our current attribute values are reflected in the dialog
     198                 :            :         void    impl_attributesToDialog_nothrow( OCopyTableWizard& _rDialog ) const;
     199                 :            : 
     200                 :            :         /// ensures the current dialog settings are reflected in our attributes
     201                 :            :         void    impl_dialogToAttributes_nothrow( const OCopyTableWizard& _rDialog );
     202                 :            : 
     203                 :            :         /** returns our typed dialog
     204                 :            : 
     205                 :            :             @throws ::com::sun::star::uno::RuntimeException
     206                 :            :                 if we don't have a dialog at the moment the method is called
     207                 :            :         */
     208                 :            :         OCopyTableWizard&
     209                 :            :                 impl_getDialog_throw();
     210                 :            : 
     211                 :            :         /** returns our typed dialog
     212                 :            : 
     213                 :            :             @throws ::com::sun::star::uno::RuntimeException
     214                 :            :                 if we don't have a dialog at the moment the method is called
     215                 :            :         */
     216                 :            :         const OCopyTableWizard&
     217                 :            :                 impl_getDialog_throw() const;
     218                 :            : 
     219                 :            :         /** ensures the given argument sequence contains a valid data access descriptor at the given position
     220                 :            :             @param _rAllArgs
     221                 :            :                 the arguments as passed to ->initialize
     222                 :            :             @param _nArgPos
     223                 :            :                 the position within ->_rAllArgs which contains the data access descriptor
     224                 :            :             @param _out_rxConnection
     225                 :            :                 will, upon successful return, contain the connection for the data source
     226                 :            :             @param _out_rxDocInteractionHandler
     227                 :            :                 will, upon successful return, contain the interaction handler which could
     228                 :            :                 be deduced from database document described by the descriptor, if any.
     229                 :            :                 (It is possible that the descriptor does not allow to deduce a database document,
     230                 :            :                 in which case <code>_out_rxDocInteractionHandler</code> will be <NULL/>.)
     231                 :            :             @return the data access descriptor
     232                 :            :         */
     233                 :            :         Reference< XPropertySet >
     234                 :            :                 impl_ensureDataAccessDescriptor_throw(
     235                 :            :                     const Sequence< Any >& _rAllArgs,
     236                 :            :                     const sal_Int16 _nArgPos,
     237                 :            :                     SharedConnection& _out_rxConnection,
     238                 :            :                     InteractionHandler& _out_rxDocInteractionHandler
     239                 :            :                 ) const;
     240                 :            : 
     241                 :            :         /** extracts the source object (table or query) described by the given descriptor,
     242                 :            :             relative to m_xSourceConnection
     243                 :            :         */
     244                 :            :         SAL_WNODEPRECATED_DECLARATIONS_PUSH
     245                 :            :         ::std::auto_ptr< ICopyTableSourceObject >
     246                 :            :                 impl_extractSourceObject_throw(
     247                 :            :                     const Reference< XPropertySet >& _rxDescriptor,
     248                 :            :                     sal_Int32& _out_rCommandType
     249                 :            :                 ) const;
     250                 :            :         SAL_WNODEPRECATED_DECLARATIONS_POP
     251                 :            : 
     252                 :            :         /** extracts the result set to copy records from, and the selection-related aspects, if any.
     253                 :            : 
     254                 :            :             Effectively, this method extracts m_xSourceResultSet, m_aSourceSelection, and m_bSourceSelectionBookmarks.
     255                 :            : 
     256                 :            :             If an inconsistent/insufficent sub set of those properties is present in the descriptor, and exception
     257                 :            :             is thrown.
     258                 :            :         */
     259                 :            :         void    impl_extractSourceResultSet_throw(
     260                 :            :                     const Reference< XPropertySet >& i_rDescriptor
     261                 :            :                 );
     262                 :            : 
     263                 :            :         /** checks whether the given copy source descriptor contains settings which are not
     264                 :            :             supported (yet)
     265                 :            : 
     266                 :            :             Throws an IllegalArgumentException if the descriptor contains a valid setting, which is
     267                 :            :             not yet supported.
     268                 :            :         */
     269                 :            :         void    impl_checkForUnsupportedSettings_throw(
     270                 :            :             const Reference< XPropertySet >& _rxSourceDescriptor ) const;
     271                 :            : 
     272                 :            :         /** obtaines the connection described by the given data access descriptor
     273                 :            : 
     274                 :            :             If needed and possible, the method will ask the user, using the interaction
     275                 :            :             handler associated with the database described by the descriptor.
     276                 :            : 
     277                 :            :             All errors are handled with the InteractionHandler associated with the data source,
     278                 :            :             if there is one. Else, they will be silenced (but asserted in non-product builds).
     279                 :            : 
     280                 :            :             @param _rxDataSourceDescriptor
     281                 :            :                 the data access descriptor describing the data source whose connection
     282                 :            :                 should be obtained. Must not be <NULL/>.
     283                 :            :             @param _out_rxDocInteractionHandler
     284                 :            :                 the interaction handler which could be deduced from the descriptor
     285                 :            : 
     286                 :            :             @throws RuntimeException
     287                 :            :                 if anything goes seriously wrong.
     288                 :            :         */
     289                 :            :         SharedConnection
     290                 :            :                 impl_extractConnection_throw(
     291                 :            :                     const Reference< XPropertySet >& _rxDataSourceDescriptor,
     292                 :            :                     InteractionHandler& _out_rxDocInteractionHandler
     293                 :            :                 ) const;
     294                 :            : 
     295                 :            :         /** actually copies the table
     296                 :            : 
     297                 :            :             This method is called after the dialog has been successfully executed.
     298                 :            :         */
     299                 :            :         void    impl_doCopy_nothrow();
     300                 :            : 
     301                 :            :         /** creates the INSERT INTO statement
     302                 :            :             @param  _xTable The destination table.
     303                 :            :         */
     304                 :            :         ::rtl::OUString impl_getServerSideCopyStatement_throw( const Reference< XPropertySet >& _xTable );
     305                 :            : 
     306                 :            :         /** creates the statement which, when executed, will produce the source data to copy
     307                 :            : 
     308                 :            :             If the source object refers to a query which contains parameters, those parameters
     309                 :            :             are filled in, using an interaction handler.
     310                 :            :         */
     311                 :            :         ::utl::SharedUNOComponent< XPreparedStatement >
     312                 :            :                 impl_createSourceStatement_throw() const;
     313                 :            : 
     314                 :            :         /** copies the data rows from the given source result set to the given destination table
     315                 :            :         */
     316                 :            :         void    impl_copyRows_throw(
     317                 :            :                     const Reference< XResultSet >& _rxSourceResultSet,
     318                 :            :                     const Reference< XPropertySet >& _rxDestTable
     319                 :            :                 );
     320                 :            : 
     321                 :            :         /** processes an error which occurred during copying
     322                 :            : 
     323                 :            :             First, all listeners are ask. If a listener tells to cancel or continue copying, this is reported to the
     324                 :            :             method's caller. If a listener tells to ask the user, this is done, and the user's decision is
     325                 :            :             reported to the method's caller.
     326                 :            : 
     327                 :            :             @return
     328                 :            :                 <TRUE/> if and only if copying should be continued.
     329                 :            :         */
     330                 :            :         bool    impl_processCopyError_nothrow(
     331                 :            :                     const CopyTableRowEvent& _rEvent );
     332                 :            : 
     333                 :            : private:
     334                 :            :         ::comphelper::ComponentContext  m_aContext;
     335                 :            : 
     336                 :            :         // attributes
     337                 :            :         sal_Int16                       m_nOperation;
     338                 :            :         ::rtl::OUString                 m_sDestinationTable;
     339                 :            :         Optional< ::rtl::OUString >     m_aPrimaryKeyName;
     340                 :            :         sal_Bool                        m_bUseHeaderLineAsColumnNames;
     341                 :            : 
     342                 :            :         // source
     343                 :            :         SharedConnection                m_xSourceConnection;
     344                 :            :         sal_Int32                       m_nCommandType;
     345                 :            :         SAL_WNODEPRECATED_DECLARATIONS_PUSH
     346                 :            :         ::std::auto_ptr< ICopyTableSourceObject >
     347                 :            :                                         m_pSourceObject;
     348                 :            :         SAL_WNODEPRECATED_DECLARATIONS_POP
     349                 :            :         Reference< XResultSet >         m_xSourceResultSet;
     350                 :            :         Sequence< Any >                 m_aSourceSelection;
     351                 :            :         sal_Bool                        m_bSourceSelectionBookmarks;
     352                 :            : 
     353                 :            :         // destination
     354                 :            :         SharedConnection                m_xDestConnection;
     355                 :            : 
     356                 :            :         // other
     357                 :            :         InteractionHandler              m_xInteractionHandler;
     358                 :            :         ::cppu::OInterfaceContainerHelper
     359                 :            :                                         m_aCopyTableListeners;
     360                 :            :         sal_Int16                       m_nOverrideExecutionResult;
     361                 :            :     };
     362                 :            : 
     363                 :            : //=========================================================================
     364                 :            : //= MethodGuard
     365                 :            : //=========================================================================
     366                 :            : class CopyTableAccessGuard
     367                 :            : {
     368                 :            : public:
     369                 :          0 :     CopyTableAccessGuard( CopyTableWizard& _rWizard )
     370                 :          0 :         :m_rWizard( _rWizard )
     371                 :            :     {
     372                 :          0 :         m_rWizard.getMutex().acquire();
     373         [ #  # ]:          0 :         if ( !m_rWizard.isInitialized() )
     374         [ #  # ]:          0 :             throw NotInitializedException();
     375                 :          0 :     }
     376                 :            : 
     377                 :          0 :     ~CopyTableAccessGuard()
     378                 :            :     {
     379                 :          0 :         m_rWizard.getMutex().release();
     380                 :          0 :     }
     381                 :            : 
     382                 :            : private:
     383                 :            :     CopyTableWizard&    m_rWizard;
     384                 :            : };
     385                 :            : 
     386                 :            : //=========================================================================
     387                 :            : //-------------------------------------------------------------------------
     388                 :          0 : CopyTableWizard::CopyTableWizard( const Reference< XMultiServiceFactory >& _rxORB )
     389                 :            :     :CopyTableWizard_Base( _rxORB )
     390                 :            :     ,m_aContext( _rxORB )
     391                 :            :     ,m_nOperation( CopyTableOperation::CopyDefinitionAndData )
     392                 :            :     ,m_sDestinationTable()
     393                 :            :     ,m_aPrimaryKeyName( sal_False, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ID" ) ))
     394                 :            :     ,m_bUseHeaderLineAsColumnNames( sal_True )
     395                 :            :     ,m_xSourceConnection()
     396                 :            :     ,m_nCommandType( CommandType::COMMAND )
     397                 :            :     ,m_pSourceObject()
     398                 :            :     ,m_xSourceResultSet()
     399                 :            :     ,m_aSourceSelection()
     400                 :            :     ,m_bSourceSelectionBookmarks( sal_True )
     401                 :            :     ,m_xDestConnection()
     402                 :            :     ,m_aCopyTableListeners( m_aMutex )
     403 [ #  # ][ #  # ]:          0 :     ,m_nOverrideExecutionResult( -1 )
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     404                 :            : {
     405                 :          0 : }
     406                 :            : 
     407                 :            : //-------------------------------------------------------------------------
     408 [ #  # ][ #  # ]:          0 : CopyTableWizard::~CopyTableWizard()
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     409                 :            : {
     410                 :          0 :     acquire();
     411                 :            : 
     412                 :            :     // protect some members whose dtor might potentially throw
     413         [ #  # ]:          0 :     try { m_xSourceConnection.clear();  }
     414   [ #  #  #  # ]:          0 :     catch( const Exception& ) { DBG_UNHANDLED_EXCEPTION(); }
     415         [ #  # ]:          0 :     try { m_xDestConnection.clear();  }
     416         [ #  # ]:          0 :     catch( const Exception& ) { DBG_UNHANDLED_EXCEPTION(); }
     417                 :            : 
     418                 :            :     // TODO: shouldn't we have explicit disposal support? If a listener is registered
     419                 :            :     // at our instance, and perhaps holds this our instance by a hard ref, then we'll never
     420                 :            :     // be destroyed.
     421                 :            :     // However, adding XComponent support to the GenericUNODialog probably requires
     422                 :            :     // some thinking - would it break existing clients which do not call a dispose, then?
     423 [ #  # ][ #  # ]:          0 : }
     424                 :            : 
     425                 :            : //-------------------------------------------------------------------------
     426                 :          0 : Reference< XInterface > CopyTableWizard::Create( const Reference< XMultiServiceFactory >& _rxFactory )
     427                 :            : {
     428         [ #  # ]:          0 :     return *( new CopyTableWizard( _rxFactory ) );
     429                 :            : }
     430                 :            : 
     431                 :            : //-------------------------------------------------------------------------
     432                 :          0 : ::rtl::OUString SAL_CALL CopyTableWizard::getImplementationName() throw(RuntimeException)
     433                 :            : {
     434                 :          0 :     return getImplementationName_Static();
     435                 :            : }
     436                 :            : 
     437                 :            : //-------------------------------------------------------------------------
     438                 :         16 : ::rtl::OUString CopyTableWizard::getImplementationName_Static() throw(RuntimeException)
     439                 :            : {
     440                 :         16 :     return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "org.openoffice.comp.dbu.CopyTableWizard" ) );
     441                 :            : }
     442                 :            : 
     443                 :            : //-------------------------------------------------------------------------
     444                 :          0 : ::comphelper::StringSequence SAL_CALL CopyTableWizard::getSupportedServiceNames() throw(RuntimeException)
     445                 :            : {
     446                 :          0 :     return getSupportedServiceNames_Static();
     447                 :            : }
     448                 :            : 
     449                 :            : //-------------------------------------------------------------------------
     450                 :          8 : ::comphelper::StringSequence CopyTableWizard::getSupportedServiceNames_Static() throw(RuntimeException)
     451                 :            : {
     452                 :          8 :     ::comphelper::StringSequence aSupported(1);
     453 [ +  - ][ +  - ]:          8 :     aSupported.getArray()[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.sdb.application.CopyTableWizard" ) );
     454                 :          8 :     return aSupported;
     455                 :            : }
     456                 :            : 
     457                 :            : //-------------------------------------------------------------------------
     458                 :          0 : Reference< XPropertySetInfo > SAL_CALL CopyTableWizard::getPropertySetInfo() throw(RuntimeException)
     459                 :            : {
     460                 :          0 :     Reference< XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) );
     461                 :          0 :     return xInfo;
     462                 :            : }
     463                 :            : 
     464                 :            : //--------------------------------------------------------------------
     465                 :          0 : ::sal_Int16 SAL_CALL CopyTableWizard::getOperation() throw (RuntimeException)
     466                 :            : {
     467         [ #  # ]:          0 :     CopyTableAccessGuard aGuard( *this );
     468         [ #  # ]:          0 :     return m_nOperation;
     469                 :            : }
     470                 :            : 
     471                 :            : //--------------------------------------------------------------------
     472                 :          0 : void SAL_CALL CopyTableWizard::setOperation( ::sal_Int16 _operation ) throw (IllegalArgumentException, RuntimeException)
     473                 :            : {
     474         [ #  # ]:          0 :     CopyTableAccessGuard aGuard( *this );
     475                 :            : 
     476 [ #  # ][ #  # ]:          0 :     if  (   ( _operation != CopyTableOperation::CopyDefinitionAndData )
         [ #  # ][ #  # ]
     477                 :            :         &&  ( _operation != CopyTableOperation::CopyDefinitionOnly )
     478                 :            :         &&  ( _operation != CopyTableOperation::CreateAsView )
     479                 :            :         &&  ( _operation != CopyTableOperation::AppendData )
     480                 :            :         )
     481 [ #  # ][ #  # ]:          0 :         throw IllegalArgumentException( ::rtl::OUString(), *this, 1 );
     482                 :            : 
     483 [ #  # ][ #  # ]:          0 :     if  (   ( _operation == CopyTableOperation::CreateAsView )
                 [ #  # ]
     484         [ #  # ]:          0 :         &&  !OCopyTableWizard::supportsViews( m_xDestConnection )
     485                 :            :         )
     486                 :            :         throw IllegalArgumentException(
     487                 :            :             String( ModuleRes( STR_CTW_NO_VIEWS_SUPPORT ) ),
     488                 :            :             *this,
     489                 :            :             1
     490 [ #  # ][ #  # ]:          0 :         );
         [ #  # ][ #  # ]
                 [ #  # ]
     491                 :            : 
     492         [ #  # ]:          0 :     m_nOperation = _operation;
     493                 :          0 : }
     494                 :            : 
     495                 :            : //--------------------------------------------------------------------
     496                 :          0 : ::rtl::OUString SAL_CALL CopyTableWizard::getDestinationTableName() throw (RuntimeException)
     497                 :            : {
     498         [ #  # ]:          0 :     CopyTableAccessGuard aGuard( *this );
     499         [ #  # ]:          0 :     return m_sDestinationTable;
     500                 :            : }
     501                 :            : 
     502                 :            : //--------------------------------------------------------------------
     503                 :          0 : void SAL_CALL CopyTableWizard::setDestinationTableName( const ::rtl::OUString& _destinationTableName ) throw (RuntimeException)
     504                 :            : {
     505         [ #  # ]:          0 :     CopyTableAccessGuard aGuard( *this );
     506         [ #  # ]:          0 :     m_sDestinationTable = _destinationTableName;
     507                 :          0 : }
     508                 :            : 
     509                 :            : //--------------------------------------------------------------------
     510                 :          0 : Optional< ::rtl::OUString > SAL_CALL CopyTableWizard::getCreatePrimaryKey() throw (RuntimeException)
     511                 :            : {
     512         [ #  # ]:          0 :     CopyTableAccessGuard aGuard( *this );
     513         [ #  # ]:          0 :     return m_aPrimaryKeyName;
     514                 :            : }
     515                 :            : 
     516                 :            : //--------------------------------------------------------------------
     517                 :          0 : void SAL_CALL CopyTableWizard::setCreatePrimaryKey( const Optional< ::rtl::OUString >& _newPrimaryKey ) throw (IllegalArgumentException, RuntimeException)
     518                 :            : {
     519         [ #  # ]:          0 :     CopyTableAccessGuard aGuard( *this );
     520                 :            : 
     521 [ #  # ][ #  # ]:          0 :     if ( _newPrimaryKey.IsPresent && !OCopyTableWizard::supportsPrimaryKey( m_xDestConnection ) )
         [ #  # ][ #  # ]
     522                 :            :         throw IllegalArgumentException(
     523                 :            :                 String( ModuleRes( STR_CTW_NO_PRIMARY_KEY_SUPPORT ) ),
     524                 :            :             *this,
     525                 :            :             1
     526 [ #  # ][ #  # ]:          0 :         );
         [ #  # ][ #  # ]
                 [ #  # ]
     527                 :            : 
     528         [ #  # ]:          0 :     m_aPrimaryKeyName = _newPrimaryKey;
     529                 :          0 : }
     530                 :            : // -----------------------------------------------------------------------------
     531                 :          0 : sal_Bool SAL_CALL CopyTableWizard::getUseHeaderLineAsColumnNames() throw (RuntimeException)
     532                 :            : {
     533         [ #  # ]:          0 :     CopyTableAccessGuard aGuard( *this );
     534         [ #  # ]:          0 :     return m_bUseHeaderLineAsColumnNames;
     535                 :            : }
     536                 :            : // -----------------------------------------------------------------------------
     537                 :          0 : void SAL_CALL CopyTableWizard::setUseHeaderLineAsColumnNames( sal_Bool _bUseHeaderLineAsColumnNames ) throw (RuntimeException)
     538                 :            : {
     539         [ #  # ]:          0 :     CopyTableAccessGuard aGuard( *this );
     540         [ #  # ]:          0 :     m_bUseHeaderLineAsColumnNames = _bUseHeaderLineAsColumnNames;
     541                 :          0 : }
     542                 :            : //--------------------------------------------------------------------
     543                 :          0 : void SAL_CALL CopyTableWizard::addCopyTableListener( const Reference< XCopyTableListener >& _rxListener ) throw (RuntimeException)
     544                 :            : {
     545         [ #  # ]:          0 :     CopyTableAccessGuard aGuard( *this );
     546         [ #  # ]:          0 :     if ( _rxListener.is() )
     547 [ #  # ][ #  # ]:          0 :         m_aCopyTableListeners.addInterface( _rxListener );
     548                 :          0 : }
     549                 :            : 
     550                 :            : //--------------------------------------------------------------------
     551                 :          0 : void SAL_CALL CopyTableWizard::removeCopyTableListener( const Reference< XCopyTableListener >& _rxListener ) throw (RuntimeException)
     552                 :            : {
     553         [ #  # ]:          0 :     CopyTableAccessGuard aGuard( *this );
     554         [ #  # ]:          0 :     if ( _rxListener.is() )
     555 [ #  # ][ #  # ]:          0 :         m_aCopyTableListeners.removeInterface( _rxListener );
     556                 :          0 : }
     557                 :            : 
     558                 :            : //--------------------------------------------------------------------
     559                 :          0 : void SAL_CALL CopyTableWizard::setTitle( const ::rtl::OUString& _rTitle ) throw (RuntimeException)
     560                 :            : {
     561         [ #  # ]:          0 :     CopyTableAccessGuard aGuard( *this );
     562 [ #  # ][ #  # ]:          0 :     CopyTableWizard_DialogBase::setTitle( _rTitle );
     563                 :          0 : }
     564                 :            : 
     565                 :            : //--------------------------------------------------------------------
     566                 :          0 : ::sal_Int16 SAL_CALL CopyTableWizard::execute(  ) throw (RuntimeException)
     567                 :            : {
     568         [ #  # ]:          0 :     CopyTableAccessGuard aGuard( *this );
     569                 :            : 
     570                 :          0 :     m_nOverrideExecutionResult = -1;
     571         [ #  # ]:          0 :     sal_Int16 nExecutionResult = CopyTableWizard_DialogBase::execute();
     572         [ #  # ]:          0 :     if ( m_nOverrideExecutionResult )
     573                 :          0 :         nExecutionResult = m_nOverrideExecutionResult;
     574                 :            : 
     575         [ #  # ]:          0 :     return nExecutionResult;
     576                 :            : }
     577                 :            : 
     578                 :            : //-------------------------------------------------------------------------
     579                 :          0 : OCopyTableWizard& CopyTableWizard::impl_getDialog_throw()
     580                 :            : {
     581         [ #  # ]:          0 :     OCopyTableWizard* pWizard = dynamic_cast< OCopyTableWizard* >( m_pDialog );
     582         [ #  # ]:          0 :     if ( !pWizard )
     583 [ #  # ][ #  # ]:          0 :         throw DisposedException( ::rtl::OUString(), *this );
     584                 :          0 :     return *pWizard;
     585                 :            : }
     586                 :            : 
     587                 :            : //-------------------------------------------------------------------------
     588                 :          0 : const OCopyTableWizard& CopyTableWizard::impl_getDialog_throw() const
     589                 :            : {
     590         [ #  # ]:          0 :     const OCopyTableWizard* pWizard = dynamic_cast< const OCopyTableWizard* >( m_pDialog );
     591         [ #  # ]:          0 :     if ( !pWizard )
     592 [ #  # ][ #  # ]:          0 :         throw DisposedException( ::rtl::OUString(), *const_cast< CopyTableWizard* >( this ) );
     593                 :          0 :     return *pWizard;
     594                 :            : }
     595                 :            : 
     596                 :            : //-------------------------------------------------------------------------
     597                 :          0 : void CopyTableWizard::impl_attributesToDialog_nothrow( OCopyTableWizard& _rDialog ) const
     598                 :            : {
     599                 :            :     // primary key column
     600                 :          0 :     _rDialog.setCreatePrimaryKey( m_aPrimaryKeyName.IsPresent, m_aPrimaryKeyName.Value );
     601                 :          0 :     _rDialog.setUseHeaderLine(m_bUseHeaderLineAsColumnNames);
     602                 :            : 
     603                 :            :     // everything else was passed at construction time already
     604                 :          0 : }
     605                 :            : 
     606                 :            : //-------------------------------------------------------------------------
     607                 :          0 : void CopyTableWizard::impl_dialogToAttributes_nothrow( const OCopyTableWizard& _rDialog )
     608                 :            : {
     609                 :          0 :     m_aPrimaryKeyName.IsPresent = _rDialog.shouldCreatePrimaryKey();
     610         [ #  # ]:          0 :     if ( m_aPrimaryKeyName.IsPresent )
     611                 :          0 :         m_aPrimaryKeyName.Value = _rDialog.getPrimaryKeyName();
     612                 :            :     else
     613                 :          0 :         m_aPrimaryKeyName.Value = ::rtl::OUString();
     614                 :            : 
     615                 :          0 :     m_sDestinationTable = _rDialog.getName();
     616                 :            : 
     617                 :          0 :     m_nOperation = _rDialog.getOperation();
     618                 :          0 :     m_bUseHeaderLineAsColumnNames = _rDialog.UseHeaderLine();
     619                 :          0 : }
     620                 :            : 
     621                 :            : //-------------------------------------------------------------------------
     622                 :            : namespace
     623                 :            : {
     624                 :            :     //.....................................................................
     625                 :            :     /** tries to obtain the InteractionHandler associated with a given data source
     626                 :            : 
     627                 :            :         If the data source is a sdb-level data source, it will have a DatabaseDocument associated
     628                 :            :         with it. This doocument may have an InteractionHandler used while loading it.
     629                 :            : 
     630                 :            :         @throws RuntimeException
     631                 :            :             if it occures during invoking any of the data source's methods, or if any of the involved
     632                 :            :             components violates its contract by not providing the required interfaces
     633                 :            :     */
     634                 :          0 :     InteractionHandler lcl_getInteractionHandler_throw( const Reference< XDataSource >& _rxDataSource, const InteractionHandler& _rFallback )
     635                 :            :     {
     636                 :          0 :         InteractionHandler xHandler( _rFallback );
     637                 :            : 
     638                 :            :         // try to obtain the document model
     639                 :          0 :         Reference< XModel > xDocumentModel;
     640         [ #  # ]:          0 :         Reference< XDocumentDataSource > xDocDataSource( _rxDataSource, UNO_QUERY );
     641         [ #  # ]:          0 :         if ( xDocDataSource.is() )
     642 [ #  # ][ #  # ]:          0 :             xDocumentModel.set( xDocDataSource->getDatabaseDocument(), UNO_QUERY_THROW );
                 [ #  # ]
     643                 :            : 
     644                 :            :         // see whether the document model can provide a handler
     645         [ #  # ]:          0 :         if ( xDocumentModel.is() )
     646                 :            :         {
     647 [ #  # ][ #  # ]:          0 :             ::comphelper::NamedValueCollection aModelArgs( xDocumentModel->getArgs() );
         [ #  # ][ #  # ]
     648 [ #  # ][ #  # ]:          0 :             xHandler = aModelArgs.getOrDefault( "InteractionHandler", xHandler );
                 [ #  # ]
     649                 :            :         }
     650                 :            : 
     651                 :          0 :         return xHandler;
     652                 :            :     }
     653                 :            :     //.....................................................................
     654                 :            :     /** tries to obtain the InteractionHandler associated with a given connection
     655                 :            : 
     656                 :            :         If the connection belongs to a sdb-level data source, then this data source
     657                 :            :         is examined for an interaction handler. Else, <NULL/> is returned.
     658                 :            : 
     659                 :            :         @throws RuntimeException
     660                 :            :             if it occures during invoking any of the data source's methods, or if any of the involved
     661                 :            :             components violates its contract by not providing the required interfaces
     662                 :            :     */
     663                 :          0 :     InteractionHandler lcl_getInteractionHandler_throw( const Reference< XConnection >& _rxConnection, const InteractionHandler& _rFallback )
     664                 :            :     {
     665                 :            :         // try whether there is a data source which the connection belongs to
     666                 :          0 :         Reference< XDataSource > xDataSource;
     667         [ #  # ]:          0 :         Reference< XChild > xAsChild( _rxConnection, UNO_QUERY );
     668         [ #  # ]:          0 :         if ( xAsChild.is() )
     669 [ #  # ][ #  # ]:          0 :             xDataSource = xDataSource.query( xAsChild->getParent() );
         [ #  # ][ #  # ]
     670                 :            : 
     671         [ #  # ]:          0 :         if ( xDataSource.is() )
     672         [ #  # ]:          0 :             return lcl_getInteractionHandler_throw( xDataSource, _rFallback );
     673                 :            : 
     674                 :          0 :         return _rFallback;
     675                 :            :     }
     676                 :            : }
     677                 :            : 
     678                 :            : //-------------------------------------------------------------------------
     679                 :          0 : Reference< XPropertySet > CopyTableWizard::impl_ensureDataAccessDescriptor_throw(
     680                 :            :     const Sequence< Any >& _rAllArgs, const sal_Int16 _nArgPos, SharedConnection& _out_rxConnection,
     681                 :            :     InteractionHandler& _out_rxDocInteractionHandler ) const
     682                 :            : {
     683                 :          0 :     Reference< XPropertySet > xDescriptor;
     684         [ #  # ]:          0 :     _rAllArgs[ _nArgPos ] >>= xDescriptor;
     685                 :            : 
     686                 :            :     // the descriptor must be non-NULL, of course
     687                 :          0 :     bool bIsValid = xDescriptor.is();
     688                 :            : 
     689                 :            :     // it must support the proper service
     690         [ #  # ]:          0 :     if ( bIsValid )
     691                 :            :     {
     692         [ #  # ]:          0 :         Reference< XServiceInfo > xSI( xDescriptor, UNO_QUERY );
     693                 :          0 :         bIsValid =  (   xSI.is()
     694 [ #  # ][ #  # ]:          0 :                     &&  xSI->supportsService( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.sdb.DataAccessDescriptor" ) ) )
         [ #  # ][ #  # ]
                 [ #  # ]
     695 [ #  # ][ #  # ]:          0 :                     );
     696                 :            :     }
     697                 :            : 
     698                 :            :     // it must be able to provide a connection
     699         [ #  # ]:          0 :     if ( bIsValid )
     700                 :            :     {
     701 [ #  # ][ #  # ]:          0 :         _out_rxConnection = impl_extractConnection_throw( xDescriptor, _out_rxDocInteractionHandler );
                 [ #  # ]
     702                 :          0 :         bIsValid = _out_rxConnection.is();
     703                 :            :     }
     704                 :            : 
     705         [ #  # ]:          0 :     if ( !bIsValid )
     706                 :            :     {
     707                 :            :         throw IllegalArgumentException(
     708                 :            :             String( ModuleRes( STR_CTW_INVALID_DATA_ACCESS_DESCRIPTOR ) ),
     709                 :            :             *const_cast< CopyTableWizard* >( this ),
     710                 :            :             _nArgPos + 1
     711 [ #  # ][ #  # ]:          0 :         );
         [ #  # ][ #  # ]
                 [ #  # ]
     712                 :            :     }
     713                 :            : 
     714                 :          0 :     return xDescriptor;
     715                 :            : }
     716                 :            : 
     717                 :            : //-------------------------------------------------------------------------
     718                 :            : namespace
     719                 :            : {
     720                 :          0 :     bool lcl_hasNonEmptyStringValue_throw( const Reference< XPropertySet >& _rxDescriptor,
     721                 :            :         const Reference< XPropertySetInfo > _rxPSI, const ::rtl::OUString& _rPropertyName )
     722                 :            :     {
     723                 :          0 :         ::rtl::OUString sValue;
     724 [ #  # ][ #  # ]:          0 :         if ( _rxPSI->hasPropertyByName( _rPropertyName ) )
                 [ #  # ]
     725                 :            :         {
     726 [ #  # ][ #  # ]:          0 :             OSL_VERIFY( _rxDescriptor->getPropertyValue( _rPropertyName ) >>= sValue );
     727                 :            :         }
     728                 :          0 :         return !sValue.isEmpty();
     729                 :            :     }
     730                 :            : }
     731                 :            : 
     732                 :            : //-------------------------------------------------------------------------
     733                 :          0 : void CopyTableWizard::impl_checkForUnsupportedSettings_throw( const Reference< XPropertySet >& _rxSourceDescriptor ) const
     734                 :            : {
     735                 :            :     OSL_PRECOND( _rxSourceDescriptor.is(), "CopyTableWizard::impl_checkForUnsupportedSettings_throw: illegal argument!" );
     736 [ #  # ][ #  # ]:          0 :     Reference< XPropertySetInfo > xPSI( _rxSourceDescriptor->getPropertySetInfo(), UNO_SET_THROW );
                 [ #  # ]
     737                 :          0 :     ::rtl::OUString sUnsupportedSetting;
     738                 :            : 
     739                 :            :     const ::rtl::OUString aSettings[] = {
     740                 :            :         PROPERTY_FILTER, PROPERTY_ORDER, PROPERTY_HAVING_CLAUSE, PROPERTY_GROUP_BY
     741 [ #  # ][ #  # ]:          0 :     };
                 [ #  # ]
           [ #  #  #  # ]
                 [ #  # ]
     742         [ #  # ]:          0 :     for ( size_t i=0; i < sizeof( aSettings ) / sizeof( aSettings[0] ); ++i )
     743                 :            :     {
     744 [ #  # ][ #  # ]:          0 :         if ( lcl_hasNonEmptyStringValue_throw( _rxSourceDescriptor, xPSI, aSettings[i] ) )
     745                 :            :         {
     746                 :          0 :             sUnsupportedSetting = aSettings[i];
     747                 :          0 :             break;
     748                 :            :         }
     749                 :            :     }
     750                 :            : 
     751         [ #  # ]:          0 :     if ( !sUnsupportedSetting.isEmpty() )
     752                 :            :     {
     753                 :            :         ::rtl::OUString sMessage(
     754                 :            :             rtl::OUString(String(ModuleRes(STR_CTW_ERROR_UNSUPPORTED_SETTING))).
     755 [ #  # ][ #  # ]:          0 :             replaceFirst("$name$", sUnsupportedSetting));
         [ #  # ][ #  # ]
     756                 :            :         throw IllegalArgumentException(
     757                 :            :             sMessage,
     758                 :            :             *const_cast< CopyTableWizard* >( this ),
     759                 :            :             1
     760 [ #  # ][ #  # ]:          0 :         );
     761 [ #  # ][ #  # ]:          0 :     }
     762                 :            : 
     763                 :          0 : }
     764                 :            : 
     765                 :            : //-------------------------------------------------------------------------
     766                 :            : SAL_WNODEPRECATED_DECLARATIONS_PUSH
     767                 :          0 : ::std::auto_ptr< ICopyTableSourceObject > CopyTableWizard::impl_extractSourceObject_throw( const Reference< XPropertySet >& _rxDescriptor, sal_Int32& _out_rCommandType ) const
     768                 :            : {
     769                 :            :     OSL_PRECOND( _rxDescriptor.is() && m_xSourceConnection.is(), "CopyTableWizard::impl_extractSourceObject_throw: illegal arguments!" );
     770                 :            : 
     771 [ #  # ][ #  # ]:          0 :     Reference< XPropertySetInfo > xPSI( _rxDescriptor->getPropertySetInfo(), UNO_SET_THROW );
                 [ #  # ]
     772 [ #  # ][ #  # ]:          0 :     if  (   !xPSI->hasPropertyByName( PROPERTY_COMMAND )
         [ #  # ][ #  # ]
                 [ #  # ]
           [ #  #  #  # ]
                 [ #  # ]
     773 [ #  # ][ #  # ]:          0 :         ||  !xPSI->hasPropertyByName( PROPERTY_COMMAND_TYPE )
         [ #  # ][ #  # ]
                 [ #  # ]
     774                 :            :         )
     775                 :            :         throw IllegalArgumentException(
     776                 :            :             ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Expecting a table or query specification." ) ),
     777                 :            :                 // TODO: resource
     778                 :            :             *const_cast< CopyTableWizard* >( this ),
     779                 :            :             1
     780 [ #  # ][ #  # ]:          0 :         );
                 [ #  # ]
     781                 :            : 
     782                 :          0 :     ::rtl::OUString sCommand;
     783                 :          0 :     _out_rCommandType = CommandType::COMMAND;
     784 [ #  # ][ #  # ]:          0 :     OSL_VERIFY( _rxDescriptor->getPropertyValue( PROPERTY_COMMAND ) >>= sCommand );
                 [ #  # ]
     785 [ #  # ][ #  # ]:          0 :     OSL_VERIFY( _rxDescriptor->getPropertyValue( PROPERTY_COMMAND_TYPE ) >>= _out_rCommandType );
                 [ #  # ]
     786                 :            : 
     787                 :          0 :     ::std::auto_ptr< ICopyTableSourceObject > pSourceObject;
     788                 :          0 :     Reference< XNameAccess > xContainer;
     789      [ #  #  # ]:          0 :     switch ( _out_rCommandType )
     790                 :            :     {
     791                 :            :     case CommandType::TABLE:
     792                 :            :     {
     793         [ #  # ]:          0 :         Reference< XTablesSupplier > xSuppTables( m_xSourceConnection.getTyped(), UNO_QUERY );
     794         [ #  # ]:          0 :         if ( xSuppTables.is() )
     795 [ #  # ][ #  # ]:          0 :             xContainer.set( xSuppTables->getTables(), UNO_SET_THROW );
                 [ #  # ]
     796                 :            :     }
     797                 :          0 :     break;
     798                 :            :     case CommandType::QUERY:
     799                 :            :     {
     800         [ #  # ]:          0 :         Reference< XQueriesSupplier > xSuppQueries( m_xSourceConnection.getTyped(), UNO_QUERY );
     801         [ #  # ]:          0 :         if ( xSuppQueries.is() )
     802 [ #  # ][ #  # ]:          0 :             xContainer.set( xSuppQueries->getQueries(), UNO_SET_THROW );
                 [ #  # ]
     803                 :            :     }
     804                 :          0 :     break;
     805                 :            :     default:
     806                 :            :         throw IllegalArgumentException(
     807                 :            :             String( ModuleRes( STR_CTW_ONLY_TABLES_AND_QUERIES_SUPPORT ) ),
     808                 :            :             *const_cast< CopyTableWizard* >( this ),
     809                 :            :             1
     810 [ #  # ][ #  # ]:          0 :         );
         [ #  # ][ #  # ]
                 [ #  # ]
     811                 :            :     }
     812                 :            : 
     813         [ #  # ]:          0 :     if ( xContainer.is() )
     814                 :            :     {
     815                 :            :         pSourceObject.reset( new ObjectCopySource( m_xSourceConnection,
     816 [ #  # ][ #  # ]:          0 :             Reference< XPropertySet >( xContainer->getByName( sCommand ), UNO_QUERY_THROW ) ) );
         [ #  # ][ #  # ]
                 [ #  # ]
     817                 :            :     }
     818                 :            :     else
     819                 :            :     {
     820                 :            :         // our source connection is an SDBC level connection only, not a SDBCX level one
     821                 :            :         // Which means it cannot provide the to-be-copied object as component.
     822                 :            : 
     823         [ #  # ]:          0 :         if ( _out_rCommandType == CommandType::QUERY )
     824                 :            :             // we cannot copy a query if the connection cannot provide it ...
     825                 :            :             throw IllegalArgumentException(
     826                 :            :                 String(ModuleRes( STR_CTW_ERROR_NO_QUERY )),
     827                 :            :                 *const_cast< CopyTableWizard* >( this ),
     828                 :            :                 1
     829 [ #  # ][ #  # ]:          0 :             );
         [ #  # ][ #  # ]
                 [ #  # ]
     830 [ #  # ][ #  # ]:          0 :         pSourceObject.reset( new NamedTableCopySource( m_xSourceConnection, sCommand ) );
     831                 :            :     }
     832                 :            : 
     833                 :          0 :     return pSourceObject;
     834                 :            : }
     835                 :            : SAL_WNODEPRECATED_DECLARATIONS_POP
     836                 :            : 
     837                 :            : //-------------------------------------------------------------------------
     838                 :          0 : void CopyTableWizard::impl_extractSourceResultSet_throw( const Reference< XPropertySet >& i_rDescriptor )
     839                 :            : {
     840 [ #  # ][ #  # ]:          0 :     Reference< XPropertySetInfo > xPSI( i_rDescriptor->getPropertySetInfo(), UNO_SET_THROW );
                 [ #  # ]
     841                 :            : 
     842                 :            :     // extract relevant settings
     843 [ #  # ][ #  # ]:          0 :     if ( xPSI->hasPropertyByName( PROPERTY_RESULT_SET ) )
         [ #  # ][ #  # ]
     844 [ #  # ][ #  # ]:          0 :         m_xSourceResultSet.set( i_rDescriptor->getPropertyValue( PROPERTY_RESULT_SET ), UNO_QUERY );
         [ #  # ][ #  # ]
     845                 :            : 
     846 [ #  # ][ #  # ]:          0 :     if ( xPSI->hasPropertyByName( PROPERTY_SELECTION ) )
         [ #  # ][ #  # ]
     847 [ #  # ][ #  # ]:          0 :         OSL_VERIFY( i_rDescriptor->getPropertyValue( PROPERTY_SELECTION ) >>= m_aSourceSelection );
         [ #  # ][ #  # ]
     848                 :            : 
     849 [ #  # ][ #  # ]:          0 :     if ( xPSI->hasPropertyByName( PROPERTY_BOOKMARK_SELECTION ) )
         [ #  # ][ #  # ]
     850 [ #  # ][ #  # ]:          0 :         OSL_VERIFY( i_rDescriptor->getPropertyValue( PROPERTY_BOOKMARK_SELECTION ) >>= m_bSourceSelectionBookmarks );
                 [ #  # ]
     851                 :            : 
     852                 :            :     // sanity checks
     853                 :          0 :     const bool bHasResultSet = m_xSourceResultSet.is();
     854                 :          0 :     const bool bHasSelection = ( m_aSourceSelection.getLength() != 0 );
     855 [ #  # ][ #  # ]:          0 :     if ( bHasSelection && !bHasResultSet )
     856                 :            :         throw IllegalArgumentException(
     857                 :            :             ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "A result set is needed when specifying a selection to copy." ) ),
     858                 :            :                 // TODO: resource
     859                 :            :             *this,
     860                 :            :             1
     861 [ #  # ][ #  # ]:          0 :         );
                 [ #  # ]
     862                 :            : 
     863 [ #  # ][ #  # ]:          0 :     if ( bHasSelection && m_bSourceSelectionBookmarks )
     864                 :            :     {
     865         [ #  # ]:          0 :         Reference< XRowLocate > xRowLocate( m_xSourceResultSet, UNO_QUERY );
     866         [ #  # ]:          0 :         if ( !xRowLocate.is() )
     867                 :            :         {
     868                 :            :             ::dbtools::throwGenericSQLException(
     869                 :            :                 String( ModuleRes( STR_CTW_COPY_SOURCE_NEEDS_BOOKMARKS ) ),
     870                 :            :                 *this
     871 [ #  # ][ #  # ]:          0 :             );
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     872                 :          0 :         }
     873                 :          0 :     }
     874                 :          0 : }
     875                 :            : 
     876                 :            : //-------------------------------------------------------------------------
     877                 :          0 : SharedConnection CopyTableWizard::impl_extractConnection_throw( const Reference< XPropertySet >& _rxDataSourceDescriptor,
     878                 :            :     InteractionHandler& _out_rxDocInteractionHandler ) const
     879                 :            : {
     880         [ #  # ]:          0 :     SharedConnection xConnection;
     881                 :            : 
     882                 :            :     OSL_PRECOND( _rxDataSourceDescriptor.is(), "CopyTableWizard::impl_extractConnection_throw: no descriptor!" );
     883         [ #  # ]:          0 :     if ( !_rxDataSourceDescriptor.is() )
     884                 :            :         return xConnection;
     885                 :            : 
     886                 :          0 :     InteractionHandler xInteractionHandler;
     887                 :            : 
     888                 :            :     do
     889                 :            :     {
     890 [ #  # ][ #  # ]:          0 :     Reference< XPropertySetInfo > xPSI( _rxDataSourceDescriptor->getPropertySetInfo(), UNO_SET_THROW );
                 [ #  # ]
     891                 :            : 
     892                 :            :     // if there's an ActiveConnection, use it
     893 [ #  # ][ #  # ]:          0 :     if ( xPSI->hasPropertyByName( PROPERTY_ACTIVE_CONNECTION ) )
         [ #  # ][ #  # ]
     894                 :            :     {
     895                 :          0 :         Reference< XConnection > xPure;
     896 [ #  # ][ #  # ]:          0 :         OSL_VERIFY( _rxDataSourceDescriptor->getPropertyValue( PROPERTY_ACTIVE_CONNECTION ) >>= xPure );
         [ #  # ][ #  # ]
     897         [ #  # ]:          0 :         xConnection.reset( xPure, SharedConnection::NoTakeOwnership );
     898                 :            :     }
     899         [ #  # ]:          0 :     if ( xConnection.is() )
     900                 :            :     {
     901 [ #  # ][ #  # ]:          0 :         xInteractionHandler = lcl_getInteractionHandler_throw( xConnection.getTyped(), m_xInteractionHandler );
     902                 :            :         OSL_POSTCOND( xInteractionHandler.is(), "CopyTableWizard::impl_extractConnection_throw: lcl_getInteractionHandler_throw returned nonsense!" );
     903                 :            :         break;
     904                 :            :     }
     905                 :            : 
     906                 :            :     // there could be a DataSourceName or a DatabaseLocation, describing the css.sdb.DataSource
     907                 :          0 :     ::rtl::OUString sDataSource, sDatabaseLocation;
     908 [ #  # ][ #  # ]:          0 :     if ( xPSI->hasPropertyByName( PROPERTY_DATASOURCENAME ) )
         [ #  # ][ #  # ]
     909 [ #  # ][ #  # ]:          0 :         OSL_VERIFY( _rxDataSourceDescriptor->getPropertyValue( PROPERTY_DATASOURCENAME ) >>= sDataSource );
                 [ #  # ]
     910 [ #  # ][ #  # ]:          0 :     if ( xPSI->hasPropertyByName( PROPERTY_DATABASE_LOCATION ) )
         [ #  # ][ #  # ]
     911 [ #  # ][ #  # ]:          0 :         OSL_VERIFY( _rxDataSourceDescriptor->getPropertyValue( PROPERTY_DATABASE_LOCATION ) >>= sDatabaseLocation );
                 [ #  # ]
     912                 :            : 
     913                 :            :     // need a DatabaseContext for loading the data source
     914 [ #  # ][ #  # ]:          0 :     Reference< XNameAccess > xDatabaseContext( m_aContext.createComponent( "com.sun.star.sdb.DatabaseContext" ), UNO_QUERY_THROW );
     915                 :          0 :     Reference< XDataSource > xDataSource;
     916         [ #  # ]:          0 :     if ( !sDataSource.isEmpty() )
     917 [ #  # ][ #  # ]:          0 :         xDataSource.set( xDatabaseContext->getByName( sDataSource ), UNO_QUERY_THROW );
                 [ #  # ]
     918 [ #  # ][ #  # ]:          0 :     if ( !xDataSource.is() && !sDatabaseLocation.isEmpty() )
                 [ #  # ]
     919 [ #  # ][ #  # ]:          0 :         xDataSource.set( xDatabaseContext->getByName( sDatabaseLocation ), UNO_QUERY_THROW );
                 [ #  # ]
     920                 :            : 
     921         [ #  # ]:          0 :     if ( xDataSource.is() )
     922                 :            :     {
     923                 :            :         // first, try connecting with completion
     924 [ #  # ][ #  # ]:          0 :         xInteractionHandler = lcl_getInteractionHandler_throw( xDataSource, m_xInteractionHandler );
     925                 :            :         OSL_POSTCOND( xInteractionHandler.is(), "CopyTableWizard::impl_extractConnection_throw: lcl_getInteractionHandler_throw returned nonsense!" );
     926         [ #  # ]:          0 :         if ( xInteractionHandler.is() )
     927                 :            :         {
     928         [ #  # ]:          0 :             Reference< XCompletedConnection > xInteractiveConnection( xDataSource, UNO_QUERY );
     929         [ #  # ]:          0 :             if ( xInteractiveConnection.is() )
     930 [ #  # ][ #  # ]:          0 :                 xConnection.reset( xInteractiveConnection->connectWithCompletion( xInteractionHandler ), SharedConnection::TakeOwnership );
                 [ #  # ]
     931                 :            :         }
     932                 :            : 
     933                 :            :         // interactively connecting was not successful or possible -> connect without interaction
     934         [ #  # ]:          0 :         if ( !xConnection.is() )
     935                 :            :         {
     936 [ #  # ][ #  # ]:          0 :             xConnection.reset( xDataSource->getConnection( ::rtl::OUString(), ::rtl::OUString() ), SharedConnection::TakeOwnership );
                 [ #  # ]
     937                 :            :         }
     938                 :            :     }
     939                 :            : 
     940         [ #  # ]:          0 :     if ( xConnection.is() )
     941                 :            :         break;
     942                 :            : 
     943                 :            :     // finally, there could be a ConnectionResource/ConnectionInfo
     944                 :          0 :     ::rtl::OUString sConnectionResource;
     945         [ #  # ]:          0 :     Sequence< PropertyValue > aConnectionInfo;
     946 [ #  # ][ #  # ]:          0 :     if ( xPSI->hasPropertyByName( PROPERTY_CONNECTION_RESOURCE ) )
         [ #  # ][ #  # ]
     947 [ #  # ][ #  # ]:          0 :         OSL_VERIFY( _rxDataSourceDescriptor->getPropertyValue( PROPERTY_CONNECTION_RESOURCE ) >>= sConnectionResource );
                 [ #  # ]
     948 [ #  # ][ #  # ]:          0 :     if ( xPSI->hasPropertyByName( PROPERTY_CONNECTION_INFO ) )
         [ #  # ][ #  # ]
     949 [ #  # ][ #  # ]:          0 :         OSL_VERIFY( _rxDataSourceDescriptor->getPropertyValue( PROPERTY_CONNECTION_INFO ) >>= aConnectionInfo );
         [ #  # ][ #  # ]
     950                 :            : 
     951                 :          0 :     Reference< XDriverManager > xDriverManager;
     952 [ #  # ][ #  # ]:          0 :     xDriverManager.set( m_aContext.createComponent( "com.sun.star.sdbc.ConnectionPool" ), UNO_QUERY );
     953         [ #  # ]:          0 :     if ( !xDriverManager.is() )
     954                 :            :         // no connection pool installed
     955 [ #  # ][ #  # ]:          0 :         xDriverManager.set( m_aContext.createComponent( "com.sun.star.sdbc.DriverManager" ), UNO_QUERY_THROW );
     956                 :            : 
     957         [ #  # ]:          0 :     if ( aConnectionInfo.getLength() )
     958 [ #  # ][ #  # ]:          0 :         xConnection.set( xDriverManager->getConnectionWithInfo( sConnectionResource, aConnectionInfo ), UNO_SET_THROW );
                 [ #  # ]
     959                 :            :     else
     960 [ #  # ][ #  # ]:          0 :         xConnection.set( xDriverManager->getConnection( sConnectionResource ), UNO_SET_THROW );
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     961                 :            :     }
     962                 :            :     while ( false );
     963                 :            : 
     964 [ #  # ][ #  # ]:          0 :     if ( xInteractionHandler != m_xInteractionHandler )
     965         [ #  # ]:          0 :         _out_rxDocInteractionHandler = xInteractionHandler;
     966                 :            : 
     967                 :          0 :     return xConnection;
     968                 :            : }
     969                 :            : 
     970                 :            : //-------------------------------------------------------------------------
     971                 :          0 : ::utl::SharedUNOComponent< XPreparedStatement > CopyTableWizard::impl_createSourceStatement_throw() const
     972                 :            : {
     973                 :            :     OSL_PRECOND( m_xSourceConnection.is(), "CopyTableWizard::impl_createSourceStatement_throw: illegal call!" );
     974         [ #  # ]:          0 :     if ( !m_xSourceConnection.is() )
     975 [ #  # ][ #  # ]:          0 :         throw RuntimeException( "CopyTableWizard::impl_createSourceStatement_throw: illegal call!", *const_cast< CopyTableWizard* >( this ));
     976                 :            : 
     977                 :          0 :     ::utl::SharedUNOComponent< XPreparedStatement > xStatement;
     978      [ #  #  # ]:          0 :     switch ( m_nCommandType )
     979                 :            :     {
     980                 :            :     case CommandType::TABLE:
     981 [ #  # ][ #  # ]:          0 :         xStatement.set( m_pSourceObject->getPreparedSelectStatement(), UNO_SET_THROW );
                 [ #  # ]
     982                 :          0 :         break;
     983                 :            : 
     984                 :            :     case CommandType::QUERY:
     985                 :            :     {
     986         [ #  # ]:          0 :         ::rtl::OUString sQueryCommand( m_pSourceObject->getSelectStatement() );
     987 [ #  # ][ #  # ]:          0 :         xStatement.set( m_pSourceObject->getPreparedSelectStatement(), UNO_SET_THROW );
                 [ #  # ]
     988                 :            : 
     989                 :            :         // check whether we have to fill in parameter values
     990                 :            :         // create and fill a composer
     991                 :            : 
     992         [ #  # ]:          0 :         Reference< XMultiServiceFactory > xFactory( m_xSourceConnection, UNO_QUERY );
     993         [ #  # ]:          0 :         ::utl::SharedUNOComponent< XSingleSelectQueryComposer > xComposer;
     994         [ #  # ]:          0 :         if ( xFactory.is() )
     995                 :            :             // note: connections below the sdb-level are allowed to not support the XMultiServiceFactory interface
     996 [ #  # ][ #  # ]:          0 :             xComposer.set( xFactory->createInstance( SERVICE_NAME_SINGLESELECTQUERYCOMPOSER ), UNO_QUERY );
         [ #  # ][ #  # ]
     997                 :            : 
     998         [ #  # ]:          0 :         if ( xComposer.is() )
     999                 :            :         {
    1000 [ #  # ][ #  # ]:          0 :             xComposer->setQuery( sQueryCommand );
    1001                 :            : 
    1002         [ #  # ]:          0 :             Reference< XParameters > xStatementParams( xStatement, UNO_QUERY );
    1003                 :            :             OSL_ENSURE( xStatementParams.is(), "CopyTableWizard::impl_createSourceStatement_throw: no access to the statement's parameters!" );
    1004                 :            :                 // the statement should be a css.sdbc.PreparedStatement (this is what
    1005                 :            :                 // we created), and a prepared statement is required to support XParameters
    1006         [ #  # ]:          0 :             if ( xStatementParams.is() )
    1007                 :            :             {
    1008                 :            :                 OSL_ENSURE( m_xInteractionHandler.is(),
    1009                 :            :                    "CopyTableWizard::impl_createSourceStatement_throw: no interaction handler for the parameters request!" );
    1010                 :            :                 // we should always have an interaction handler - as last fallback, we create an own one in ::initialize
    1011                 :            : 
    1012         [ #  # ]:          0 :                 if ( m_xInteractionHandler.is() )
    1013 [ #  # ][ #  # ]:          0 :                     ::dbtools::askForParameters( xComposer, xStatementParams, m_xSourceConnection, m_xInteractionHandler );
    1014                 :          0 :             }
    1015         [ #  # ]:          0 :         }
    1016                 :            :     }
    1017                 :          0 :     break;
    1018                 :            : 
    1019                 :            :     default:
    1020                 :            :         // this should not have survived initialization phase
    1021 [ #  # ][ #  # ]:          0 :         throw RuntimeException("No case matched, this should not have survived the initialization phase", *const_cast< CopyTableWizard* >( this ));
    1022                 :            :     }
    1023                 :            : 
    1024                 :          0 :     return xStatement;
    1025                 :            : }
    1026                 :            : 
    1027                 :            : //-------------------------------------------------------------------------
    1028                 :            : namespace
    1029                 :            : {
    1030                 :          0 :     class ValueTransfer
    1031                 :            :     {
    1032                 :            :     public:
    1033                 :          0 :         ValueTransfer( const sal_Int32& _rSourcePos, const sal_Int32& _rDestPos, const ::std::vector< sal_Int32 >& _rColTypes,
    1034                 :            :             const Reference< XRow >& _rxSource, const Reference< XParameters >& _rxDest )
    1035                 :            :             :m_rSourcePos( _rSourcePos )
    1036                 :            :             ,m_rDestPos( _rDestPos )
    1037                 :            :             ,m_rColTypes( _rColTypes )
    1038                 :            :             ,m_xSource( _rxSource )
    1039                 :          0 :             ,m_xDest( _rxDest )
    1040                 :            :         {
    1041                 :          0 :         }
    1042                 :            : 
    1043                 :            :     template< typename VALUE_TYPE >
    1044                 :          0 :     void transferValue( VALUE_TYPE ( SAL_CALL XRow::*_pGetter )( sal_Int32 ),
    1045                 :            :         void (SAL_CALL XParameters::*_pSetter)( sal_Int32, VALUE_TYPE ) )
    1046                 :            :     {
    1047 [ #  # ][ #  # ]:          0 :         VALUE_TYPE value( (m_xSource.get()->*_pGetter)( m_rSourcePos ) );
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1048   [ #  #  #  #  :          0 :         if ( m_xSource->wasNull() )
          #  #  #  #  #  
             #  #  #  #  
                      # ]
    1049                 :          0 :             m_xDest->setNull( m_rDestPos, m_rColTypes[ m_rSourcePos ] );
    1050                 :            :         else
    1051 [ #  # ][ #  # ]:          0 :             (m_xDest.get()->*_pSetter)( m_rDestPos, value );
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1052                 :          0 :     }
    1053                 :            :  template< typename VALUE_TYPE >
    1054                 :          0 :     void transferComplexValue( VALUE_TYPE ( SAL_CALL XRow::*_pGetter )( sal_Int32 ),
    1055                 :            :         void (SAL_CALL XParameters::*_pSetter)( sal_Int32, const VALUE_TYPE& ) )
    1056                 :            :     {
    1057 [ #  # ][ #  # ]:          0 :         const VALUE_TYPE value( (m_xSource.get()->*_pGetter)( m_rSourcePos ) );
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1058                 :            :                {
    1059 [ #  # ][ #  # ]:          0 :         if ( m_xSource->wasNull() )
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1060 [ #  # ][ #  # ]:          0 :             m_xDest->setNull( m_rDestPos, m_rColTypes[ m_rSourcePos ] );
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1061                 :            :         else
    1062 [ #  # ][ #  # ]:          0 :             (m_xDest.get()->*_pSetter)( m_rDestPos, value );
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1063                 :            :                }
    1064                 :          0 :     }
    1065                 :            :     private:
    1066                 :            :         const sal_Int32&                    m_rSourcePos;
    1067                 :            :         const sal_Int32&                    m_rDestPos;
    1068                 :            :         const ::std::vector< sal_Int32 >    m_rColTypes;
    1069                 :            :         const Reference< XRow >             m_xSource;
    1070                 :            :         const Reference< XParameters >      m_xDest;
    1071                 :            :     };
    1072                 :            : }
    1073                 :            : 
    1074                 :            : //-------------------------------------------------------------------------
    1075                 :          0 : bool CopyTableWizard::impl_processCopyError_nothrow( const CopyTableRowEvent& _rEvent )
    1076                 :            : {
    1077                 :          0 :     Reference< XCopyTableListener > xListener;
    1078                 :            :     try
    1079                 :            :     {
    1080         [ #  # ]:          0 :         ::cppu::OInterfaceIteratorHelper aIter( m_aCopyTableListeners );
    1081         [ #  # ]:          0 :         while ( aIter.hasMoreElements() )
    1082                 :            :         {
    1083 [ #  # ][ #  # ]:          0 :             xListener.set( aIter.next(), UNO_QUERY_THROW );
    1084 [ #  # ][ #  # ]:          0 :             sal_Int16 nListenerChoice = xListener->copyRowError( _rEvent );
    1085   [ #  #  #  #  :          0 :             switch ( nListenerChoice )
                      # ]
    1086                 :            :             {
    1087                 :          0 :             case CopyTableContinuation::Proceed:            return true;    // continue copying
    1088                 :          0 :             case CopyTableContinuation::CallNextHandler:    continue;       // continue the loop, ask next listener
    1089                 :          0 :             case CopyTableContinuation::Cancel:             return false;   // cancel copying
    1090                 :          0 :             case CopyTableContinuation::AskUser:            break;          // stop asking the listeners, ask the user
    1091                 :            : 
    1092                 :            :             default:
    1093                 :            :                 OSL_FAIL( "CopyTableWizard::impl_processCopyError_nothrow: invalid listener response!" );
    1094                 :            :                 // ask next listener
    1095                 :          0 :                 continue;
    1096                 :            :             }
    1097 [ #  # ][ #  # ]:          0 :         }
                 [ #  # ]
    1098                 :            :     }
    1099         [ #  # ]:          0 :     catch( const Exception& )
    1100                 :            :     {
    1101                 :            :         DBG_UNHANDLED_EXCEPTION();
    1102                 :            :     }
    1103                 :            : 
    1104                 :            :     // no listener felt responsible for the error, or a listener told to ask the user
    1105                 :            : 
    1106                 :            :     try
    1107                 :            :     {
    1108         [ #  # ]:          0 :         SQLContext aError;
    1109 [ #  # ][ #  # ]:          0 :         aError.Context = *this;
    1110 [ #  # ][ #  # ]:          0 :         aError.Message = String( ModuleRes( STR_ERROR_OCCURRED_WHILE_COPYING ) );
         [ #  # ][ #  # ]
    1111                 :            : 
    1112         [ #  # ]:          0 :         ::dbtools::SQLExceptionInfo aInfo( _rEvent.Error );
    1113         [ #  # ]:          0 :         if ( aInfo.isValid() )
    1114                 :          0 :             aError.NextException = _rEvent.Error;
    1115                 :            :         else
    1116                 :            :         {
    1117                 :            :             // a non-SQL exception happend
    1118         [ #  # ]:          0 :             Exception aException;
    1119         [ #  # ]:          0 :             OSL_VERIFY( _rEvent.Error >>= aException );
    1120         [ #  # ]:          0 :             SQLContext aContext;
    1121         [ #  # ]:          0 :             aContext.Context = aException.Context;
    1122                 :          0 :             aContext.Message = aException.Message;
    1123                 :          0 :             aContext.Details = _rEvent.Error.getValueTypeName();
    1124 [ #  # ][ #  # ]:          0 :             aError.NextException <<= aContext;
                 [ #  # ]
    1125                 :            :         }
    1126                 :            : 
    1127 [ #  # ][ #  # ]:          0 :         ::rtl::Reference< ::comphelper::OInteractionRequest > xRequest( new ::comphelper::OInteractionRequest( makeAny( aError ) ) );
    1128                 :            : 
    1129         [ #  # ]:          0 :         ::rtl::Reference< ::comphelper::OInteractionApprove > xYes = new ::comphelper::OInteractionApprove;
    1130 [ #  # ][ #  # ]:          0 :         xRequest->addContinuation( xYes.get() );
                 [ #  # ]
    1131 [ #  # ][ #  # ]:          0 :         xRequest->addContinuation( new ::comphelper::OInteractionDisapprove );
         [ #  # ][ #  # ]
    1132                 :            : 
    1133                 :            :         OSL_ENSURE( m_xInteractionHandler.is(),
    1134                 :            :             "CopyTableWizard::impl_processCopyError_nothrow: we always should have an interaction handler!" );
    1135         [ #  # ]:          0 :         if ( m_xInteractionHandler.is() )
    1136 [ #  # ][ #  # ]:          0 :             m_xInteractionHandler->handle( xRequest.get() );
         [ #  # ][ #  # ]
    1137                 :            : 
    1138         [ #  # ]:          0 :         if ( xYes->wasSelected() )
    1139                 :            :             // continue copying
    1140 [ #  # ][ #  # ]:          0 :             return true;
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1141                 :            :     }
    1142         [ #  # ]:          0 :     catch( const Exception& )
    1143                 :            :     {
    1144                 :            :         DBG_UNHANDLED_EXCEPTION();
    1145                 :            :     }
    1146                 :            : 
    1147                 :            :     // cancel copying
    1148                 :          0 :     return false;
    1149                 :            : }
    1150                 :            : 
    1151                 :            : //-------------------------------------------------------------------------
    1152                 :          0 : void CopyTableWizard::impl_copyRows_throw( const Reference< XResultSet >& _rxSourceResultSet,
    1153                 :            :     const Reference< XPropertySet >& _rxDestTable )
    1154                 :            : {
    1155                 :            :     OSL_PRECOND( m_xDestConnection.is(), "CopyTableWizard::impl_copyRows_throw: illegal call!" );
    1156         [ #  # ]:          0 :     if ( !m_xDestConnection.is() )
    1157 [ #  # ][ #  # ]:          0 :         throw RuntimeException( "m_xDestConnection is set to null, CopyTableWizard::impl_copyRows_throw: illegal call!", *this );
    1158                 :            : 
    1159 [ #  # ][ #  # ]:          0 :     Reference< XDatabaseMetaData > xDestMetaData( m_xDestConnection->getMetaData(), UNO_QUERY_THROW );
                 [ #  # ]
    1160                 :            : 
    1161         [ #  # ]:          0 :     const OCopyTableWizard& rWizard             = impl_getDialog_throw();
    1162         [ #  # ]:          0 :     ODatabaseExport::TPositions aColumnMapping  = rWizard.GetColumnPositions();
    1163         [ #  # ]:          0 :     bool bAutoIncrement                         = rWizard.shouldCreatePrimaryKey();
    1164                 :            : 
    1165         [ #  # ]:          0 :     Reference< XRow > xRow              ( _rxSourceResultSet, UNO_QUERY_THROW );
    1166         [ #  # ]:          0 :     Reference< XRowLocate > xRowLocate  ( _rxSourceResultSet, UNO_QUERY_THROW );
    1167                 :            : 
    1168         [ #  # ]:          0 :     Reference< XResultSetMetaDataSupplier > xSuppResMeta( _rxSourceResultSet, UNO_QUERY_THROW );
    1169 [ #  # ][ #  # ]:          0 :     Reference< XResultSetMetaData> xMeta( xSuppResMeta->getMetaData() );
    1170                 :            : 
    1171                 :            :     // we need a vector which all types
    1172 [ #  # ][ #  # ]:          0 :     sal_Int32 nCount = xMeta->getColumnCount();
    1173         [ #  # ]:          0 :     ::std::vector< sal_Int32 > aSourceColTypes;
    1174         [ #  # ]:          0 :     aSourceColTypes.reserve( nCount + 1 );
    1175         [ #  # ]:          0 :     aSourceColTypes.push_back( -1 ); // just to avoid a everytime i-1 call
    1176                 :            : 
    1177         [ #  # ]:          0 :     ::std::vector< sal_Int32 > aSourcePrec;
    1178         [ #  # ]:          0 :     aSourcePrec.reserve( nCount + 1 );
    1179         [ #  # ]:          0 :     aSourcePrec.push_back( -1 ); // just to avoid a everytime i-1 call
    1180                 :            : 
    1181         [ #  # ]:          0 :     for ( sal_Int32 k=1; k <= nCount; ++k )
    1182                 :            :     {
    1183 [ #  # ][ #  # ]:          0 :         aSourceColTypes.push_back( xMeta->getColumnType( k ) );
                 [ #  # ]
    1184 [ #  # ][ #  # ]:          0 :         aSourcePrec.push_back( xMeta->getPrecision( k ) );
                 [ #  # ]
    1185                 :            :     }
    1186                 :            : 
    1187                 :            :     // now create, fill and execute the prepared statement
    1188 [ #  # ][ #  # ]:          0 :     Reference< XPreparedStatement > xStatement( ODatabaseExport::createPreparedStatment( xDestMetaData, _rxDestTable, aColumnMapping ), UNO_SET_THROW );
    1189         [ #  # ]:          0 :     Reference< XParameters > xStatementParams( xStatement, UNO_QUERY_THROW );
    1190                 :            : 
    1191                 :          0 :     const bool bSelectedRecordsOnly = m_aSourceSelection.getLength() != 0;
    1192                 :          0 :     const Any* pSelectedRow         = m_aSourceSelection.getConstArray();
    1193                 :          0 :     const Any* pSelEnd              = pSelectedRow + m_aSourceSelection.getLength();
    1194                 :            : 
    1195                 :          0 :     sal_Int32 nRowCount = 0;
    1196                 :          0 :     bool bContinue = false;
    1197                 :            : 
    1198         [ #  # ]:          0 :     CopyTableRowEvent aCopyEvent;
    1199 [ #  # ][ #  # ]:          0 :     aCopyEvent.Source = *this;
    1200         [ #  # ]:          0 :     aCopyEvent.SourceData = _rxSourceResultSet;
    1201                 :            : 
    1202         [ #  # ]:          0 :     do // loop as long as there are more rows or the selection ends
    1203                 :            :     {
    1204                 :          0 :         bContinue = false;
    1205         [ #  # ]:          0 :         if ( bSelectedRecordsOnly )
    1206                 :            :         {
    1207         [ #  # ]:          0 :             if ( pSelectedRow != pSelEnd )
    1208                 :            :             {
    1209         [ #  # ]:          0 :                 if ( m_bSourceSelectionBookmarks )
    1210                 :            :                 {
    1211 [ #  # ][ #  # ]:          0 :                     bContinue = xRowLocate->moveToBookmark( *pSelectedRow );
    1212                 :            :                 }
    1213                 :            :                 else
    1214                 :            :                 {
    1215                 :          0 :                     sal_Int32 nPos = 0;
    1216                 :          0 :                     OSL_VERIFY( *pSelectedRow >>= nPos );
    1217 [ #  # ][ #  # ]:          0 :                     bContinue = _rxSourceResultSet->absolute( nPos );
    1218                 :            :                 }
    1219                 :          0 :                 ++pSelectedRow;
    1220                 :            :             }
    1221                 :            :         }
    1222                 :            :         else
    1223 [ #  # ][ #  # ]:          0 :             bContinue = _rxSourceResultSet->next();
    1224                 :            : 
    1225         [ #  # ]:          0 :         if ( !bContinue )
    1226                 :            :         {
    1227                 :            :             break;
    1228                 :            :         }
    1229                 :            : 
    1230                 :          0 :         ++nRowCount;
    1231                 :          0 :         sal_Bool bInsertAutoIncrement = sal_True;
    1232         [ #  # ]:          0 :         ODatabaseExport::TPositions::const_iterator aPosIter = aColumnMapping.begin();
    1233         [ #  # ]:          0 :         ODatabaseExport::TPositions::const_iterator aPosEnd = aColumnMapping.end();
    1234                 :            : 
    1235                 :          0 :         aCopyEvent.Error.clear();
    1236                 :            :         try
    1237                 :            :         {
    1238                 :            :             // notify listeners
    1239         [ #  # ]:          0 :             m_aCopyTableListeners.notifyEach( &XCopyTableListener::copyingRow, aCopyEvent );
    1240                 :            : 
    1241                 :          0 :             sal_Int32 nDestColumn( 0 );
    1242                 :          0 :             sal_Int32 nSourceColumn( 1 );
    1243         [ #  # ]:          0 :             ValueTransfer aTransfer( nSourceColumn, nDestColumn, aSourceColTypes, xRow, xStatementParams );
    1244                 :            : 
    1245 [ #  # ][ #  # ]:          0 :             for ( ; aPosIter != aPosEnd; ++aPosIter )
                 [ #  # ]
    1246                 :            :             {
    1247         [ #  # ]:          0 :                 nDestColumn = aPosIter->first;
    1248         [ #  # ]:          0 :                 if ( nDestColumn == COLUMN_POSITION_NOT_FOUND )
    1249                 :            :                 {
    1250                 :          0 :                     ++nSourceColumn;
    1251                 :            :                     // otherwise we don't get the correct value when only the 2nd source column was selected
    1252                 :          0 :                     continue;
    1253                 :            :                 }
    1254                 :            : 
    1255 [ #  # ][ #  # ]:          0 :                 if ( bAutoIncrement && bInsertAutoIncrement )
    1256                 :            :                 {
    1257 [ #  # ][ #  # ]:          0 :                     xStatementParams->setInt( 1, nRowCount );
    1258                 :          0 :                     bInsertAutoIncrement = sal_False;
    1259                 :          0 :                     continue;
    1260                 :            :                 }
    1261                 :            : 
    1262 [ #  # ][ #  # ]:          0 :                 if ( ( nSourceColumn < 1 ) || ( nSourceColumn >= (sal_Int32)aSourceColTypes.size() ) )
                 [ #  # ]
    1263                 :            :                 {   // ( we have to check here against 1 because the parameters are 1 based)
    1264                 :            :                     ::dbtools::throwSQLException(
    1265                 :            :                         ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Internal error: invalid column type index." ) ),
    1266                 :            :                         ::dbtools::SQL_INVALID_DESCRIPTOR_INDEX,
    1267                 :            :                         *this
    1268 [ #  # ][ #  # ]:          0 :                     );
                 [ #  # ]
    1269                 :            :                 }
    1270                 :            : 
    1271 [ #  # ][ #  #  :          0 :                 switch ( aSourceColTypes[ nSourceColumn ] )
          #  #  #  #  #  
          #  #  #  #  #  
             #  #  #  # ]
    1272                 :            :                 {
    1273                 :            :                     case DataType::DOUBLE:
    1274                 :            :                     case DataType::REAL:
    1275         [ #  # ]:          0 :                         aTransfer.transferValue( &XRow::getDouble, &XParameters::setDouble );
    1276                 :          0 :                         break;
    1277                 :            : 
    1278                 :            :                     case DataType::CHAR:
    1279                 :            :                     case DataType::VARCHAR:
    1280                 :            :                     case DataType::LONGVARCHAR:
    1281                 :            :                     case DataType::DECIMAL:
    1282                 :            :                     case DataType::NUMERIC:
    1283         [ #  # ]:          0 :                         aTransfer.transferComplexValue( &XRow::getString, &XParameters::setString );
    1284                 :          0 :                         break;
    1285                 :            : 
    1286                 :            :                     case DataType::BIGINT:
    1287         [ #  # ]:          0 :                         aTransfer.transferValue( &XRow::getLong, &XParameters::setLong );
    1288                 :          0 :                         break;
    1289                 :            : 
    1290                 :            :                     case DataType::FLOAT:
    1291         [ #  # ]:          0 :                         aTransfer.transferValue( &XRow::getFloat, &XParameters::setFloat );
    1292                 :          0 :                         break;
    1293                 :            : 
    1294                 :            :                     case DataType::LONGVARBINARY:
    1295                 :            :                     case DataType::BINARY:
    1296                 :            :                     case DataType::VARBINARY:
    1297         [ #  # ]:          0 :                         aTransfer.transferComplexValue( &XRow::getBytes, &XParameters::setBytes );
    1298                 :          0 :                         break;
    1299                 :            : 
    1300                 :            :                     case DataType::DATE:
    1301         [ #  # ]:          0 :                         aTransfer.transferComplexValue( &XRow::getDate, &XParameters::setDate );
    1302                 :          0 :                         break;
    1303                 :            : 
    1304                 :            :                     case DataType::TIME:
    1305         [ #  # ]:          0 :                         aTransfer.transferComplexValue( &XRow::getTime, &XParameters::setTime );
    1306                 :          0 :                         break;
    1307                 :            : 
    1308                 :            :                     case DataType::TIMESTAMP:
    1309         [ #  # ]:          0 :                         aTransfer.transferComplexValue( &XRow::getTimestamp, &XParameters::setTimestamp );
    1310                 :          0 :                         break;
    1311                 :            : 
    1312                 :            :                     case DataType::BIT:
    1313 [ #  # ][ #  # ]:          0 :                         if ( aSourcePrec[nSourceColumn] > 1 )
    1314                 :            :                         {
    1315         [ #  # ]:          0 :                             aTransfer.transferComplexValue( &XRow::getBytes, &XParameters::setBytes );
    1316                 :          0 :                             break;
    1317                 :            :                         }
    1318                 :            :                         // run through
    1319                 :            :                     case DataType::BOOLEAN:
    1320         [ #  # ]:          0 :                         aTransfer.transferValue( &XRow::getBoolean, &XParameters::setBoolean );
    1321                 :          0 :                         break;
    1322                 :            : 
    1323                 :            :                     case DataType::TINYINT:
    1324         [ #  # ]:          0 :                         aTransfer.transferValue( &XRow::getByte, &XParameters::setByte );
    1325                 :          0 :                         break;
    1326                 :            : 
    1327                 :            :                     case DataType::SMALLINT:
    1328         [ #  # ]:          0 :                         aTransfer.transferValue( &XRow::getShort, &XParameters::setShort );
    1329                 :          0 :                         break;
    1330                 :            : 
    1331                 :            :                     case DataType::INTEGER:
    1332         [ #  # ]:          0 :                         aTransfer.transferValue( &XRow::getInt, &XParameters::setInt );
    1333                 :          0 :                         break;
    1334                 :            : 
    1335                 :            :                     case DataType::BLOB:
    1336         [ #  # ]:          0 :                         aTransfer.transferComplexValue( &XRow::getBlob, &XParameters::setBlob );
    1337                 :          0 :                         break;
    1338                 :            : 
    1339                 :            :                     case DataType::CLOB:
    1340         [ #  # ]:          0 :                         aTransfer.transferComplexValue( &XRow::getClob, &XParameters::setClob );
    1341                 :          0 :                         break;
    1342                 :            : 
    1343                 :            :                     default:
    1344                 :            :                     {
    1345 [ #  # ][ #  # ]:          0 :                         ::rtl::OUString aMessage( String( ModuleRes( STR_CTW_UNSUPPORTED_COLUMN_TYPE ) ) );
         [ #  # ][ #  # ]
    1346                 :            : 
    1347         [ #  # ]:          0 :                         aMessage.replaceAt( aMessage.indexOfAsciiL( "$type$", 6 ), 6, ::rtl::OUString::valueOf( aSourceColTypes[ nSourceColumn ] ) );
    1348                 :          0 :                         aMessage.replaceAt( aMessage.indexOfAsciiL( "$pos$", 5 ), 5, ::rtl::OUString::valueOf( nSourceColumn ) );
    1349                 :            : 
    1350                 :            :                         ::dbtools::throwSQLException(
    1351                 :            :                             aMessage,
    1352                 :            :                             ::dbtools::SQL_INVALID_SQL_DATA_TYPE,
    1353                 :            :                             *this
    1354 [ #  # ][ #  # ]:          0 :                         );
    1355                 :            :                     }
    1356                 :            :                 }
    1357                 :          0 :                 ++nSourceColumn;
    1358                 :            :             }
    1359 [ #  # ][ #  # ]:          0 :             xStatement->executeUpdate();
    1360                 :            : 
    1361                 :            :             // notify listeners
    1362 [ #  # ][ #  # ]:          0 :             m_aCopyTableListeners.notifyEach( &XCopyTableListener::copiedRow, aCopyEvent );
    1363                 :            :         }
    1364   [ #  #  #  # ]:          0 :         catch( const Exception& )
    1365                 :            :         {
    1366         [ #  # ]:          0 :             aCopyEvent.Error = ::cppu::getCaughtException();
    1367                 :            :         }
    1368                 :            : 
    1369         [ #  # ]:          0 :         if ( aCopyEvent.Error.hasValue() )
    1370         [ #  # ]:          0 :             bContinue = impl_processCopyError_nothrow( aCopyEvent );
    1371                 :            :     }
    1372         [ #  # ]:          0 :     while( bContinue );
    1373                 :          0 : }
    1374                 :            : //-------------------------------------------------------------------------
    1375                 :          0 : void CopyTableWizard::impl_doCopy_nothrow()
    1376                 :            : {
    1377                 :          0 :     Any aError;
    1378                 :            : 
    1379                 :            :     try
    1380                 :            :     {
    1381         [ #  # ]:          0 :         OCopyTableWizard& rWizard( impl_getDialog_throw() );
    1382                 :            : 
    1383 [ #  # ][ #  # ]:          0 :         WaitObject aWO( rWizard.GetParent() );
    1384                 :          0 :         Reference< XPropertySet > xTable;
    1385                 :            : 
    1386   [ #  #  #  # ]:          0 :         switch ( rWizard.getOperation() )
                 [ #  # ]
    1387                 :            :         {
    1388                 :            :             case CopyTableOperation::CopyDefinitionOnly:
    1389                 :            :             case CopyTableOperation::CopyDefinitionAndData:
    1390                 :            :             {
    1391 [ #  # ][ #  # ]:          0 :                 xTable = rWizard.createTable();
    1392                 :            : 
    1393         [ #  # ]:          0 :                 if( !xTable.is() )
    1394                 :            :                 {
    1395                 :            :                     OSL_FAIL( "CopyTableWizard::impl_doCopy_nothrow: createTable should throw here, shouldn't it?" );
    1396                 :          0 :                     break;
    1397                 :            :                 }
    1398                 :            : 
    1399 [ #  # ][ #  # ]:          0 :                 if( CopyTableOperation::CopyDefinitionOnly == rWizard.getOperation() )
    1400                 :          0 :                     break;
    1401                 :            :             }
    1402                 :            :             // run through
    1403                 :            : 
    1404                 :            :             case CopyTableOperation::AppendData:
    1405                 :            :             {
    1406                 :            : 
    1407         [ #  # ]:          0 :                 if ( !xTable.is() )
    1408                 :            :                 {
    1409 [ #  # ][ #  # ]:          0 :                     xTable = rWizard.createTable();
    1410         [ #  # ]:          0 :                     if ( !xTable.is() )
    1411                 :            :                     {
    1412                 :            :                         OSL_FAIL( "CopyTableWizard::impl_doCopy_nothrow: createTable should throw here, shouldn't it?" );
    1413                 :            :                         break;
    1414                 :            :                     }
    1415                 :            :                 }
    1416                 :            : 
    1417         [ #  # ]:          0 :                 ::utl::SharedUNOComponent< XPreparedStatement > xSourceStatement;
    1418         [ #  # ]:          0 :                 ::utl::SharedUNOComponent< XResultSet > xSourceResultSet;
    1419                 :            : 
    1420         [ #  # ]:          0 :                 if ( m_xSourceResultSet.is() )
    1421                 :            :                 {
    1422         [ #  # ]:          0 :                     xSourceResultSet.reset( m_xSourceResultSet, ::utl::SharedUNOComponent< XResultSet >::NoTakeOwnership );
    1423                 :            :                 }
    1424                 :            :                 else
    1425                 :            :                 {
    1426         [ #  # ]:          0 :                     const bool bIsSameConnection = ( m_xSourceConnection.getTyped() == m_xDestConnection.getTyped() );
    1427                 :          0 :                     const bool bIsTable = ( CommandType::TABLE == m_nCommandType );
    1428                 :          0 :                     bool bDone = false;
    1429 [ #  # ][ #  # ]:          0 :                     if ( bIsSameConnection && bIsTable )
    1430                 :            :                     {
    1431                 :            :                         // try whether the server supports copying via SQL
    1432                 :            :                         try
    1433                 :            :                         {
    1434 [ #  # ][ #  # ]:          0 :                             m_xDestConnection->createStatement()->executeUpdate( impl_getServerSideCopyStatement_throw(xTable) );
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
    1435                 :          0 :                             bDone = true;
    1436                 :            :                         }
    1437         [ #  # ]:          0 :                         catch( const Exception& )
    1438                 :            :                         {
    1439                 :            :                             // this is allowed.
    1440                 :            :                         }
    1441                 :            :                     }
    1442                 :            : 
    1443         [ #  # ]:          0 :                     if ( !bDone )
    1444                 :            :                     {
    1445 [ #  # ][ #  # ]:          0 :                         xSourceStatement.set( impl_createSourceStatement_throw(), UNO_SET_THROW );
                 [ #  # ]
    1446 [ #  # ][ #  # ]:          0 :                         xSourceResultSet.set( xSourceStatement->executeQuery(), UNO_SET_THROW );
                 [ #  # ]
    1447                 :            :                     }
    1448                 :            :                 }
    1449                 :            : 
    1450         [ #  # ]:          0 :                 if ( xSourceResultSet.is() )
    1451 [ #  # ][ #  # ]:          0 :                     impl_copyRows_throw( xSourceResultSet, xTable );
                 [ #  # ]
    1452                 :            :             }
    1453                 :          0 :             break;
    1454                 :            : 
    1455                 :            :             case CopyTableOperation::CreateAsView:
    1456         [ #  # ]:          0 :                 rWizard.createView();
    1457                 :          0 :                 break;
    1458                 :            : 
    1459                 :            :             default:
    1460                 :            :                 OSL_FAIL( "CopyTableWizard::impl_doCopy_nothrow: What operation, please?" );
    1461                 :          0 :                 break;
    1462         [ #  # ]:          0 :         }
    1463                 :            :     }
    1464   [ #  #  #  # ]:          0 :     catch( const Exception& )
    1465                 :            :     {
    1466         [ #  # ]:          0 :         aError = ::cppu::getCaughtException();
    1467                 :            : 
    1468                 :            :         // silence the error of the user cancelling the parameter's dialog
    1469         [ #  # ]:          0 :         SQLException aSQLError;
    1470   [ #  #  #  #  :          0 :         if ( ( aError >>= aSQLError ) && ( aSQLError.ErrorCode == ::dbtools::ParameterInteractionCancelled ) )
             #  #  #  # ]
    1471                 :            :         {
    1472                 :          0 :             aError.clear();
    1473                 :          0 :             m_nOverrideExecutionResult = RET_CANCEL;
    1474         [ #  # ]:          0 :         }
    1475                 :            :     }
    1476                 :            : 
    1477 [ #  # ][ #  # ]:          0 :     if ( aError.hasValue() && m_xInteractionHandler.is() )
                 [ #  # ]
    1478                 :            :     {
    1479                 :            :         try
    1480                 :            :         {
    1481         [ #  # ]:          0 :             ::rtl::Reference< ::comphelper::OInteractionRequest > xRequest( new ::comphelper::OInteractionRequest( aError ) );
    1482 [ #  # ][ #  # ]:          0 :             m_xInteractionHandler->handle( xRequest.get() );
         [ #  # ][ #  # ]
                 [ #  # ]
    1483                 :            :         }
    1484         [ #  # ]:          0 :         catch( const Exception& )
    1485                 :            :         {
    1486                 :            :             DBG_UNHANDLED_EXCEPTION();
    1487                 :            :         }
    1488                 :          0 :     }
    1489                 :          0 : }
    1490                 :            : // -----------------------------------------------------------------------------
    1491                 :          0 : ::rtl::OUString CopyTableWizard::impl_getServerSideCopyStatement_throw(const Reference< XPropertySet >& _xTable)
    1492                 :            : {
    1493         [ #  # ]:          0 :     const Reference<XColumnsSupplier> xDestColsSup(_xTable,UNO_QUERY_THROW);
    1494 [ #  # ][ #  # ]:          0 :     const Sequence< ::rtl::OUString> aDestColumnNames = xDestColsSup->getColumns()->getElementNames();
         [ #  # ][ #  # ]
    1495         [ #  # ]:          0 :     const Sequence< ::rtl::OUString > aColumnNames = m_pSourceObject->getColumnNames();
    1496 [ #  # ][ #  # ]:          0 :     const Reference< XDatabaseMetaData > xDestMetaData( m_xDestConnection->getMetaData(), UNO_QUERY_THROW );
                 [ #  # ]
    1497 [ #  # ][ #  # ]:          0 :     const ::rtl::OUString sQuote = xDestMetaData->getIdentifierQuoteString();
    1498                 :          0 :     ::rtl::OUStringBuffer sColumns;
    1499                 :            :     // 1st check if the columns matching
    1500         [ #  # ]:          0 :     const OCopyTableWizard& rWizard             = impl_getDialog_throw();
    1501         [ #  # ]:          0 :     ODatabaseExport::TPositions aColumnMapping  = rWizard.GetColumnPositions();
    1502         [ #  # ]:          0 :     ODatabaseExport::TPositions::const_iterator aPosIter = aColumnMapping.begin();
    1503 [ #  # ][ #  # ]:          0 :     for ( sal_Int32 i = 0; aPosIter != aColumnMapping.end() ; ++aPosIter,++i )
                 [ #  # ]
    1504                 :            :     {
    1505 [ #  # ][ #  # ]:          0 :         if ( COLUMN_POSITION_NOT_FOUND != aPosIter->second )
    1506                 :            :         {
    1507         [ #  # ]:          0 :             if ( sColumns.getLength() )
    1508         [ #  # ]:          0 :                 sColumns.appendAscii(",");
    1509         [ #  # ]:          0 :             sColumns.append(sQuote);
    1510 [ #  # ][ #  # ]:          0 :             sColumns.append(aDestColumnNames[aPosIter->second - 1]);
    1511         [ #  # ]:          0 :             sColumns.append(sQuote);
    1512                 :            :         }
    1513                 :            :     }
    1514                 :          0 :     ::rtl::OUStringBuffer sSql;
    1515         [ #  # ]:          0 :     sSql.appendAscii("INSERT INTO ");
    1516         [ #  # ]:          0 :     const ::rtl::OUString sComposedTableName = ::dbtools::composeTableName( xDestMetaData, _xTable, ::dbtools::eInDataManipulation, false, false, true );
    1517         [ #  # ]:          0 :     sSql.append( sComposedTableName );
    1518         [ #  # ]:          0 :     sSql.appendAscii(" ( ");
    1519 [ #  # ][ #  # ]:          0 :     sSql.append( sColumns.makeStringAndClear() );
    1520         [ #  # ]:          0 :     sSql.appendAscii(" ) ( ");
    1521 [ #  # ][ #  # ]:          0 :     sSql.append( m_pSourceObject->getSelectStatement());
    1522         [ #  # ]:          0 :     sSql.appendAscii(" )");
    1523                 :            : 
    1524 [ #  # ][ #  # ]:          0 :     return sSql.makeStringAndClear();
                 [ #  # ]
    1525                 :            : }
    1526                 :            : //-------------------------------------------------------------------------
    1527                 :          0 : void SAL_CALL CopyTableWizard::initialize( const Sequence< Any >& _rArguments ) throw (Exception, RuntimeException)
    1528                 :            : {
    1529         [ #  # ]:          0 :     ::osl::MutexGuard aGuard( m_aMutex );
    1530 [ #  # ][ #  # ]:          0 :     if ( isInitialized() )
    1531 [ #  # ][ #  # ]:          0 :         throw AlreadyInitializedException( ::rtl::OUString(), *this );
    1532                 :            : 
    1533                 :          0 :     sal_Int32 nArgCount( _rArguments.getLength() );
    1534 [ #  # ][ #  # ]:          0 :     if ( ( nArgCount != 2 ) && ( nArgCount != 3 ) )
    1535                 :            :         throw IllegalArgumentException(
    1536                 :            :             String( ModuleRes( STR_CTW_ILLEGAL_PARAMETER_COUNT ) ),
    1537                 :            :             *this,
    1538                 :            :             1
    1539 [ #  # ][ #  # ]:          0 :         );
         [ #  # ][ #  # ]
                 [ #  # ]
    1540                 :            : 
    1541                 :            :     try
    1542                 :            :     {
    1543         [ #  # ]:          0 :         if ( nArgCount == 3 )
    1544                 :            :         {   // ->createWithInteractionHandler
    1545 [ #  # ][ #  # ]:          0 :             if ( !( _rArguments[2] >>= m_xInteractionHandler ) )
    1546                 :            :                 throw IllegalArgumentException(
    1547                 :            :                     String(ModuleRes( STR_CTW_ERROR_INVALID_INTERACTIONHANDLER )),
    1548                 :            :                     *this,
    1549                 :            :                     3
    1550 [ #  # ][ #  # ]:          0 :                 );
         [ #  # ][ #  # ]
                 [ #  # ]
    1551                 :            :         }
    1552         [ #  # ]:          0 :         if ( !m_xInteractionHandler.is() )
    1553 [ #  # ][ #  # ]:          0 :             m_xInteractionHandler.set( m_aContext.createComponent( "com.sun.star.task.InteractionHandler" ), UNO_QUERY_THROW );
    1554                 :            : 
    1555                 :          0 :         InteractionHandler xSourceDocHandler;
    1556         [ #  # ]:          0 :         Reference< XPropertySet > xSourceDescriptor( impl_ensureDataAccessDescriptor_throw( _rArguments, 0, m_xSourceConnection, xSourceDocHandler ) );
    1557         [ #  # ]:          0 :         impl_checkForUnsupportedSettings_throw( xSourceDescriptor );
    1558 [ #  # ][ #  # ]:          0 :         m_pSourceObject = impl_extractSourceObject_throw( xSourceDescriptor, m_nCommandType );
    1559         [ #  # ]:          0 :         impl_extractSourceResultSet_throw( xSourceDescriptor );
    1560                 :            : 
    1561                 :          0 :         InteractionHandler xDestDocHandler;
    1562         [ #  # ]:          0 :         impl_ensureDataAccessDescriptor_throw( _rArguments, 1, m_xDestConnection, xDestDocHandler );
    1563                 :            : 
    1564 [ #  # ][ #  # ]:          0 :         if ( xDestDocHandler.is() && !m_xInteractionHandler.is() )
                 [ #  # ]
    1565         [ #  # ]:          0 :             m_xInteractionHandler = xDestDocHandler;
    1566                 :            :     }
    1567                 :          0 :     catch( const RuntimeException& ) { throw; }
    1568                 :          0 :     catch( const IllegalArgumentException& ) { throw; }
    1569                 :          0 :     catch( const SQLException& ) { throw; }
    1570   [ #  #  #  #  :          0 :     catch( const Exception& )
                      # ]
    1571                 :            :     {
    1572                 :            :         throw WrappedTargetException(
    1573                 :            :             String( ModuleRes( STR_CTW_ERROR_DURING_INITIALIZATION ) ),
    1574                 :            :             *this,
    1575                 :            :             ::cppu::getCaughtException()
    1576   [ #  #  #  #  :          0 :         );
          #  #  #  #  #  
                #  #  # ]
    1577         [ #  # ]:          0 :     }
    1578                 :          0 : }
    1579                 :            : 
    1580                 :            : //-------------------------------------------------------------------------
    1581                 :          0 : ::cppu::IPropertyArrayHelper& CopyTableWizard::getInfoHelper()
    1582                 :            : {
    1583                 :          0 :     return *getArrayHelper();
    1584                 :            : }
    1585                 :            : 
    1586                 :            : //------------------------------------------------------------------------------
    1587                 :          0 : ::cppu::IPropertyArrayHelper* CopyTableWizard::createArrayHelper( ) const
    1588                 :            : {
    1589         [ #  # ]:          0 :     Sequence< Property > aProps;
    1590         [ #  # ]:          0 :     describeProperties( aProps );
    1591 [ #  # ][ #  # ]:          0 :     return new ::cppu::OPropertyArrayHelper( aProps );
    1592                 :            : }
    1593                 :            : 
    1594                 :            : //------------------------------------------------------------------------------
    1595                 :          0 : Dialog* CopyTableWizard::createDialog( Window* _pParent )
    1596                 :            : {
    1597                 :            :     OSL_PRECOND( isInitialized(), "CopyTableWizard::createDialog: not initialized!" );
    1598                 :            :         // this should have been prevented in ::execute already
    1599                 :            : 
    1600                 :            :     OCopyTableWizard* pWizard = new OCopyTableWizard(
    1601                 :            :         _pParent,
    1602                 :            :         m_sDestinationTable,
    1603                 :            :         m_nOperation,
    1604                 :          0 :         *m_pSourceObject,
    1605                 :          0 :         m_xSourceConnection.getTyped(),
    1606                 :          0 :         m_xDestConnection.getTyped(),
    1607                 :            :         m_aContext.getLegacyServiceFactory(),
    1608                 :            :         m_xInteractionHandler
    1609 [ #  # ][ #  # ]:          0 :     );
    1610                 :            : 
    1611                 :          0 :     impl_attributesToDialog_nothrow( *pWizard );
    1612                 :            : 
    1613                 :          0 :     return pWizard;
    1614                 :            : }
    1615                 :            : 
    1616                 :            : //------------------------------------------------------------------------------
    1617                 :          0 : void CopyTableWizard::executedDialog( sal_Int16 _nExecutionResult )
    1618                 :            : {
    1619                 :          0 :     CopyTableWizard_DialogBase::executedDialog( _nExecutionResult );
    1620                 :            : 
    1621         [ #  # ]:          0 :     if ( _nExecutionResult == RET_OK )
    1622                 :          0 :         impl_doCopy_nothrow();
    1623                 :            : 
    1624                 :            :     // do this after impl_doCopy_nothrow: The attributes may change during copying, for instance
    1625                 :            :     // if the user entered an unqualified table name
    1626                 :          0 :     impl_dialogToAttributes_nothrow( impl_getDialog_throw() );
    1627                 :          0 : }
    1628                 :            : 
    1629                 :            : //........................................................................
    1630                 :            : } // namespace dbaui
    1631                 :            : //........................................................................
    1632                 :            : 
    1633                 :          8 : extern "C" void SAL_CALL createRegistryInfo_CopyTableWizard()
    1634                 :            : {
    1635 [ +  - ][ +  - ]:          8 :     static ::dbaui::OMultiInstanceAutoRegistration< ::dbaui::CopyTableWizard > aAutoRegistration;
         [ +  - ][ #  # ]
    1636                 :          8 : }
    1637                 :            : 
    1638                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10