Fixed: potential nil pointer access
Fixed "cannot start a transaction within a transaction" bug due to missing transaction cleanup; fixed transaction retry logic; enabled sqlite shared cached and WAL mode