Postgres and C

The libpq library makes postgres easy to use in C programs. My only issue with it is that it is too "low level" for most uses. In other contexts I have enjoyed using the postgres command line client, psql, in shell scripts. One can pipe a query through psql and let the result flow through to stdout or to a file or capture the output in a variable for further processing. No knowledge of internals is required.

I desired to use postgres with C while enjoying the same "ease of use". I also wanted to be able to run many queries with one connection. These wrappers provide most of that.

They are not nearly perfect, but usable.

Wrapper Functions

Possible Improvements

The database_init function could take a connection string instead of just a database name as a parameter. This assumes more knowledge on the part of the user.

The get_query_fields funtion could be altered to return 0 on success which would make it more consistent. Done.

Other improvements?

The code

Warts and all View at your own peril.