I've looked at the C library for PostgreSQL and then wanted to see if there were any C++ wrappers for it. The most current appears to be libpqxx. On first blush, it looks very good. It if functional and robust. But... it has one draw back. The library insists on converting all binary stuff into text for passing back to the caller. For some applications, that can be a reasonable library simplifier.
But in this day and age of Templates and polymorphism, it seems to be a copout. Yes, if
I had time, I'd probably try my hand at implementing some sort of 'variant' implementation
to handle the various types of data that come back.
Sigh. As much as I'd like to use the library, I really want my data in the native form
in which I stored it. Perhaps once I've worked with the API, and I've worked my own working
version of variants, maybe I'll be in a position to offer up some workable suggestions.
... several hours later ...
I now realize that the PostgreSQL API returns everything as strings. So now I understand
the reasoning behind the library and what it returns.
To get binary values, from my understanding, one has to use the COPY routines and
decipher the result streams directly. I would have hoped there was some middle ground,
where the API will provide the binary values when needed. The API implies that it does, but
in actual fact, didn't. I spent an hour or two figuring it out the hardway. I'm really
going to have to figure out how gdb works so I can single step through stuff and analyze
variables. As it was, I reverted back to the stone age and put in print statements to
figure out what was happening.
Now I have a tri-choice:
- Stick with the C API, which seems to have everything one needs, including access to
true parameterized queries (I found out after the fact, that the Perl libraries actually do
string concatenation, which creates a possibility for SQL Injection attacks).
- Use the libpqxx library and convert stuff to binary when I need it. I must say
working with everything as strings is a simplifying assumption, but doesn't do much for
accuraccy and performance.
- Start working on some sort of wrapper to examine the results of COPY commands, which
is probably more work than I really want to do right now.