Do not roll back when importing CSV file without final line break

When importing a CSV file which uses quotes to escape characters we
would throw an error if the very last character in the file is the end
quote character. This commit changes it to only error when ending in the
middle of a quoted field but not at the end anymore.

See issue #1986.
This commit is contained in:
Martin Kleusberg
2019-09-04 09:16:20 +02:00
parent 64d83568ec
commit fc3248554d

View File

@@ -292,7 +292,9 @@ CSVParser::ParserResult CSVParser::parse(csvRowFunction insertFunction, QTextStr
if(m_pCSVProgress)
m_pCSVProgress->end();
return (state == StateNormal) ? ParserResult::ParserResultSuccess : ParserResult::ParserResultError;
// Check if we are in StateNormal or StateEndQuote state. The first is what we should be in for unquoted data and all files which
// end with a line break. The latter is what we are in for quoted data with no final line break.
return (state == StateNormal || state == StateEndQuote) ? ParserResult::ParserResultSuccess : ParserResult::ParserResultError;
}
bool CSVParser::look_ahead(QTextStream& stream, QByteArray& sBuffer, const char** it, const char** sBufferEnd, char expected)