Fix several bugs in and improve the performance of the SQLite backend.

Signed-off-by: Jason Lynch <jason@calindora.com>