Sqlite3 optimizations and bugfixes

Signed-off-by: Markus Pargmann <mpargmann@allfex.org>