Sped up test query setup.

Moved out all the query string formatting out of the loop which gets
executed for every query into a 'prepare' method - specifically,
json.dumps() doesn't get called for every query execution. Function
'rands()' is used to add a random string for each query - it is pretty
fast (tried it with timeit()). So all in all the overhead of preparing
the queries is neglegible.