mirror of
https://github.com/sqlitebrowser/sqlitebrowser.git
synced 2026-01-20 11:00:44 -06:00
Some improvements to the Export SQL dialog
When possible, don't write 'CREATE TABLE/VIEW/... `name`' but 'CREATE TABLE/VIEW/... IF NOT EXISTS `name`' to the file. Add an option to add DROP TABLE statements before each create statement. This needs to be enhanced to apply to views, indices, and triggers as well. See issue #629. Clean up code.
This commit is contained in:
@@ -427,14 +427,17 @@ ObjectPtr Table::parseSQL(const QString &sSQL)
|
||||
return TablePtr(new Table(""));
|
||||
}
|
||||
|
||||
QString Table::sql() const
|
||||
QString Table::sql(bool ifNotExists) const
|
||||
{
|
||||
// Special handling for virtual tables: just build an easy create statement and copy the using part in there
|
||||
if(isVirtual())
|
||||
return QString("CREATE VIRTUAL TABLE %1 USING %2;").arg(escapeIdentifier(m_name)).arg(m_virtual);
|
||||
|
||||
// This is a normal table, not a virtual one
|
||||
QString sql = QString("CREATE %1TABLE %2 (\n").arg(m_temporary ? QString("TEMPORARY ") : QString("")).arg(escapeIdentifier(m_name));
|
||||
QString sql = QString("CREATE %1TABLE%2 %3 (\n")
|
||||
.arg(m_temporary ? QString("TEMPORARY ") : QString(""))
|
||||
.arg(ifNotExists ? QString(" IF NOT EXISTS") : QString(""))
|
||||
.arg(escapeIdentifier(m_name));
|
||||
|
||||
sql += fieldList().join(",\n");
|
||||
|
||||
@@ -1137,11 +1140,12 @@ QStringList Index::columnSqlList() const
|
||||
return sl;
|
||||
}
|
||||
|
||||
QString Index::sql() const
|
||||
QString Index::sql(bool ifNotExists) const
|
||||
{
|
||||
// Start CREATE (UNIQUE) INDEX statement
|
||||
QString sql = QString("CREATE %1INDEX %2 ON %3 (\n")
|
||||
QString sql = QString("CREATE %1INDEX%2 %3 ON %4 (\n")
|
||||
.arg(m_unique ? QString("UNIQUE ") : QString(""))
|
||||
.arg(ifNotExists ? QString(" IF NOT EXISTS") : QString(""))
|
||||
.arg(escapeIdentifier(m_name))
|
||||
.arg(escapeIdentifier(m_table));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user