There are some error-handling functions or status functions available to check the results of a function.
The
PQresultStatus
function sreturns the status of a command. This function is very important to get the result status after executing the query. This function is the base of the program logic, because a program should take action based on the result status. The syntax for PQtresultStatus
is as follows:
ExecStatusType PQresultStatus(const PGresult *res);
The following is a code snippet to explain the PQresultStatus
function:
/* Execute a query using PQexec */ result = PQexec(conn, "SELECT id, name FROM foo LIMIT 3"); switch(PQresultStatus(result)) { case PGRES_COMMAND_OK: /* Query successful and no data to return */ break; case PGRES_TUPLES_OK: /* Query ok and data available */ break; case PGRES_EMPTY_QUERY: /* Query string was empty */ break; case PGRES_COPY_OUT: /* Data transfer from server side started */ break; case...