diff options
author | Norbert Thiebaud <nthiebaud@gmail.com> | 2014-06-27 17:07:23 +0200 |
---|---|---|
committer | Norbert Thiebaud <nthiebaud@gmail.com> | 2014-06-27 17:08:04 +0200 |
commit | 0181a13904daef160bee543e9806b23a835f79c8 (patch) | |
tree | d295606c21a25986b643f9ad6e9751903f48543a /connectivity | |
parent | 01a882039ec4d0edf4da7d3e10ffea569a3e4aee (diff) |
odbc properly support platform with sizeof(SQLWCHAR) = 4
Change-Id: I06d5a6c93817d2623fac3962b82c1319caf13276
Diffstat (limited to 'connectivity')
-rw-r--r-- | connectivity/source/drivers/odbc/OPreparedStatement.cxx | 27 | ||||
-rw-r--r-- | connectivity/source/drivers/odbc/OTools.cxx | 24 |
2 files changed, 29 insertions, 22 deletions
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; } |