Question about libpq and count(*) - Mailing list pgsql-interfaces

From moorleghen
Subject Question about libpq and count(*)
Date
Msg-id 371E0FCC.8E8746EF@gci-net.com
Whole thread Raw
List pgsql-interfaces
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


pgsql-interfaces by date:

Previous
From: "Brett W. McCoy"
Date:
Subject: Re: [SQL] perl and postgres. . .
Next
From: "Brett W. McCoy"
Date:
Subject: Detecting existance of table