From a840a4316170344afbda929d960f58cf3bb72891 Mon Sep 17 00:00:00 2001 From: Martin Kleusberg Date: Fri, 15 Feb 2019 10:55:31 +0100 Subject: [PATCH] Don't ask for saving changes when importing a SQL file When importing a SQL file into a new database, we would create a database file, import everything, then close the database and open it in the GUI. While closing, however, the application asks you whether you want to save the changes you made which can be confusing. This is solved by creating an empty database, then closing it immediately without any changes just to then open it in the GUI. Only then the import takes place. See comment in issue #1045. --- src/MainWindow.cpp | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index 066bba78..848c1acd 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -1734,7 +1734,10 @@ void MainWindow::importDatabaseFromSQL() return; } + // Create the new file and open it in the browser db.create(newDbFile); + db.close(); + fileOpen(newDbFile); } // Defer foreign keys. Just deferring them instead of disabling them should work fine because in the import we only expect CREATE and INSERT @@ -1760,14 +1763,9 @@ void MainWindow::importDatabaseFromSQL() // Restore the former foreign key settings db.setPragma("defer_foreign_keys", foreignKeysOldSettings); - // Refresh window when importing into an existing DB or - when creating a new file - just open it correctly - if(newDbFile.size()) - { - fileOpen(newDbFile); - } else { - db.updateSchema(); - populateTable(); - } + // Refresh views + db.updateSchema(); + populateTable(); } void MainWindow::openPreferences()