Database Reference
In-Depth Information
Using status functions
There are some error-handling functions or status functions available to check the
results of a function.
Using PQresultStatus
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 PGRES_COPY_IN:
/* Data transferred started to server */
break;
case PGRES_BAD_RESPONSE:
/* Invalid response from server*/
break;
case PGRES_NONFATAL_ERROR:
/* A notice or warning occurred */
break;
case PGRES_FATAL_ERROR:
/* Fata error occurred. */
break;
case PGRES_COPY_BOTH:
 
Search WWH ::




Custom Search