odbc properly support platform with sizeof(SQLWCHAR) = 4
Change-Id: I06d5a6c93817d2623fac3962b82c1319caf13276
This commit is contained in:
parent
01a882039e
commit
0181a13904
@ -8797,7 +8797,7 @@ dnl ===================================================================
|
||||
dnl Check for system odbc
|
||||
dnl ===================================================================
|
||||
AC_MSG_CHECKING([which odbc headers to use])
|
||||
if test "$with_system_odbc" = "yes"; then
|
||||
if test "$with_system_odbc" = "yes" -o "$_os" = Darwin ; then
|
||||
AC_MSG_RESULT([external])
|
||||
SYSTEM_ODBC_HEADERS=TRUE
|
||||
|
||||
|
@ -317,6 +317,7 @@ void OPreparedStatement::setParameter(const sal_Int32 parameterIndex, const sal_
|
||||
sal_Int32 nCharLen;
|
||||
sal_Int32 nByteLen;
|
||||
void *pData;
|
||||
OString sOData;
|
||||
if (useWChar)
|
||||
{
|
||||
/*
|
||||
@ -332,23 +333,27 @@ void OPreparedStatement::setParameter(const sal_Int32 parameterIndex, const sal_
|
||||
* and the established API that most drivers implement.
|
||||
* As wchar is often 32 bits, this differs from C-style strings of wchar!
|
||||
*
|
||||
* On MacOS X, the "W" variants use wchar_t, which is UCS4
|
||||
*
|
||||
* Our internal OUString storage is always UTF-16, so no conversion to do here.
|
||||
*/
|
||||
BOOST_STATIC_ASSERT( sizeof(sal_Unicode) == 2 );
|
||||
BOOST_STATIC_ASSERT( sizeof(SQLWCHAR) == 2 );
|
||||
nCharLen = _sData.getLength();
|
||||
nByteLen = nCharLen * sizeof(sal_Unicode);
|
||||
pData = allocBindBuf(parameterIndex, nByteLen);
|
||||
memcpy(pData, _sData.getStr(), nByteLen);
|
||||
rtl_TextEncoding nSQLWCHAREncoding = RTL_TEXTENCODING_UCS2;
|
||||
if( sizeof(SQLWCHAR) == 4 )
|
||||
{
|
||||
nSQLWCHAREncoding = RTL_TEXTENCODING_UCS4;
|
||||
}
|
||||
|
||||
sOData = OUStringToOString(_sData, nSQLWCHAREncoding);
|
||||
nByteLen = sOData.getLength();
|
||||
nCharLen = nByteLen / sizeof(SQLWCHAR);
|
||||
}
|
||||
else
|
||||
{
|
||||
OString sOData( OUStringToOString(_sData, getOwnConnection()->getTextEncoding()) );
|
||||
nCharLen = sOData.getLength();
|
||||
nByteLen = nCharLen;
|
||||
sOData = OUStringToOString(_sData, getOwnConnection()->getTextEncoding());
|
||||
nCharLen = nByteLen = sOData.getLength();
|
||||
}
|
||||
pData = allocBindBuf(parameterIndex, nByteLen);
|
||||
memcpy(pData, sOData.getStr(), nByteLen);
|
||||
}
|
||||
|
||||
setParameter( parameterIndex, _nType, nCharLen, _nScale, pData, nByteLen, nByteLen );
|
||||
}
|
||||
|
@ -405,7 +405,7 @@ OUString OTools::getStringValue(OConnection* _pConnection,
|
||||
SQLSMALLINT _fSqlType,
|
||||
bool &_bWasNull,
|
||||
const Reference< XInterface >& _xInterface,
|
||||
rtl_TextEncoding _nTextEncoding) throw(SQLException, RuntimeException)
|
||||
const rtl_TextEncoding _nTextEncoding) throw(SQLException, RuntimeException)
|
||||
{
|
||||
OUStringBuffer aData;
|
||||
switch(_fSqlType)
|
||||
@ -414,15 +414,18 @@ OUString OTools::getStringValue(OConnection* _pConnection,
|
||||
case SQL_WCHAR:
|
||||
case SQL_WLONGVARCHAR:
|
||||
{
|
||||
sal_Unicode waCharArray[2048];
|
||||
// we assume everyone (LibO & ODBC) uses UTF-16; see OPreparedStatement::setParameter
|
||||
BOOST_STATIC_ASSERT(sizeof(sal_Unicode) == 2);
|
||||
BOOST_STATIC_ASSERT(sizeof(SQLWCHAR) == 2);
|
||||
BOOST_STATIC_ASSERT(sizeof(waCharArray) % 2 == 0);
|
||||
SQLWCHAR waCharArray[2048];
|
||||
rtl_TextEncoding nSQLWCHAREncoding = RTL_TEXTENCODING_UCS2;
|
||||
BOOST_STATIC_ASSERT(sizeof(SQLWCHAR) == 2 || sizeof(SQLWCHAR) == 4);
|
||||
if(sizeof(SQLWCHAR) == 4)
|
||||
{
|
||||
// we assume LibO uses UTF-16 and & ODBC uses UCS4 (UTF-32); see OPreparedStatement::setParameter
|
||||
nSQLWCHAREncoding = RTL_TEXTENCODING_UCS4;
|
||||
}
|
||||
// Size == number of bytes, Len == number of UTF-16 code units
|
||||
const SQLLEN nMaxSize = sizeof(waCharArray);
|
||||
const SQLLEN nMaxLen = sizeof(waCharArray) / sizeof(sal_Unicode);
|
||||
BOOST_STATIC_ASSERT(nMaxLen * sizeof(sal_Unicode) == nMaxSize);
|
||||
const SQLLEN nMaxLen = sizeof(waCharArray) / sizeof(SQLWCHAR);
|
||||
BOOST_STATIC_ASSERT(nMaxLen * sizeof(SQLWCHAR) == nMaxSize);
|
||||
|
||||
// read the unicode data
|
||||
SQLLEN pcbValue = SQL_NO_TOTAL;
|
||||
@ -456,11 +459,10 @@ OUString OTools::getStringValue(OConnection* _pConnection,
|
||||
}
|
||||
else
|
||||
{
|
||||
nReadChars = pcbValue/sizeof(sal_Unicode);
|
||||
nReadChars = pcbValue/sizeof(SQLWCHAR);
|
||||
}
|
||||
|
||||
aData.append(waCharArray, nReadChars);
|
||||
|
||||
aData.append(OUString((sal_Char*)waCharArray, nReadChars, nSQLWCHAREncoding));
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user