1
0
mirror of https://github.com/postgres/postgres.git synced 2025-10-25 13:17:41 +03:00

Fix missed cases in libpq's error handling.

Commit 618c16707 invented an "error_result" flag in PGconn, which
intends to represent the state that we have an error condition and
need to build a PGRES_FATAL_ERROR PGresult from the message text in
conn->errorMessage, but have not yet done so.  (Postponing construction
of the error object simplifies dealing with out-of-memory conditions
and with concatenation of messages for multiple errors.)  For nearly all
purposes, this "virtual" PGresult object should act the same as if it
were already materialized.  But a couple of places in fe-protocol3.c
didn't get that memo, and were only testing conn->result as they used
to, without also checking conn->error_result.

In hopes of reducing the probability of similar mistakes in future,
I invented a pgHavePendingResult() macro that includes both tests.

Per report from Peter Eisentraut.

Discussion: https://postgr.es/m/b52277b9-fa66-b027-4a37-fb8989c73ff8@enterprisedb.com
This commit is contained in:
Tom Lane
2022-04-21 17:12:49 -04:00
parent 2cb1272445
commit 914611ea73
3 changed files with 16 additions and 7 deletions

View File

@@ -852,6 +852,14 @@ extern void pqTraceOutputNoTypeByteMessage(PGconn *conn, const char *message);
(resetPQExpBuffer(&(conn)->errorMessage), \
(conn)->errorReported = 0)
/*
* Check whether we have a PGresult pending to be returned --- either a
* constructed one in conn->result, or a "virtual" error result that we
* don't intend to materialize until the end of the query cycle.
*/
#define pgHavePendingResult(conn) \
((conn)->result != NULL || (conn)->error_result)
/*
* this is so that we can check if a connection is non-blocking internally
* without the overhead of a function call