Use pysqlite for db re-init as apsw cannot discard problem statements

Also move the atomic_rename retry logic into atomic_rename itself,
making it simpler.