Fix potential race condition crash.

There was no thread safety enforcement in the DbQuery at the time of
resolving the query to SQL and executing it. Thus there was a
possibility of native SQLite crash.