metadata: fix a printf formatting issue with incompatible types that broke 32bit runtime. Also remove some code duplication inserting metadata to db