I'm working on a postgreSQL client application using libpq. gcc compiles it without error. When I run the program, however, this function:
void print_column(PGconn *connection) {
PGresult *id_list;
int row;
// process_query() calls PQexec(), checks for errors, then returns the result
id_list = process_query(connection, "SELECT id FROM customers WHERE state='CA'");
for(row = 0; row < PQntuples(id_list); row++) {
printf("%s\n", PQgetvalue(id_list, row, 0));
// to pause the loop on each rep for debugging
getchar();
}
}
Produces the error:
row number 1701734765 is out of range 0..8
Segmentation fault
What's strange is that the for loop does the first five repetitions without a problem. Then it causes the segmentation fault on the sixth.
I didn't post the whole program because it's 1000+ lines. Any suggestions will be greatly appreciated.