db: factorisation of code in gdbm

Reducing the duplication of code improves it on several sides:
readability, maitainability, understanding.

Signed-off-by: José Bollo <jose.bollo@open.eurogiciel.org>