Bugfix in executeQuery

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