Database Reference
In-Depth Information
Establishing a connection
asynchronously
The
libpq
library provides functions to connect to the PostgreSQL database
asynchronously; these functions are called nonblocking functions. The nonblocking
functions do not block and return immediately. The
libpq
library has functions
that are both variant blocking and nonblocking connection functions. We've already
discussed the blocking functions, and now it's time to discuss nonblocking functions.
Using PQconnectStartParams
The
PQconnectStartParams
function is a nonblocking variant of the
PQconnectdbParams
function. The complete connection is made in an application
loop rather than inside the library function. The syntax for
PQconnectStartParams
is as follows:
PGconn *PQconnectStartParams(const char **keywords,
const char **values,
int expand_dbname);
Using PQconnectStart
The
PQconnectStart
function is a nonblocking variant of the
PQconnectdb
function.
Like the
PQconnectStartParams
function, it also does not block. The syntax for
PQconnectdbParams
is as follows:
PGconn *PQconnectStart(const char *conninfo);
Using PQconnectPoll
The
PQconnectPoll
function is used to poll the connection status of a connection.
The syntax for
PQconnectPoll
is as follows:
PostgresPollingStatusType PQconnectPoll(PGconn *conn);