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
Showing
- doc/src/sgml/ref/psql-ref.sgml 21 additions, 12 deletionsdoc/src/sgml/ref/psql-ref.sgml
- src/bin/psql/command.c 46 additions, 36 deletionssrc/bin/psql/command.c
- src/bin/psql/common.c 0 additions, 1 deletionsrc/bin/psql/common.c
- src/bin/psql/input.c 1 addition, 1 deletionsrc/bin/psql/input.c
- src/bin/psql/mainloop.c 1 addition, 1 deletionsrc/bin/psql/mainloop.c
- src/bin/psql/startup.c 72 additions, 49 deletionssrc/bin/psql/startup.c
- src/bin/psql/variables.c 163 additions, 65 deletionssrc/bin/psql/variables.c
- src/bin/psql/variables.h 34 additions, 16 deletionssrc/bin/psql/variables.h
- src/test/regress/expected/psql.out 10 additions, 1 deletionsrc/test/regress/expected/psql.out
- src/test/regress/sql/psql.sql 8 additions, 0 deletionssrc/test/regress/sql/psql.sql
Loading
Please register or sign in to comment