Avoid removing multiple line breaks inside strings for simple cases

In order to avoid removing multiple line breaks inside strings, the
replacement is only done when removeCommentsFromQuery has performed some
substitution. Otherwise the query is left as is.

This will improve the problem described in issue #1334 for simple cases.
There will be still problems when the query has comments and multiple line
breaks inside strings.
This commit is contained in:
mgrojo
2018-03-05 21:13:08 +01:00
parent 211f7341ff
commit b51cf69cbf

View File

@@ -654,7 +654,10 @@ void SqliteTableModel::buildQuery()
setQuery(customQuery(true), true);
}
void SqliteTableModel::removeCommentsFromQuery(QString& query) {
void SqliteTableModel::removeCommentsFromQuery(QString& query)
{
int oldSize = query.size();
// first remove block comments
{
QRegExp rxSQL("^((?:(?:[^'/]|/(?![*]))*|'[^']*')*)(/[*](?:[^*]|[*](?!/))*[*]/)(.*)$"); // set up regex to find block comment
@@ -706,11 +709,13 @@ void SqliteTableModel::removeCommentsFromQuery(QString& query) {
query = result.trimmed();
}
// Remove multiple line breaks that might have been created by deleting comments till the end of the line but not including the line break
query.replace(QRegExp("\\n+"), "\n");
if (oldSize != query.size()) {
// Remove multiple line breaks that might have been created by deleting comments till the end of the line but not including the line break
query.replace(QRegExp("\\n+"), "\n");
// Also remove any remaining whitespace at the end of each line
query.replace(QRegExp("[ \t]+\n"), "\n");
// Also remove any remaining whitespace at the end of each line
query.replace(QRegExp("[ \t]+\n"), "\n");
}
}
QStringList SqliteTableModel::getColumns(const QString& sQuery, QVector<int>& fieldsTypes)