Better identifier quoting

This commit fixes the SQL export which did not quote the field names in
the INSERT statements.

This also simplifies the code for escaping SQL identifiers.
This commit is contained in:
Martin Kleusberg
2018-11-16 11:05:13 +01:00
parent 9e36f21112
commit ef7492adfb

View File

@@ -734,7 +734,7 @@ bool DBBrowserDB::dump(const QString& filePath,
{
stream << "INSERT INTO " << sqlb::escapeIdentifier(it->name());
if (insertColNames)
stream << " (" << cols.join(",") << ")";
stream << " (" << sqlb::escapeIdentifier(cols).join(",") << ")";
stream << " VALUES (";
}
else
@@ -1139,9 +1139,7 @@ QString DBBrowserDB::emptyInsertStmt(const QString& schemaName, const sqlb::Tabl
stmt.append(" DEFAULT VALUES;");
} else {
stmt.append("(");
for(const QString& f : fields)
stmt.append(sqlb::escapeIdentifier(f) + ",");
stmt.chop(1);
stmt.append(sqlb::escapeIdentifier(fields).join(","));
stmt.append(") VALUES (");
stmt.append(vals.join(","));
stmt.append(");");