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