LCOV - code coverage report
Current view: top level - dbaccess/source/ui/misc - WCopyTable.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 783 0.0 %
Date: 2014-04-14 Functions: 0 82 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include "dbu_misc.hrc"
      21             : #include "dbustrings.hrc"
      22             : #include "moduledbu.hxx"
      23             : #include "sqlmessage.hxx"
      24             : #include "UITools.hxx"
      25             : #include "WColumnSelect.hxx"
      26             : #include "WCopyTable.hxx"
      27             : #include "WCPage.hxx"
      28             : #include "WExtendPages.hxx"
      29             : #include "WizardPages.hrc"
      30             : #include "WNameMatch.hxx"
      31             : #include "WTypeSelect.hxx"
      32             : 
      33             : #include <com/sun/star/sdb/application/CopyTableOperation.hpp>
      34             : #include <com/sun/star/sdb/SQLContext.hpp>
      35             : #include <com/sun/star/sdbc/ColumnValue.hpp>
      36             : #include <com/sun/star/sdbc/DataType.hpp>
      37             : #include <com/sun/star/sdbc/XResultSet.hpp>
      38             : #include <com/sun/star/sdbc/XRow.hpp>
      39             : #include <com/sun/star/sdbcx/KeyType.hpp>
      40             : #include <com/sun/star/sdbcx/XAppend.hpp>
      41             : #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
      42             : #include <com/sun/star/sdbcx/XDataDescriptorFactory.hpp>
      43             : #include <com/sun/star/sdbcx/XKeysSupplier.hpp>
      44             : #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
      45             : #include <com/sun/star/sdbcx/XViewsSupplier.hpp>
      46             : #include <com/sun/star/sdbc/XResultSetMetaDataSupplier.hpp>
      47             : #include <com/sun/star/task/InteractionHandler.hpp>
      48             : 
      49             : #include <comphelper/extract.hxx>
      50             : #include <comphelper/processfactory.hxx>
      51             : #include <comphelper/types.hxx>
      52             : #include <comphelper/interaction.hxx>
      53             : #include <connectivity/dbtools.hxx>
      54             : #include <connectivity/dbmetadata.hxx>
      55             : #include <connectivity/dbexception.hxx>
      56             : 
      57             : #include <rtl/ustrbuf.hxx>
      58             : #include <tools/debug.hxx>
      59             : #include <tools/diagnose_ex.h>
      60             : #include <vcl/lstbox.hxx>
      61             : #include <vcl/msgbox.hxx>
      62             : #include <vcl/waitobj.hxx>
      63             : 
      64             : #include <functional>
      65             : #include <o3tl/compat_functional.hxx>
      66             : 
      67             : using namespace ::dbaui;
      68             : using namespace ::com::sun::star::uno;
      69             : using namespace ::com::sun::star::beans;
      70             : using namespace ::com::sun::star::container;
      71             : using namespace ::com::sun::star::util;
      72             : using namespace ::com::sun::star::sdb;
      73             : using namespace ::com::sun::star::sdbc;
      74             : using namespace ::com::sun::star::sdbcx;
      75             : using namespace ::com::sun::star::lang;
      76             : using namespace ::com::sun::star::task;
      77             : using namespace dbtools;
      78             : 
      79             : namespace CopyTableOperation = ::com::sun::star::sdb::application::CopyTableOperation;
      80             : 
      81             : #define MAX_PAGES   4   // max. number of pages, which are shown
      82             : 
      83             : namespace
      84             : {
      85           0 :     void clearColumns(ODatabaseExport::TColumns& _rColumns, ODatabaseExport::TColumnVector& _rColumnsVec)
      86             :     {
      87           0 :         ODatabaseExport::TColumns::iterator aIter = _rColumns.begin();
      88           0 :         ODatabaseExport::TColumns::iterator aEnd  = _rColumns.end();
      89             : 
      90           0 :         for(;aIter != aEnd;++aIter)
      91           0 :             delete aIter->second;
      92             : 
      93           0 :         _rColumnsVec.clear();
      94           0 :         _rColumns.clear();
      95           0 :     }
      96             : }
      97             : 
      98             : // ICopyTableSourceObject
      99           0 : ICopyTableSourceObject::~ICopyTableSourceObject()
     100             : {
     101           0 : }
     102             : 
     103             : // ObjectCopySource
     104           0 : ObjectCopySource::ObjectCopySource( const Reference< XConnection >& _rxConnection, const Reference< XPropertySet >& _rxObject )
     105             :     :m_xConnection( _rxConnection, UNO_SET_THROW )
     106           0 :     ,m_xMetaData( _rxConnection->getMetaData(), UNO_SET_THROW )
     107             :     ,m_xObject( _rxObject, UNO_SET_THROW )
     108           0 :     ,m_xObjectPSI( _rxObject->getPropertySetInfo(), UNO_SET_THROW )
     109           0 :     ,m_xObjectColumns( Reference< XColumnsSupplier >( _rxObject, UNO_QUERY_THROW )->getColumns(), UNO_SET_THROW )
     110             : {
     111           0 : }
     112             : 
     113           0 : OUString ObjectCopySource::getQualifiedObjectName() const
     114             : {
     115           0 :     OUString sName;
     116             : 
     117           0 :     if ( !m_xObjectPSI->hasPropertyByName( PROPERTY_COMMAND ) )
     118           0 :         sName = ::dbtools::composeTableName( m_xMetaData, m_xObject, ::dbtools::eInDataManipulation, false, false, false );
     119             :     else
     120           0 :         m_xObject->getPropertyValue( PROPERTY_NAME ) >>= sName;
     121           0 :     return sName;
     122             : }
     123             : 
     124           0 : bool ObjectCopySource::isView() const
     125             : {
     126           0 :     bool bIsView = false;
     127             :     try
     128             :     {
     129           0 :         if ( m_xObjectPSI->hasPropertyByName( PROPERTY_TYPE ) )
     130             :         {
     131           0 :             OUString sObjectType;
     132           0 :             OSL_VERIFY( m_xObject->getPropertyValue( PROPERTY_TYPE ) >>= sObjectType );
     133           0 :             bIsView = sObjectType == "VIEW";
     134             :         }
     135             :     }
     136           0 :     catch( const Exception& )
     137             :     {
     138             :         DBG_UNHANDLED_EXCEPTION();
     139             :     }
     140           0 :     return bIsView;
     141             : }
     142             : 
     143           0 : void ObjectCopySource::copyUISettingsTo( const Reference< XPropertySet >& _rxObject ) const
     144             : {
     145             :     const OUString aCopyProperties[] = {
     146             :         OUString(PROPERTY_FONT), OUString(PROPERTY_ROW_HEIGHT), OUString(PROPERTY_TEXTCOLOR),OUString(PROPERTY_TEXTLINECOLOR),OUString(PROPERTY_TEXTEMPHASIS),OUString(PROPERTY_TEXTRELIEF)
     147           0 :     };
     148           0 :     for ( size_t i=0; i < sizeof( aCopyProperties ) / sizeof( aCopyProperties[0] ); ++i )
     149             :     {
     150           0 :         if ( m_xObjectPSI->hasPropertyByName( aCopyProperties[i] ) )
     151           0 :             _rxObject->setPropertyValue( aCopyProperties[i], m_xObject->getPropertyValue( aCopyProperties[i] ) );
     152           0 :     }
     153           0 : }
     154             : 
     155           0 : void ObjectCopySource::copyFilterAndSortingTo( const Reference< XConnection >& _xConnection,const Reference< XPropertySet >& _rxObject ) const
     156             : {
     157             :     ::std::pair< OUString, OUString > aProperties[] = {
     158             :                  ::std::pair< OUString, OUString >(PROPERTY_FILTER,OUString(" AND "))
     159             :                 ,::std::pair< OUString, OUString >(PROPERTY_ORDER,OUString(" ORDER BY "))
     160           0 :     };
     161             : 
     162             :     try
     163             :     {
     164           0 :         const OUString sSourceName = ::dbtools::composeTableNameForSelect(m_xConnection,m_xObject) + ".";
     165           0 :         const OUString sTargetName = ::dbtools::composeTableNameForSelect(_xConnection,_rxObject);
     166           0 :         const OUString sTargetNameTemp = sTargetName + ".";
     167             : 
     168           0 :         OUString sStatement = "SELECT * FROM " + sTargetName + " WHERE 0=1";
     169             : 
     170           0 :         for ( size_t i=0; i < SAL_N_ELEMENTS(aProperties); ++i )
     171             :         {
     172           0 :             if ( m_xObjectPSI->hasPropertyByName( aProperties[i].first ) )
     173             :             {
     174           0 :                 OUString sFilter;
     175           0 :                 m_xObject->getPropertyValue( aProperties[i].first ) >>= sFilter;
     176           0 :                 if ( !sFilter.isEmpty() )
     177             :                 {
     178           0 :                     sStatement += aProperties[i].second;
     179           0 :                     OUString sReplace = sFilter;
     180           0 :                     sReplace = sReplace.replaceFirst(sSourceName,sTargetNameTemp);
     181           0 :                     sFilter = sReplace;
     182           0 :                     _rxObject->setPropertyValue( aProperties[i].first, makeAny(sFilter) );
     183           0 :                     sStatement += sFilter;
     184           0 :                 }
     185             :             }
     186             :         }
     187             : 
     188           0 :         _xConnection->createStatement()->executeQuery(sStatement);
     189             : 
     190           0 :         if ( m_xObjectPSI->hasPropertyByName( PROPERTY_APPLYFILTER ) )
     191           0 :             _rxObject->setPropertyValue( PROPERTY_APPLYFILTER, m_xObject->getPropertyValue( PROPERTY_APPLYFILTER ) );
     192             :     }
     193           0 :     catch(Exception&)
     194             :     {
     195           0 :     }
     196           0 : }
     197             : 
     198           0 : Sequence< OUString > ObjectCopySource::getColumnNames() const
     199             : {
     200           0 :     return m_xObjectColumns->getElementNames();
     201             : }
     202             : 
     203           0 : Sequence< OUString > ObjectCopySource::getPrimaryKeyColumnNames() const
     204             : {
     205           0 :     const Reference<XNameAccess> xPrimaryKeyColumns = getPrimaryKeyColumns_throw(m_xObject);
     206           0 :     Sequence< OUString > aKeyColNames;
     207           0 :     if ( xPrimaryKeyColumns.is() )
     208           0 :         aKeyColNames = xPrimaryKeyColumns->getElementNames();
     209           0 :     return aKeyColNames;
     210             : }
     211             : 
     212           0 : OFieldDescription* ObjectCopySource::createFieldDescription( const OUString& _rColumnName ) const
     213             : {
     214           0 :     Reference< XPropertySet > xColumn( m_xObjectColumns->getByName( _rColumnName ), UNO_QUERY_THROW );
     215           0 :     return new OFieldDescription( xColumn );
     216             : }
     217             : 
     218           0 : OUString ObjectCopySource::getSelectStatement() const
     219             : {
     220           0 :     OUString sSelectStatement;
     221           0 :     if ( m_xObjectPSI->hasPropertyByName( PROPERTY_COMMAND ) )
     222             :     {   // query
     223           0 :         OSL_VERIFY( m_xObject->getPropertyValue( PROPERTY_COMMAND ) >>= sSelectStatement );
     224             :     }
     225             :     else
     226             :     {   // table
     227           0 :         OUStringBuffer aSQL;
     228           0 :         aSQL.appendAscii( "SELECT " );
     229             : 
     230             :         // we need to create the sql stmt with column names
     231             :         // otherwise it is possible that names don't match
     232           0 :         const OUString sQuote = m_xMetaData->getIdentifierQuoteString();
     233             : 
     234           0 :         Sequence< OUString > aColumnNames = getColumnNames();
     235           0 :         const OUString* pColumnName = aColumnNames.getConstArray();
     236           0 :         const OUString* pEnd = pColumnName + aColumnNames.getLength();
     237           0 :         for ( ; pColumnName != pEnd; )
     238             :         {
     239           0 :             aSQL.append( ::dbtools::quoteName( sQuote, *pColumnName++ ) );
     240             : 
     241           0 :             if ( pColumnName == pEnd )
     242           0 :                 aSQL.appendAscii( " " );
     243             :             else
     244           0 :                 aSQL.appendAscii( ", " );
     245             :         }
     246             : 
     247           0 :         aSQL.append( "FROM " + ::dbtools::composeTableNameForSelect( m_xConnection, m_xObject ) );
     248             : 
     249           0 :         sSelectStatement = aSQL.makeStringAndClear();
     250             :     }
     251             : 
     252           0 :     return sSelectStatement;
     253             : }
     254             : 
     255           0 : ::utl::SharedUNOComponent< XPreparedStatement > ObjectCopySource::getPreparedSelectStatement() const
     256             : {
     257             :     ::utl::SharedUNOComponent< XPreparedStatement > xStatement(
     258           0 :         m_xConnection->prepareStatement( getSelectStatement() ),
     259             :         ::utl::SharedUNOComponent< XPreparedStatement >::TakeOwnership
     260           0 :     );
     261           0 :     return xStatement;
     262             : }
     263             : 
     264             : // NamedTableCopySource
     265           0 : NamedTableCopySource::NamedTableCopySource( const Reference< XConnection >& _rxConnection, const OUString& _rTableName )
     266             :     :m_xConnection( _rxConnection, UNO_SET_THROW )
     267           0 :     ,m_xMetaData( _rxConnection->getMetaData(), UNO_SET_THROW )
     268             :     ,m_sTableName( _rTableName )
     269           0 :     ,m_aColumnInfo()
     270             : {
     271           0 :     ::dbtools::qualifiedNameComponents( m_xMetaData, m_sTableName, m_sTableCatalog, m_sTableSchema, m_sTableBareName, ::dbtools::eComplete );
     272           0 :     impl_ensureColumnInfo_throw();
     273           0 : }
     274             : 
     275           0 : OUString NamedTableCopySource::getQualifiedObjectName() const
     276             : {
     277           0 :     return m_sTableName;
     278             : }
     279             : 
     280           0 : bool NamedTableCopySource::isView() const
     281             : {
     282           0 :     OUString sTableType;
     283             :     try
     284             :     {
     285           0 :         Reference< XResultSet > xTableDesc( m_xMetaData->getTables( makeAny( m_sTableCatalog ), m_sTableSchema, m_sTableBareName,
     286           0 :             Sequence< OUString >() ) );
     287           0 :         Reference< XRow > xTableDescRow( xTableDesc, UNO_QUERY_THROW );
     288           0 :         OSL_VERIFY( xTableDesc->next() );
     289           0 :         sTableType = xTableDescRow->getString( 4 );
     290           0 :         OSL_ENSURE( !xTableDescRow->wasNull(), "NamedTableCopySource::isView: invalid table type!" );
     291             :     }
     292           0 :     catch( const Exception& )
     293             :     {
     294             :         DBG_UNHANDLED_EXCEPTION();
     295             :     }
     296           0 :     return sTableType == "VIEW";
     297             : }
     298             : 
     299           0 : void NamedTableCopySource::copyUISettingsTo( const Reference< XPropertySet >& /*_rxObject*/ ) const
     300             : {
     301             :     // not supported: we do not have UI settings to copy
     302           0 : }
     303             : 
     304           0 : void NamedTableCopySource::copyFilterAndSortingTo( const Reference< XConnection >& ,const Reference< XPropertySet >& /*_rxObject*/ ) const
     305             : {
     306           0 : }
     307             : 
     308           0 : void NamedTableCopySource::impl_ensureColumnInfo_throw()
     309             : {
     310           0 :     if ( !m_aColumnInfo.empty() )
     311           0 :         return;
     312             : 
     313           0 :     Reference< XResultSetMetaDataSupplier > xStatementMetaSupp( impl_ensureStatement_throw().getTyped(), UNO_QUERY_THROW );
     314           0 :     Reference< XResultSetMetaData > xStatementMeta( xStatementMetaSupp->getMetaData(), UNO_SET_THROW );
     315             : 
     316           0 :     sal_Int32 nColCount( xStatementMeta->getColumnCount() );
     317           0 :     for ( sal_Int32 i = 1; i <= nColCount; ++i )
     318             :     {
     319           0 :         OFieldDescription aDesc;
     320             : 
     321           0 :         aDesc.SetName(          xStatementMeta->getColumnName(      i ) );
     322           0 :         aDesc.SetHelpText(      xStatementMeta->getColumnLabel(     i ) );
     323           0 :         aDesc.SetTypeValue(     xStatementMeta->getColumnType(      i ) );
     324           0 :         aDesc.SetTypeName(      xStatementMeta->getColumnTypeName(  i ) );
     325           0 :         aDesc.SetPrecision(     xStatementMeta->getPrecision(       i ) );
     326           0 :         aDesc.SetScale(         xStatementMeta->getScale(           i ) );
     327           0 :         aDesc.SetIsNullable(    xStatementMeta->isNullable(         i ) );
     328           0 :         aDesc.SetCurrency(      xStatementMeta->isCurrency(         i ) );
     329           0 :         aDesc.SetAutoIncrement( xStatementMeta->isAutoIncrement(    i ) );
     330             : 
     331           0 :         m_aColumnInfo.push_back( aDesc );
     332           0 :     }
     333             : }
     334             : 
     335           0 : ::utl::SharedUNOComponent< XPreparedStatement > NamedTableCopySource::impl_ensureStatement_throw()
     336             : {
     337           0 :     if ( !m_xStatement.is() )
     338           0 :         m_xStatement.set( m_xConnection->prepareStatement( getSelectStatement() ), UNO_SET_THROW );
     339           0 :     return m_xStatement;
     340             : }
     341             : 
     342           0 : Sequence< OUString > NamedTableCopySource::getColumnNames() const
     343             : {
     344           0 :     Sequence< OUString > aNames( m_aColumnInfo.size() );
     345           0 :     for (   ::std::vector< OFieldDescription >::const_iterator col = m_aColumnInfo.begin();
     346           0 :             col != m_aColumnInfo.end();
     347             :             ++col
     348             :         )
     349           0 :         aNames[ col - m_aColumnInfo.begin() ] = col->GetName();
     350             : 
     351           0 :     return aNames;
     352             : }
     353             : 
     354           0 : Sequence< OUString > NamedTableCopySource::getPrimaryKeyColumnNames() const
     355             : {
     356           0 :     Sequence< OUString > aPKColNames;
     357             : 
     358             :     try
     359             :     {
     360           0 :         Reference< XResultSet > xPKDesc( m_xMetaData->getPrimaryKeys( makeAny( m_sTableCatalog ), m_sTableSchema, m_sTableBareName ) );
     361           0 :         Reference< XRow > xPKDescRow( xPKDesc, UNO_QUERY_THROW );
     362           0 :         while ( xPKDesc->next() )
     363             :         {
     364           0 :             sal_Int32 len( aPKColNames.getLength() );
     365           0 :             aPKColNames.realloc( len + 1 );
     366           0 :             aPKColNames[ len ] = xPKDescRow->getString( 4 );    // COLUMN_NAME
     367           0 :         }
     368             :     }
     369           0 :     catch( const Exception& )
     370             :     {
     371             :         DBG_UNHANDLED_EXCEPTION();
     372             :     }
     373             : 
     374           0 :     return aPKColNames;
     375             : }
     376             : 
     377           0 : OFieldDescription* NamedTableCopySource::createFieldDescription( const OUString& _rColumnName ) const
     378             : {
     379           0 :     for (   ::std::vector< OFieldDescription >::const_iterator col = m_aColumnInfo.begin();
     380           0 :             col != m_aColumnInfo.end();
     381             :             ++col
     382             :         )
     383           0 :         if ( col->GetName() == _rColumnName )
     384           0 :             return new OFieldDescription( *col );
     385             : 
     386           0 :     return NULL;
     387             : }
     388             : 
     389           0 : OUString NamedTableCopySource::getSelectStatement() const
     390             : {
     391           0 :     OUStringBuffer aSQL;
     392           0 :     aSQL.appendAscii( "SELECT * FROM " );
     393             : 
     394           0 :     aSQL.append( ::dbtools::composeTableNameForSelect( m_xConnection, m_sTableCatalog, m_sTableSchema, m_sTableBareName ) );
     395             : 
     396           0 :     return aSQL.makeStringAndClear();
     397             : }
     398             : 
     399           0 : ::utl::SharedUNOComponent< XPreparedStatement > NamedTableCopySource::getPreparedSelectStatement() const
     400             : {
     401           0 :     return const_cast< NamedTableCopySource* >( this )->impl_ensureStatement_throw();
     402             : }
     403             : 
     404             : // DummyCopySource
     405           0 : class DummyCopySource : public ICopyTableSourceObject
     406             : {
     407             : public:
     408           0 :     DummyCopySource() { }
     409             : 
     410             :     static const DummyCopySource& Instance();
     411             : 
     412             :     // ICopyTableSourceObject overridables
     413             :     virtual OUString     getQualifiedObjectName() const SAL_OVERRIDE;
     414             :     virtual bool                isView() const SAL_OVERRIDE;
     415             :     virtual void                copyUISettingsTo( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxObject ) const SAL_OVERRIDE;
     416             :     virtual void                copyFilterAndSortingTo(const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >& _xConnection, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxObject ) const SAL_OVERRIDE;
     417             :     virtual ::com::sun::star::uno::Sequence< OUString >
     418             :                                 getColumnNames() const SAL_OVERRIDE;
     419             :     virtual ::com::sun::star::uno::Sequence< OUString >
     420             :                                 getPrimaryKeyColumnNames() const SAL_OVERRIDE;
     421             :     virtual OFieldDescription*  createFieldDescription( const OUString& _rColumnName ) const SAL_OVERRIDE;
     422             :     virtual OUString     getSelectStatement() const SAL_OVERRIDE;
     423             :     virtual ::utl::SharedUNOComponent< XPreparedStatement >
     424             :                                 getPreparedSelectStatement() const SAL_OVERRIDE;
     425             : };
     426             : 
     427           0 : const DummyCopySource& DummyCopySource::Instance()
     428             : {
     429           0 :     static DummyCopySource s_aTheInstance;
     430           0 :     return s_aTheInstance;
     431             : }
     432             : 
     433           0 : OUString DummyCopySource::getQualifiedObjectName() const
     434             : {
     435             :     SAL_WARN("dbaccess.ui",  "DummyCopySource::getQualifiedObjectName: not to be called!" );
     436           0 :     return OUString();
     437             : }
     438             : 
     439           0 : bool DummyCopySource::isView() const
     440             : {
     441             :     SAL_WARN("dbaccess.ui",  "DummyCopySource::isView: not to be called!" );
     442           0 :     return false;
     443             : }
     444             : 
     445           0 : void DummyCopySource::copyUISettingsTo( const Reference< XPropertySet >& /*_rxObject*/ ) const
     446             : {
     447             :     // no support
     448           0 : }
     449             : 
     450           0 : void DummyCopySource::copyFilterAndSortingTo( const Reference< XConnection >& ,const Reference< XPropertySet >& /*_rxObject*/ ) const
     451             : {
     452           0 : }
     453             : 
     454           0 : Sequence< OUString > DummyCopySource::getColumnNames() const
     455             : {
     456           0 :     return Sequence< OUString >();
     457             : }
     458             : 
     459           0 : Sequence< OUString > DummyCopySource::getPrimaryKeyColumnNames() const
     460             : {
     461             :     SAL_WARN("dbaccess.ui",  "DummyCopySource::getPrimaryKeyColumnNames: not to be called!" );
     462           0 :     return Sequence< OUString >();
     463             : }
     464             : 
     465           0 : OFieldDescription* DummyCopySource::createFieldDescription( const OUString& /*_rColumnName*/ ) const
     466             : {
     467             :     SAL_WARN("dbaccess.ui",  "DummyCopySource::createFieldDescription: not to be called!" );
     468           0 :     return NULL;
     469             : }
     470             : 
     471           0 : OUString DummyCopySource::getSelectStatement() const
     472             : {
     473             :     SAL_WARN("dbaccess.ui",  "DummyCopySource::getSelectStatement: not to be called!" );
     474           0 :     return OUString();
     475             : }
     476             : 
     477           0 : ::utl::SharedUNOComponent< XPreparedStatement > DummyCopySource::getPreparedSelectStatement() const
     478             : {
     479             :     SAL_WARN("dbaccess.ui",  "DummyCopySource::getPreparedSelectStatement: not to be called!" );
     480           0 :     return ::utl::SharedUNOComponent< XPreparedStatement >();
     481             : }
     482             : 
     483             : namespace
     484             : {
     485           0 :     bool lcl_canCreateViewFor_nothrow( const Reference< XConnection >& _rxConnection )
     486             :     {
     487           0 :         Reference< XViewsSupplier > xSup( _rxConnection, UNO_QUERY );
     488           0 :         Reference< XDataDescriptorFactory > xViewFac;
     489           0 :         if ( xSup.is() )
     490           0 :             xViewFac.set( xSup->getViews(), UNO_QUERY );
     491           0 :         return xViewFac.is();
     492             :     }
     493             : 
     494           0 :     bool lcl_sameConnection_throw( const Reference< XConnection >& _rxLHS, const Reference< XConnection >& _rxRHS )
     495             :     {
     496           0 :         Reference< XDatabaseMetaData > xMetaLHS( _rxLHS->getMetaData(), UNO_QUERY_THROW );
     497           0 :         Reference< XDatabaseMetaData > xMetaRHS( _rxRHS->getMetaData(), UNO_QUERY_THROW );
     498           0 :         return xMetaLHS->getURL().equals( xMetaRHS->getURL() );
     499             :     }
     500             : }
     501             : 
     502             : // OCopyTableWizard
     503           0 : OCopyTableWizard::OCopyTableWizard( Window * pParent, const OUString& _rDefaultName, sal_Int16 _nOperation,
     504             :         const ICopyTableSourceObject& _rSourceObject, const Reference< XConnection >& _xSourceConnection,
     505             :         const Reference< XConnection >& _xConnection, const Reference< XComponentContext >& _rxContext,
     506             :         const Reference< XInteractionHandler>&   _xInteractionHandler)
     507             :     : WizardDialog( pParent, ModuleRes(WIZ_RTFCOPYTABLE))
     508             :     ,m_pbHelp( this , ModuleRes(PB_HELP))
     509             :     ,m_pbCancel( this , ModuleRes(PB_CANCEL))
     510             :     ,m_pbPrev( this , ModuleRes(PB_PREV))
     511             :     ,m_pbNext( this , ModuleRes(PB_NEXT))
     512             :     ,m_pbFinish( this , ModuleRes(PB_OK))
     513           0 :     ,m_mNameMapping(_xConnection->getMetaData().is() && _xConnection->getMetaData()->supportsMixedCaseQuotedIdentifiers())
     514             :     ,m_xDestConnection( _xConnection )
     515             :     ,m_rSourceObject( _rSourceObject )
     516             :     ,m_xFormatter( getNumberFormatter( _xConnection, _rxContext ) )
     517             :     ,m_xContext(_rxContext)
     518             :     ,m_xInteractionHandler(_xInteractionHandler)
     519             :     ,m_sTypeNames(ModuleRes(STR_TABLEDESIGN_DBFIELDTYPES))
     520             :     ,m_nPageCount(0)
     521             :     ,m_bDeleteSourceColumns(sal_True)
     522           0 :     ,m_bInterConnectionCopy( _xSourceConnection != _xConnection )
     523             :     ,m_sName( _rDefaultName )
     524             :     ,m_nOperation( _nOperation )
     525             :     ,m_ePressed( WIZARD_NONE )
     526           0 :     ,m_bCreatePrimaryKeyColumn(sal_False)
     527             : {
     528             :     SAL_INFO("dbaccess.ui", "OCopyTableWizard::OCopyTableWizard" );
     529           0 :     construct();
     530             : 
     531             :     // extract table name
     532           0 :     OUString sInitialTableName( _rDefaultName );
     533             :     try
     534             :     {
     535           0 :         m_sSourceName = m_rSourceObject.getQualifiedObjectName();
     536             :         OSL_ENSURE( !m_sSourceName.isEmpty(), "OCopyTableWizard::OCopyTableWizard: unable to retrieve the source object's name!" );
     537             : 
     538           0 :         if ( sInitialTableName.isEmpty() )
     539           0 :             sInitialTableName = m_sSourceName;
     540             : 
     541           0 :         if ( m_sName.isEmpty() )
     542             :         {
     543           0 :             if ( _xSourceConnection == m_xDestConnection )
     544             :             {
     545           0 :                 Reference< XTablesSupplier > xSup( m_xDestConnection, UNO_QUERY_THROW );
     546           0 :                 m_sName = ::dbtools::createUniqueName( xSup->getTables(), sInitialTableName, false );
     547             :             }
     548             :             else
     549           0 :                 m_sName = sInitialTableName;
     550             :         }
     551             :     }
     552           0 :     catch ( const Exception& )
     553             :     {
     554           0 :         m_sName = sInitialTableName;
     555             :     }
     556             : 
     557           0 :     ::dbaui::fillTypeInfo( _xSourceConnection, m_sTypeNames, m_aTypeInfo, m_aTypeInfoIndex );
     558           0 :     ::dbaui::fillTypeInfo( m_xDestConnection, m_sTypeNames, m_aDestTypeInfo, m_aDestTypeInfoIndex );
     559           0 :     impl_loadSourceData();
     560             : 
     561           0 :     bool bAllowViews = true;
     562             :     // if the source is a, don't allow creating views
     563           0 :     if ( m_rSourceObject.isView() )
     564           0 :         bAllowViews = false;
     565             :     // no views if the target connection does not support creating them
     566           0 :     if ( !lcl_canCreateViewFor_nothrow( m_xDestConnection ) )
     567           0 :         bAllowViews = false;
     568             :     // no views if we're copying to a different database
     569           0 :     if ( !lcl_sameConnection_throw( _xSourceConnection, m_xDestConnection ) )
     570           0 :         bAllowViews = false;
     571             : 
     572           0 :     if ( m_bInterConnectionCopy )
     573             :     {
     574           0 :         Reference< XDatabaseMetaData > xSrcMeta = _xSourceConnection->getMetaData();
     575           0 :         OUString sCatalog;
     576           0 :         OUString sSchema;
     577           0 :         OUString sTable;
     578             :         ::dbtools::qualifiedNameComponents( xSrcMeta,
     579             :                                             m_sName,
     580             :                                             sCatalog,
     581             :                                             sSchema,
     582             :                                             sTable,
     583           0 :                                             ::dbtools::eInDataManipulation);
     584             : 
     585           0 :         m_sName = ::dbtools::composeTableName(m_xDestConnection->getMetaData(),sCatalog,sSchema,sTable,false,::dbtools::eInTableDefinitions);
     586             :     }
     587             : 
     588           0 :     OCopyTable* pPage1( new OCopyTable( this ) );
     589           0 :     pPage1->disallowUseHeaderLine();
     590           0 :     if ( !bAllowViews )
     591           0 :         pPage1->disallowViews();
     592           0 :     pPage1->setCreateStyleAction();
     593           0 :     AddWizardPage(pPage1);
     594             : 
     595           0 :     AddWizardPage( new OWizNameMatching( this ) );
     596           0 :     AddWizardPage( new OWizColumnSelect( this ) );
     597           0 :     AddWizardPage( new OWizNormalExtend( this ) );
     598           0 :     ActivatePage();
     599           0 : }
     600             : 
     601           0 : OCopyTableWizard::OCopyTableWizard( Window* pParent, const OUString& _rDefaultName, sal_Int16 _nOperation,
     602             :         const ODatabaseExport::TColumns& _rSourceColumns, const ODatabaseExport::TColumnVector& _rSourceColVec,
     603             :         const Reference< XConnection >& _xConnection, const Reference< XNumberFormatter >&  _xFormatter,
     604             :         TypeSelectionPageFactory _pTypeSelectionPageFactory, SvStream& _rTypeSelectionPageArg, const Reference< XComponentContext >& _rxContext )
     605             :     :WizardDialog( pParent, ModuleRes(WIZ_RTFCOPYTABLE))
     606             :     ,m_vSourceColumns(_rSourceColumns)
     607             :     ,m_pbHelp( this , ModuleRes(PB_HELP))
     608             :     ,m_pbCancel( this , ModuleRes(PB_CANCEL))
     609             :     ,m_pbPrev( this , ModuleRes(PB_PREV))
     610             :     ,m_pbNext( this , ModuleRes(PB_NEXT))
     611             :     ,m_pbFinish( this , ModuleRes(PB_OK))
     612           0 :     ,m_mNameMapping(_xConnection->getMetaData().is() && _xConnection->getMetaData()->supportsMixedCaseQuotedIdentifiers())
     613             :     ,m_xDestConnection( _xConnection )
     614           0 :     ,m_rSourceObject( DummyCopySource::Instance() )
     615             :     ,m_xFormatter(_xFormatter)
     616             :     ,m_xContext(_rxContext)
     617             :     ,m_sTypeNames(ModuleRes(STR_TABLEDESIGN_DBFIELDTYPES))
     618             :     ,m_nPageCount(0)
     619             :     ,m_bDeleteSourceColumns(sal_False)
     620             :     ,m_bInterConnectionCopy( false )
     621             :     ,m_sName(_rDefaultName)
     622             :     ,m_nOperation( _nOperation )
     623             :     ,m_ePressed( WIZARD_NONE )
     624           0 :     ,m_bCreatePrimaryKeyColumn(sal_False)
     625             : {
     626             :     SAL_INFO("dbaccess.ui", "OCopyTableWizard::OCopyTableWizard" );
     627           0 :     construct();
     628           0 :     ODatabaseExport::TColumnVector::const_iterator aIter = _rSourceColVec.begin();
     629           0 :     ODatabaseExport::TColumnVector::const_iterator aEnd = _rSourceColVec.end();
     630           0 :     for (; aIter != aEnd ; ++aIter)
     631             :     {
     632           0 :         m_vSourceVec.push_back(m_vSourceColumns.find((*aIter)->first));
     633             :     }
     634             : 
     635           0 :     ::dbaui::fillTypeInfo( _xConnection, m_sTypeNames, m_aTypeInfo, m_aTypeInfoIndex );
     636           0 :     ::dbaui::fillTypeInfo( _xConnection, m_sTypeNames, m_aDestTypeInfo, m_aDestTypeInfoIndex );
     637             : 
     638           0 :     m_xInteractionHandler.set( InteractionHandler::createWithParent(m_xContext, 0), UNO_QUERY );
     639             : 
     640           0 :     OCopyTable* pPage1( new OCopyTable( this ) );
     641           0 :     pPage1->disallowViews();
     642           0 :     pPage1->setCreateStyleAction();
     643           0 :     AddWizardPage( pPage1 );
     644             : 
     645           0 :     AddWizardPage( new OWizNameMatching( this ) );
     646           0 :     AddWizardPage( new OWizColumnSelect( this ) );
     647           0 :     AddWizardPage( (*_pTypeSelectionPageFactory)( this, _rTypeSelectionPageArg ) );
     648             : 
     649           0 :     ActivatePage();
     650           0 : }
     651             : 
     652           0 : void OCopyTableWizard::construct()
     653             : {
     654             :     SAL_INFO("dbaccess.ui", "OCopyTableWizard::construct" );
     655           0 :     AddButton( &m_pbHelp, WIZARDDIALOG_BUTTON_STDOFFSET_X );
     656           0 :     AddButton( &m_pbCancel, WIZARDDIALOG_BUTTON_STDOFFSET_X );
     657           0 :     AddButton( &m_pbPrev );
     658           0 :     AddButton( &m_pbNext, WIZARDDIALOG_BUTTON_STDOFFSET_X );
     659           0 :     AddButton( &m_pbFinish );
     660             : 
     661           0 :     m_pbPrev.SetClickHdl( LINK( this, OCopyTableWizard, ImplPrevHdl ) );
     662           0 :     m_pbNext.SetClickHdl( LINK( this, OCopyTableWizard, ImplNextHdl ) );
     663           0 :     m_pbFinish.SetClickHdl( LINK( this, OCopyTableWizard, ImplOKHdl ) );
     664             : 
     665           0 :     SetActivatePageHdl( LINK( this, OCopyTableWizard, ImplActivateHdl ) );
     666             : 
     667           0 :     SetPrevButton( &m_pbPrev );
     668           0 :     SetNextButton( &m_pbNext );
     669             : 
     670           0 :     ShowButtonFixedLine( true );
     671             : 
     672           0 :     m_pbNext.GrabFocus();
     673             : 
     674           0 :     if (m_vDestColumns.size())
     675             :         // source is a html or rtf table
     676           0 :         m_pbNext.SetStyle(m_pbFinish.GetStyle() | WB_DEFBUTTON);
     677             :     else
     678           0 :         m_pbFinish.SetStyle(m_pbFinish.GetStyle() | WB_DEFBUTTON);
     679             : 
     680           0 :     FreeResource();
     681             : 
     682           0 :     m_pTypeInfo = TOTypeInfoSP(new OTypeInfo());
     683           0 :     m_pTypeInfo->aUIName = m_sTypeNames.getToken(TYPE_OTHER, ';');
     684           0 :     m_bAddPKFirstTime = sal_True;
     685           0 : }
     686             : 
     687           0 : OCopyTableWizard::~OCopyTableWizard()
     688             : {
     689             :     for ( ;; )
     690             :     {
     691           0 :         TabPage *pPage = GetPage(0);
     692           0 :         if ( pPage == NULL )
     693           0 :             break;
     694           0 :         RemovePage( pPage );
     695           0 :         delete pPage;
     696           0 :     }
     697             : 
     698           0 :     if ( m_bDeleteSourceColumns )
     699           0 :         clearColumns(m_vSourceColumns,m_vSourceVec);
     700             : 
     701           0 :     clearColumns(m_vDestColumns,m_aDestVec);
     702             : 
     703             :     // clear the type information
     704           0 :     m_aTypeInfoIndex.clear();
     705           0 :     m_aTypeInfo.clear();
     706           0 :     m_aDestTypeInfoIndex.clear();
     707           0 : }
     708             : 
     709           0 : IMPL_LINK_NOARG(OCopyTableWizard, ImplPrevHdl)
     710             : {
     711           0 :     m_ePressed = WIZARD_PREV;
     712           0 :     if ( GetCurLevel() )
     713             :     {
     714           0 :         if ( getOperation() != CopyTableOperation::AppendData )
     715             :         {
     716           0 :             if(GetCurLevel() == 2)
     717           0 :                 ShowPage(GetCurLevel()-2);
     718             :             else
     719           0 :                 ShowPrevPage();
     720             :         }
     721             :         else
     722           0 :             ShowPrevPage();
     723             :     }
     724           0 :     return 0;
     725             : }
     726             : 
     727           0 : IMPL_LINK_NOARG(OCopyTableWizard, ImplNextHdl)
     728             : {
     729           0 :     m_ePressed = WIZARD_NEXT;
     730           0 :     if ( GetCurLevel() < MAX_PAGES )
     731             :     {
     732           0 :         if ( getOperation() != CopyTableOperation::AppendData )
     733             :         {
     734           0 :             if(GetCurLevel() == 0)
     735           0 :                 ShowPage(GetCurLevel()+2);
     736             :             else
     737           0 :                 ShowNextPage();
     738             :         }
     739             :         else
     740           0 :             ShowNextPage();
     741             :     }
     742           0 :     return 0;
     743             : }
     744             : 
     745           0 : sal_Bool OCopyTableWizard::CheckColumns(sal_Int32& _rnBreakPos)
     746             : {
     747             :     SAL_INFO("dbaccess.ui", "OCopyTableWizard::CheckColumns" );
     748           0 :     sal_Bool bRet = sal_True;
     749           0 :     m_vColumnPos.clear();
     750           0 :     m_vColumnTypes.clear();
     751             : 
     752             :     OSL_ENSURE( m_xDestConnection.is(), "OCopyTableWizard::CheckColumns: No connection!" );
     753             :     // If database is able to process PrimaryKeys, set PrimaryKey
     754           0 :     if ( m_xDestConnection.is() )
     755             :     {
     756           0 :         sal_Bool bPKeyAllowed = supportsPrimaryKey();
     757             : 
     758           0 :         sal_Bool bContainsColumns = !m_vDestColumns.empty();
     759             : 
     760           0 :         if ( bPKeyAllowed && shouldCreatePrimaryKey() )
     761             :         {
     762             :             // add extra column for the primary key
     763           0 :             TOTypeInfoSP pTypeInfo = queryPrimaryKeyType(m_aDestTypeInfo);
     764           0 :             if ( pTypeInfo.get() )
     765             :             {
     766           0 :                 if ( m_bAddPKFirstTime )
     767             :                 {
     768           0 :                     OFieldDescription* pField = new OFieldDescription();
     769           0 :                     pField->SetName(m_aKeyName);
     770           0 :                     pField->FillFromTypeInfo(pTypeInfo,sal_True,sal_True);
     771           0 :                     pField->SetPrimaryKey(sal_True);
     772           0 :                     m_bAddPKFirstTime = sal_False;
     773           0 :                     insertColumn(0,pField);
     774             :                 }
     775           0 :                 m_vColumnPos.push_back(ODatabaseExport::TPositions::value_type(1,1));
     776           0 :                 m_vColumnTypes.push_back(pTypeInfo->nType);
     777           0 :             }
     778             :         }
     779             : 
     780           0 :         if ( bContainsColumns )
     781             :         {   // we have dest columns so look for the matching column
     782           0 :             ODatabaseExport::TColumnVector::const_iterator aSrcIter = m_vSourceVec.begin();
     783           0 :             ODatabaseExport::TColumnVector::const_iterator aSrcEnd = m_vSourceVec.end();
     784           0 :             for(;aSrcIter != aSrcEnd;++aSrcIter)
     785             :             {
     786           0 :                 ODatabaseExport::TColumns::iterator aDestIter = m_vDestColumns.find(m_mNameMapping[(*aSrcIter)->first]);
     787             : 
     788           0 :                 if ( aDestIter != m_vDestColumns.end() )
     789             :                 {
     790           0 :                     ODatabaseExport::TColumnVector::const_iterator aFind = ::std::find(m_aDestVec.begin(),m_aDestVec.end(),aDestIter);
     791           0 :                     sal_Int32 nPos = (aFind - m_aDestVec.begin())+1;
     792           0 :                     m_vColumnPos.push_back(ODatabaseExport::TPositions::value_type(nPos,nPos));
     793           0 :                     m_vColumnTypes.push_back((*aFind)->second->GetType());
     794             :                 }
     795             :                 else
     796             :                 {
     797           0 :                     m_vColumnPos.push_back( ODatabaseExport::TPositions::value_type( COLUMN_POSITION_NOT_FOUND, COLUMN_POSITION_NOT_FOUND ) );
     798           0 :                     m_vColumnTypes.push_back(0);
     799             :                 }
     800             :             }
     801             :         }
     802             :         else
     803             :         {
     804           0 :             Reference< XDatabaseMetaData > xMetaData( m_xDestConnection->getMetaData() );
     805           0 :             OUString sExtraChars = xMetaData->getExtraNameCharacters();
     806           0 :             sal_Int32 nMaxNameLen       = getMaxColumnNameLength();
     807             : 
     808           0 :             ODatabaseExport::TColumnVector::const_iterator aSrcIter = m_vSourceVec.begin();
     809           0 :             ODatabaseExport::TColumnVector::const_iterator aSrcEnd = m_vSourceVec.end();
     810           0 :             for(_rnBreakPos=0;aSrcIter != aSrcEnd && bRet ;++aSrcIter,++_rnBreakPos)
     811             :             {
     812           0 :                 OFieldDescription* pField = new OFieldDescription(*(*aSrcIter)->second);
     813           0 :                 pField->SetName(convertColumnName(TExportColumnFindFunctor(&m_vDestColumns),(*aSrcIter)->first,sExtraChars,nMaxNameLen));
     814           0 :                 TOTypeInfoSP pType = convertType((*aSrcIter)->second->getSpecialTypeInfo(),bRet);
     815           0 :                 pField->SetType(pType);
     816           0 :                 if ( !bPKeyAllowed )
     817           0 :                     pField->SetPrimaryKey(sal_False);
     818             : 
     819             :                 // now create a column
     820           0 :                 insertColumn(m_vDestColumns.size(),pField);
     821           0 :                 m_vColumnPos.push_back(ODatabaseExport::TPositions::value_type(m_vDestColumns.size(),m_vDestColumns.size()));
     822           0 :                 m_vColumnTypes.push_back((*aSrcIter)->second->GetType());
     823           0 :             }
     824             :         }
     825             :     }
     826           0 :     return bRet;
     827             : }
     828             : 
     829           0 : IMPL_LINK_NOARG(OCopyTableWizard, ImplOKHdl)
     830             : {
     831           0 :     m_ePressed = WIZARD_FINISH;
     832           0 :     sal_Bool bFinish = DeactivatePage() != 0;
     833             : 
     834           0 :     if(bFinish)
     835             :     {
     836           0 :         WaitObject aWait(this);
     837           0 :         switch(getOperation())
     838             :         {
     839             :             case CopyTableOperation::CopyDefinitionAndData:
     840             :             case CopyTableOperation::CopyDefinitionOnly:
     841             :             {
     842           0 :                 sal_Bool bOnFirstPage = GetCurLevel() == 0;
     843           0 :                 if ( bOnFirstPage )
     844             :                 {
     845             :                     // we came from the first page so we have to clear
     846             :                     // all column information already collected
     847           0 :                     clearDestColumns();
     848           0 :                     m_mNameMapping.clear();
     849             :                 }
     850           0 :                 sal_Int32 nBreakPos = 0;
     851           0 :                 sal_Bool bCheckOk = CheckColumns(nBreakPos);
     852           0 :                 if ( bOnFirstPage && !bCheckOk )
     853             :                 {
     854           0 :                     showColumnTypeNotSupported(m_vSourceVec[nBreakPos-1]->first);
     855           0 :                     OWizTypeSelect* pPage = static_cast<OWizTypeSelect*>(GetPage(3));
     856           0 :                     if ( pPage )
     857             :                     {
     858           0 :                         m_mNameMapping.clear();
     859           0 :                         pPage->setDisplayRow(nBreakPos);
     860           0 :                         ShowPage(3);
     861           0 :                         return 0;
     862             :                     }
     863             :                 }
     864           0 :                 if ( m_xDestConnection.is() )
     865             :                 {
     866           0 :                     if ( supportsPrimaryKey() )
     867             :                     {
     868             :                         ODatabaseExport::TColumns::iterator aFind = ::std::find_if(m_vDestColumns.begin(),m_vDestColumns.end()
     869           0 :                             ,::o3tl::compose1(::std::mem_fun(&OFieldDescription::IsPrimaryKey),::o3tl::select2nd<ODatabaseExport::TColumns::value_type>()));
     870           0 :                         if ( aFind == m_vDestColumns.end() && m_xInteractionHandler.is() )
     871             :                         {
     872             : 
     873           0 :                             OUString sMsg(ModuleRes(STR_TABLEDESIGN_NO_PRIM_KEY));
     874           0 :                             SQLContext aError;
     875           0 :                             aError.Message = sMsg;
     876           0 :                             ::rtl::Reference< ::comphelper::OInteractionRequest > xRequest( new ::comphelper::OInteractionRequest( makeAny( aError ) ) );
     877           0 :                             ::rtl::Reference< ::comphelper::OInteractionApprove > xYes = new ::comphelper::OInteractionApprove;
     878           0 :                             xRequest->addContinuation( xYes.get() );
     879           0 :                             xRequest->addContinuation( new ::comphelper::OInteractionDisapprove );
     880           0 :                             ::rtl::Reference< ::comphelper::OInteractionAbort > xAbort = new ::comphelper::OInteractionAbort;
     881           0 :                             xRequest->addContinuation( xAbort.get() );
     882             : 
     883           0 :                             m_xInteractionHandler->handle( xRequest.get() );
     884             : 
     885           0 :                             if ( xYes->wasSelected() )
     886             :                             {
     887           0 :                                 OCopyTable* pPage = static_cast<OCopyTable*>(GetPage(0));
     888           0 :                                 m_bCreatePrimaryKeyColumn = sal_True;
     889           0 :                                 m_aKeyName = pPage->GetKeyName();
     890           0 :                                 if ( m_aKeyName.isEmpty() )
     891           0 :                                     m_aKeyName = "ID";
     892           0 :                                 m_aKeyName = createUniqueName( m_aKeyName );
     893           0 :                                 sal_Int32 nBreakPos2 = 0;
     894           0 :                                 CheckColumns(nBreakPos2);
     895             :                             }
     896           0 :                             else if ( xAbort->wasSelected() )
     897             :                             {
     898           0 :                                 ShowPage(3);
     899           0 :                                 return 0;
     900           0 :                             }
     901             :                         }
     902             :                     }
     903             :                 }
     904           0 :                 break;
     905             :             }
     906             :             case CopyTableOperation::AppendData:
     907             :             case CopyTableOperation::CreateAsView:
     908           0 :                 break;
     909             :             default:
     910             :             {
     911             :                 SAL_WARN("dbaccess.ui", "OCopyTableWizard::ImplOKHdl: invalid creation style!");
     912             :             }
     913             :         }
     914             : 
     915           0 :         EndDialog(RET_OK);
     916             :     }
     917           0 :     return bFinish;
     918             : }
     919             : 
     920           0 : sal_Bool OCopyTableWizard::shouldCreatePrimaryKey() const
     921             : {
     922             :     SAL_INFO("dbaccess.ui", "OCopyTableWizard::shouldCreatePrimaryKey" );
     923           0 :     return m_bCreatePrimaryKeyColumn;
     924             : }
     925             : 
     926           0 : void OCopyTableWizard::setCreatePrimaryKey( bool _bDoCreate, const OUString& _rSuggestedName )
     927             : {
     928             :     SAL_INFO("dbaccess.ui", "OCopyTableWizard::setCreatePrimaryKey" );
     929           0 :     m_bCreatePrimaryKeyColumn = _bDoCreate;
     930           0 :     if ( !_rSuggestedName.isEmpty() )
     931           0 :         m_aKeyName = _rSuggestedName;
     932             : 
     933           0 :     OCopyTable* pSettingsPage = dynamic_cast< OCopyTable* >( GetPage( 0 ) );
     934             :     OSL_ENSURE( pSettingsPage, "OCopyTableWizard::setCreatePrimaryKey: page should have been added in the ctor!" );
     935           0 :     if ( pSettingsPage )
     936           0 :         pSettingsPage->setCreatePrimaryKey( _bDoCreate, _rSuggestedName );
     937           0 : }
     938             : 
     939           0 : IMPL_LINK_NOARG(OCopyTableWizard, ImplActivateHdl)
     940             : {
     941           0 :     OWizardPage* pCurrent = (OWizardPage*)GetPage(GetCurLevel());
     942           0 :     if(pCurrent)
     943             :     {
     944           0 :         sal_Bool bFirstTime = pCurrent->IsFirstTime();
     945           0 :         if(bFirstTime)
     946           0 :             pCurrent->Reset();
     947             : 
     948           0 :         CheckButtons();
     949             : 
     950           0 :         SetText(pCurrent->GetTitle());
     951             : 
     952           0 :         Invalidate();
     953             :     }
     954           0 :     return 0;
     955             : }
     956             : 
     957           0 : void OCopyTableWizard::CheckButtons()
     958             : {
     959             :     SAL_INFO("dbaccess.ui", "OCopyTableWizard::CheckButtons" );
     960           0 :     if(GetCurLevel() == 0) // the first page has no back button
     961             :     {
     962           0 :         if(m_nPageCount > 1)
     963           0 :             m_pbNext.Enable(true);
     964             :         else
     965           0 :             m_pbNext.Enable(false);
     966             : 
     967           0 :         m_pbPrev.Enable(false);
     968             :     }
     969           0 :     else if(GetCurLevel() == m_nPageCount-1) // the last page has no next button
     970             :     {
     971           0 :         m_pbNext.Enable(false);
     972           0 :         m_pbPrev.Enable(true);
     973             :     }
     974             :     else
     975             :     {
     976           0 :         m_pbPrev.Enable(true);
     977             :         // next already has its state
     978             :     }
     979           0 : }
     980             : 
     981           0 : void OCopyTableWizard::EnableButton(Wizard_Button_Style eStyle,sal_Bool bEnable)
     982             : {
     983             :     SAL_INFO("dbaccess.ui", "OCopyTableWizard::EnableButton" );
     984             :     Button* pButton;
     985           0 :     if(eStyle == WIZARD_NEXT)
     986           0 :         pButton = &m_pbNext;
     987           0 :     else if(eStyle == WIZARD_PREV)
     988           0 :         pButton = &m_pbPrev;
     989             :     else
     990           0 :         pButton = &m_pbFinish;
     991           0 :     pButton->Enable(bEnable);
     992             : 
     993           0 : }
     994             : 
     995           0 : long OCopyTableWizard::DeactivatePage()
     996             : {
     997             :     SAL_INFO("dbaccess.ui", "OCopyTableWizard::DeactivatePage" );
     998           0 :     OWizardPage* pPage = (OWizardPage*)GetPage(GetCurLevel());
     999           0 :     return pPage ? pPage->LeavePage() : sal_False;
    1000             : }
    1001             : 
    1002           0 : void OCopyTableWizard::AddWizardPage(OWizardPage* pPage)
    1003             : {
    1004             :     SAL_INFO("dbaccess.ui", "OCopyTableWizard::AddWizardPage" );
    1005           0 :     AddPage(pPage);
    1006           0 :     ++m_nPageCount;
    1007           0 : }
    1008             : 
    1009           0 : void OCopyTableWizard::insertColumn(sal_Int32 _nPos,OFieldDescription* _pField)
    1010             : {
    1011             :     SAL_INFO("dbaccess.ui", "OCopyTableWizard::insertColumn" );
    1012             :     OSL_ENSURE(_pField,"FieldDescrioption is null!");
    1013           0 :     if ( _pField )
    1014             :     {
    1015           0 :         ODatabaseExport::TColumns::iterator aFind = m_vDestColumns.find(_pField->GetName());
    1016           0 :         if ( aFind != m_vDestColumns.end() )
    1017             :         {
    1018           0 :             delete aFind->second;
    1019           0 :             m_vDestColumns.erase(aFind);
    1020             :         }
    1021             : 
    1022           0 :         m_aDestVec.insert(m_aDestVec.begin() + _nPos,
    1023           0 :             m_vDestColumns.insert(ODatabaseExport::TColumns::value_type(_pField->GetName(),_pField)).first);
    1024           0 :         m_mNameMapping[_pField->GetName()] = _pField->GetName();
    1025             :     }
    1026           0 : }
    1027             : 
    1028           0 : void OCopyTableWizard::replaceColumn(sal_Int32 _nPos,OFieldDescription* _pField,const OUString& _sOldName)
    1029             : {
    1030             :     SAL_INFO("dbaccess.ui", "OCopyTableWizard::replaceColumn" );
    1031             :     OSL_ENSURE(_pField,"FieldDescrioption is null!");
    1032           0 :     if ( _pField )
    1033             :     {
    1034           0 :         m_vDestColumns.erase(_sOldName);
    1035             :         OSL_ENSURE( m_vDestColumns.find(_pField->GetName()) == m_vDestColumns.end(),"Column with that name already exist!");
    1036             : 
    1037           0 :         m_aDestVec[_nPos] =
    1038           0 :             m_vDestColumns.insert(ODatabaseExport::TColumns::value_type(_pField->GetName(),_pField)).first;
    1039             :     }
    1040           0 : }
    1041             : 
    1042           0 : void OCopyTableWizard::impl_loadSourceData()
    1043             : {
    1044             :     SAL_INFO("dbaccess.ui", "OCopyTableWizard::impl_loadSourceData" );
    1045           0 :     loadData( m_rSourceObject, m_vSourceColumns, m_vSourceVec );
    1046           0 : }
    1047             : 
    1048           0 : void OCopyTableWizard::loadData(  const ICopyTableSourceObject& _rSourceObject, ODatabaseExport::TColumns& _rColumns, ODatabaseExport::TColumnVector& _rColVector )
    1049             : {
    1050             :     SAL_INFO("dbaccess.ui", "OCopyTableWizard::loadData" );
    1051           0 :     ODatabaseExport::TColumns::iterator colEnd = _rColumns.end();
    1052           0 :     for ( ODatabaseExport::TColumns::iterator col = _rColumns.begin(); col != colEnd; ++col )
    1053           0 :         delete col->second;
    1054             : 
    1055           0 :     _rColVector.clear();
    1056           0 :     _rColumns.clear();
    1057             : 
    1058           0 :     OFieldDescription* pActFieldDescr = NULL;
    1059           0 :     OUString sCreateParam("x");
    1060             :     // ReadOnly-Flag
    1061             :     // On drop no line must be editable.
    1062             :     // On add only empty lines must be editable.
    1063             :     // On Add and Drop all lines can be edited.
    1064           0 :     Sequence< OUString > aColumns( _rSourceObject.getColumnNames() );
    1065           0 :     const OUString* pColumn      = aColumns.getConstArray();
    1066           0 :     const OUString* pColumnEnd   = pColumn + aColumns.getLength();
    1067             : 
    1068           0 :     for ( ; pColumn != pColumnEnd; ++pColumn )
    1069             :     {
    1070             :         // get the properties of the column
    1071           0 :         pActFieldDescr = _rSourceObject.createFieldDescription( *pColumn );
    1072             :         OSL_ENSURE( pActFieldDescr, "OCopyTableWizard::loadData: illegal field description!" );
    1073           0 :         if ( !pActFieldDescr )
    1074           0 :             continue;
    1075             : 
    1076           0 :         sal_Int32 nType           = pActFieldDescr->GetType();
    1077           0 :         sal_Int32 nScale          = pActFieldDescr->GetScale();
    1078           0 :         sal_Int32 nPrecision      = pActFieldDescr->GetPrecision();
    1079           0 :         sal_Bool bAutoIncrement   = pActFieldDescr->IsAutoIncrement();
    1080           0 :         OUString sTypeName = pActFieldDescr->GetTypeName();
    1081             : 
    1082             :         // search for type
    1083             :         sal_Bool bForce;
    1084           0 :         TOTypeInfoSP pTypeInfo = ::dbaui::getTypeInfoFromType(m_aTypeInfo,nType,sTypeName,sCreateParam,nPrecision,nScale,bAutoIncrement,bForce);
    1085           0 :         if ( !pTypeInfo.get() )
    1086           0 :             pTypeInfo = m_pTypeInfo;
    1087             : 
    1088           0 :         pActFieldDescr->FillFromTypeInfo(pTypeInfo,sal_True,sal_False);
    1089           0 :         _rColVector.push_back(_rColumns.insert(ODatabaseExport::TColumns::value_type(pActFieldDescr->GetName(),pActFieldDescr)).first);
    1090           0 :     }
    1091             : 
    1092             :     // determine which coumns belong to the primary key
    1093           0 :     Sequence< OUString > aPrimaryKeyColumns( _rSourceObject.getPrimaryKeyColumnNames() );
    1094           0 :     const OUString* pKeyColName  = aPrimaryKeyColumns.getConstArray();
    1095           0 :     const OUString* pKeyColEnd   = pKeyColName + aPrimaryKeyColumns.getLength();
    1096             : 
    1097           0 :     for( ; pKeyColName != pKeyColEnd; ++pKeyColName )
    1098             :     {
    1099           0 :         ODatabaseExport::TColumns::iterator keyPos = _rColumns.find( *pKeyColName );
    1100           0 :         if ( keyPos != _rColumns.end() )
    1101             :         {
    1102           0 :             keyPos->second->SetPrimaryKey( sal_True );
    1103           0 :             keyPos->second->SetIsNullable( ColumnValue::NO_NULLS );
    1104             :         }
    1105           0 :     }
    1106           0 : }
    1107             : 
    1108           0 : void OCopyTableWizard::clearDestColumns()
    1109             : {
    1110             :     SAL_INFO("dbaccess.ui", "OCopyTableWizard::clearDestColumns" );
    1111           0 :     clearColumns(m_vDestColumns,m_aDestVec);
    1112           0 :     m_bAddPKFirstTime = sal_True;
    1113           0 :     m_mNameMapping.clear();
    1114           0 : }
    1115             : 
    1116           0 : void OCopyTableWizard::appendColumns( Reference<XColumnsSupplier>& _rxColSup, const ODatabaseExport::TColumnVector* _pVec, sal_Bool _bKeyColumns) const
    1117             : {
    1118             :     SAL_INFO("dbaccess.ui", "OCopyTableWizard::appendColumns" );
    1119             :     // now append the columns
    1120             :     OSL_ENSURE(_rxColSup.is(),"No columns supplier");
    1121           0 :     if(!_rxColSup.is())
    1122           0 :         return;
    1123           0 :     Reference<XNameAccess> xColumns = _rxColSup->getColumns();
    1124             :     OSL_ENSURE(xColumns.is(),"No columns");
    1125           0 :     Reference<XDataDescriptorFactory> xColumnFactory(xColumns,UNO_QUERY);
    1126             : 
    1127           0 :     Reference<XAppend> xAppend(xColumns,UNO_QUERY);
    1128             :     OSL_ENSURE(xAppend.is(),"No XAppend Interface!");
    1129             : 
    1130           0 :     ODatabaseExport::TColumnVector::const_iterator aIter = _pVec->begin();
    1131           0 :     ODatabaseExport::TColumnVector::const_iterator aEnd = _pVec->end();
    1132           0 :     for(;aIter != aEnd;++aIter)
    1133             :     {
    1134           0 :         OFieldDescription* pField = (*aIter)->second;
    1135           0 :         if(!pField)
    1136           0 :             continue;
    1137             : 
    1138           0 :         Reference<XPropertySet> xColumn;
    1139           0 :         if(pField->IsPrimaryKey() || !_bKeyColumns)
    1140           0 :             xColumn = xColumnFactory->createDataDescriptor();
    1141           0 :         if(xColumn.is())
    1142             :         {
    1143           0 :             if(!_bKeyColumns)
    1144           0 :                 dbaui::setColumnProperties(xColumn,pField);
    1145             :             else
    1146           0 :                 xColumn->setPropertyValue(PROPERTY_NAME,makeAny(pField->GetName()));
    1147             : 
    1148           0 :             xAppend->appendByDescriptor(xColumn);
    1149           0 :             xColumn = NULL;
    1150             :             // now only the settings are missing
    1151           0 :             if(xColumns->hasByName(pField->GetName()))
    1152             :             {
    1153           0 :                 xColumn.set(xColumns->getByName(pField->GetName()),UNO_QUERY);
    1154             :                 OSL_ENSURE(xColumn.is(),"OCopyTableWizard::appendColumns: Column is NULL!");
    1155           0 :                 if ( xColumn.is() )
    1156           0 :                     pField->copyColumnSettingsTo(xColumn);
    1157             :             }
    1158             :             else
    1159             :             {
    1160             :                 SAL_WARN("dbaccess.ui", "OCopyTableWizard::appendColumns: invalid field name!");
    1161             :             }
    1162             : 
    1163             :         }
    1164           0 :     }
    1165             : }
    1166             : 
    1167           0 : void OCopyTableWizard::appendKey( Reference<XKeysSupplier>& _rxSup, const ODatabaseExport::TColumnVector* _pVec) const
    1168             : {
    1169             :     SAL_INFO("dbaccess.ui", "OCopyTableWizard::appendKey" );
    1170           0 :     if(!_rxSup.is())
    1171           0 :         return; // the database doesn't support keys
    1172             :     OSL_ENSURE(_rxSup.is(),"No XKeysSupplier!");
    1173           0 :     Reference<XDataDescriptorFactory> xKeyFactory(_rxSup->getKeys(),UNO_QUERY);
    1174             :     OSL_ENSURE(xKeyFactory.is(),"No XDataDescriptorFactory Interface!");
    1175           0 :     if ( !xKeyFactory.is() )
    1176           0 :         return;
    1177           0 :     Reference<XAppend> xAppend(xKeyFactory,UNO_QUERY);
    1178             :     OSL_ENSURE(xAppend.is(),"No XAppend Interface!");
    1179             : 
    1180           0 :     Reference<XPropertySet> xKey = xKeyFactory->createDataDescriptor();
    1181             :     OSL_ENSURE(xKey.is(),"Key is null!");
    1182           0 :     xKey->setPropertyValue(PROPERTY_TYPE,makeAny(KeyType::PRIMARY));
    1183             : 
    1184           0 :     Reference<XColumnsSupplier> xColSup(xKey,UNO_QUERY);
    1185           0 :     if(xColSup.is())
    1186             :     {
    1187           0 :         appendColumns(xColSup,_pVec,sal_True);
    1188           0 :         Reference<XNameAccess> xColumns = xColSup->getColumns();
    1189           0 :         if(xColumns.is() && xColumns->getElementNames().getLength())
    1190           0 :             xAppend->appendByDescriptor(xKey);
    1191           0 :     }
    1192             : 
    1193             : }
    1194             : 
    1195           0 : Reference< XPropertySet > OCopyTableWizard::createView() const
    1196             : {
    1197             :     SAL_INFO("dbaccess.ui", "OCopyTableWizard::createView" );
    1198           0 :     OUString sCommand( m_rSourceObject.getSelectStatement() );
    1199             :     OSL_ENSURE( !sCommand.isEmpty(), "OCopyTableWizard::createView: no statement in the source object!" );
    1200             :         // there are legitimate cases in which getSelectStatement does not provide a statement,
    1201             :         // but in all those cases, this method here should never be called.
    1202           0 :     return ::dbaui::createView( m_sName, m_xDestConnection, sCommand );
    1203             : }
    1204             : 
    1205           0 : Reference< XPropertySet > OCopyTableWizard::createTable()
    1206             : {
    1207             :     SAL_INFO("dbaccess.ui", "OCopyTableWizard::createTable" );
    1208           0 :     Reference< XPropertySet > xTable;
    1209             : 
    1210           0 :     Reference<XTablesSupplier> xSup( m_xDestConnection, UNO_QUERY );
    1211           0 :     Reference< XNameAccess > xTables;
    1212           0 :     if(xSup.is())
    1213           0 :         xTables = xSup->getTables();
    1214           0 :     if ( getOperation() != CopyTableOperation::AppendData )
    1215             :     {
    1216           0 :         Reference<XDataDescriptorFactory> xFact(xTables,UNO_QUERY);
    1217             :         OSL_ENSURE(xFact.is(),"No XDataDescriptorFactory available!");
    1218           0 :         if(!xFact.is())
    1219           0 :             return NULL;
    1220             : 
    1221           0 :         xTable = xFact->createDataDescriptor();
    1222             :         OSL_ENSURE(xTable.is(),"Could not create a new object!");
    1223           0 :         if(!xTable.is())
    1224           0 :             return NULL;
    1225             : 
    1226           0 :         OUString sCatalog,sSchema,sTable;
    1227           0 :         Reference< XDatabaseMetaData> xMetaData = m_xDestConnection->getMetaData();
    1228             :         ::dbtools::qualifiedNameComponents(xMetaData,
    1229             :                                             m_sName,
    1230             :                                             sCatalog,
    1231             :                                             sSchema,
    1232             :                                             sTable,
    1233           0 :                                             ::dbtools::eInDataManipulation);
    1234             : 
    1235           0 :         if ( sCatalog.isEmpty() && xMetaData->supportsCatalogsInTableDefinitions() )
    1236             :         {
    1237           0 :             sCatalog = m_xDestConnection->getCatalog();
    1238             :         }
    1239             : 
    1240           0 :         if ( sSchema.isEmpty() && xMetaData->supportsSchemasInTableDefinitions() )
    1241             :         {
    1242           0 :             sSchema = xMetaData->getUserName();
    1243             :         }
    1244             : 
    1245           0 :         xTable->setPropertyValue(PROPERTY_CATALOGNAME,makeAny(sCatalog));
    1246           0 :         xTable->setPropertyValue(PROPERTY_SCHEMANAME,makeAny(sSchema));
    1247           0 :         xTable->setPropertyValue(PROPERTY_NAME,makeAny(sTable));
    1248             : 
    1249           0 :         Reference< XColumnsSupplier > xSuppDestinationColumns( xTable, UNO_QUERY );
    1250             :         // now append the columns
    1251           0 :         const ODatabaseExport::TColumnVector* pVec = getDestVector();
    1252           0 :         appendColumns( xSuppDestinationColumns, pVec );
    1253             :         // now append the primary key
    1254           0 :         Reference<XKeysSupplier> xKeySup(xTable,UNO_QUERY);
    1255           0 :         appendKey(xKeySup,pVec);
    1256             : 
    1257           0 :         Reference<XAppend> xAppend(xTables,UNO_QUERY);
    1258           0 :         if(xAppend.is())
    1259           0 :             xAppend->appendByDescriptor(xTable);
    1260             : 
    1261             :         //  xTable = NULL;
    1262             :         // we need to reget the table because after appending it it is no longer valid
    1263           0 :         if(xTables->hasByName(m_sName))
    1264           0 :             xTables->getByName(m_sName) >>= xTable;
    1265             :         else
    1266             :         {
    1267             :             OUString sComposedName(
    1268           0 :                 ::dbtools::composeTableName( m_xDestConnection->getMetaData(), xTable, ::dbtools::eInDataManipulation, false, false, false ) );
    1269           0 :             if(xTables->hasByName(sComposedName))
    1270             :             {
    1271           0 :                 xTables->getByName(sComposedName) >>= xTable;
    1272           0 :                 m_sName = sComposedName;
    1273             :             }
    1274             :             else
    1275           0 :                 xTable = NULL;
    1276             :         }
    1277           0 :         if(xTable.is())
    1278             :         {
    1279           0 :             xSuppDestinationColumns.set( xTable, UNO_QUERY_THROW );
    1280             :             // insert new table name into table filter
    1281           0 :             ::dbaui::appendToFilter( m_xDestConnection, m_sName, GetComponentContext(), this );
    1282             : 
    1283             :             // copy ui settings
    1284           0 :             m_rSourceObject.copyUISettingsTo( xTable );
    1285             :             //copy filter and sorting
    1286           0 :             m_rSourceObject.copyFilterAndSortingTo(m_xDestConnection,xTable);
    1287             :             // set column mappings
    1288           0 :             Reference<XNameAccess> xNameAccess = xSuppDestinationColumns->getColumns();
    1289           0 :             Sequence< OUString> aSeq = xNameAccess->getElementNames();
    1290           0 :             const OUString* pIter = aSeq.getConstArray();
    1291           0 :             const OUString* pEnd   = pIter + aSeq.getLength();
    1292             : 
    1293           0 :             for(sal_Int32 nNewPos=1;pIter != pEnd;++pIter,++nNewPos)
    1294             :             {
    1295           0 :                 ODatabaseExport::TColumns::const_iterator aDestIter = m_vDestColumns.find(*pIter);
    1296             : 
    1297           0 :                 if ( aDestIter != m_vDestColumns.end() )
    1298             :                 {
    1299           0 :                     ODatabaseExport::TColumnVector::const_iterator aFind = ::std::find(m_aDestVec.begin(),m_aDestVec.end(),aDestIter);
    1300           0 :                     sal_Int32 nPos = (aFind - m_aDestVec.begin())+1;
    1301             : 
    1302             :                     ODatabaseExport::TPositions::iterator aPosFind = ::std::find_if(
    1303             :                         m_vColumnPos.begin(),
    1304             :                         m_vColumnPos.end(),
    1305           0 :                         ::o3tl::compose1(    ::std::bind2nd( ::std::equal_to< sal_Int32 >(), nPos ),
    1306             :                                             ::o3tl::select1st< ODatabaseExport::TPositions::value_type >()
    1307             :                         )
    1308           0 :                     );
    1309             : 
    1310           0 :                     if ( m_vColumnPos.end() != aPosFind )
    1311             :                     {
    1312           0 :                         aPosFind->second = nNewPos;
    1313             :                         OSL_ENSURE( m_vColumnTypes.size() > size_t( aPosFind - m_vColumnPos.begin() ),
    1314             :                             "Invalid index for vector!" );
    1315           0 :                         m_vColumnTypes[ aPosFind - m_vColumnPos.begin() ] = (*aFind)->second->GetType();
    1316             :                     }
    1317             :                 }
    1318           0 :             }
    1319           0 :         }
    1320             :     }
    1321           0 :     else if(xTables.is() && xTables->hasByName(m_sName))
    1322           0 :         xTables->getByName(m_sName) >>= xTable;
    1323             : 
    1324           0 :     return xTable;
    1325             : }
    1326             : 
    1327           0 : bool OCopyTableWizard::supportsPrimaryKey( const Reference< XConnection >& _rxConnection )
    1328             : {
    1329             :     OSL_PRECOND( _rxConnection.is(), "OCopyTableWizard::supportsPrimaryKey: invalid connection!" );
    1330           0 :     if ( !_rxConnection.is() )
    1331           0 :         return false;
    1332             : 
    1333           0 :     ::dbtools::DatabaseMetaData aMetaData( _rxConnection );
    1334           0 :     return aMetaData.supportsPrimaryKeys();
    1335             : }
    1336             : 
    1337           0 : bool OCopyTableWizard::supportsViews( const Reference< XConnection >& _rxConnection )
    1338             : {
    1339             :     SAL_INFO("dbaccess.ui", "OCopyTableWizard::supportsViews" );
    1340             :     OSL_PRECOND( _rxConnection.is(), "OCopyTableWizard::supportsViews: invalid connection!" );
    1341           0 :     if ( !_rxConnection.is() )
    1342           0 :         return false;
    1343             : 
    1344           0 :     bool bSupportsViews( false );
    1345             :     try
    1346             :     {
    1347           0 :         Reference< XDatabaseMetaData > xMetaData( _rxConnection->getMetaData(), UNO_SET_THROW );
    1348           0 :         Reference< XViewsSupplier > xViewSups( _rxConnection, UNO_QUERY );
    1349           0 :         bSupportsViews = xViewSups.is();
    1350           0 :         if ( !bSupportsViews )
    1351             :         {
    1352             :             try
    1353             :             {
    1354           0 :                 Reference< XResultSet > xRs( xMetaData->getTableTypes(), UNO_SET_THROW );
    1355           0 :                 Reference< XRow > xRow( xRs, UNO_QUERY_THROW );
    1356           0 :                 while ( xRs->next() )
    1357             :                 {
    1358           0 :                     OUString sValue = xRow->getString( 1 );
    1359           0 :                     if ( !xRow->wasNull() && sValue.equalsIgnoreAsciiCase("View") )
    1360             :                     {
    1361           0 :                         bSupportsViews = true;
    1362           0 :                         break;
    1363             :                     }
    1364           0 :                 }
    1365             :             }
    1366           0 :             catch( const SQLException& )
    1367             :             {
    1368             :                 DBG_UNHANDLED_EXCEPTION();
    1369             :             }
    1370           0 :         }
    1371             :     }
    1372           0 :     catch( const Exception& )
    1373             :     {
    1374             :         DBG_UNHANDLED_EXCEPTION();
    1375             :     }
    1376           0 :     return bSupportsViews;
    1377             : }
    1378             : 
    1379           0 : sal_Int32 OCopyTableWizard::getMaxColumnNameLength() const
    1380             : {
    1381             :     SAL_INFO("dbaccess.ui", "OCopyTableWizard::getMaxColumnNameLength" );
    1382           0 :     sal_Int32 nLen = 0;
    1383           0 :     if ( m_xDestConnection.is() )
    1384             :     {
    1385             :         try
    1386             :         {
    1387           0 :             Reference< XDatabaseMetaData > xMetaData( m_xDestConnection->getMetaData(), UNO_SET_THROW );
    1388           0 :             nLen = xMetaData->getMaxColumnNameLength();
    1389             :         }
    1390           0 :         catch(const Exception&)
    1391             :         {
    1392             :             DBG_UNHANDLED_EXCEPTION();
    1393             :         }
    1394             :     }
    1395           0 :     return nLen;
    1396             : }
    1397             : 
    1398           0 : void OCopyTableWizard::setOperation( const sal_Int16 _nOperation )
    1399             : {
    1400             :     SAL_INFO("dbaccess.ui", "OCopyTableWizard::setOperation" );
    1401           0 :     m_nOperation = _nOperation;
    1402           0 : }
    1403             : 
    1404           0 : sal_Int16 OCopyTableWizard::getOperation() const
    1405             : {
    1406             :     SAL_INFO("dbaccess.ui", "OCopyTableWizard::getOperation" );
    1407           0 :     return m_nOperation;
    1408             : }
    1409             : 
    1410           0 : OUString OCopyTableWizard::convertColumnName(const TColumnFindFunctor&   _rCmpFunctor,
    1411             :                                                     const OUString&  _sColumnName,
    1412             :                                                     const OUString&  _sExtraChars,
    1413             :                                                     sal_Int32               _nMaxNameLen)
    1414             : {
    1415             :     SAL_INFO("dbaccess.ui", "OCopyTableWizard::convertColumnName" );
    1416           0 :     OUString sAlias = _sColumnName;
    1417           0 :     if ( isSQL92CheckEnabled( m_xDestConnection ) )
    1418           0 :         sAlias = ::dbtools::convertName2SQLName(_sColumnName,_sExtraChars);
    1419           0 :     if((_nMaxNameLen && sAlias.getLength() > _nMaxNameLen) || _rCmpFunctor(sAlias))
    1420             :     {
    1421           0 :         sal_Int32 nDiff = 1;
    1422           0 :         do
    1423             :         {
    1424           0 :             ++nDiff;
    1425           0 :             if(_nMaxNameLen && sAlias.getLength() >= _nMaxNameLen)
    1426           0 :                 sAlias = sAlias.copy(0,sAlias.getLength() - (sAlias.getLength()-_nMaxNameLen+nDiff));
    1427             : 
    1428           0 :             OUString sName(sAlias);
    1429           0 :             sal_Int32 nPos = 1;
    1430           0 :             sName += OUString::number(nPos);
    1431             : 
    1432           0 :             while(_rCmpFunctor(sName))
    1433             :             {
    1434           0 :                 sName = sAlias;
    1435           0 :                 sName += OUString::number(++nPos);
    1436             :             }
    1437           0 :             sAlias = sName;
    1438             :             // we have to check again, it could happen that the name is already to long
    1439             :         }
    1440           0 :         while(_nMaxNameLen && sAlias.getLength() > _nMaxNameLen);
    1441             :     }
    1442             :     OSL_ENSURE(m_mNameMapping.find(_sColumnName) == m_mNameMapping.end(),"name doubled!");
    1443           0 :     m_mNameMapping[_sColumnName] = sAlias;
    1444           0 :     return sAlias;
    1445             : }
    1446             : 
    1447           0 : void OCopyTableWizard::removeColumnNameFromNameMap(const OUString& _sName)
    1448             : {
    1449             :     SAL_INFO("dbaccess.ui", "OCopyTableWizard::removeColumnNameFromNameMap" );
    1450           0 :     m_mNameMapping.erase(_sName);
    1451           0 : }
    1452             : 
    1453           0 : sal_Bool OCopyTableWizard::supportsType(sal_Int32 _nDataType,sal_Int32& _rNewDataType)
    1454             : {
    1455             :     SAL_INFO("dbaccess.ui", "OCopyTableWizard::supportsType" );
    1456           0 :     sal_Bool bRet = m_aDestTypeInfo.find(_nDataType) != m_aDestTypeInfo.end();
    1457           0 :     if ( bRet )
    1458           0 :         _rNewDataType = _nDataType;
    1459           0 :     return bRet;
    1460             : }
    1461             : 
    1462           0 : TOTypeInfoSP OCopyTableWizard::convertType(const TOTypeInfoSP& _pType,sal_Bool& _bNotConvert)
    1463             : {
    1464             :     SAL_INFO("dbaccess.ui", "OCopyTableWizard::convertType" );
    1465           0 :     if ( !m_bInterConnectionCopy )
    1466             :         // no need to convert if the source and destination connection are the same
    1467           0 :         return _pType;
    1468             : 
    1469             :     sal_Bool bForce;
    1470           0 :     TOTypeInfoSP pType = ::dbaui::getTypeInfoFromType(m_aDestTypeInfo,_pType->nType,_pType->aTypeName,_pType->aCreateParams,_pType->nPrecision,_pType->nMaximumScale,_pType->bAutoIncrement,bForce);
    1471           0 :     if ( !pType.get() || bForce )
    1472             :     { // no type found so we have to find the correct one ourself
    1473           0 :         sal_Int32 nDefaultType = DataType::VARCHAR;
    1474           0 :         switch(_pType->nType)
    1475             :         {
    1476             :             case DataType::TINYINT:
    1477           0 :                 if(supportsType(DataType::SMALLINT,nDefaultType))
    1478           0 :                     break;
    1479             :                 // run through
    1480             :             case DataType::SMALLINT:
    1481           0 :                 if(supportsType(DataType::INTEGER,nDefaultType))
    1482           0 :                     break;
    1483             :                 // run through
    1484             :             case DataType::INTEGER:
    1485           0 :                 if(supportsType(DataType::FLOAT,nDefaultType))
    1486           0 :                     break;
    1487             :                 // run through
    1488             :             case DataType::FLOAT:
    1489           0 :                 if(supportsType(DataType::REAL,nDefaultType))
    1490           0 :                     break;
    1491             :                 // run through
    1492             :             case DataType::DATE:
    1493             :             case DataType::TIME:
    1494           0 :                 if( DataType::DATE == _pType->nType || DataType::TIME == _pType->nType )
    1495             :                 {
    1496           0 :                     if(supportsType(DataType::TIMESTAMP,nDefaultType))
    1497           0 :                         break;
    1498             :                 }
    1499             :                 // run through
    1500             :             case DataType::TIMESTAMP:
    1501             :             case DataType::REAL:
    1502             :             case DataType::BIGINT:
    1503           0 :                 if ( supportsType(DataType::DOUBLE,nDefaultType) )
    1504           0 :                     break;
    1505             :                 // run through
    1506             :             case DataType::DOUBLE:
    1507           0 :                 if ( supportsType(DataType::NUMERIC,nDefaultType) )
    1508           0 :                     break;
    1509             :                 // run through
    1510             :             case DataType::NUMERIC:
    1511           0 :                 supportsType(DataType::DECIMAL,nDefaultType);
    1512           0 :                 break;
    1513             :             case DataType::DECIMAL:
    1514           0 :                 if ( supportsType(DataType::NUMERIC,nDefaultType) )
    1515           0 :                     break;
    1516           0 :                 if ( supportsType(DataType::DOUBLE,nDefaultType) )
    1517           0 :                     break;
    1518           0 :                 break;
    1519             :             case DataType::VARCHAR:
    1520           0 :                 if ( supportsType(DataType::LONGVARCHAR,nDefaultType) )
    1521           0 :                     break;
    1522           0 :                 break;
    1523             :             case DataType::LONGVARCHAR:
    1524           0 :                 if ( supportsType(DataType::CLOB,nDefaultType) )
    1525           0 :                     break;
    1526           0 :                 break;
    1527             :             case DataType::BINARY:
    1528           0 :                 if ( supportsType(DataType::VARBINARY,nDefaultType) )
    1529           0 :                     break;
    1530           0 :                 break;
    1531             :             case DataType::VARBINARY:
    1532           0 :                 if ( supportsType(DataType::LONGVARBINARY,nDefaultType) )
    1533           0 :                     break;
    1534           0 :                 break;
    1535             :             case DataType::LONGVARBINARY:
    1536           0 :                 if ( supportsType(DataType::BLOB,nDefaultType) )
    1537           0 :                     break;
    1538           0 :                 if ( supportsType(DataType::LONGVARCHAR,nDefaultType) )
    1539           0 :                     break;
    1540           0 :                 if ( supportsType(DataType::CLOB,nDefaultType) )
    1541           0 :                     break;
    1542           0 :                 break;
    1543             :             default:
    1544           0 :                 nDefaultType = DataType::VARCHAR;
    1545             :         }
    1546           0 :         pType = ::dbaui::getTypeInfoFromType(m_aDestTypeInfo,nDefaultType,_pType->aTypeName,_pType->aCreateParams,_pType->nPrecision,_pType->nMaximumScale,_pType->bAutoIncrement,bForce);
    1547           0 :         if ( !pType.get() )
    1548             :         {
    1549           0 :             _bNotConvert = sal_False;
    1550           0 :             OUString sCreate("x");
    1551           0 :             pType = ::dbaui::getTypeInfoFromType(m_aDestTypeInfo,DataType::VARCHAR,_pType->aTypeName,sCreate,50,0,sal_False,bForce);
    1552           0 :             if ( !pType.get() )
    1553           0 :                 pType = m_pTypeInfo;
    1554             :         }
    1555           0 :         else if ( bForce )
    1556           0 :             _bNotConvert = sal_False;
    1557             :     }
    1558           0 :     return pType;
    1559             : }
    1560             : 
    1561           0 : OUString OCopyTableWizard::createUniqueName(const OUString& _sName)
    1562             : {
    1563             :     SAL_INFO("dbaccess.ui", "OCopyTableWizard::createUniqueName" );
    1564           0 :     OUString sName = _sName;
    1565           0 :     Sequence< OUString > aColumnNames( m_rSourceObject.getColumnNames() );
    1566           0 :     if ( aColumnNames.getLength() )
    1567           0 :         sName = ::dbtools::createUniqueName( aColumnNames, sName, false );
    1568             :     else
    1569             :     {
    1570           0 :         if ( m_vSourceColumns.find(sName) != m_vSourceColumns.end())
    1571             :         {
    1572           0 :             sal_Int32 nPos = 0;
    1573           0 :             while(m_vSourceColumns.find(sName) != m_vSourceColumns.end())
    1574             :             {
    1575           0 :                 sName = _sName;
    1576           0 :                 sName += OUString::number(++nPos);
    1577             :             }
    1578             :         }
    1579             :     }
    1580           0 :     return sName;
    1581             : }
    1582             : 
    1583           0 : void OCopyTableWizard::showColumnTypeNotSupported(const OUString& _rColumnName)
    1584             : {
    1585             :     SAL_INFO("dbaccess.ui", "OCopyTableWizard::showColumnTypeNotSupported" );
    1586           0 :     OUString sMessage( ModuleRes( STR_UNKNOWN_TYPE_FOUND ) );
    1587           0 :     sMessage = sMessage.replaceFirst("#1",_rColumnName);
    1588           0 :     showError(sMessage);
    1589           0 : }
    1590             : 
    1591           0 : void OCopyTableWizard::showError(const OUString& _sErrorMesage)
    1592             : {
    1593           0 :     SQLExceptionInfo aInfo(_sErrorMesage);
    1594           0 :     showError(aInfo.get());
    1595           0 : }
    1596             : 
    1597           0 : void OCopyTableWizard::showError(const Any& _aError)
    1598             : {
    1599           0 :     if ( _aError.hasValue() && m_xInteractionHandler.is() )
    1600             :     {
    1601             :         try
    1602             :         {
    1603           0 :             ::rtl::Reference< ::comphelper::OInteractionRequest > xRequest( new ::comphelper::OInteractionRequest( _aError ) );
    1604           0 :             m_xInteractionHandler->handle( xRequest.get() );
    1605             :         }
    1606           0 :         catch( const Exception& )
    1607             :         {
    1608             :             DBG_UNHANDLED_EXCEPTION();
    1609             :         }
    1610             :     }
    1611           0 : }
    1612             : 
    1613             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10