Fix loggin statement
Add test for failure for malformed SQL queries
Fix bug in QueriesResourceService

The savepoint was being created to late. If an exception were thrown
when building the SQL string, then the savepoint would never be created
and the catch block would try to rollback to a non-existent savepoint.