Add unit tests for the DatabaseException.

Fix a bug with the DatabaseException getQuery.
Changes to the tests. Run some of them in a separate process.