diff --git a/dbaccess/source/filter/hsqldb/createparser.cxx b/dbaccess/source/filter/hsqldb/createparser.cxx index 893cfa93330a..9054a2f9bf72 100644 --- a/dbaccess/source/filter/hsqldb/createparser.cxx +++ b/dbaccess/source/filter/hsqldb/createparser.cxx @@ -27,6 +27,42 @@ using namespace css::sdbc; namespace { +//Find ascii escaped unicode +sal_Int32 lcl_IndexOfUnicode(const OString& rSource, const sal_Int32 nFrom = 0) +{ + const OString sHexDigits = "0123456789abcdefABCDEF"; + sal_Int32 nIndex = rSource.indexOf("\\u", nFrom); + if (nIndex == -1) + { + return -1; + } + bool bIsUnicode = true; + for (short nDist = 2; nDist <= 5; ++nDist) + { + if (sHexDigits.indexOf(rSource[nIndex + nDist]) == -1) + { + bIsUnicode = false; + } + } + return bIsUnicode ? nIndex : -1; +} + +//Convert ascii escaped unicode to utf-8 +OUString lcl_ConvertToUTF8(const OString& rText) +{ + OString sResult = rText; + sal_Int32 nIndex = lcl_IndexOfUnicode(sResult); + while (nIndex != -1 && nIndex < rText.getLength()) + { + const OString sHex = sResult.copy(nIndex + 2, 4); + const sal_Unicode cDec = static_cast(strtol(sHex.getStr(), nullptr, 16)); + const OString sNewChar = OString(&cDec, 1, RTL_TEXTENCODING_UTF8); + sResult = sResult.replaceAll("\\u" + sHex, sNewChar); + nIndex = lcl_IndexOfUnicode(sResult, nIndex); + } + return OStringToOUString(sResult, RTL_TEXTENCODING_UTF8); +} + /// Returns substring of sSql from the first occurrence of '(' until the /// last occurrence of ')' (excluding the parenthesis) OUString lcl_getColumnPart(const OUString& sSql) @@ -192,7 +228,7 @@ void CreateStmtParser::parseColumnPart(const OUString& sColumnPart) // to fetch the whole column name, including quotes auto nEndColumnName = bIsQuoteUsedForColumnName ? sColumn.indexOf("\"", 1) : sColumn.indexOf(" "); - const OUString& rColumnName + OUString rColumnName = sColumn.copy(0, bIsQuoteUsedForColumnName ? nEndColumnName + 1 : nEndColumnName); // create a buffer which begins on column type @@ -232,6 +268,7 @@ void CreateStmtParser::parseColumnPart(const OUString& sColumnPart) } bool bCaseInsensitive = sTypeName.indexOf("IGNORECASE") >= 0; + rColumnName = lcl_ConvertToUTF8(OUStringToOString(rColumnName, RTL_TEXTENCODING_UTF8)); bool isPrimaryKey = lcl_isPrimaryKey(sColumn); if (isPrimaryKey)