So I made the switch from MySQL to PostgreSQL a while ago and I needed to access the database via a C/C++ API. Even with some creative googling, I was not able to find much in terms of good, up-to-date documentation or examples out there.
I first tried searching for a C++ API and I found some hits for libpq++ in some of the older PostgreSQL documentation. However, I later read that libpq++ is obsolete and was replaced with libpqxx. I find it kind of odd that libpqxx declared themselves the “official C++ API of PostgreSQL” on their website, but in the PostgreSQL documentation, they list libpqxx under Appendix G: External Projects. After browsing the libpqxx C++ header, I decided I didn’t like their API design and I decided to go with the native libpq C API instead.
Here are the three best (read: most credible) references that I found for libpq.
PostgreSQL. (2009). PostgreSQL Manual (8.4). Retrieved from http://www.postgresql.org/docs/8.4/interactive/libpq.html
Klebic, Z. (n.d.). Introduction to Programming with the PostgreSQL C API (libpq) [PDF document]. Retrieved from http://www.chicagolug.org/wiki/images/a/a6/PostgreSQL®_by_Zlatan_Klebic.pdf
Klebic, Z. (n.d.). PostgreSQL Programming Tutorial using PostgreSQL Native C API (libpq) [PDF document]. Retrieved from http://www.openinformatics.net/pdf/atm_machine_tutorial.pdf
Definitely enough to hit the ground running, but I would like to see some best practices documentation out there that shows all of the necessary defensive programming error checks. Once I figure it out, I’ll get my examples posted. Chances are my examples will be in C++ calling the C API functions.