move query generation into httpd code