I'm using a C program to talk to a Postgres database.
I'd like to create a method that will allow the user to type a custom query in the C program and see the results printed as Postgres would print in its command line client psql.
For other queries, I was able to use functions I found in the documentation. The trouble is that these only work because I know the amount of columns I need and the appropriate headers etc.
For example:
void* executeCustomQuery(const char* query){
PGresult* res = PQexec(conn, query);
//print all entries
printf(PRODUCTS_TABLE_HEADER);
int i;
for (i = 0; i < PQntuples(res); i++){
printf("| %s | %s | %s |", PQgetvalue(res, i, 0), PQgetvalue(res, i, 1), PQgetvalue(res, i, 2));
}
PQclear(res);
}
I can't use this code if I don't know what I'm getting back.
Does anyone know of any way to print out the direct results from Postgres?
psqlcode.PQprint) already exists. What about that doesn't meet your needs?