Install infrastructure to manage psql's hidden query labels better.

Commit 41d69e6dc added labels to psql's internally-generated queries,
which are sent to the server and possibly recorded in the server log.
In that commit we always attempted to translate the labels per psql's
NLS environment, but that is hazardous: non-ASCII labels might fail
to be translatable to the server's encoding, rendering some or all of
these operations unusable since the server will throw an error and
not execute the query.  Hence, we need some gating checks to decide
whether it's safe to translate a label.

To allow that to be managed in just one place, invent a new function
addQueryComment() that is responsible for outputting these labels.
(Probably it should have been done that way to start with, but better
late than never.)

This commit just does the heavy lifting of creating that function and
fixing all the call sites.  The actual choice of whether to translate
is stubbed out, so that this commit in itself changes no behavior.
Once we've settled on the correct gating checks to use, a much smaller
follow-on commit will install them.

Author: shihao zhong <[email protected]>
Reviewed-by: Fujii Masao <[email protected]>
Reviewed-by: Tom Lane <[email protected]>
Discussion: 
https://postgr.es/m/CAGRkXqRv7yhBOhF0YvSr6ZB7rvsPCjnXSPj8=3bkcsjuyvn...@mail.gmail.com
Backpatch-through: 19

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/294d2196c7abec253fd3959d3ca4c6dcae3068d6

Modified Files
--------------
src/bin/psql/command.c  |   8 +-
src/bin/psql/common.c   |  22 ++++++
src/bin/psql/common.h   |   2 +
src/bin/psql/describe.c | 191 ++++++++++++++++++++----------------------------
src/bin/psql/nls.mk     |   3 +-
5 files changed, 110 insertions(+), 116 deletions(-)

Reply via email to