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