2000-01-19 00:30:24 +01:00
|
|
|
/*
|
|
|
|
* psql - the PostgreSQL interactive terminal
|
|
|
|
*
|
2016-01-02 19:33:40 +01:00
|
|
|
* Copyright (c) 2000-2016, PostgreSQL Global Development Group
|
2000-01-19 00:30:24 +01:00
|
|
|
*
|
2010-09-20 22:08:53 +02:00
|
|
|
* src/bin/psql/variables.h
|
2000-01-19 00:30:24 +01:00
|
|
|
*/
|
2006-08-29 17:19:51 +02:00
|
|
|
#ifndef VARIABLES_H
|
|
|
|
#define VARIABLES_H
|
2000-01-19 00:30:24 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* This implements a sort of variable repository. One could also think of it
|
2006-08-29 17:19:51 +02:00
|
|
|
* as a cheap version of an associative array. In each one of these
|
|
|
|
* datastructures you can store name/value pairs. There can also be an
|
|
|
|
* "assign hook" function that is called whenever the variable's value is
|
|
|
|
* changed.
|
|
|
|
*
|
|
|
|
* An "unset" operation causes the hook to be called with newval == NULL.
|
|
|
|
*
|
|
|
|
* Note: if value == NULL then the variable is logically unset, but we are
|
|
|
|
* keeping the struct around so as not to forget about its hook function.
|
1999-11-04 22:56:02 +01:00
|
|
|
*/
|
2006-08-29 17:19:51 +02:00
|
|
|
typedef void (*VariableAssignHook) (const char *newval);
|
1999-11-04 22:56:02 +01:00
|
|
|
|
1999-11-05 00:14:30 +01:00
|
|
|
struct _variable
|
|
|
|
{
|
|
|
|
char *name;
|
|
|
|
char *value;
|
2006-08-29 17:19:51 +02:00
|
|
|
VariableAssignHook assign_hook;
|
1999-11-05 00:14:30 +01:00
|
|
|
struct _variable *next;
|
1999-11-04 22:56:02 +01:00
|
|
|
};
|
|
|
|
|
1999-11-05 00:14:30 +01:00
|
|
|
typedef struct _variable *VariableSpace;
|
1999-11-04 22:56:02 +01:00
|
|
|
|
|
|
|
VariableSpace CreateVariableSpace(void);
|
1999-11-05 00:14:30 +01:00
|
|
|
const char *GetVariable(VariableSpace space, const char *name);
|
2003-03-20 07:43:35 +01:00
|
|
|
|
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.
2014-12-31 18:16:53 +01:00
|
|
|
bool ParseVariableBool(const char *value, const char *name);
|
2006-08-29 17:19:51 +02:00
|
|
|
int ParseVariableNum(const char *val,
|
|
|
|
int defaultval,
|
|
|
|
int faultval,
|
|
|
|
bool allowtrail);
|
2003-08-04 02:43:34 +02:00
|
|
|
int GetVariableNum(VariableSpace space,
|
2006-08-29 17:19:51 +02:00
|
|
|
const char *name,
|
2003-08-04 02:43:34 +02:00
|
|
|
int defaultval,
|
|
|
|
int faultval,
|
|
|
|
bool allowtrail);
|
2003-03-20 07:43:35 +01:00
|
|
|
|
2003-08-04 02:43:34 +02:00
|
|
|
void PrintVariables(VariableSpace space);
|
2003-03-20 07:43:35 +01:00
|
|
|
|
2003-08-04 02:43:34 +02:00
|
|
|
bool SetVariable(VariableSpace space, const char *name, const char *value);
|
2006-08-29 17:19:51 +02:00
|
|
|
bool SetVariableAssignHook(VariableSpace space, const char *name, VariableAssignHook hook);
|
2003-08-04 02:43:34 +02:00
|
|
|
bool SetVariableBool(VariableSpace space, const char *name);
|
|
|
|
bool DeleteVariable(VariableSpace space, const char *name);
|
1999-11-04 22:56:02 +01:00
|
|
|
|
2001-11-05 18:46:40 +01:00
|
|
|
#endif /* VARIABLES_H */
|