diff options
author | Julien Nabet <serval2412@yahoo.fr> | 2018-05-18 14:17:13 +0200 |
---|---|---|
committer | Julien Nabet <serval2412@yahoo.fr> | 2018-05-24 13:23:13 +0200 |
commit | 9082e37400baf75296cb94c5588ddeb3d18f0b09 (patch) | |
tree | dd806caa77146a43c1f455d95a14365e8831f67d | |
parent | aed4d485df525ef934e0a6bbf6eededb976a9299 (diff) |
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 <ci@libreoffice.org>
Reviewed-by: Tamás Bunth <btomi96@gmail.com>
Reviewed-by: Julien Nabet <serval2412@yahoo.fr>
-rw-r--r-- | dbaccess/source/filter/hsqldb/createparser.cxx | 46 |
1 files changed, 33 insertions, 13 deletions
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); |