diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2022-04-21 17:12:49 -0400 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2022-04-21 17:12:49 -0400 |
commit | 914611ea738a3601717990faff0f5d71a0f14a3d (patch) | |
tree | ec442f83b60a34edf0ff7d358c1ff1b140758844 /src/interfaces/libpq/fe-protocol3.c | |
parent | 2cb1272445d2a6616991fc6ede274d9f1f62ff73 (diff) |
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
Diffstat (limited to 'src/interfaces/libpq/fe-protocol3.c')
-rw-r--r-- | src/interfaces/libpq/fe-protocol3.c | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/src/interfaces/libpq/fe-protocol3.c b/src/interfaces/libpq/fe-protocol3.c index 94b4a448b90..10c76daf6ed 100644 --- a/src/interfaces/libpq/fe-protocol3.c +++ b/src/interfaces/libpq/fe-protocol3.c @@ -209,7 +209,7 @@ pqParseInput3(PGconn *conn) case 'C': /* command complete */ if (pqGets(&conn->workBuffer, conn)) return; - if (conn->result == NULL) + if (!pgHavePendingResult(conn)) { conn->result = PQmakeEmptyPGresult(conn, PGRES_COMMAND_OK); @@ -263,7 +263,7 @@ pqParseInput3(PGconn *conn) } break; case 'I': /* empty query */ - if (conn->result == NULL) + if (!pgHavePendingResult(conn)) { conn->result = PQmakeEmptyPGresult(conn, PGRES_EMPTY_QUERY); @@ -281,7 +281,7 @@ pqParseInput3(PGconn *conn) if (conn->cmd_queue_head && conn->cmd_queue_head->queryclass == PGQUERY_PREPARE) { - if (conn->result == NULL) + if (!pgHavePendingResult(conn)) { conn->result = PQmakeEmptyPGresult(conn, PGRES_COMMAND_OK); @@ -362,7 +362,7 @@ pqParseInput3(PGconn *conn) if (conn->cmd_queue_head && conn->cmd_queue_head->queryclass == PGQUERY_DESCRIBE) { - if (conn->result == NULL) + if (!pgHavePendingResult(conn)) { conn->result = PQmakeEmptyPGresult(conn, PGRES_COMMAND_OK); @@ -2133,7 +2133,7 @@ pqFunctionCall3(PGconn *conn, Oid fnid, * report COMMAND_OK. Otherwise, the backend violated the * protocol, so complain. */ - if (!(conn->result || conn->error_result)) + if (!pgHavePendingResult(conn)) { if (status == PGRES_COMMAND_OK) { |