Reputation: 217
I have code like below (it's partial, ofcourse). I can connect sucessfully to the database, I can do INSERT INTO
and all that stuff, but the result of SELECT FROM
never can be displayed.
snprintf(sqlSelect, sizeof(sqlSelect), "select * from %s", sqlTableName);
res = PQexec(conn, sqlSelect);
if (PQresultStatus(res) != PGRES_TUPLES_OK) {
fprintf(stderr, "SELECT FROM failed: %s", PQerrorMessage(conn));
PQclear(res);
exitNicely(conn);
}
PQclear(res);
Why above code doesn't print SELECT * FROM db_name
result in the terminal?
Upvotes: 0
Views: 2989
Reputation: 324275
The code doesn't print out or otherwise use the result rows, it just fetches them and throws them away.
You need to iterate over the result set and actually do something with it. See the libpq examples for some ways to do this.
(CW because I'm just converting Erwin's point into an answer).
Upvotes: 1