From 511ae628f31b4e791cd5c7836e46cb84dcf145fd Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Mon, 30 Jan 2017 16:37:15 -0500 Subject: Make psql reject attempts to set special variables to invalid values. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- src/bin/psql/input.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/bin/psql/input.c') diff --git a/src/bin/psql/input.c b/src/bin/psql/input.c index 972bea4cbf..3e3e97ad0d 100644 --- a/src/bin/psql/input.c +++ b/src/bin/psql/input.c @@ -541,7 +541,7 @@ finishInput(void) { int hist_size; - hist_size = GetVariableNum(pset.vars, "HISTSIZE", 500, -1, true); + hist_size = GetVariableNum(pset.vars, "HISTSIZE", 500, -1); (void) saveHistory(psql_history, hist_size); free(psql_history); psql_history = NULL; -- cgit v1.2.1