diff options
-rw-r--r-- | configure.ac | 2 | ||||
-rw-r--r-- | connectivity/source/drivers/odbc/OPreparedStatement.cxx | 27 | ||||
-rw-r--r-- | connectivity/source/drivers/odbc/OTools.cxx | 24 |
3 files changed, 30 insertions, 23 deletions
diff --git a/configure.ac b/configure.ac index 2f58380e64de..4da7afc124bb 100644 --- a/configure.ac +++ b/configure.ac @@ -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 diff --git a/connectivity/source/drivers/odbc/OPreparedStatement.cxx b/connectivity/source/drivers/odbc/OPreparedStatement.cxx index 74eb5c327b27..1a39897f433d 100644 --- a/connectivity/source/drivers/odbc/OPreparedStatement.cxx +++ b/connectivity/source/drivers/odbc/OPreparedStatement.cxx @@ -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; - pData = allocBindBuf(parameterIndex, nByteLen); - memcpy(pData, sOData.getStr(), nByteLen); + 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 ); } diff --git a/connectivity/source/drivers/odbc/OTools.cxx b/connectivity/source/drivers/odbc/OTools.cxx index 70452dd7c469..bbfc1ead1186 100644 --- a/connectivity/source/drivers/odbc/OTools.cxx +++ b/connectivity/source/drivers/odbc/OTools.cxx @@ -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; } |