separate file for SQL related functions
using Upsert
fixed handling of optional parameter in dbg()