Refactor SQLite lock handling
This MR enforces the need for an active sqlite context (aka lock) when executing a statement.
This fixes a small race window in which an existing connection could be user after the database was dropped.
It might also fix some rare crashes due to improper syncronization/missing locks for some requests.
Fix #405 (closed) and #413 (closed)
I really doubt this can be backported though.