add checksum if missing
log queries in $DEBUG mode