Move dbtype depending logic into object per type

Please review, this was #2220 but that was closed by the merge and pretty old.

@karlitschek @tanghus @icewind1991 @Raydiation @DeepDiver1975 @butonic @MTGap @VicDeo @eMerzh