Refactor most of the libpq API

I wrapped most of the libpq API into a thin C++ layer that adds some
useful semantics to the API's pointers. Notable that they cannot be
copied. This prevents freeing them multiple times.

Also fixes a few bugs I found along the way.