diff options
Diffstat (limited to 'dbaccess/source/ui/misc/WCopyTable.cxx')
-rw-r--r-- | dbaccess/source/ui/misc/WCopyTable.cxx | 148 |
1 files changed, 65 insertions, 83 deletions
diff --git a/dbaccess/source/ui/misc/WCopyTable.cxx b/dbaccess/source/ui/misc/WCopyTable.cxx index 9c92f1301c71..7825c1af26c8 100644 --- a/dbaccess/source/ui/misc/WCopyTable.cxx +++ b/dbaccess/source/ui/misc/WCopyTable.cxx @@ -53,7 +53,10 @@ #include <o3tl/safeint.hxx> #include <rtl/ustrbuf.hxx> #include <sal/log.hxx> -#include <tools/diagnose_ex.h> +#include <comphelper/diagnose_ex.hxx> + +#include <algorithm> +#include <utility> using namespace ::dbaui; using namespace ::com::sun::star::uno; @@ -130,21 +133,21 @@ bool ObjectCopySource::isView() const void ObjectCopySource::copyUISettingsTo( const Reference< XPropertySet >& _rxObject ) const { - const OUString aCopyProperties[] = { - OUString(PROPERTY_FONT), OUString(PROPERTY_ROW_HEIGHT), OUString(PROPERTY_TEXTCOLOR),OUString(PROPERTY_TEXTLINECOLOR),OUString(PROPERTY_TEXTEMPHASIS),OUString(PROPERTY_TEXTRELIEF) + static constexpr OUString aCopyProperties[] { + PROPERTY_FONT, PROPERTY_ROW_HEIGHT, PROPERTY_TEXTCOLOR,PROPERTY_TEXTLINECOLOR,PROPERTY_TEXTEMPHASIS,PROPERTY_TEXTRELIEF }; - for (const auto & aCopyPropertie : aCopyProperties) + for (const auto & aCopyProperty : aCopyProperties) { - if ( m_xObjectPSI->hasPropertyByName( aCopyPropertie ) ) - _rxObject->setPropertyValue( aCopyPropertie, m_xObject->getPropertyValue( aCopyPropertie ) ); + if ( m_xObjectPSI->hasPropertyByName( aCopyProperty ) ) + _rxObject->setPropertyValue( aCopyProperty, m_xObject->getPropertyValue( aCopyProperty ) ); } } void ObjectCopySource::copyFilterAndSortingTo( const Reference< XConnection >& _xConnection,const Reference< XPropertySet >& _rxObject ) const { - std::pair< OUString, OUString > aProperties[] = { - std::pair< OUString, OUString >(PROPERTY_FILTER,OUString(" AND ")) - ,std::pair< OUString, OUString >(PROPERTY_ORDER,OUString(" ORDER BY ")) + static constexpr std::pair< OUString, OUString > aProperties[] { + std::pair< OUString, OUString >(PROPERTY_FILTER,u" AND "_ustr) + ,std::pair< OUString, OUString >(PROPERTY_ORDER,u" ORDER BY "_ustr) }; try @@ -155,17 +158,17 @@ void ObjectCopySource::copyFilterAndSortingTo( const Reference< XConnection >& _ OUStringBuffer sStatement = "SELECT * FROM " + sTargetName + " WHERE 0=1"; - for (const std::pair<OUString,OUString> & aPropertie : aProperties) + for (const std::pair<OUString,OUString> & aProperty : aProperties) { - if ( m_xObjectPSI->hasPropertyByName( aPropertie.first ) ) + if ( m_xObjectPSI->hasPropertyByName( aProperty.first ) ) { OUString sFilter; - m_xObject->getPropertyValue( aPropertie.first ) >>= sFilter; + m_xObject->getPropertyValue( aProperty.first ) >>= sFilter; if ( !sFilter.isEmpty() ) { - sStatement.append(aPropertie.second); + sStatement.append(aProperty.second); sFilter = sFilter.replaceFirst(sSourceName,sTargetNameTemp); - _rxObject->setPropertyValue( aPropertie.first, makeAny(sFilter) ); + _rxObject->setPropertyValue( aProperty.first, Any(sFilter) ); sStatement.append(sFilter); } } @@ -210,27 +213,21 @@ OUString ObjectCopySource::getSelectStatement() const } else { // table - OUStringBuffer aSQL; - aSQL.append( "SELECT " ); + OUStringBuffer aSQL( "SELECT " ); // we need to create the sql stmt with column names // otherwise it is possible that names don't match const OUString sQuote = m_xMetaData->getIdentifierQuoteString(); Sequence< OUString > aColumnNames = getColumnNames(); - const OUString* pColumnName = aColumnNames.getConstArray(); - const OUString* pEnd = pColumnName + aColumnNames.getLength(); - for ( ; pColumnName != pEnd; ) + for (sal_Int32 i = 0; i < aColumnNames.getLength(); ++i) { - aSQL.append( ::dbtools::quoteName( sQuote, *pColumnName++ ) ); - - if ( pColumnName == pEnd ) - aSQL.append( " " ); - else - aSQL.append( ", " ); + if (i > 0) + aSQL.append(", "); + aSQL.append(::dbtools::quoteName(sQuote, aColumnNames[i])); } - aSQL.append( "FROM " ).append( ::dbtools::composeTableNameForSelect( m_xConnection, m_xObject ) ); + aSQL.append( " FROM " + ::dbtools::composeTableNameForSelect( m_xConnection, m_xObject ) ); sSelectStatement = aSQL.makeStringAndClear(); } @@ -248,11 +245,10 @@ OUString ObjectCopySource::getSelectStatement() const } // NamedTableCopySource -NamedTableCopySource::NamedTableCopySource( const Reference< XConnection >& _rxConnection, const OUString& _rTableName ) +NamedTableCopySource::NamedTableCopySource( const Reference< XConnection >& _rxConnection, OUString _sTableName ) :m_xConnection( _rxConnection, UNO_SET_THROW ) ,m_xMetaData( _rxConnection->getMetaData(), UNO_SET_THROW ) - ,m_sTableName( _rTableName ) - ,m_aColumnInfo() + ,m_sTableName(std::move( _sTableName )) { ::dbtools::qualifiedNameComponents( m_xMetaData, m_sTableName, m_sTableCatalog, m_sTableSchema, m_sTableBareName, ::dbtools::EComposeRule::Complete ); impl_ensureColumnInfo_throw(); @@ -268,7 +264,7 @@ bool NamedTableCopySource::isView() const OUString sTableType; try { - Reference< XResultSet > xTableDesc( m_xMetaData->getTables( makeAny( m_sTableCatalog ), m_sTableSchema, m_sTableBareName, + Reference< XResultSet > xTableDesc( m_xMetaData->getTables( Any( m_sTableCatalog ), m_sTableSchema, m_sTableBareName, Sequence< OUString >() ) ); Reference< XRow > xTableDescRow( xTableDesc, UNO_QUERY_THROW ); OSL_VERIFY( xTableDesc->next() ); @@ -328,9 +324,8 @@ void NamedTableCopySource::impl_ensureColumnInfo_throw() Sequence< OUString > NamedTableCopySource::getColumnNames() const { Sequence< OUString > aNames( m_aColumnInfo.size() ); - size_t nPos = 0; - for (auto const& elem : m_aColumnInfo) - aNames[ nPos++ ] = elem.GetName(); + std::transform(m_aColumnInfo.begin(), m_aColumnInfo.end(), aNames.getArray(), + [](const auto& elem) { return elem.GetName(); }); return aNames; } @@ -341,13 +336,13 @@ Sequence< OUString > NamedTableCopySource::getPrimaryKeyColumnNames() const try { - Reference< XResultSet > xPKDesc( m_xMetaData->getPrimaryKeys( makeAny( m_sTableCatalog ), m_sTableSchema, m_sTableBareName ) ); + Reference< XResultSet > xPKDesc( m_xMetaData->getPrimaryKeys( Any( 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 + aPKColNames.getArray()[ len ] = xPKDescRow->getString( 4 ); // COLUMN_NAME } } catch( const Exception& ) @@ -369,12 +364,8 @@ OFieldDescription* NamedTableCopySource::createFieldDescription( const OUString& OUString NamedTableCopySource::getSelectStatement() const { - OUStringBuffer aSQL; - aSQL.append( "SELECT * FROM " ); - - aSQL.append( ::dbtools::composeTableNameForSelect( m_xConnection, m_sTableCatalog, m_sTableSchema, m_sTableBareName ) ); - - return aSQL.makeStringAndClear(); + return "SELECT * FROM " + + ::dbtools::composeTableNameForSelect( m_xConnection, m_sTableCatalog, m_sTableSchema, m_sTableBareName ); } ::utl::SharedUNOComponent< XPreparedStatement > NamedTableCopySource::getPreparedSelectStatement() const @@ -490,7 +481,7 @@ OCopyTableWizard::OCopyTableWizard(weld::Window* pParent, const OUString& _rDefa const Reference< XConnection >& _xConnection, const Reference< XComponentContext >& _rxContext, const Reference< XInteractionHandler>& _xInteractionHandler) : vcl::RoadmapWizardMachine(pParent) - , m_mNameMapping(_xConnection->getMetaData().is() && _xConnection->getMetaData()->supportsMixedCaseQuotedIdentifiers()) + , m_mNameMapping(comphelper::UStringMixLess(_xConnection->getMetaData().is() && _xConnection->getMetaData()->supportsMixedCaseQuotedIdentifiers())) , m_xDestConnection( _xConnection ) , m_rSourceObject( _rSourceObject ) , m_xFormatter( getNumberFormatter( _xConnection, _rxContext ) ) @@ -582,18 +573,18 @@ OCopyTableWizard::OCopyTableWizard(weld::Window* pParent, const OUString& _rDefa weld::Container* OCopyTableWizard::CreatePageContainer() { - OString sIdent(OString::number(m_nPageCount)); + OUString sIdent(OUString::number(m_nPageCount)); weld::Container* pPageContainer = m_xAssistant->append_page(sIdent); return pPageContainer; } -OCopyTableWizard::OCopyTableWizard( weld::Window* pParent, const OUString& _rDefaultName, sal_Int16 _nOperation, - const ODatabaseExport::TColumns& _rSourceColumns, const ODatabaseExport::TColumnVector& _rSourceColVec, +OCopyTableWizard::OCopyTableWizard( weld::Window* pParent, OUString _sDefaultName, sal_Int16 _nOperation, + ODatabaseExport::TColumns&& _rSourceColumns, const ODatabaseExport::TColumnVector& _rSourceColVec, const Reference< XConnection >& _xConnection, const Reference< XNumberFormatter >& _xFormatter, TypeSelectionPageFactory _pTypeSelectionPageFactory, SvStream& _rTypeSelectionPageArg, const Reference< XComponentContext >& _rxContext ) : vcl::RoadmapWizardMachine(pParent) - , m_vSourceColumns(_rSourceColumns) - , m_mNameMapping(_xConnection->getMetaData().is() && _xConnection->getMetaData()->supportsMixedCaseQuotedIdentifiers()) + , m_vSourceColumns(std::move(_rSourceColumns)) + , m_mNameMapping(comphelper::UStringMixLess(_xConnection->getMetaData().is() && _xConnection->getMetaData()->supportsMixedCaseQuotedIdentifiers())) , m_xDestConnection( _xConnection ) , m_rSourceObject( DummyCopySource::Instance() ) , m_xFormatter(_xFormatter) @@ -602,7 +593,7 @@ OCopyTableWizard::OCopyTableWizard( weld::Window* pParent, const OUString& _rDef , m_nPageCount(0) , m_bDeleteSourceColumns(false) , m_bInterConnectionCopy( false ) - , m_sName(_rDefaultName) + , m_sName(std::move(_sDefaultName)) , m_nOperation( _nOperation ) , m_ePressed( WIZARD_NONE ) , m_bCreatePrimaryKeyColumn(false) @@ -655,9 +646,9 @@ void OCopyTableWizard::construct() if (!m_vDestColumns.empty()) // source is a html or rtf table - m_xNextPage->set_has_default(true); + m_xAssistant->change_default_widget(nullptr, m_xNextPage.get()); else - m_xFinish->set_has_default(true); + m_xAssistant->change_default_widget(nullptr, m_xFinish.get()); m_pTypeInfo = std::make_shared<OTypeInfo>(); m_pTypeInfo->aUIName = m_sTypeNames.getToken(TYPE_OTHER, ';'); @@ -675,6 +666,7 @@ OCopyTableWizard::~OCopyTableWizard() m_aTypeInfoIndex.clear(); m_aTypeInfo.clear(); m_aDestTypeInfoIndex.clear(); + m_aDestTypeInfo.clear(); } IMPL_LINK_NOARG(OCopyTableWizard, ImplPrevHdl, weld::Button&, void) @@ -740,6 +732,7 @@ bool OCopyTableWizard::CheckColumns(sal_Int32& _rnBreakPos) OFieldDescription* pField = new OFieldDescription(); pField->SetName(m_aKeyName); pField->FillFromTypeInfo(pTypeInfo,true,true); + pField->SetAutoIncrement(pTypeInfo->bAutoIncrement); pField->SetPrimaryKey(true); m_bAddPKFirstTime = false; insertColumn(0,pField); @@ -845,16 +838,15 @@ IMPL_LINK_NOARG(OCopyTableWizard, ImplOKHdl, weld::Button&, void) { OUString sMsg(DBA_RES(STR_TABLEDESIGN_NO_PRIM_KEY)); - SQLContext aError; - aError.Message = sMsg; - ::rtl::Reference xRequest( new ::comphelper::OInteractionRequest( makeAny( aError ) ) ); + SQLContext aError(sMsg, {}, {}, 0, {}, {}); + ::rtl::Reference xRequest( new ::comphelper::OInteractionRequest( Any( aError ) ) ); ::rtl::Reference xYes = new ::comphelper::OInteractionApprove; - xRequest->addContinuation( xYes.get() ); + xRequest->addContinuation( xYes ); xRequest->addContinuation( new ::comphelper::OInteractionDisapprove ); ::rtl::Reference< ::comphelper::OInteractionAbort > xAbort = new ::comphelper::OInteractionAbort; - xRequest->addContinuation( xAbort.get() ); + xRequest->addContinuation( xAbort ); - m_xInteractionHandler->handle( xRequest.get() ); + m_xInteractionHandler->handle( xRequest ); if ( xYes->wasSelected() ) { @@ -995,19 +987,15 @@ void OCopyTableWizard::loadData( const ICopyTableSourceObject& _rSourceObject, _rColumns.clear(); OFieldDescription* pActFieldDescr = nullptr; - OUString const sCreateParam("x"); + static constexpr OUStringLiteral sCreateParam(u"x"); // ReadOnly-Flag // On drop no line must be editable. // On add only empty lines must be editable. // On Add and Drop all lines can be edited. - Sequence< OUString > aColumns( _rSourceObject.getColumnNames() ); - const OUString* pColumn = aColumns.getConstArray(); - const OUString* pColumnEnd = pColumn + aColumns.getLength(); - - for ( ; pColumn != pColumnEnd; ++pColumn ) + for (auto& column : _rSourceObject.getColumnNames()) { // get the properties of the column - pActFieldDescr = _rSourceObject.createFieldDescription( *pColumn ); + pActFieldDescr = _rSourceObject.createFieldDescription(column); OSL_ENSURE( pActFieldDescr, "OCopyTableWizard::loadData: illegal field description!" ); if ( !pActFieldDescr ) continue; @@ -1029,13 +1017,9 @@ void OCopyTableWizard::loadData( const ICopyTableSourceObject& _rSourceObject, } // determine which columns belong to the primary key - Sequence< OUString > aPrimaryKeyColumns( _rSourceObject.getPrimaryKeyColumnNames() ); - const OUString* pKeyColName = aPrimaryKeyColumns.getConstArray(); - const OUString* pKeyColEnd = pKeyColName + aPrimaryKeyColumns.getLength(); - - for( ; pKeyColName != pKeyColEnd; ++pKeyColName ) + for (auto& keyColName : _rSourceObject.getPrimaryKeyColumnNames()) { - ODatabaseExport::TColumns::const_iterator keyPos = _rColumns.find( *pKeyColName ); + ODatabaseExport::TColumns::const_iterator keyPos = _rColumns.find(keyColName); if ( keyPos != _rColumns.end() ) { keyPos->second->SetPrimaryKey( true ); @@ -1078,7 +1062,7 @@ void OCopyTableWizard::appendColumns( Reference<XColumnsSupplier> const & _rxCol if(!_bKeyColumns) dbaui::setColumnProperties(xColumn,pField); else - xColumn->setPropertyValue(PROPERTY_NAME,makeAny(pField->GetName())); + xColumn->setPropertyValue(PROPERTY_NAME,Any(pField->GetName())); xAppend->appendByDescriptor(xColumn); xColumn = nullptr; @@ -1113,7 +1097,7 @@ void OCopyTableWizard::appendKey( Reference<XKeysSupplier> const & _rxSup, const Reference<XPropertySet> xKey = xKeyFactory->createDataDescriptor(); OSL_ENSURE(xKey.is(),"Key is null!"); - xKey->setPropertyValue(PROPERTY_TYPE,makeAny(KeyType::PRIMARY)); + xKey->setPropertyValue(PROPERTY_TYPE,Any(KeyType::PRIMARY)); Reference<XColumnsSupplier> xColSup(xKey,UNO_QUERY); if(xColSup.is()) @@ -1198,16 +1182,16 @@ Reference< XPropertySet > OCopyTableWizard::createTable() if(xMetaData->getDatabaseProductName() == "MySQL") { Reference< XStatement > xSelect = m_xDestConnection->createStatement(); - Reference< XResultSet > xRs = xSelect->executeQuery("select database()"); + Reference< XResultSet > xRs = xSelect->executeQuery(u"select database()"_ustr); (void)xRs->next(); // first and only result Reference< XRow > xRow( xRs, UNO_QUERY_THROW ); sSchema = xRow->getString(1); } } - xTable->setPropertyValue(PROPERTY_CATALOGNAME,makeAny(sCatalog)); - xTable->setPropertyValue(PROPERTY_SCHEMANAME,makeAny(sSchema)); - xTable->setPropertyValue(PROPERTY_NAME,makeAny(sTable)); + xTable->setPropertyValue(PROPERTY_CATALOGNAME,Any(sCatalog)); + xTable->setPropertyValue(PROPERTY_SCHEMANAME,Any(sSchema)); + xTable->setPropertyValue(PROPERTY_NAME,Any(sTable)); Reference< XColumnsSupplier > xSuppDestinationColumns( xTable, UNO_QUERY ); // now append the columns @@ -1251,12 +1235,10 @@ Reference< XPropertySet > OCopyTableWizard::createTable() // set column mappings Reference<XNameAccess> xNameAccess = xSuppDestinationColumns->getColumns(); Sequence< OUString> aSeq = xNameAccess->getElementNames(); - const OUString* pIter = aSeq.getConstArray(); - const OUString* pEnd = pIter + aSeq.getLength(); - for(sal_Int32 nNewPos=1;pIter != pEnd;++pIter,++nNewPos) + for (sal_Int32 i = 0; i < aSeq.getLength(); ++i) { - ODatabaseExport::TColumns::const_iterator aDestIter = m_vDestColumns.find(*pIter); + ODatabaseExport::TColumns::const_iterator aDestIter = m_vDestColumns.find(aSeq[i]); if ( aDestIter != m_vDestColumns.end() ) { @@ -1273,7 +1255,7 @@ Reference< XPropertySet > OCopyTableWizard::createTable() if ( m_vColumnPositions.end() != aPosFind ) { - aPosFind->second = nNewPos; + aPosFind->second = i + 1; OSL_ENSURE( m_vColumnTypes.size() > o3tl::make_unsigned( aPosFind - m_vColumnPositions.begin() ), "Invalid index for vector!" ); m_vColumnTypes[ aPosFind - m_vColumnPositions.begin() ] = (*aFind)->second->GetType(); @@ -1362,7 +1344,7 @@ void OCopyTableWizard::setOperation( const sal_Int16 _nOperation ) OUString OCopyTableWizard::convertColumnName(const TColumnFindFunctor& _rCmpFunctor, const OUString& _sColumnName, - const OUString& _sExtraChars, + std::u16string_view _sExtraChars, sal_Int32 _nMaxNameLen) { OUString sAlias = _sColumnName; @@ -1495,7 +1477,7 @@ TOTypeInfoSP OCopyTableWizard::convertType(const TOTypeInfoSP& _pType, bool& _bN if ( !pType ) { _bNotConvert = false; - pType = ::dbaui::getTypeInfoFromType(m_aDestTypeInfo,DataType::VARCHAR,_pType->aTypeName,"x",50,0,false,bForce); + pType = ::dbaui::getTypeInfoFromType(m_aDestTypeInfo,DataType::VARCHAR,_pType->aTypeName,u"x"_ustr,50,0,false,bForce); if ( !pType ) pType = m_pTypeInfo; } @@ -1545,7 +1527,7 @@ void OCopyTableWizard::showError(const Any& _aError) try { ::rtl::Reference< ::comphelper::OInteractionRequest > xRequest( new ::comphelper::OInteractionRequest( _aError ) ); - m_xInteractionHandler->handle( xRequest.get() ); + m_xInteractionHandler->handle( xRequest ); } catch( const Exception& ) { |