From c4f7a6b87ff350200f4b3afb9fe05e2899161070 Mon Sep 17 00:00:00 2001 From: Michael Paquier Date: Wed, 1 Sep 2021 11:48:08 +0900 Subject: [PATCH] Refactor one conversion of SQLSTATE to string in elog.c unpack_sql_state() has been introduced in d46bc44 to refactor the unpacking of a SQLSTATE into a string, but it forgot one code path when sending error reports to clients that could make use of it. This changes the code to also use unpack_sql_state() there, simplifying a bit the code. Author: Peter Smith Discussion: https://postgr.es/m/CAHut+PuYituuD1-VVZUNcmCQuc3ZzZMPoO57POgm8tnXOkwJAA@mail.gmail.com --- src/backend/utils/error/elog.c | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/src/backend/utils/error/elog.c b/src/backend/utils/error/elog.c index a3e1c59a829..816b071afaa 100644 --- a/src/backend/utils/error/elog.c +++ b/src/backend/utils/error/elog.c @@ -3312,8 +3312,6 @@ send_message_to_frontend(ErrorData *edata) /* New style with separate fields */ const char *sev; char tbuf[12]; - int ssval; - int i; /* 'N' (Notice) is for nonfatal conditions, 'E' is for errors */ pq_beginmessage(&msgbuf, (edata->elevel < ERROR) ? 'N' : 'E'); @@ -3324,17 +3322,8 @@ send_message_to_frontend(ErrorData *edata) pq_sendbyte(&msgbuf, PG_DIAG_SEVERITY_NONLOCALIZED); err_sendstring(&msgbuf, sev); - /* unpack MAKE_SQLSTATE code */ - ssval = edata->sqlerrcode; - for (i = 0; i < 5; i++) - { - tbuf[i] = PGUNSIXBIT(ssval); - ssval >>= 6; - } - tbuf[i] = '\0'; - pq_sendbyte(&msgbuf, PG_DIAG_SQLSTATE); - err_sendstring(&msgbuf, tbuf); + err_sendstring(&msgbuf, unpack_sql_state(edata->sqlerrcode)); /* M field is required per protocol, so always send something */ pq_sendbyte(&msgbuf, PG_DIAG_MESSAGE_PRIMARY);