User: kz Date: 2006/12/13 08:14:13 Modified: dba/connectivity/source/commontools/dbtools2.cxx
Log: INTEGRATION: CWS dba22ui (1.19.14); FILE MERGED 2006/12/05 09:46:53 fs 1.19.14.2: copying the fix for #i72252# from CWS dba22b to dba22ui - intended for the latter, but wrongly checked in into the former 2006/10/25 10:20:29 fs 1.19.14.1: +convertUnicodeStringToLength Issue number: #i62664# Submitted by: [EMAIL PROTECTED] Extended by: [EMAIL PROTECTED] File Changes: Directory: /dba/connectivity/source/commontools/ ================================================ File [changed]: dbtools2.cxx Url: http://dba.openoffice.org/source/browse/dba/connectivity/source/commontools/dbtools2.cxx?r1=1.19&r2=1.20 Delta lines: +104 -31 ---------------------- --- dbtools2.cxx 25 Sep 2006 09:42:05 -0000 1.19 +++ dbtools2.cxx 13 Dec 2006 16:14:09 -0000 1.20 @@ -41,8 +41,16 @@ #endif #include "connectivity/dbconversion.hxx" #ifndef _DBHELPER_DBCHARSET_HXX_ -#include <connectivity/dbcharset.hxx> +#include "connectivity/dbcharset.hxx" #endif + +#ifndef CONNECTIVITY_SHAREDRESOURCES_HXX +#include "resource/sharedresources.hxx" +#endif +#ifndef CONNECTIVITY_RESOURCE_COMMON_HRC +#include "resource/common_res.hrc" +#endif + #ifndef _COM_SUN_STAR_SDBC_XCONNECTION_HPP_ #include <com/sun/star/sdbc/XConnection.hpp> #endif @@ -95,6 +103,8 @@ #include <com/sun/star/container/XChild.hpp> #endif +#include <tools/diagnose_ex.h> + //......................................................................... namespace dbtools { @@ -569,6 +579,31 @@ return xProp; } + +// ----------------------------------------------------------------------------- +bool getBooleanDataSourceSetting( const Reference< XConnection >& _rxConnection, const sal_Char* _pAsciiSettingName ) +{ + bool bValue( false ); + try + { + Reference< XPropertySet> xDataSourceProperties( findDataSource( _rxConnection ), UNO_QUERY ); + OSL_ENSURE( xDataSourceProperties.is(), "::dbtools::getBooleanDataSourceSetting: somebody is using this with a non-SDB-level connection!" ); + if ( xDataSourceProperties.is() ) + { + Reference< XPropertySet > xSettings( + xDataSourceProperties->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Settings") ) ), + UNO_QUERY_THROW + ); + OSL_VERIFY( xSettings->getPropertyValue( ::rtl::OUString::createFromAscii( _pAsciiSettingName ) ) >>= bValue ); + } + } + catch( const Exception& ) + { + DBG_UNHANDLED_EXCEPTION(); + } + return bValue; +} + // ----------------------------------------------------------------------------- sal_Bool isDataSourcePropertyEnabled(const Reference<XInterface>& _xProp,const ::rtl::OUString& _sProperty,sal_Bool _bDefault) { @@ -589,7 +624,7 @@ } catch(SQLException&) { - OSL_ASSERT(!"isDataSourcePropertyEnabled"); + DBG_UNHANDLED_EXCEPTION(); } return bEnabled; } @@ -816,9 +851,26 @@ } return bIsEmbedded; } - // ----------------------------------------------------------------------------- -sal_Int32 DBTypeConversion::convertUnicodeString( const ::rtl::OUString& _rSource, ::rtl::OString& _rDest, rtl_TextEncoding _eEncoding ) SAL_THROW((com::sun::star::sdbc::SQLException)) +// ----------------------------------------------------------------------------- +namespace +{ + ::rtl::OUString lcl_getEncodingName( rtl_TextEncoding _eEncoding ) { + ::rtl::OUString sEncodingName; + + OCharsetMap aCharsets; + OCharsetMap::CharsetIterator aEncodingPos = aCharsets.find( _eEncoding ); + OSL_ENSURE( aEncodingPos != aCharsets.end(), "lcl_getEncodingName: *which* encoding?" ); + if ( aEncodingPos != aCharsets.end() ) + sEncodingName = (*aEncodingPos).getIanaName(); + + return sEncodingName; + } +} + +// ----------------------------------------------------------------------------- +sal_Int32 DBTypeConversion::convertUnicodeString( const ::rtl::OUString& _rSource, ::rtl::OString& _rDest, rtl_TextEncoding _eEncoding ) SAL_THROW((com::sun::star::sdbc::SQLException)) +{ if ( !rtl_convertUStringToString( &_rDest.pData, _rSource.getStr(), _rSource.getLength(), _eEncoding, RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR | @@ -827,19 +879,14 @@ RTL_UNICODETOTEXT_FLAGS_NOCOMPOSITE ) ) { - ::rtl::OUString sExplanation( RTL_CONSTASCII_USTRINGPARAM( "The string '" ) ); - sExplanation += _rSource; - sExplanation += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "' cannot be converted using the encoding '" ) ); - - OCharsetMap aCharsets; - OCharsetMap::CharsetIterator aEncodingPos = aCharsets.find( _eEncoding ); - OSL_ENSURE( aEncodingPos != aCharsets.end(), "ODbaseTable::UpdateBuffer: *which* encoding?" ); - if ( aEncodingPos != aCharsets.end() ) - sExplanation += (*aEncodingPos).getIanaName(); - sExplanation += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "'." ) ); + SharedResources aResources; + ::rtl::OUString sMessage = aResources.getResourceStringWithSubstitution( STR_CANNOT_CONVERT_STRING, + "$string$", _rSource, + "$charset$", lcl_getEncodingName( _eEncoding ) + ); throw SQLException( - sExplanation, + sMessage, NULL, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "22018" ) ), 22018, @@ -848,7 +895,33 @@ } return _rDest.getLength(); +} + +// ----------------------------------------------------------------------------- +sal_Int32 DBTypeConversion::convertUnicodeStringToLength( const ::rtl::OUString& _rSource, ::rtl::OString& _rDest, + sal_Int32 _nMaxLen, rtl_TextEncoding _eEncoding ) SAL_THROW((SQLException)) +{ + sal_Int32 nLen = convertUnicodeString( _rSource, _rDest, _eEncoding ); + if ( nLen > _nMaxLen ) + { + SharedResources aResources; + ::rtl::OUString sMessage = aResources.getResourceStringWithSubstitution( STR_STRING_LENGTH_EXCEEDED, + "$string$", _rSource, + "$maxlen$", ::rtl::OUString::valueOf( _nMaxLen ), + "$charset$", lcl_getEncodingName( _eEncoding ) + ); + + throw SQLException( + sMessage, + NULL, + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "22001" ) ), + 22001, + Any() + ); } + + return nLen; +} //......................................................................... } // namespace dbtools //......................................................................... --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
