(PDB-5216) query->sql: simplify before making query-id universal
(PDB-5216) query->sql: simplify before making query-id universal

Rework query->sql to simplify it a bit in preparation for making the
query-id availble all the time, whether or not we log it.

Move the local sql conversion code into a separate regular-query->sql
function, and move the query logging inside query->sql.

puppetlabs/puppetdb,puppetlabs/puppetdb,puppetlabs/puppetdb,puppetlabs/puppetdb,puppetlabs/puppetdb