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
This commit is contained in:
Michael Paquier 2021-09-01 11:48:08 +09:00
parent de1d4fef71
commit c4f7a6b87f

View File

@ -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);