Rewrite of database compare code to make use of general compare subroutines rather than database specific ones