Skip to content

Commit

Permalink
Pretty-print CREATE statements in SQL export
Browse files Browse the repository at this point in the history
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 sqlitebrowser#629.
  • Loading branch information
MKleusberg committed Jan 27, 2017
1 parent a75f2da commit 2981351
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/sqlitedb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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";
}
}
}

Expand Down

0 comments on commit 2981351

Please sign in to comment.