Blind fix for OPreparedStatement::setParameter's useWChar case
...after 0181a13904
"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
This commit is contained in:
@@ -317,7 +317,6 @@ 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)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
@@ -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.
|
* Our internal OUString storage is always UTF-16, so no conversion to do here.
|
||||||
*/
|
*/
|
||||||
rtl_TextEncoding nSQLWCHAREncoding = RTL_TEXTENCODING_UCS2;
|
BOOST_STATIC_ASSERT(sizeof (SQLWCHAR) == 2 || sizeof (SQLWCHAR) == 4);
|
||||||
if( 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
|
else
|
||||||
{
|
{
|
||||||
sOData = OUStringToOString(_sData, getOwnConnection()->getTextEncoding());
|
OString sOData(
|
||||||
|
OUStringToOString(_sData, getOwnConnection()->getTextEncoding()));
|
||||||
nCharLen = nByteLen = sOData.getLength();
|
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 );
|
setParameter( parameterIndex, _nType, nCharLen, _nScale, pData, nByteLen, nByteLen );
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user