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

Generated by: LCOV version 1.10