tdf#116171: Tunnel arbitrary rtl_TextEncoding from sc to sdbc:dbase connection
...including those that have no corresponding textual IANA character set name representation, like RTL_TEXTENCODING_MS_950 which is apparently used in some DBase files. In the past, if eCharSet was RTL_TEXTENCODING_DONTKNOW in lcl_getDBaseConnection it was sent as an empty string CharSet property, which the receiving OConnection::construct translated back to else m_nTextEncoding = RTL_TEXTENCODING_DONTKNOW; so the net effect remains the same for that special case. Change-Id: I84eec8a93d000752b3c429976c58721ea9ea32a4 Reviewed-on: https://gerrit.libreoffice.org/50772 Reviewed-by: Lionel Elie Mamane <lionel@mamane.lu> Tested-by: Jenkins <ci@libreoffice.org>
This commit is contained in:
@@ -38,6 +38,7 @@
|
|||||||
#include <ucbhelper/content.hxx>
|
#include <ucbhelper/content.hxx>
|
||||||
#include <connectivity/dbcharset.hxx>
|
#include <connectivity/dbcharset.hxx>
|
||||||
#include <connectivity/dbexception.hxx>
|
#include <connectivity/dbexception.hxx>
|
||||||
|
#include <o3tl/any.hxx>
|
||||||
#include <osl/thread.h>
|
#include <osl/thread.h>
|
||||||
#include <osl/nlsupport.h>
|
#include <osl/nlsupport.h>
|
||||||
#include <strings.hrc>
|
#include <strings.hrc>
|
||||||
@@ -98,15 +99,22 @@ void OConnection::construct(const OUString& url,const Sequence< PropertyValue >&
|
|||||||
OSL_VERIFY( pIter->Value >>= aExt );
|
OSL_VERIFY( pIter->Value >>= aExt );
|
||||||
else if( pIter->Name == "CharSet" )
|
else if( pIter->Name == "CharSet" )
|
||||||
{
|
{
|
||||||
OUString sIanaName;
|
if (auto const numeric = o3tl::tryAccess<sal_uInt16>(pIter->Value))
|
||||||
OSL_VERIFY( pIter->Value >>= sIanaName );
|
{
|
||||||
|
m_nTextEncoding = *numeric;
|
||||||
::dbtools::OCharsetMap aLookupIanaName;
|
}
|
||||||
::dbtools::OCharsetMap::const_iterator aLookup = aLookupIanaName.find(sIanaName, ::dbtools::OCharsetMap::IANA());
|
|
||||||
if (aLookup != aLookupIanaName.end())
|
|
||||||
m_nTextEncoding = (*aLookup).getEncoding();
|
|
||||||
else
|
else
|
||||||
m_nTextEncoding = RTL_TEXTENCODING_DONTKNOW;
|
{
|
||||||
|
OUString sIanaName;
|
||||||
|
OSL_VERIFY( pIter->Value >>= sIanaName );
|
||||||
|
|
||||||
|
::dbtools::OCharsetMap aLookupIanaName;
|
||||||
|
::dbtools::OCharsetMap::const_iterator aLookup = aLookupIanaName.find(sIanaName, ::dbtools::OCharsetMap::IANA());
|
||||||
|
if (aLookup != aLookupIanaName.end())
|
||||||
|
m_nTextEncoding = (*aLookup).getEncoding();
|
||||||
|
else
|
||||||
|
m_nTextEncoding = RTL_TEXTENCODING_DONTKNOW;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if( pIter->Name == "ShowDeleted" )
|
else if( pIter->Name == "ShowDeleted" )
|
||||||
{
|
{
|
||||||
|
@@ -45,6 +45,10 @@ service FILEConnectionProperties
|
|||||||
|
|
||||||
<p>See the <a href="http://www.iana.org/assignments/character-sets">IANA character set list</a>
|
<p>See the <a href="http://www.iana.org/assignments/character-sets">IANA character set list</a>
|
||||||
for a list of valid values.</p>
|
for a list of valid values.</p>
|
||||||
|
|
||||||
|
<p>For internal purposes (e.g., when using an encoding for which no IANA character set name
|
||||||
|
exists), this may also be an UNSIGNED SHORT value representing one of the rtl_TextEncoding
|
||||||
|
values in rtl/textenc.h.</p>
|
||||||
*/
|
*/
|
||||||
[optional, property] string CharSet;
|
[optional, property] string CharSet;
|
||||||
};
|
};
|
||||||
|
@@ -30,10 +30,6 @@
|
|||||||
#include <svx/txenctab.hxx>
|
#include <svx/txenctab.hxx>
|
||||||
#include <unotools/sharedunocomponent.hxx>
|
#include <unotools/sharedunocomponent.hxx>
|
||||||
|
|
||||||
#if HAVE_FEATURE_DBCONNECTIVITY
|
|
||||||
#include <svx/dbcharsethelper.hxx>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <com/sun/star/sdb/CommandType.hpp>
|
#include <com/sun/star/sdb/CommandType.hpp>
|
||||||
#include <com/sun/star/sdbc/DataType.hpp>
|
#include <com/sun/star/sdbc/DataType.hpp>
|
||||||
#include <com/sun/star/sdbc/SQLException.hpp>
|
#include <com/sun/star/sdbc/SQLException.hpp>
|
||||||
@@ -124,26 +120,13 @@ namespace
|
|||||||
OUString aConnUrl("sdbc:dbase:");
|
OUString aConnUrl("sdbc:dbase:");
|
||||||
aConnUrl += aPath;
|
aConnUrl += aPath;
|
||||||
|
|
||||||
::std::vector< rtl_TextEncoding > aEncodings;
|
// sdbc:dbase is based on the css.sdbc.FILEConnectionProperties UNOIDL service, so we can
|
||||||
svxform::charset_helper::getSupportedTextEncodings( aEncodings );
|
// transport the raw rtl_TextEncoding value instead of having to translate it into a IANA
|
||||||
::std::vector< rtl_TextEncoding >::iterator aIter = ::std::find(aEncodings.begin(),aEncodings.end(), eCharSet);
|
// character set name string (which might not exist for certain eCharSet values, like
|
||||||
if ( aIter == aEncodings.end() )
|
// RTL_TEXTENCODING_MS_950):
|
||||||
{
|
|
||||||
OSL_FAIL( "DBaseImport: dbtools::OCharsetMap doesn't know text encoding" );
|
|
||||||
return SCERR_IMPORT_CONNECT;
|
|
||||||
} // if ( aIter == aMap.end() )
|
|
||||||
OUString aCharSetStr;
|
|
||||||
if ( RTL_TEXTENCODING_DONTKNOW != *aIter )
|
|
||||||
{ // it's not the virtual "system charset"
|
|
||||||
const char* pIanaName = rtl_getMimeCharsetFromTextEncoding( *aIter );
|
|
||||||
OSL_ENSURE( pIanaName, "invalid mime name!" );
|
|
||||||
if ( pIanaName )
|
|
||||||
aCharSetStr = OUString::createFromAscii( pIanaName );
|
|
||||||
}
|
|
||||||
|
|
||||||
uno::Sequence<beans::PropertyValue> aProps( comphelper::InitPropertySequence({
|
uno::Sequence<beans::PropertyValue> aProps( comphelper::InitPropertySequence({
|
||||||
{ SC_DBPROP_EXTENSION, uno::Any(aExtension) },
|
{ SC_DBPROP_EXTENSION, uno::Any(aExtension) },
|
||||||
{ SC_DBPROP_CHARSET, uno::Any(aCharSetStr) }
|
{ SC_DBPROP_CHARSET, uno::Any(eCharSet) }
|
||||||
}));
|
}));
|
||||||
|
|
||||||
_rConnection = _rDrvMgr->getConnectionWithInfo( aConnUrl, aProps );
|
_rConnection = _rDrvMgr->getConnectionWithInfo( aConnUrl, aProps );
|
||||||
|
Reference in New Issue
Block a user