MainWindow: Fix possible endless loop in executeQuery

Don't get into an endless loop when there is a syntax error in the SQL
statement to execute.