From 5ae5241b95a238bec610ad41337bf5dbce227218 Mon Sep 17 00:00:00 2001 From: Martin Kleusberg Date: Fri, 11 Aug 2017 17:19:42 +0200 Subject: [PATCH] Don't allow query execution when no database is opened Some time ago we changed the Execute SQL tab to allow open SQL files even if no database is loaded in order to provide an SQL editor without needing a database. If no database file is opened the Execute buttons were greyed out but the F5/Ctrl+R shortcut would still work, causing an "out of memory" error. That error doesn't cause any harm but is a bit confusing. So this commit disables the keyboard shortcuts too. --- src/MainWindow.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index 07dbd199..b695eeba 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -897,6 +897,11 @@ void MainWindow::dataTableSelectionChanged(const QModelIndex& index) */ void MainWindow::executeQuery() { + // Make sure a database is opened. This is necessary because we allow opened SQL editor tabs even if no database is loaded. Hitting F5 or similar + // then might call this function. + if(!db.isOpen()) + return; + SqlExecutionArea* sqlWidget = qobject_cast(ui->tabSqlAreas->currentWidget()); // Get SQL code to execute. This depends on the button that's been pressed