mirror of
https://github.com/postgres/postgres.git
synced 2026-03-28 13:23:48 -04:00
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.
147 lines
3.2 KiB
C
147 lines
3.2 KiB
C
/*
|
|
* psql - the PostgreSQL interactive terminal
|
|
*
|
|
* Copyright (c) 2000-2014, PostgreSQL Global Development Group
|
|
*
|
|
* src/bin/psql/settings.h
|
|
*/
|
|
#ifndef SETTINGS_H
|
|
#define SETTINGS_H
|
|
|
|
|
|
#include "variables.h"
|
|
#include "print.h"
|
|
|
|
#define DEFAULT_FIELD_SEP "|"
|
|
#define DEFAULT_RECORD_SEP "\n"
|
|
|
|
#if defined(WIN32) || defined(__CYGWIN__)
|
|
#define DEFAULT_EDITOR "notepad.exe"
|
|
/* no DEFAULT_EDITOR_LINENUMBER_ARG for Notepad */
|
|
#else
|
|
#define DEFAULT_EDITOR "vi"
|
|
#define DEFAULT_EDITOR_LINENUMBER_ARG "+"
|
|
#endif
|
|
|
|
#define DEFAULT_PROMPT1 "%/%R%# "
|
|
#define DEFAULT_PROMPT2 "%/%R%# "
|
|
#define DEFAULT_PROMPT3 ">> "
|
|
|
|
/*
|
|
* Note: these enums should generally be chosen so that zero corresponds
|
|
* to the default behavior.
|
|
*/
|
|
|
|
typedef enum
|
|
{
|
|
PSQL_ECHO_NONE,
|
|
PSQL_ECHO_QUERIES,
|
|
PSQL_ECHO_ALL
|
|
} PSQL_ECHO;
|
|
|
|
typedef enum
|
|
{
|
|
PSQL_ECHO_HIDDEN_OFF,
|
|
PSQL_ECHO_HIDDEN_ON,
|
|
PSQL_ECHO_HIDDEN_NOEXEC
|
|
} PSQL_ECHO_HIDDEN;
|
|
|
|
typedef enum
|
|
{
|
|
PSQL_ERROR_ROLLBACK_OFF,
|
|
PSQL_ERROR_ROLLBACK_INTERACTIVE,
|
|
PSQL_ERROR_ROLLBACK_ON
|
|
} PSQL_ERROR_ROLLBACK;
|
|
|
|
typedef enum
|
|
{
|
|
PSQL_COMP_CASE_PRESERVE_UPPER,
|
|
PSQL_COMP_CASE_PRESERVE_LOWER,
|
|
PSQL_COMP_CASE_UPPER,
|
|
PSQL_COMP_CASE_LOWER
|
|
} PSQL_COMP_CASE;
|
|
|
|
typedef enum
|
|
{
|
|
hctl_none = 0,
|
|
hctl_ignorespace = 1,
|
|
hctl_ignoredups = 2,
|
|
hctl_ignoreboth = hctl_ignorespace | hctl_ignoredups
|
|
} HistControl;
|
|
|
|
enum trivalue
|
|
{
|
|
TRI_DEFAULT,
|
|
TRI_NO,
|
|
TRI_YES
|
|
};
|
|
|
|
typedef struct _psqlSettings
|
|
{
|
|
PGconn *db; /* connection to backend */
|
|
int encoding; /* client_encoding */
|
|
FILE *queryFout; /* where to send the query results */
|
|
bool queryFoutPipe; /* queryFout is from a popen() */
|
|
|
|
FILE *copyStream; /* Stream to read/write for \copy command */
|
|
|
|
printQueryOpt popt;
|
|
|
|
char *gfname; /* one-shot file output argument for \g */
|
|
char *gset_prefix; /* one-shot prefix argument for \gset */
|
|
|
|
bool notty; /* stdin or stdout is not a tty (as determined
|
|
* on startup) */
|
|
enum trivalue getPassword; /* prompt the user for a username and password */
|
|
FILE *cur_cmd_source; /* describe the status of the current main
|
|
* loop */
|
|
bool cur_cmd_interactive;
|
|
int sversion; /* backend server version */
|
|
const char *progname; /* in case you renamed psql */
|
|
char *inputfile; /* file being currently processed, if any */
|
|
uint64 lineno; /* also for error reporting */
|
|
|
|
bool timing; /* enable timing of all queries */
|
|
|
|
FILE *logfile; /* session log file handle */
|
|
|
|
VariableSpace vars; /* "shell variable" repository */
|
|
|
|
/*
|
|
* The remaining fields are set by assign hooks associated with entries in
|
|
* "vars". They should not be set directly except by those hook
|
|
* functions.
|
|
*/
|
|
bool autocommit;
|
|
bool on_error_stop;
|
|
bool quiet;
|
|
bool singleline;
|
|
bool singlestep;
|
|
int fetch_count;
|
|
PSQL_ECHO echo;
|
|
PSQL_ECHO_HIDDEN echo_hidden;
|
|
PSQL_ERROR_ROLLBACK on_error_rollback;
|
|
PSQL_COMP_CASE comp_case;
|
|
HistControl histcontrol;
|
|
const char *prompt1;
|
|
const char *prompt2;
|
|
const char *prompt3;
|
|
PGVerbosity verbosity; /* current error verbosity level */
|
|
} PsqlSettings;
|
|
|
|
extern PsqlSettings pset;
|
|
|
|
|
|
#ifndef EXIT_SUCCESS
|
|
#define EXIT_SUCCESS 0
|
|
#endif
|
|
|
|
#ifndef EXIT_FAILURE
|
|
#define EXIT_FAILURE 1
|
|
#endif
|
|
|
|
#define EXIT_BADCONN 2
|
|
|
|
#define EXIT_USER 3
|
|
|
|
#endif
|