libpq library.
-
-
Database Connection Functions
+
+
Database Connection Functions
- The following routines deal with making a connection to
- a
Postgres backend server. The application
- program can have several backend connections open at one time.
- (One reason to do that is to access more than one database.)
- Each connection is represented by a PGconn object which is obtained
- from PQconnectdb() or PQsetdbLogin(). Note that these functions
- will always return a non-null object pointer, unless perhaps
- there is too little memory even to allocate the PGconn object.
- The PQstatus function should be called
- to check whether a connection was successfully made
- before queries are sent via the connection object.
+ The following routines deal with making a connection to a
+
Postgres backend server. The
+ application program can have several backend connections open at
+ one time. (One reason to do that is to access more than one
+ database.) Each connection is represented by a
+ PGconn> object which is obtained from
+ PQconnectdb> or PQsetdbLogin>. Note that
+ these functions will always return a non-null object pointer,
+ unless perhaps there is too little memory even to allocate the
+ PGconn> object. The PQstatus> function
+ should be called to check whether a connection was successfully
+ made before queries are sent via the connection object.
Name of host to connect to. If a non-zero-length string is
- specified, TCP/IP
- communication is used. Using this parameter causes a hostname look-up.
- See hostaddr.
+ specified, TCP/IP communication is used, else Unix sockets.
+ Using this parameter causes a hostname look-up. See hostaddr.
-
-
Sample Programs
-
-
Sample Program 1
+
+
Example Programs
+
+
+
libpq Example Program 1
/*
- * testlibpq.c Test the C version of Libpq, the Postgres frontend
- * library.
- *
+ * testlibpq.c
*
+ * Test the C version of libpq, the PostgreSQL frontend
+ * library.
*/
#include <stdio.h>
-#include "libpq-fe.h"
+#include <libpq-fe.h>
void
exit_nicely(PGconn *conn)
}
-
-
+
->
-Sample Program 2
+ >
+ libpq Example Program 2
/*
* testlibpq2.c
return 0;
}
-
-
+
->
-Sample Program 3>
+ >
+ libpq Example Program 3>
/*
* testlibpq3.c Test the C version of Libpq, the Postgres frontend
return 0;
}
->
+ >
-
-
+