From 97ac77f067910fa5e8206d75160fa63546a9358d Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 4 May 2024 07:03:24 +0200 Subject: Merging upstream version 4:24.2.3. Signed-off-by: Daniel Baumann --- dbaccess/source/ui/dlg/DBSetupConnectionPages.cxx | 6 ++- dbaccess/source/ui/dlg/dbwizsetup.cxx | 3 ++ dbaccess/source/ui/dlg/generalpage.cxx | 32 ++++++++------- dbaccess/source/ui/misc/UITools.cxx | 45 ++++++++++++++-------- dbaccess/source/ui/misc/WCopyTable.cxx | 1 + dbaccess/source/ui/tabledesign/TableController.cxx | 4 +- 6 files changed, 54 insertions(+), 37 deletions(-) (limited to 'dbaccess') diff --git a/dbaccess/source/ui/dlg/DBSetupConnectionPages.cxx b/dbaccess/source/ui/dlg/DBSetupConnectionPages.cxx index 22cdefdd6c..ad81680ba4 100644 --- a/dbaccess/source/ui/dlg/DBSetupConnectionPages.cxx +++ b/dbaccess/source/ui/dlg/DBSetupConnectionPages.cxx @@ -239,9 +239,13 @@ using namespace ::com::sun::star; if ( bHasMySQLNative ) m_xNATIVEDatabase->show(); - // if any of the options is checked, then there's nothing to do + // tdf#103068: if any of the options is checked, then just update the selected kind: + // it could happen that the selection and the wizard path are not in sync if ( m_xODBCDatabase->get_active() || m_xJDBCDatabase->get_active() || m_xNATIVEDatabase->get_active() ) + { + maClickHdl.Call(this); return; + } // prefer "native" or "JDBC" if ( bHasMySQLNative ) diff --git a/dbaccess/source/ui/dlg/dbwizsetup.cxx b/dbaccess/source/ui/dlg/dbwizsetup.cxx index 720892e2a0..2fb260e18e 100644 --- a/dbaccess/source/ui/dlg/dbwizsetup.cxx +++ b/dbaccess/source/ui/dlg/dbwizsetup.cxx @@ -312,6 +312,9 @@ void ODbTypeWizDialogSetup::activateDatabasePath() { OUString sOld = m_sURL; m_sURL = m_pGeneralPage->GetSelectedType(); + if (m_sURL.startsWith("sdbc:mysql:") && sOld.startsWith("sdbc:mysql:")) + m_sURL = sOld; // The type of MySQL connection was already set elsewhere; just use it, + // instead of the hardcoded one from the selector DataSourceInfoConverter::convert(getORB(), m_pCollection,sOld,m_sURL,m_pImpl->getCurrentDataSource()); ::dbaccess::DATASOURCE_TYPE eType = VerifyDataSourceType(m_pCollection->determineType(m_sURL)); if (eType == ::dbaccess::DST_UNKNOWN) diff --git a/dbaccess/source/ui/dlg/generalpage.cxx b/dbaccess/source/ui/dlg/generalpage.cxx index a2a48158c5..bb30884552 100644 --- a/dbaccess/source/ui/dlg/generalpage.cxx +++ b/dbaccess/source/ui/dlg/generalpage.cxx @@ -226,31 +226,29 @@ namespace dbaui OUString OGeneralPageWizard::getEmbeddedDBName( const SfxItemSet& _rSet ) { + if (!m_pCollection) + return {}; // first check whether or not the selection is invalid or readonly (invalid implies readonly, but not vice versa) bool bValid, bReadonly; getFlags( _rSet, bValid, bReadonly ); - - // if the selection is invalid, disable everything - - implSetCurrentType( OUString() ); + if (!bValid) + return {}; // compare the DSN prefix with the registered ones - OUString sDisplayName; - - if (m_pCollection && bValid) - { - implSetCurrentType( dbaccess::ODsnTypeCollection::getEmbeddedDatabase() ); - sDisplayName = m_pCollection->getTypeDisplayName( m_eCurrentSelection ); - onTypeSelected(m_eCurrentSelection); - } - - // select the correct datasource type - if ( dbaccess::ODsnTypeCollection::isEmbeddedDatabase( m_eCurrentSelection ) - && m_xEmbeddedDBType->find_text(sDisplayName) == -1 ) + OUString sDBURL; + if (const SfxStringItem* pUrlItem = _rSet.GetItem(DSID_CONNECTURL)) + if (dbaccess::ODsnTypeCollection::isEmbeddedDatabase(pUrlItem->GetValue())) + sDBURL = pUrlItem->GetValue(); + if (sDBURL.isEmpty()) + sDBURL = dbaccess::ODsnTypeCollection::getEmbeddedDatabase(); + OUString sDisplayName = m_pCollection->getTypeDisplayName(sDBURL); + + // ensure presence of the correct datasource type + if (!sDisplayName.isEmpty() && m_xEmbeddedDBType->find_text(sDisplayName) == -1) { // this indicates it's really a type which is known in general, but not supported on the current platform // show a message saying so // eSpecialMessage = smUnsupportedType; - insertEmbeddedDBTypeEntryData( m_eCurrentSelection, sDisplayName ); + insertEmbeddedDBTypeEntryData(sDBURL, sDisplayName); } return sDisplayName; diff --git a/dbaccess/source/ui/misc/UITools.cxx b/dbaccess/source/ui/misc/UITools.cxx index 483afced10..910baad617 100644 --- a/dbaccess/source/ui/misc/UITools.cxx +++ b/dbaccess/source/ui/misc/UITools.cxx @@ -1047,29 +1047,40 @@ void setEvalDateFormatForFormatter(Reference< css::util::XNumberFormatter > cons } } +static bool TypeIsGreater(const TOTypeInfoSP& lhs, const TOTypeInfoSP& rhs) +{ + assert(lhs); + if (!rhs) + return true; + if (lhs->nNumPrecRadix == rhs->nNumPrecRadix) + return lhs->nPrecision > rhs->nPrecision; + if (lhs->nPrecision == rhs->nPrecision) + return lhs->nNumPrecRadix > rhs->nNumPrecRadix; + if ((lhs->nNumPrecRadix > rhs->nNumPrecRadix) == (lhs->nPrecision > rhs->nPrecision)) + return lhs->nPrecision > rhs->nPrecision; + return std::pow(lhs->nNumPrecRadix, lhs->nPrecision) + > std::pow(rhs->nNumPrecRadix, rhs->nPrecision); +} + TOTypeInfoSP queryPrimaryKeyType(const OTypeInfoMap& _rTypeInfo) { - TOTypeInfoSP pTypeInfo; - // first we search for a type which supports autoIncrement + TOTypeInfoSP pTypeInfo, pFallback; + // first we search for a largest type which supports autoIncrement for (auto const& elem : _rTypeInfo) { - // OJ: we don't want to set an autoincrement column to be key - // because we don't have the possibility to know how to create - // such auto increment column later on - // so until we know how to do it, we create a column without autoincrement - // therefore we have searched - if ( elem.second->nType == DataType::INTEGER ) - { - pTypeInfo = elem.second; // alternative - break; - } - else if ( !pTypeInfo && elem.second->nType == DataType::DOUBLE ) - pTypeInfo = elem.second; // alternative - else if ( !pTypeInfo && elem.second->nType == DataType::REAL ) - pTypeInfo = elem.second; // alternative + if (elem.second->bAutoIncrement && TypeIsGreater(elem.second, pTypeInfo)) + pTypeInfo = elem.second; + if (pTypeInfo) + continue; + if (elem.second->nType == DataType::INTEGER) + pFallback = elem.second; // default alternative + else if (!pFallback && elem.second->nType == DataType::DOUBLE) + pFallback = elem.second; // alternative + else if (!pFallback && elem.second->nType == DataType::REAL) + pFallback = elem.second; // alternative } if ( !pTypeInfo ) // just a fallback - pTypeInfo = queryTypeInfoByType(DataType::VARCHAR,_rTypeInfo); + pTypeInfo = pFallback ? pFallback : queryTypeInfoByType(DataType::VARCHAR, _rTypeInfo); OSL_ENSURE(pTypeInfo,"checkColumns: can't find a type which is usable as a key!"); return pTypeInfo; diff --git a/dbaccess/source/ui/misc/WCopyTable.cxx b/dbaccess/source/ui/misc/WCopyTable.cxx index 29be877474..a2737543c7 100644 --- a/dbaccess/source/ui/misc/WCopyTable.cxx +++ b/dbaccess/source/ui/misc/WCopyTable.cxx @@ -737,6 +737,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); diff --git a/dbaccess/source/ui/tabledesign/TableController.cxx b/dbaccess/source/ui/tabledesign/TableController.cxx index 7e13ba566b..fd53297cad 100644 --- a/dbaccess/source/ui/tabledesign/TableController.cxx +++ b/dbaccess/source/ui/tabledesign/TableController.cxx @@ -903,15 +903,15 @@ bool OTableController::checkColumns(bool _bNew) { case RET_YES: { - auto pNewRow = std::make_shared(); TOTypeInfoSP pTypeInfo = ::dbaui::queryPrimaryKeyType(m_aTypeInfo); if ( !pTypeInfo ) break; + auto pNewRow = std::make_shared(); pNewRow->SetFieldType( pTypeInfo ); OFieldDescription* pActFieldDescr = pNewRow->GetActFieldDescr(); - pActFieldDescr->SetAutoIncrement(false); + pActFieldDescr->SetAutoIncrement(pTypeInfo->bAutoIncrement); pActFieldDescr->SetIsNullable(ColumnValue::NO_NULLS); pActFieldDescr->SetName( createUniqueName("ID" )); -- cgit v1.2.3