Clarify error message about trying to PQgetvalue() nonexistent row.

This commit is contained in:
Bryan Henderson 1996-12-24 09:03:16 +00:00
parent ab90c18d12
commit 9b55904647
1 changed files with 17 additions and 12 deletions

View File

@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-exec.c,v 1.22 1996/12/20 20:34:38 momjian Exp $ * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-exec.c,v 1.23 1996/12/24 09:03:16 bryanh Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -1486,8 +1486,7 @@ const char* PQoidStatus(PGresult *res) {
/* /*
PQgetvalue: PQgetvalue:
return the attribute value of field 'field_num' of return the value of field 'field_num' of row 'tup_num'
row 'tup_num'
If res is binary, then the value returned is NOT a null-terminated If res is binary, then the value returned is NOT a null-terminated
ASCII string, but the binary representation in the server's native ASCII string, but the binary representation in the server's native
@ -1499,21 +1498,27 @@ char*
PQgetvalue(PGresult *res, int tup_num, int field_num) PQgetvalue(PGresult *res, int tup_num, int field_num)
{ {
if (!res) { if (!res) {
fprintf(stderr, "PQgetvalue() -- pointer to PQresult is null"); fprintf(stderr, "PQgetvalue: pointer to PQresult is null\n");
return NULL;
} else if (tup_num > (res->ntups - 1)) {
fprintf(stderr,
"PQgetvalue: There is no row %d in the query results. "
"The highest numbered row is %d.\n",
tup_num, res->ntups - 1);
return NULL;
} else if (field_num > (res->numAttributes - 1)) {
fprintf(stderr,
"PQgetvalue: There is no field %d in the query results. "
"The highest numbered field is %d.\n",
field_num, res->numAttributes - 1);
return NULL; return NULL;
}
if (tup_num > (res->ntups - 1) ||
field_num > (res->numAttributes - 1)) {
fprintf(stderr,
"PQgetvalue: ERROR! field %d(of %d) of row %d(of %d) "
"is not available",
field_num, res->numAttributes - 1, tup_num, res->ntups);
} }
return res->tuples[tup_num][field_num].value; return res->tuples[tup_num][field_num].value;
} }
/* PQgetlength: /* PQgetlength:
returns the length of a field value in bytes. If res is binary, returns the length of a field value in bytes. If res is binary,
i.e. a result of a binary portal, then the length returned does i.e. a result of a binary portal, then the length returned does