Fix up the insert victim code in the DB API to check the hashes collection in a more safe way

As it is the DB API assumes that the victim_table variable has been
initialised when checking the hashes collection for a clashing entry
with the one being added, this is unsafe as the victim_table
variable might not always be initialised. For safety check if that
variable is initialised before trying to do any operations on it.