diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2014-12-31 12:16:53 -0500 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2014-12-31 12:18:50 -0500 |
commit | 28551797a46c0ada035c34cf9cf2bc90448e3c26 (patch) | |
tree | 9f06ea227de115f2dc2d24775588844503ee0add /src/bin/psql/variables.c | |
parent | ba66c9d0681f0c5ec834255fb4e7f6ef6b626747 (diff) | |
download | postgresql-28551797a46c0ada035c34cf9cf2bc90448e3c26.tar.gz postgresql-28551797a46c0ada035c34cf9cf2bc90448e3c26.zip |
Improve consistency of parsing of psql's magic variables.
For simple boolean variables such as ON_ERROR_STOP, psql has for a long
time recognized variant spellings of "on" and "off" (such as "1"/"0"),
and it also made a point of warning you if you'd misspelled the setting.
But these conveniences did not exist for other keyword-valued variables.
In particular, though ECHO_HIDDEN and ON_ERROR_ROLLBACK include "on" and
"off" as possible values, none of the alternative spellings for those were
recognized; and to make matters worse the code would just silently assume
"on" was meant for any unrecognized spelling. Several people have reported
getting bitten by this, so let's fix it. In detail, this patch:
* Allows all spellings recognized by ParseVariableBool() for ECHO_HIDDEN
and ON_ERROR_ROLLBACK.
* Reports a warning for unrecognized values for COMP_KEYWORD_CASE, ECHO,
ECHO_HIDDEN, HISTCONTROL, ON_ERROR_ROLLBACK, and VERBOSITY.
* Recognizes all values for all these variables case-insensitively;
previously there was a mishmash of case-sensitive and case-insensitive
behaviors.
Back-patch to all supported branches. There is a small risk of breaking
existing scripts that were accidentally failing to malfunction; but the
consensus is that the chance of detecting real problems and preventing
future mistakes outweighs this.
Diffstat (limited to 'src/bin/psql/variables.c')
-rw-r--r-- | src/bin/psql/variables.c | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/src/bin/psql/variables.c b/src/bin/psql/variables.c index 1f871d7fa01..29c50f969c0 100644 --- a/src/bin/psql/variables.c +++ b/src/bin/psql/variables.c @@ -79,11 +79,16 @@ GetVariable(VariableSpace space, const char *name) } /* - * Try to interpret value as boolean value. Valid values are: true, - * false, yes, no, on, off, 1, 0; as well as unique prefixes thereof. + * Try to interpret "value" as boolean value. + * + * Valid values are: true, false, yes, no, on, off, 1, 0; as well as unique + * prefixes thereof. + * + * "name" is the name of the variable we're assigning to, to use in error + * report if any. Pass name == NULL to suppress the error report. */ bool -ParseVariableBool(const char *value) +ParseVariableBool(const char *value, const char *name) { size_t len; @@ -112,7 +117,9 @@ ParseVariableBool(const char *value) else { /* NULL is treated as false, so a non-matching value is 'true' */ - psql_error("unrecognized Boolean value; assuming \"on\"\n"); + if (name) + psql_error("unrecognized value \"%s\" for \"%s\"; assuming \"%s\"\n", + value, name, "on"); return true; } } |