Tag: cws_src680_oj14 User: oj Date: 2006/07/04 01:13:35 Modified: dba/dbaccess/source/ui/misc/WCopyTable.cxx
Log: RESYNC: (1.42-1.45); FILE MERGED 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.41.4.4&r2=1.41.4.5 Delta lines: +103 -35 ---------------------- --- WCopyTable.cxx 25 Apr 2006 13:03:17 -0000 1.41.4.4 +++ WCopyTable.cxx 4 Jul 2006 08:13:32 -0000 1.41.4.5 @@ -102,6 +102,9 @@ #ifndef DBAUI_TOOLS_HXX #include "UITools.hxx" #endif +#ifndef DBAUI_WIZARD_CPAGE_HXX +#include "WCPage.hxx" +#endif #ifndef _SV_WAITOBJ_HXX #include <vcl/waitobj.hxx> #endif @@ -124,7 +127,7 @@ #define MAX_PAGES 4 // max. Pages die angezeigt werden -DBG_NAME(OCopyTableWizard); +DBG_NAME(OCopyTableWizard) namespace { void clearColumns(ODatabaseExport::TColumns& _rColumns,ODatabaseExport::TColumnVector& _rColumnsVec) @@ -152,17 +155,18 @@ ,m_pbPrev( this , ModuleRes(PB_PREV)) ,m_pbNext( this , ModuleRes(PB_NEXT)) ,m_pbFinish( this , ModuleRes(PB_OK)) - ,m_nPageCount(0) + ,m_mNameMapping(_xConnection->getMetaData().is() && _xConnection->getMetaData()->supportsMixedCaseQuotedIdentifiers()) ,m_xConnection(_xConnection) ,m_xSourceObject(_xSourceObject) - ,m_bCreatePrimaryColumn(sal_False) - ,m_eCreateStyle(WIZARD_DEF_DATA) - ,m_mNameMapping(_xConnection->getMetaData().is() && _xConnection->getMetaData()->supportsMixedCaseQuotedIdentifiers()) + ,m_xSourceConnection(_xSourceConnection) ,m_xFormatter(_xFormatter) - ,m_sTypeNames(ModuleRes(STR_TABLEDESIGN_DBFIELDTYPES)) ,m_xFactory(_rM) - ,m_xSourceConnection(_xSourceConnection) + ,m_sTypeNames(ModuleRes(STR_TABLEDESIGN_DBFIELDTYPES)) + ,m_nPageCount(0) ,m_bDeleteSourceColumns(sal_True) + ,m_eCreateStyle(WIZARD_DEF_DATA) + ,m_ePressed( WIZARD_NONE ) + ,m_bCreatePrimaryColumn(sal_False) { DBG_CTOR(OCopyTableWizard,NULL); construct(); @@ -179,11 +183,18 @@ m_sSourceName = ::dbtools::composeTableName(m_xConnection->getMetaData(),m_xSourceObject,sal_False,::dbtools::eInDataManipulation); else _xSourceObject->getPropertyValue(PROPERTY_NAME) >>= m_sSourceName; + if ( m_xSourceConnection == m_xConnection ) + { + Reference<XTablesSupplier> xSup(m_xConnection,UNO_QUERY_THROW); + m_sName = ::dbtools::createUniqueName(xSup->getTables(),m_sSourceName,sal_False); + } + else m_sName = m_sSourceName; } } - catch(Exception) + catch(const Exception&) { + m_sName = m_sSourceName; } } // ----------------------------------------------------------------------------- @@ -194,28 +205,34 @@ const Reference< XConnection >& _xConnection, const Reference< XNumberFormatter >& _xFormatter, const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rM) - : WizardDialog( pParent, ModuleRes(WIZ_RTFCOPYTABLE)) + :WizardDialog( pParent, ModuleRes(WIZ_RTFCOPYTABLE)) + ,m_vSourceColumns(_rSourceColumns) ,m_pbHelp( this , ModuleRes(PB_HELP)) ,m_pbCancel( this , ModuleRes(PB_CANCEL)) ,m_pbPrev( this , ModuleRes(PB_PREV)) ,m_pbNext( this , ModuleRes(PB_NEXT)) ,m_pbFinish( this , ModuleRes(PB_OK)) - ,m_nPageCount(0) - ,m_xConnection(_xConnection) - ,m_bCreatePrimaryColumn(sal_False) - ,m_eCreateStyle(WIZARD_DEF_DATA) ,m_mNameMapping(_xConnection->getMetaData().is() && _xConnection->getMetaData()->supportsMixedCaseQuotedIdentifiers()) - ,m_vSourceColumns(_rSourceColumns) + ,m_xConnection(_xConnection) + ,m_xSourceConnection(_xConnection) // in this case source connection and dest connection are the same ,m_xFormatter(_xFormatter) - ,m_sTypeNames(ModuleRes(STR_TABLEDESIGN_DBFIELDTYPES)) ,m_xFactory(_rM) - ,m_sName(_rDefaultName) - ,m_vSourceVec(_rSourceColVec) - ,m_xSourceConnection(_xConnection) // in this case source connection and dest connection are the same + ,m_sTypeNames(ModuleRes(STR_TABLEDESIGN_DBFIELDTYPES)) + ,m_nPageCount(0) ,m_bDeleteSourceColumns(sal_False) + ,m_sName(_rDefaultName) + ,m_eCreateStyle(WIZARD_DEF_DATA) + ,m_ePressed( WIZARD_NONE ) + ,m_bCreatePrimaryColumn(sal_False) { DBG_CTOR(OCopyTableWizard,NULL); construct(); + ODatabaseExport::TColumnVector::const_iterator aIter = _rSourceColVec.begin(); + ODatabaseExport::TColumnVector::const_iterator aEnd = _rSourceColVec.end(); + for (; aIter != aEnd ; ++aIter) + { + m_vSourceVec.push_back(m_vSourceColumns.find((*aIter)->first)); + } } // ----------------------------------------------------------------------------- void OCopyTableWizard::construct() @@ -366,7 +383,7 @@ } else { - m_vColumnPos.push_back(ODatabaseExport::TPositions::value_type(CONTAINER_ENTRY_NOTFOUND,CONTAINER_ENTRY_NOTFOUND)); + m_vColumnPos.push_back( ODatabaseExport::TPositions::value_type( COLUMN_POSITION_NOT_FOUND, COLUMN_POSITION_NOT_FOUND ) ); m_vColumnTypes.push_back(0); } } @@ -430,6 +447,50 @@ return 0; } } + if ( m_xConnection.is() ) + { + sal_Bool bPKeyAllowed = sal_False; + try + { + Reference< XDatabaseMetaData > xMetaData(m_xConnection->getMetaData()); + bPKeyAllowed = xMetaData->supportsCoreSQLGrammar(); + } + catch(const Exception&) + { + OSL_ENSURE(0,"Exception caught while asking for supportsCoreSQLGrammar!"); + } + if ( bPKeyAllowed ) + { + ODatabaseExport::TColumns::iterator aFind = ::std::find_if(m_vDestColumns.begin(),m_vDestColumns.end() + ,::std::compose1(::std::mem_fun(&OFieldDescription::IsPrimaryKey),::std::select2nd<ODatabaseExport::TColumns::value_type>())); + if ( aFind == m_vDestColumns.end() ) + { + String sTitle(ModuleRes(STR_TABLEDESIGN_NO_PRIM_KEY_HEAD)); + String sMsg(ModuleRes(STR_TABLEDESIGN_NO_PRIM_KEY)); + OSQLMessageBox aBox(this, sTitle,sMsg, WB_YES_NO_CANCEL | WB_DEF_YES); + + INT16 nReturn = aBox.Execute(); + + switch(nReturn ) + { + case RET_YES: + { + OCopyTable* pPage = reinterpret_cast<OCopyTable*>(GetPage(0)); + m_bCreatePrimaryColumn = sal_True; + m_aKeyName = pPage->GetKeyName(); + sal_Int32 nBreakPos2 = 0; + CheckColumns(nBreakPos2); + break; + } + case RET_CANCEL: + ShowPage(3); + return 0; + default: + ; + } + } + } + } break; } case WIZARD_APPEND_DATA: @@ -636,11 +697,11 @@ for(;pKeyBegin != pKeyEnd;++pKeyBegin) { - ODatabaseExport::TColumns::iterator aIter = _rColumns.find(*pKeyBegin); - if ( aIter != _rColumns.end() ) + ODatabaseExport::TColumns::iterator keyPos = _rColumns.find(*pKeyBegin); + if ( keyPos != _rColumns.end() ) { - aIter->second->SetPrimaryKey(sal_True); - aIter->second->SetIsNullable(ColumnValue::NO_NULLS); + keyPos->second->SetPrimaryKey(sal_True); + keyPos->second->SetIsNullable(ColumnValue::NO_NULLS); } } } @@ -723,8 +784,9 @@ // now only the settings are missing if(xColumns->hasByName(pField->GetName())) { - xColumns->getByName(pField->GetName()) >>= xColumn; - if(xColumn.is()) + xColumn.set(xColumns->getByName(pField->GetName()),UNO_QUERY); + OSL_ENSURE(xColumn.is(),"OCopyTableWizard::appendColumns: Column is NULL!"); + if ( xColumn.is() ) dbaui::setColumnUiProperties(xColumn,pField); } else @@ -823,10 +885,11 @@ m_xDestObject->setPropertyValue(PROPERTY_TEXTCOLOR,m_xSourceObject->getPropertyValue(PROPERTY_TEXTCOLOR)); // can not be copied yet, because the filter or and order clause could the old table name } + + Reference< XColumnsSupplier > xSuppDestinationColumns( m_xDestObject, UNO_QUERY ); // now append the columns const ODatabaseExport::TColumnVector* pVec = getDestVector(); - Reference<XColumnsSupplier> xColSup(m_xDestObject,UNO_QUERY); - appendColumns(xColSup,pVec); + appendColumns( xSuppDestinationColumns, pVec ); // now append the primary key Reference<XKeysSupplier> xKeySup(m_xDestObject,UNO_QUERY); appendKey(xKeySup,pVec); @@ -856,8 +919,7 @@ // insert new table name into table filter ::dbaui::appendToFilter(m_xConnection,m_sName,GetFactory(),this); // set column mappings - Reference<XColumnsSupplier> xColSup(m_xDestObject,UNO_QUERY); - Reference<XNameAccess> xNameAccess = xColSup->getColumns(); + Reference<XNameAccess> xNameAccess = xSuppDestinationColumns->getColumns(); Sequence< ::rtl::OUString> aSeq = xNameAccess->getElementNames(); const ::rtl::OUString* pBegin = aSeq.getConstArray(); const ::rtl::OUString* pEnd = pBegin + aSeq.getLength(); @@ -895,7 +957,7 @@ ODatabaseExport::TPositions::iterator aColPos = m_vColumnPos.begin(); for(; aColPos != m_vColumnPos.end() && nOldPos;++aColPos,++aFound) { - if(aColPos->second != CONTAINER_ENTRY_NOTFOUND && !*aFound && nOldPos == aColPos->second) + if(aColPos->second != COLUMN_POSITION_NOT_FOUND && !*aFound && nOldPos == aColPos->second) break; } if(aColPos != m_vColumnPos.end()) @@ -1004,6 +1066,11 @@ return sAlias; } // ----------------------------------------------------------------------------- +void OCopyTableWizard::removeColumnNameFromNameMap(const ::rtl::OUString& _sName) +{ + m_mNameMapping.erase(_sName); +} +// ----------------------------------------------------------------------------- sal_Bool OCopyTableWizard::supportsType(sal_Int32 _nDataType,sal_Int32& _rNewDataType) { DBG_CHKTHIS(OCopyTableWizard,NULL); @@ -1138,3 +1205,4 @@ aMsg.Execute(); } // ----------------------------------------------------------------------------- + --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
