fix database iteration