Thread: Question about libpq and count(*)

Question about libpq and count(*)

From
moorleghen
Date:
What I am trying to do is grab the total records in the database table
and add one so that the next record written gets a unquie id assigned.

this is the snippet of code I am currently using ----

res = PQexec(conn, "SELECT COUNT(*) FROM prob_entry");
if  (PQresultStatus(res) != PGRES_TUPLES_OK) {
  printf("Content type: test/html\r\n\r\n");
  printf("SELECT FAILED!\r\n");
  printf("%s\r\n",PQerrorMessage(conn));
  printf("Notify System Administrator\r\n");
  exit_nicely(conn);
}

problem.prob_num = (int *)PQntuples(res);
PQclear(res);

The script dies with a premature end of script headers message, but if I
comment out the problem.prob_num = (int *)PQntuples(res); line it
functions properly.

problem.prob_num is defined int.

The rest of the database functions are working properly. I can INSERT
and even SELECT, but this still does not work.

Suggestions and comments welcome.

Regards,
Michael