When modifying a view use DROP VIEW IF EXISTS instead of just DROP VIEW

Clicking on Edit View in the database structure tab opens a new SQL tab
with a DROP VIEW statement to delete the existing view and a copy of the
CREATE VIEW statement used for the current view. When the user modifies
the CREATE VIEW statement introduces an error in it, and then executes
the statements, the view is deleted and an error reported. Fixing that
error and re-running the script then fails at the DROP VIEW statement.
This means it makes more sense to make it a DROP VIEW IF EXISTS
statement.

See issue #2661.
This commit is contained in:
Martin Kleusberg
2021-05-23 11:08:46 +02:00
parent bbfaca2e06
commit 6cde3f51ad

View File

@@ -992,7 +992,7 @@ void MainWindow::editObject()
refreshTableBrowsers();
} else if(type == "view") {
sqlb::TablePtr view = db.getTableByName(obj);
runSqlNewTab(QString("DROP VIEW %1;\n%2").arg(QString::fromStdString(obj.toString()), QString::fromStdString(view->sql())),
runSqlNewTab(QString("DROP VIEW IF EXISTS %1;\n%2").arg(QString::fromStdString(obj.toString()), QString::fromStdString(view->sql())),
tr("Edit View %1").arg(QString::fromStdString(obj.toDisplayString())),
"https://www.sqlite.org/lang_createview.html",
/* autoRun */ false);