Move CSV handling to QueryContext

We want to consolidate access to the outside world
behind this facade. That makes it possible to handle
freeing of resources in QueryContext's, instead of
having multiple places remember to clean up state
after a query is finished.