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