Database Reference
In-Depth Information
fprintf(stderr, "failed to execute query using
PQexecPrepared\n");
fprintf(stderr, "%s", PQerrorMessage(conn));
return -1;
}
PQfinish(conn);
return 0;
}
Retrieving data
Now, the next step is to get data from PostgreSQL. Here are the functions that are
used to extract data after query execution.
Using PQntuples
The
PQntuples
function returns the number of rows normally called tuples in the
result. Its syntax is as follows:
int PQntuples(const PGresult *res);
A value larger than 32 bits might overlow.
Using PQnields
The PQnields function returns the number of columns in each row. The syntax
for
PQnfields
is as follows:
int PQnfields(const PGresult *res);
Using PQfname
The
PQfname
function returns the name of the column associated with the
column_number
argument. The syntax for
PQfname
is as follows:
char *PQfname(const PGresult *res,
int column_number);