diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2014-06-27 23:07:00 +0200 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2014-06-27 23:07:00 +0200 |
commit | 939ce4afbb36673e03e90881c48fd4e2bbb74bb8 (patch) | |
tree | 36c42671e35f9da58004cc94fb41b141e01fcf57 /connectivity/source/drivers/odbc | |
parent | 8100100298b877765e1781fb0eed285e82749ad1 (diff) |
Blind fix for OPreparedStatement::setParameter's useWChar case
...after 0181a13904daef160bee543e9806b23a835f79c8 "odbc properly support
platform with sizeof(SQLWCHAR) = 4" introduced usage of RTL_TEXTENCODING_UCS2/4
there, which do not make sense in combination with converting between OString
and OUString.
OTools::getStringValue will need a corresponding fix, too, in the other
direction (where the OUString(sal_uInt32 const * codePoints,
sal_Int32 codPointCount) ctor will be useful).
Change-Id: Ia94cd0deec46d269b6ee43362f4849837bb011c5
Diffstat (limited to 'connectivity/source/drivers/odbc')
-rw-r--r-- | connectivity/source/drivers/odbc/OPreparedStatement.cxx | 33 |
1 files changed, 22 insertions, 11 deletions
diff --git a/connectivity/source/drivers/odbc/OPreparedStatement.cxx b/connectivity/source/drivers/odbc/OPreparedStatement.cxx index 1a39897f433d..e2bf7ce3624f 100644 --- a/connectivity/source/drivers/odbc/OPreparedStatement.cxx +++ b/connectivity/source/drivers/odbc/OPreparedStatement.cxx @@ -317,7 +317,6 @@ void OPreparedStatement::setParameter(const sal_Int32 parameterIndex, const sal_ sal_Int32 nCharLen; sal_Int32 nByteLen; void *pData; - OString sOData; if (useWChar) { /* @@ -337,23 +336,35 @@ void OPreparedStatement::setParameter(const sal_Int32 parameterIndex, const sal_ * * Our internal OUString storage is always UTF-16, so no conversion to do here. */ - rtl_TextEncoding nSQLWCHAREncoding = RTL_TEXTENCODING_UCS2; - if( sizeof(SQLWCHAR) == 4 ) + BOOST_STATIC_ASSERT(sizeof (SQLWCHAR) == 2 || sizeof (SQLWCHAR) == 4); + if (sizeof (SQLWCHAR) == 2) { - nSQLWCHAREncoding = RTL_TEXTENCODING_UCS4; + nCharLen = _sData.getLength(); + nByteLen = 2 * nCharLen; + pData = allocBindBuf(parameterIndex, nByteLen); + memcpy(pData, _sData.getStr(), nByteLen); + } + else + { + std::vector<sal_uInt32> u; + for (sal_Int32 i = 0; i != _sData.getLength();) + { + u.push_back(_sData.iterateCodePoints(&i)); + } + nCharLen = u.size(); + nByteLen = 4 * nCharLen; + pData = allocBindBuf(parameterIndex, nByteLen); + memcpy(pData, u.empty() ? 0 : &u[0], nByteLen); } - - sOData = OUStringToOString(_sData, nSQLWCHAREncoding); - nByteLen = sOData.getLength(); - nCharLen = nByteLen / sizeof(SQLWCHAR); } else { - sOData = OUStringToOString(_sData, getOwnConnection()->getTextEncoding()); + OString sOData( + OUStringToOString(_sData, getOwnConnection()->getTextEncoding())); nCharLen = nByteLen = sOData.getLength(); + 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 ); } |