Pretty-print CREATE statements in SQL export

When exporting a database to an SQL file, output the CREATE statements
in a standardised format, including line breaks, indentation and proper
quoting. This requires our grammar parser to fully understand the schema
of a database object in order to make sure no information is lost during
the export. Because of this we fall back to the old way of doing this
for all database objects that couldn't be fully parsed.

See issue #629.
This commit is contained in:
Martin Kleusberg
2017-01-27 18:07:02 +01:00
parent a75f2dac11
commit 2981351cc6

View File

@@ -496,7 +496,12 @@ bool DBBrowserDB::dump(const QString& filename,
// Write the SQL string used to create this table to the output file
if(exportSchema)
stream << (*it)->originalSql() << ";\n";
{
if((*it)->fullyParsed())
stream << (*it)->sql() << "\n";
else
stream << (*it)->originalSql() << ";\n";
}
// If the user doesn't want the data to be exported skip the rest of the loop block here
if(!exportData)
@@ -599,7 +604,12 @@ bool DBBrowserDB::dump(const QString& filename,
// Write the SQL string used to create this object to the output file
if(!(*it)->originalSql().isEmpty())
stream << (*it)->originalSql() << ";\n";
{
if((*it)->fullyParsed())
stream << (*it)->sql() << "\n";
else
stream << (*it)->originalSql() << ";\n";
}
}
}