diff options
Diffstat (limited to 'dbaccess/source/ui/dlg/DbAdminImpl.cxx')
-rw-r--r-- | dbaccess/source/ui/dlg/DbAdminImpl.cxx | 74 |
1 files changed, 54 insertions, 20 deletions
diff --git a/dbaccess/source/ui/dlg/DbAdminImpl.cxx b/dbaccess/source/ui/dlg/DbAdminImpl.cxx index 551f613fe5bb..3fa122bf6c69 100644 --- a/dbaccess/source/ui/dlg/DbAdminImpl.cxx +++ b/dbaccess/source/ui/dlg/DbAdminImpl.cxx @@ -50,7 +50,7 @@ #include <connectivity/DriversConfig.hxx> #include <connectivity/dbexception.hxx> #include <osl/file.hxx> -#include <tools/diagnose_ex.h> +#include <comphelper/diagnose_ex.hxx> #include <osl/diagnose.h> #include <sal/log.hxx> #include <typelib/typedescription.hxx> @@ -62,6 +62,7 @@ #include <iterator> #include <functional> #include <o3tl/functional.hxx> +#include <comphelper/string.hxx> namespace dbaui { @@ -72,7 +73,6 @@ using namespace com::sun::star::ucb; using namespace com::sun::star::task; using namespace com::sun::star::sdbc; using namespace com::sun::star::sdb; -using namespace com::sun::star::lang; using namespace com::sun::star::beans; using namespace com::sun::star::util; using namespace com::sun::star::container; @@ -88,7 +88,7 @@ namespace OSL_ENSURE( pPool, "implCheckItemType: invalid item pool!" ); if ( pPool ) { - const SfxPoolItem& rDefItem = pPool->GetDefaultItem( _nId ); + const SfxPoolItem& rDefItem = pPool->GetUserOrPoolDefaultItem( _nId ); bCorrectType = isItemType(&rDefItem); } return bCorrectType; @@ -210,7 +210,7 @@ bool ODbDataSourceAdministrationHelper::getCurrentSettings(Sequence< PropertyVal const SfxStringItem* pUser = m_pItemSetHelper->getOutputSet()->GetItem<SfxStringItem>(DSID_USER); if (pUser && pUser->GetValue().getLength()) aReturn.emplace_back( "user", 0, - makeAny(pUser->GetValue()), PropertyState_DIRECT_VALUE); + Any(pUser->GetValue()), PropertyState_DIRECT_VALUE); // check if the connection type requires a password if (hasAuthentication(*m_pItemSetHelper->getOutputSet())) @@ -260,7 +260,7 @@ bool ODbDataSourceAdministrationHelper::getCurrentSettings(Sequence< PropertyVal aRequest.HasAccount = false; // aRequest.Account - rtl::Reference<comphelper::OInteractionRequest> pRequest = new comphelper::OInteractionRequest(makeAny(aRequest)); + rtl::Reference<comphelper::OInteractionRequest> pRequest = new comphelper::OInteractionRequest(Any(aRequest)); // build an interaction request // two continuations (Ok and Cancel) @@ -294,7 +294,7 @@ bool ODbDataSourceAdministrationHelper::getCurrentSettings(Sequence< PropertyVal if (!sPassword.isEmpty()) aReturn.emplace_back( "password", 0, - makeAny(sPassword), PropertyState_DIRECT_VALUE); + Any(sPassword), PropertyState_DIRECT_VALUE); } if ( !aReturn.empty() ) @@ -320,7 +320,7 @@ void ODbDataSourceAdministrationHelper::successfullyConnected() OUString sPassword = pPassword->GetValue(); Reference< XPropertySet > xCurrentDatasource = getCurrentDataSource(); - lcl_putProperty(xCurrentDatasource,m_aDirectPropTranslator[DSID_PASSWORD], makeAny(sPassword)); + lcl_putProperty(xCurrentDatasource,m_aDirectPropTranslator[DSID_PASSWORD], Any(sPassword)); } } } @@ -465,7 +465,6 @@ OUString ODbDataSourceAdministrationHelper::getConnectionURL() const case ::dbaccess::DST_WRITER: break; case ::dbaccess::DST_MSACCESS: - case ::dbaccess::DST_MSACCESS_2007: { OUString sFileName = pCollection->cutPrefix(pUrlItem->GetValue()); OUString sNewFileName; @@ -523,6 +522,39 @@ OUString ODbDataSourceAdministrationHelper::getConnectionURL() const sNewUrl = pCollection->cutPrefix(pUrlItem->GetValue()) + lcl_createHostWithPort(nullptr,pPortNumber); } break; + case ::dbaccess::DST_POSTGRES: + { + sNewUrl = pCollection->cutPrefix(pUrlItem->GetValue()); + OUString rURL(comphelper::string::stripEnd(pUrlItem->GetValue(), '*')); + const SfxStringItem* pHostName = m_pItemSetHelper->getOutputSet()->GetItem<SfxStringItem>(DSID_CONN_HOSTNAME); + const SfxInt32Item* pPortNumber = m_pItemSetHelper->getOutputSet()->GetItem<SfxInt32Item>(DSID_POSTGRES_PORTNUMBER); + const SfxStringItem* pDatabaseName = m_pItemSetHelper->getOutputSet()->GetItem<SfxStringItem>(DSID_DATABASENAME); + if (pHostName && pHostName->GetValue().getLength()) + { + OUString hostname( pHostName->GetValue() ); + hostname = hostname.replaceAll( "\\", "\\\\"); + hostname = hostname.replaceAll( "\'", "\\'"); + hostname = "'" + hostname + "'"; + rURL += " host=" + hostname; + } + // tdf#157260: if port is already in the URL, don't add another one + if (pPortNumber && pPortNumber->GetValue() && (rURL.indexOf("port=") == -1)) + { + OUString port = "'" + OUString::number(pPortNumber->GetValue()) + "'"; + rURL += " port=" + port; + } + if (pDatabaseName && pDatabaseName->GetValue().getLength()) + { + OUString dbname( pDatabaseName->GetValue() ); + dbname = dbname.replaceAll( "\\", "\\\\"); + dbname = dbname.replaceAll( "\'", "\\'"); + dbname = "'" + dbname + "'"; + rURL += " dbname=" + dbname; + } + sNewUrl = rURL; + return sNewUrl; + } + break; case ::dbaccess::DST_JDBC: // run through default: @@ -530,7 +562,7 @@ OUString ODbDataSourceAdministrationHelper::getConnectionURL() const } if ( !sNewUrl.isEmpty() ) sNewUrl = pCollection->getPrefix(eType) + sNewUrl; - else + else if (pUrlItem) sNewUrl = pUrlItem->GetValue(); return sNewUrl; @@ -579,7 +611,7 @@ void ODbDataSourceAdministrationHelper::translateProperties(const Reference< XPr // collect the names of the additional settings PropertyValueSet aInfos; - for (const PropertyValue& rAdditionalInfo : std::as_const(aAdditionalInfo)) + for (const PropertyValue& rAdditionalInfo : aAdditionalInfo) { if( rAdditionalInfo.Name == "JDBCDRV" ) { // compatibility @@ -631,7 +663,7 @@ void ODbDataSourceAdministrationHelper::translateProperties(const SfxItemSet& _r try { xInfo = _rxDest->getPropertySetInfo(); } catch(Exception&) { } - static const OUStringLiteral sUrlProp(u"URL"); + static constexpr OUStringLiteral sUrlProp(u"URL"); // transfer the direct properties for (auto const& elem : m_aDirectPropTranslator) { @@ -648,7 +680,7 @@ void ODbDataSourceAdministrationHelper::translateProperties(const SfxItemSet& _r { if ( sUrlProp == elem.second ) { - Any aValue(makeAny(getConnectionURL())); + Any aValue(getConnectionURL()); // aValue <<= OUString(); lcl_putProperty(_rxDest, elem.second,aValue); } @@ -671,7 +703,7 @@ void ODbDataSourceAdministrationHelper::translateProperties(const SfxItemSet& _r // overwrite and extend them fillDatasourceInfo(_rSource, aInfo); // and propagate the (newly composed) sequence to the set - lcl_putProperty(_rxDest,PROPERTY_INFO, makeAny(aInfo)); + lcl_putProperty(_rxDest,PROPERTY_INFO, Any(aInfo)); } void ODbDataSourceAdministrationHelper::fillDatasourceInfo(const SfxItemSet& _rSource, Sequence< css::beans::PropertyValue >& _rInfo) @@ -700,7 +732,7 @@ void ODbDataSourceAdministrationHelper::fillDatasourceInfo(const SfxItemSet& _rS OUString sCharSet; implTranslateProperty(pCurrent) >>= sCharSet; if ( !sCharSet.isEmpty() ) - aRelevantSettings.insert(PropertyValue(aTranslation->second, 0, makeAny(sCharSet), PropertyState_DIRECT_VALUE)); + aRelevantSettings.insert(PropertyValue(aTranslation->second, 0, Any(sCharSet), PropertyState_DIRECT_VALUE)); } else aRelevantSettings.insert(PropertyValue(aTranslation->second, 0, implTranslateProperty(pCurrent), PropertyState_DIRECT_VALUE)); @@ -770,7 +802,7 @@ void ODbDataSourceAdministrationHelper::fillDatasourceInfo(const SfxItemSet& _rS // here we have a special entry for types from oracle if ( aTypeSettings.hasElements() ) { - aRelevantSettings.insert(PropertyValue("TypeInfoSettings", 0, makeAny(aTypeSettings), PropertyState_DIRECT_VALUE)); + aRelevantSettings.insert(PropertyValue("TypeInfoSettings", 0, Any(aTypeSettings), PropertyState_DIRECT_VALUE)); } // check which values are still left ('cause they were not present in the original sequence, but are to be set) @@ -860,8 +892,7 @@ OString ODbDataSourceAdministrationHelper::translatePropertyId( sal_Int32 _nId ) aString = indirectPos->second; } - OString aReturn( aString.getStr(), aString.getLength(), RTL_TEXTENCODING_ASCII_US ); - return aReturn; + return OUStringToOString( aString, RTL_TEXTENCODING_ASCII_US ); } template<class T> static bool checkItemType(const SfxPoolItem* pItem){ return dynamic_cast<const T*>(pItem) != nullptr;} @@ -914,7 +945,7 @@ void ODbDataSourceAdministrationHelper::implTranslateProperty( SfxItemSet& _rSet { sal_Int32 nValue = 0; _rValue >>= nValue; - _rSet.Put( SfxInt32Item( _nId, nValue ) ); + _rSet.Put( SfxInt32Item( TypedWhichId<SfxInt32Item>(_nId), nValue ) ); } else { SAL_WARN( "dbaccess", "ODbDataSourceAdministrationHelper::implTranslateProperty: invalid property value (" @@ -981,7 +1012,7 @@ void ODbDataSourceAdministrationHelper::convertUrl(SfxItemSet& _rDest) ::dbaccess::ODsnTypeCollection* pCollection = pTypeCollection->getCollection(); OSL_ENSURE(pCollection, "ODbAdminDialog::getDatasourceType: invalid type collection!"); - sal_uInt16 nPortNumberId = 0; + TypedWhichId<SfxInt32Item> nPortNumberId(0); sal_Int32 nPortNumber = -1; OUString sNewHostName; OUString sUrlPart; @@ -1001,6 +1032,9 @@ void ODbDataSourceAdministrationHelper::convertUrl(SfxItemSet& _rDest) case ::dbaccess::DST_LDAP: nPortNumberId = DSID_CONN_LDAP_PORTNUMBER; break; + case ::dbaccess::DST_POSTGRES: + nPortNumberId = DSID_POSTGRES_PORTNUMBER; + break; default: break; } @@ -1021,7 +1055,7 @@ void ODbDataSourceAdministrationHelper::convertUrl(SfxItemSet& _rDest) if ( !sNewHostName.isEmpty() ) _rDest.Put(SfxStringItem(DSID_CONN_HOSTNAME, sNewHostName)); - if ( nPortNumber != -1 && nPortNumberId != 0 ) + if ( nPortNumber != -1 && nPortNumberId != TypedWhichId<SfxInt32Item>(0) ) _rDest.Put(SfxInt32Item(nPortNumberId, nPortNumber)); } |