mirror of
https://github.com/sqlitebrowser/sqlitebrowser.git
synced 2026-01-20 11:00:44 -06:00
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:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user