Basically finished the entire dynamic query generator

The function for this is currently NOT protected against
buffer overflow. The only thing that prevents a buffer overflow
in that function right now is the rather big buffer (64 kilobytes).

Signed-off-by: Toon Schoenmakers <nighteyes1993@gmail.com>