ndo2db: Start cleanup of SQL date/timestamp formatting.

With SQL we often need to use a timestamp value/column as a datetime,
and vice versa. Two functions handled these conversions, encapsulating
DB specific operations, but with the cost of extra memory allocation
and movement. Since ndo2db_db_timet_to_sql() was accounting for a
significant fraction of CPU time (approaching 10% of the DB writer CPU
time on some workloads), and it's basically a fancy printf format,
we'll make it and the corresponding ndo2db_db_sql_to_timet() exactly
fancy printf format macros, a la C99's PRI macros.

This commit handles the few cases in db.c, the bulk remains to be done
in dbhandlers.c.
ndo2db/dbhandlers: Cleanup of SQL date/timestamp formatting.

First occurance in dbhandlers.c. Along the way, fix a dodgy cast, don't
do an extra malloc only to immediately free the original, and make sure
the temporary escaped string is accounted for on all return paths.