Refactor TestSQLite store and fix various bugs it uncovered