dbaccess/source/filter/hsqldb/createparser.cxx | 46 +++++++++++++++++-------- 1 file changed, 33 insertions(+), 13 deletions(-)
New commits: commit 9082e37400baf75296cb94c5588ddeb3d18f0b09 Author: Julien Nabet <serval2...@yahoo.fr> Date: Fri May 18 14:17:13 2018 +0200 tdf#117670: migration Firebird, deal with multiword column by changing parsing process a bit Change-Id: I77c06ba218e9bc0d241dbff10f76860d0ca5ed44 Reviewed-on: https://gerrit.libreoffice.org/54542 Tested-by: Jenkins <c...@libreoffice.org> Reviewed-by: Tamás Bunth <btom...@gmail.com> Reviewed-by: Julien Nabet <serval2...@yahoo.fr> diff --git a/dbaccess/source/filter/hsqldb/createparser.cxx b/dbaccess/source/filter/hsqldb/createparser.cxx index 1323d74e5ce7..893cfa93330a 100644 --- a/dbaccess/source/filter/hsqldb/createparser.cxx +++ b/dbaccess/source/filter/hsqldb/createparser.cxx @@ -180,25 +180,45 @@ void CreateStmtParser::parseColumnPart(const OUString& sColumnPart) continue; } - std::vector<OUString> words = string::split(sColumn, sal_Unicode(u' ')); - - if (words[0] == "CONSTRAINT") + if (sColumn.startsWithIgnoreAsciiCase("CONSTRAINT")) { m_aForeignParts.push_back(sColumn); continue; } - std::vector<sal_Int32> aParams; - OUString sTypeName = words[1]; + bool bIsQuoteUsedForColumnName(sColumn[0] == '\"'); + // find next quote after the initial quote + // or next space if quote isn't used as delimiter + // to fetch the whole column name, including quotes + auto nEndColumnName + = bIsQuoteUsedForColumnName ? sColumn.indexOf("\"", 1) : sColumn.indexOf(" "); + const OUString& rColumnName + = sColumn.copy(0, bIsQuoteUsedForColumnName ? nEndColumnName + 1 : nEndColumnName); - // TODO what if there is a whitespace between type name and param? - sal_Int32 nParenPos = words[1].indexOf("("); + // create a buffer which begins on column type + // with extra spaces removed + const OUString& buffer + = sColumn.copy(bIsQuoteUsedForColumnName ? nEndColumnName + 1 : nEndColumnName).trim(); + + // Now let's manage the column type + // search next space to get the whole type name + // eg: INTEGER, VARCHAR(10), DECIMAL(6,3) + auto nNextSpace = buffer.indexOf(" "); + OUString sFullTypeName; + OUString sTypeName; + if (nNextSpace > 0) + sFullTypeName = buffer.copy(0, nNextSpace); + // perhaps column type corresponds to the last info here + else + sFullTypeName = buffer; + + auto nParenPos = sFullTypeName.indexOf("("); + std::vector<sal_Int32> aParams; if (nParenPos > 0) { - sTypeName = words[1].copy(0, nParenPos); - + sTypeName = sFullTypeName.copy(0, nParenPos).trim(); OUString sParamStr - = words[1].copy(nParenPos + 1, words[1].lastIndexOf(")") - nParenPos - 1); + = sFullTypeName.copy(nParenPos + 1, sFullTypeName.indexOf(")") - nParenPos - 1); auto sParams = string::split(sParamStr, sal_Unicode(u',')); for (auto& sParam : sParams) { @@ -207,17 +227,17 @@ void CreateStmtParser::parseColumnPart(const OUString& sColumnPart) } else { + sTypeName = sFullTypeName.trim(); lcl_addDefaultParameters(aParams, lcl_getDataTypeFromHsql(sTypeName)); } bool bCaseInsensitive = sTypeName.indexOf("IGNORECASE") >= 0; - const OUString& rTableName = words[0]; bool isPrimaryKey = lcl_isPrimaryKey(sColumn); if (isPrimaryKey) - m_PrimaryKeys.push_back(rTableName); + m_PrimaryKeys.push_back(rColumnName); - ColumnDefinition aColDef(rTableName, lcl_getDataTypeFromHsql(sTypeName), aParams, + ColumnDefinition aColDef(rColumnName, lcl_getDataTypeFromHsql(sTypeName), aParams, isPrimaryKey, lcl_getAutoIncrementDefault(sColumn), lcl_isNullable(sColumn), bCaseInsensitive); _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits