Tag: cws_src680_dba24d User: fs Date: 2007-11-15 15:16:49+0000 Modified: dba/dbaccess/source/ui/misc/WCopyTable.cxx
Log: #i81658# also allow to copy a table from an SDBC level connection File Changes: Directory: /dba/dbaccess/source/ui/misc/ ======================================== File [changed]: WCopyTable.cxx Url: http://dba.openoffice.org/source/browse/dba/dbaccess/source/ui/misc/WCopyTable.cxx?r1=1.53.28.2&r2=1.53.28.3 Delta lines: +105 -26 ---------------------- --- WCopyTable.cxx 2007-11-15 10:04:59+0000 1.53.28.2 +++ WCopyTable.cxx 2007-11-15 15:16:46+0000 1.53.28.3 @@ -4,9 +4,9 @@ * * $RCSfile: WCopyTable.cxx,v $ * - * $Revision: 1.53.28.2 $ + * $Revision: 1.53.28.3 $ * - * last change: $Author: fs $ $Date: 2007/11/15 10:04:59 $ + * last change: $Author: fs $ $Date: 2007/11/15 15:16:46 $ * * The Contents of this file are made available subject to * the terms of GNU Lesser General Public License Version 2.1. @@ -306,7 +306,9 @@ :m_xConnection( _rxConnection, UNO_SET_THROW ) ,m_xMetaData( _rxConnection->getMetaData(), UNO_SET_THROW ) ,m_sTableName( _rTableName ) + ,m_aColumnInfo() { + ::dbtools::qualifiedNameComponents( m_xMetaData, m_sTableName, m_sTableCatalog, m_sTableSchema, m_sTableBareName, ::dbtools::eComplete ); } //------------------------------------------------------------------------ @@ -318,8 +320,21 @@ //------------------------------------------------------------------------ bool NamedTableCopySource::isView() const { - // TODO: ask the meta data - return false; + ::rtl::OUString sTableType; + try + { + Reference< XResultSet > xTableDesc( m_xMetaData->getTables( makeAny( m_sTableCatalog ), m_sTableSchema, m_sTableBareName, + Sequence< ::rtl::OUString >() ) ); + Reference< XRow > xTableDescRow( xTableDesc, UNO_QUERY_THROW ); + OSL_VERIFY( xTableDesc->next() ); + sTableType = xTableDescRow->getString( 4 ); + OSL_ENSURE( !xTableDescRow->wasNull(), "NamedTableCopySource::isView: invalid table type!" ); + } + catch( const Exception& ) + { + DBG_UNHANDLED_EXCEPTION(); + } + return sTableType.equalsAscii( "VIEW" ); } //------------------------------------------------------------------------ @@ -329,24 +344,89 @@ } //------------------------------------------------------------------------ +void NamedTableCopySource::impl_ensureColumnInfo_nothrow() +{ + if ( !m_aColumnInfo.empty() ) + return; + + try + { + Reference< XResultSet > xColumnDesc( m_xMetaData->getColumns( makeAny( m_sTableCatalog ), m_sTableSchema, m_sTableBareName, + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "%" ) ) ), UNO_SET_THROW ); + + Reference< XRow > xDescRow( xColumnDesc, UNO_QUERY_THROW ); + while ( xColumnDesc->next() ) + { + OFieldDescription aDesc; + aDesc.SetName( xDescRow->getString( 4 ) ); // COLUMN_NAME + aDesc.SetDescription( xDescRow->getString( 12 ) ); // REMARKS + aDesc.SetTypeValue( xDescRow->getInt ( 5 ) ); // DATA_TYPE + aDesc.SetTypeName( xDescRow->getString( 6 ) ); // TYPE_NAME + aDesc.SetPrecision( xDescRow->getInt ( 7 ) ); // COLUMN_SIZE + aDesc.SetScale( xDescRow->getInt ( 9 ) ); // DECIMAL_DIGITS + aDesc.SetIsNullable( xDescRow->getInt ( 11 ) ); // NULLABLE + + aDesc.SetDefaultValue( makeAny( xDescRow->getString( 13 ) ) ); // COLUMN_DEF + + m_aColumnInfo[ aDesc.GetName() ] = aDesc; + } + } + catch( const Exception& ) + { + DBG_UNHANDLED_EXCEPTION(); + } +} + +//------------------------------------------------------------------------ Sequence< ::rtl::OUString > NamedTableCopySource::getColumnNames() const { - // TODO: ask the meta data - return Sequence< ::rtl::OUString >(); + const_cast< NamedTableCopySource* >( this )->impl_ensureColumnInfo_nothrow(); + + Sequence< ::rtl::OUString > aNames( m_aColumnInfo.size() ); + ::std::transform( + m_aColumnInfo.begin(), + m_aColumnInfo.end(), + aNames.getArray(), + ::std::select1st< ::std::map< ::rtl::OUString, OFieldDescription >::value_type >() + ); + + return aNames; } //------------------------------------------------------------------------ Sequence< ::rtl::OUString > NamedTableCopySource::getPrimaryKeyColumnNames() const { - // TODO: ask the meta data - return Sequence< ::rtl::OUString >(); + Sequence< ::rtl::OUString > aPKColNames; + + try + { + Reference< XResultSet > xPKDesc( m_xMetaData->getPrimaryKeys( makeAny( m_sTableCatalog ), m_sTableSchema, m_sTableBareName ) ); + Reference< XRow > xPKDescRow( xPKDesc, UNO_QUERY_THROW ); + while ( xPKDesc->next() ) + { + sal_Int32 len( aPKColNames.getLength() ); + aPKColNames.realloc( len + 1 ); + aPKColNames[ len ] = xPKDescRow->getString( 4 ); // COLUMN_NAME + } + } + catch( const Exception& ) + { + DBG_UNHANDLED_EXCEPTION(); + } + + return aPKColNames; } //------------------------------------------------------------------------ -OFieldDescription* NamedTableCopySource::createFieldDescription( const ::rtl::OUString& /*_rColumnName*/ ) const +OFieldDescription* NamedTableCopySource::createFieldDescription( const ::rtl::OUString& _rColumnName ) const { - // TODO + const_cast< NamedTableCopySource* >( this )->impl_ensureColumnInfo_nothrow(); + + ::std::map< ::rtl::OUString, OFieldDescription >::const_iterator pos = m_aColumnInfo.find( _rColumnName ); + if ( pos == m_aColumnInfo.end() ) return NULL; + + return new OFieldDescription( pos->second ); } //------------------------------------------------------------------------ @@ -355,9 +435,7 @@ ::rtl::OUStringBuffer aSQL; aSQL.appendAscii( "SELECT * FROM " ); - ::rtl::OUString sCatalog, sSchema, sName; - ::dbtools::qualifiedNameComponents( m_xMetaData, getQualifiedObjectName(), sCatalog, sSchema, sName, ::dbtools::eComplete ); - aSQL.append( ::dbtools::composeTableNameForSelect( m_xConnection, sCatalog, sSchema, sName ) ); + aSQL.append( ::dbtools::composeTableNameForSelect( m_xConnection, m_sTableCatalog, m_sTableSchema, m_sTableBareName ) ); return aSQL.makeStringAndClear(); } @@ -454,12 +532,12 @@ ,m_mNameMapping(_xConnection->getMetaData().is() && _xConnection->getMetaData()->supportsMixedCaseQuotedIdentifiers()) ,m_xDestConnection( _xConnection ) ,m_rSourceObject( _rSourceObject ) - ,m_xSourceConnection(_xSourceConnection) ,m_xFormatter( getNumberFormatter( _xConnection, _rxORB ) ) ,m_xFactory(_rxORB) ,m_sTypeNames(ModuleRes(STR_TABLEDESIGN_DBFIELDTYPES)) ,m_nPageCount(0) ,m_bDeleteSourceColumns(sal_True) + ,m_bInterConnectionCopy( _xSourceConnection != _xConnection ) ,m_sName( _rDefaultName ) ,m_nOperation( _nOperation ) ,m_ePressed( WIZARD_NONE ) @@ -480,7 +558,7 @@ if ( !m_sName.getLength() ) { - if ( m_xSourceConnection == m_xDestConnection ) + if ( _xSourceConnection == m_xDestConnection ) { Reference< XTablesSupplier > xSup( m_xDestConnection, UNO_QUERY_THROW ); m_sName = ::dbtools::createUniqueName( xSup->getTables(), sInitialTableName, sal_False ); @@ -494,7 +572,8 @@ m_sName = sInitialTableName; } - impl_fillTypeInfo(); + ::dbaui::fillTypeInfo( _xSourceConnection, m_sTypeNames, m_aTypeInfo, m_aTypeInfoIndex ); + ::dbaui::fillTypeInfo( m_xDestConnection, m_sTypeNames, m_aDestTypeInfo, m_aDestTypeInfoIndex ); impl_loadSourceData(); OCopyTable* pPage1( new OCopyTable( this ) ); @@ -525,12 +604,12 @@ ,m_mNameMapping(_xConnection->getMetaData().is() && _xConnection->getMetaData()->supportsMixedCaseQuotedIdentifiers()) ,m_xDestConnection( _xConnection ) ,m_rSourceObject( DummyCopySource::Instance() ) - ,m_xSourceConnection(_xConnection) // in this case source connection and dest connection are the same ,m_xFormatter(_xFormatter) ,m_xFactory(_rM) ,m_sTypeNames(ModuleRes(STR_TABLEDESIGN_DBFIELDTYPES)) ,m_nPageCount(0) ,m_bDeleteSourceColumns(sal_False) + ,m_bInterConnectionCopy( false ) ,m_sName(_rDefaultName) ,m_nOperation( _nOperation ) ,m_ePressed( WIZARD_NONE ) @@ -545,7 +624,8 @@ m_vSourceVec.push_back(m_vSourceColumns.find((*aIter)->first)); } - impl_fillTypeInfo(); + ::dbaui::fillTypeInfo( _xConnection, m_sTypeNames, m_aTypeInfo, m_aTypeInfoIndex ); + ::dbaui::fillTypeInfo( _xConnection, m_sTypeNames, m_aDestTypeInfo, m_aDestTypeInfoIndex ); OCopyTable* pPage1( new OCopyTable( this ) ); pPage1->disallowViews(); @@ -961,6 +1041,10 @@ { // get the properties of the column pActFieldDescr = _rSourceObject.createFieldDescription( *pColumn ); + OSL_ENSURE( pActFieldDescr, "OCopyTableWizard::loadData: illegal field description!" ); + if ( !pActFieldDescr ) + continue; + sal_Int32 nType = pActFieldDescr->GetType(); sal_Int32 nScale = pActFieldDescr->GetScale(); sal_Int32 nPrecision = pActFieldDescr->GetPrecision(); @@ -1376,7 +1460,8 @@ // ----------------------------------------------------------------------------- TOTypeInfoSP OCopyTableWizard::convertType(const TOTypeInfoSP& _pType,sal_Bool& _bNotConvert) { - if ( m_xSourceConnection == m_xDestConnection ) + if ( !m_bInterConnectionCopy ) + // no need to convert if the source and destination connection are the same return _pType; sal_Bool bForce; @@ -1472,12 +1557,6 @@ return sName; } // ----------------------------------------------------------------------------- -void OCopyTableWizard::impl_fillTypeInfo() -{ - ::dbaui::fillTypeInfo( m_xSourceConnection, m_sTypeNames, m_aTypeInfo, m_aTypeInfoIndex ); - ::dbaui::fillTypeInfo( m_xDestConnection, m_sTypeNames, m_aDestTypeInfo, m_aDestTypeInfoIndex ); -} -// ----------------------------------------------------------------------------- void OCopyTableWizard::showColumnTypeNotSupported(const ::rtl::OUString& _rColumnName) { UniString sTitle(ModuleRes(STR_STAT_WARNING)); --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
