Kaydet (Commit) 9082e374 authored tarafından Julien Nabet's avatar Julien Nabet

tdf#117670: migration Firebird, deal with multiword column

by changing parsing process a bit

Change-Id: I77c06ba218e9bc0d241dbff10f76860d0ca5ed44
Reviewed-on: https://gerrit.libreoffice.org/54542Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarTamás Bunth <btomi96@gmail.com>
Reviewed-by: 's avatarJulien Nabet <serval2412@yahoo.fr>
üst aed4d485
......@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment