User Tools

Site Tools


programming:c:libpq

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
programming:c:libpq [2018-02-07 22:50] – created zlgprogramming:c:libpq [2018-07-03 01:00] (current) – external edit 127.0.0.1
Line 1: Line 1:
 +====== PostgreSQL with libpq ======
 +
 ''libpq'' is the frontend API for PostgreSQL, written in C. Upstream has fantastic [[https://www.postgresql.org/docs/current/static/|documentation]], but the workflows aren't obvious unless you've used other database APIs like PHP's ''PDO'' class or the ''sqlite'' module in Python. This page will outline a few common tasks and how to do them. ''libpq'' is the frontend API for PostgreSQL, written in C. Upstream has fantastic [[https://www.postgresql.org/docs/current/static/|documentation]], but the workflows aren't obvious unless you've used other database APIs like PHP's ''PDO'' class or the ''sqlite'' module in Python. This page will outline a few common tasks and how to do them.
 +
 +===== Linking =====
 +
 +The ''-lpq'' argument to your compiler should be enough. You should already have PostgreSQL server installed (and/or its headers) to link to the library correctly.
  
 ===== Basic Connection ===== ===== Basic Connection =====
Line 19: Line 25:
  
 int main(int argc, char **argv) { int main(int argc, char **argv) {
 +    // create what we need to connect: the db connection structure and its options
     PGconn *conn;     PGconn *conn;
     const char *dbopts;     const char *dbopts;
programming/c/libpq.1518043843.txt.gz · Last modified: 2018-07-03 01:00 (external edit)