1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-27 12:41:57 +03:00

Make psql reject attempts to set special variables to invalid values.

Previously, if the user set a special variable such as ECHO to an
unrecognized value, psql would bleat but store the new value anyway, and
then fall back to a default setting for the behavior controlled by the
variable.  This was agreed to be a not particularly good idea.  With
this patch, invalid values result in an error message and no change in
state.

(But this applies only to variables that affect psql's behavior; purely
informational variables such as ENCODING can still be set to random
values.)

To do this, modify the API for psql's assign-hook functions so that they
can return an OK/not OK result, and give them the responsibility for
printing error messages when they reject a value.  Adjust the APIs for
ParseVariableBool and ParseVariableNum to support the new behavior
conveniently.

In passing, document the variable VERSION, which had somehow escaped that.
And improve the quite-inadequate commenting in psql/variables.c.

Daniel Vérité, reviewed by Rahila Syed, some further tweaking by me

Discussion: https://postgr.es/m/7356e741-fa59-4146-a8eb-cf95fd6b21fb@mm
This commit is contained in:
Tom Lane
2017-01-30 16:37:15 -05:00
parent 46aae5949f
commit 511ae628f3
10 changed files with 356 additions and 182 deletions

View File

@ -3078,10 +3078,8 @@ bar
by <application>psql</application>. They represent certain option
settings that can be changed at run time by altering the value of
the variable, or in some cases represent changeable state of
<application>psql</application>. Although
you can use these variables for other purposes, this is not
recommended, as the program behavior might grow really strange
really quickly. By convention, all specially treated variables' names
<application>psql</application>.
By convention, all specially treated variables' names
consist of all upper-case ASCII letters (and possibly digits and
underscores). To ensure maximum compatibility in the future, avoid
using such variable names for your own purposes. A list of all specially
@ -3170,12 +3168,11 @@ bar
start-up, use the switch <option>-a</option>. If set to
<literal>queries</literal>,
<application>psql</application> prints each query to standard output
as it is sent to the server. The switch for this is
as it is sent to the server. The switch to select this behavior is
<option>-e</option>. If set to <literal>errors</literal>, then only
failed queries are displayed on standard error output. The switch
for this is <option>-b</option>. If unset, or if set to
<literal>none</literal> (or any other value than those above) then
no queries are displayed.
for this behavior is <option>-b</option>. If unset, or if set to
<literal>none</literal>, then no queries are displayed.
</para>
</listitem>
</varlistentry>
@ -3201,6 +3198,9 @@ bar
<listitem>
<para>
The current client character set encoding.
This is set every time you connect to a database (including
program start-up), and when you change the encoding
with <literal>\encoding</>, but it can be unset.
</para>
</listitem>
</varlistentry>
@ -3241,9 +3241,8 @@ bar
list. If set to a value of <literal>ignoredups</literal>, lines
matching the previous history line are not entered. A value of
<literal>ignoreboth</literal> combines the two options. If
unset, or if set to <literal>none</literal> (or any other value
than those above), all lines read in interactive mode are
saved on the history list.
unset, or if set to <literal>none</literal> (the default), all lines
read in interactive mode are saved on the history list.
</para>
<note>
<para>
@ -3312,7 +3311,7 @@ bar
to an interactive session of <application>psql</application>
will terminate the application. If set to a numeric value,
that many <acronym>EOF</> characters are ignored before the
application terminates. If the variable is set but has no
application terminates. If the variable is set but not to a
numeric value, the default is 10.
</para>
<note>
@ -3477,6 +3476,16 @@ bar
</listitem>
</varlistentry>
<varlistentry>
<term><varname>VERSION</varname></term>
<listitem>
<para>
This variable is set at program start-up to
reflect <application>psql</>'s version. It can be unset or changed.
</para>
</listitem>
</varlistentry>
</variablelist>
</refsect3>