Run query to database query database

Two passes, First pass to convert to QueryDatabase, the second pass to convert it to StringFormat form where possible.

I tried to keep 'fixes' and keep the commits combined but I had some issues with that at points.