Lots of refactoring.

Removes a handle to database in RevisionInternal, since it wasn't used anyway.

Enables WAL for sqlite.

Fixes the test used to repro issue 348.

Confirms the issue is RunInTransaction. The delegates never return, leading to deadlocks and failure to commit the transactions.