diff options
-rw-r--r-- | connectivity/source/commontools/dbtools.cxx | 10 | ||||
-rw-r--r-- | include/comphelper/propertysequence.hxx | 40 |
2 files changed, 45 insertions, 5 deletions
diff --git a/connectivity/source/commontools/dbtools.cxx b/connectivity/source/commontools/dbtools.cxx index b385eb7ac7f4..f5d564c21906 100644 --- a/connectivity/source/commontools/dbtools.cxx +++ b/connectivity/source/commontools/dbtools.cxx @@ -68,6 +68,7 @@ #include <comphelper/interaction.hxx> #include <comphelper/processfactory.hxx> #include <comphelper/property.hxx> +#include <comphelper/propertysequence.hxx> #include <connectivity/conncleanup.hxx> #include <connectivity/dbconversion.hxx> #include <connectivity/dbexception.hxx> @@ -410,11 +411,10 @@ SharedConnection lcl_connectRowSet(const Reference< XRowSet>& _rxRowSet, const R xRowSetProps->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_PASSWORD)) >>= sPwd; if (!sUser.isEmpty()) { // use user and pwd together with the url - Sequence< PropertyValue> aInfo(2); - aInfo.getArray()[0].Name = "user"; - aInfo.getArray()[0].Value <<= sUser; - aInfo.getArray()[1].Name = "password"; - aInfo.getArray()[1].Value <<= sPwd; + auto aInfo(::comphelper::InitPropertySequence({ + { "user", makeAny(sUser) }, + { "password", makeAny(sPwd) } + })); xPureConnection = xDriverManager->getConnectionWithInfo( sURL, aInfo ); } else diff --git a/include/comphelper/propertysequence.hxx b/include/comphelper/propertysequence.hxx new file mode 100644 index 000000000000..ce28e4f813ce --- /dev/null +++ b/include/comphelper/propertysequence.hxx @@ -0,0 +1,40 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#ifndef INCLUDED_COMPHELPER_PROPERTYSEQUENCE_HXX +#define INCLUDED_COMPHELPER_PROPERTYSEQUENCE_HXX + +#include <utility> +#include <initializer_list> +#include <com/sun/star/uno/Any.hxx> +#include <com/sun/star/uno/Sequence.hxx> +#include <com/sun/star/beans/PropertyValue.hpp> + +namespace comphelper +{ + ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > InitPropertySequence( + ::std::initializer_list< ::std::pair< OUString, ::com::sun::star::uno::Any > > vInit) + { + ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue> vResult{static_cast<sal_Int32>(vInit.size())}; + size_t nCount{0}; + for(auto aEntry : vInit) + { + vResult[nCount].Name = std::move(aEntry.first); + vResult[nCount].Value = std::move(aEntry.second); + ++nCount; + } + return std::move(vResult); + } +} // namespace comphelper + + + +#endif // INCLUDED_COMPHELPER_PROPERTYSEQUENCE_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |