2 * psql - the PostgreSQL interactive terminal
4 * Copyright (c) 2000-2017, PostgreSQL Global Development Group
6 * src/bin/psql/startup.c
8 #include "postgres_fe.h"
17 #include "getopt_long.h"
25 #include "fe_utils/print.h"
36 #define SYSPSQLRC "psqlrc"
37 #define PSQLRC ".psqlrc"
39 #define SYSPSQLRC "psqlrc"
40 #define PSQLRC "psqlrc.conf"
44 * Structures to pass information between the option parsing routine
45 * and the main function
54 typedef struct SimpleActionListCell
56 struct SimpleActionListCell *next;
59 } SimpleActionListCell;
61 typedef struct SimpleActionList
63 SimpleActionListCell *head;
64 SimpleActionListCell *tail;
78 SimpleActionList actions;
81 static void parse_psql_options(int argc, char *argv[],
82 struct adhoc_opts *options);
83 static void simple_action_list_append(SimpleActionList *list,
84 enum _actions action, const char *val);
85 static void process_psqlrc(char *argv0);
86 static void process_psqlrc_file(char *filename);
87 static void showVersion(void);
88 static void EstablishVariableSpace(void);
98 main(int argc, char *argv[])
100 struct adhoc_opts options;
102 bool have_password = false;
104 char *password_prompt = NULL;
107 set_pglocale_pgservice(argv[0], PG_TEXTDOMAIN("psql"));
111 if ((strcmp(argv[1], "-?") == 0) || (argc == 2 && (strcmp(argv[1], "--help") == 0)))
116 if (strcmp(argv[1], "--version") == 0 || strcmp(argv[1], "-V") == 0)
124 setvbuf(stderr, NULL, _IONBF, 0);
127 pset.progname = get_progname(argv[0]);
131 pset.encoding = PQenv2encoding();
132 pset.queryFout = stdout;
133 pset.queryFoutPipe = false;
134 pset.copyStream = NULL;
135 pset.last_error_result = NULL;
136 pset.cur_cmd_source = stdin;
137 pset.cur_cmd_interactive = false;
139 /* We rely on unmentioned fields of pset.popt to start out 0/false/NULL */
140 pset.popt.topt.format = PRINT_ALIGNED;
141 pset.popt.topt.border = 1;
142 pset.popt.topt.pager = 1;
143 pset.popt.topt.pager_min_lines = 0;
144 pset.popt.topt.start_table = true;
145 pset.popt.topt.stop_table = true;
146 pset.popt.topt.default_footer = true;
148 pset.popt.topt.unicode_border_linestyle = UNICODE_LINESTYLE_SINGLE;
149 pset.popt.topt.unicode_column_linestyle = UNICODE_LINESTYLE_SINGLE;
150 pset.popt.topt.unicode_header_linestyle = UNICODE_LINESTYLE_SINGLE;
152 refresh_utf8format(&(pset.popt.topt));
154 /* We must get COLUMNS here before readline() sets it */
155 pset.popt.topt.env_columns = getenv("COLUMNS") ? atoi(getenv("COLUMNS")) : 0;
157 pset.notty = (!isatty(fileno(stdin)) || !isatty(fileno(stdout)));
159 pset.getPassword = TRI_DEFAULT;
161 EstablishVariableSpace();
163 /* Create variables showing psql version number */
164 SetVariable(pset.vars, "VERSION", PG_VERSION_STR);
165 SetVariable(pset.vars, "VERSION_NAME", PG_VERSION);
166 SetVariable(pset.vars, "VERSION_NUM", CppAsString2(PG_VERSION_NUM));
168 /* Default values for variables (that don't match the result of \unset) */
169 SetVariableBool(pset.vars, "AUTOCOMMIT");
170 SetVariable(pset.vars, "PROMPT1", DEFAULT_PROMPT1);
171 SetVariable(pset.vars, "PROMPT2", DEFAULT_PROMPT2);
172 SetVariable(pset.vars, "PROMPT3", DEFAULT_PROMPT3);
174 parse_psql_options(argc, argv, &options);
177 * If no action was specified and we're in non-interactive mode, treat it
178 * as if the user had specified "-f -". This lets single-transaction mode
181 if (options.actions.head == NULL && pset.notty)
182 simple_action_list_append(&options.actions, ACT_FILE, NULL);
184 /* Bail out if -1 was specified but will be ignored. */
185 if (options.single_txn && options.actions.head == NULL)
187 fprintf(stderr, _("%s: -1 can only be used in non-interactive mode\n"), pset.progname);
191 if (!pset.popt.topt.fieldSep.separator &&
192 !pset.popt.topt.fieldSep.separator_zero)
194 pset.popt.topt.fieldSep.separator = pg_strdup(DEFAULT_FIELD_SEP);
195 pset.popt.topt.fieldSep.separator_zero = false;
197 if (!pset.popt.topt.recordSep.separator &&
198 !pset.popt.topt.recordSep.separator_zero)
200 pset.popt.topt.recordSep.separator = pg_strdup(DEFAULT_RECORD_SEP);
201 pset.popt.topt.recordSep.separator_zero = false;
204 if (options.username == NULL)
205 password_prompt = pg_strdup(_("Password: "));
207 password_prompt = psprintf(_("Password for user %s: "),
210 if (pset.getPassword == TRI_YES)
212 simple_prompt(password_prompt, password, sizeof(password), false);
213 have_password = true;
216 /* loop until we have a password if requested by backend */
219 #define PARAMS_ARRAY_SIZE 8
220 const char **keywords = pg_malloc(PARAMS_ARRAY_SIZE * sizeof(*keywords));
221 const char **values = pg_malloc(PARAMS_ARRAY_SIZE * sizeof(*values));
223 keywords[0] = "host";
224 values[0] = options.host;
225 keywords[1] = "port";
226 values[1] = options.port;
227 keywords[2] = "user";
228 values[2] = options.username;
229 keywords[3] = "password";
230 values[3] = have_password ? password : NULL;
231 keywords[4] = "dbname"; /* see do_connect() */
232 values[4] = (options.list_dbs && options.dbname == NULL) ?
233 "postgres" : options.dbname;
234 keywords[5] = "fallback_application_name";
235 values[5] = pset.progname;
236 keywords[6] = "client_encoding";
237 values[6] = (pset.notty || getenv("PGCLIENTENCODING")) ? NULL : "auto";
242 pset.db = PQconnectdbParams(keywords, values, true);
246 if (PQstatus(pset.db) == CONNECTION_BAD &&
247 PQconnectionNeedsPassword(pset.db) &&
249 pset.getPassword != TRI_NO)
252 simple_prompt(password_prompt, password, sizeof(password), false);
253 have_password = true;
258 free(password_prompt);
260 if (PQstatus(pset.db) == CONNECTION_BAD)
262 fprintf(stderr, "%s: %s", pset.progname, PQerrorMessage(pset.db));
267 setup_cancel_handler();
269 PQsetNoticeProcessor(pset.db, NoticeProcessor, NULL);
273 if (options.list_dbs)
277 if (!options.no_psqlrc)
278 process_psqlrc(argv[0]);
280 success = listAllDbs(NULL, false);
282 exit(success ? EXIT_SUCCESS : EXIT_FAILURE);
285 if (options.logfilename)
287 pset.logfile = fopen(options.logfilename, "a");
290 fprintf(stderr, _("%s: could not open log file \"%s\": %s\n"),
291 pset.progname, options.logfilename, strerror(errno));
296 if (!options.no_psqlrc)
297 process_psqlrc(argv[0]);
300 * If any actions were given by user, process them in the order in which
301 * they were specified. Note single_txn is only effective in this mode.
303 if (options.actions.head != NULL)
306 SimpleActionListCell *cell;
308 successResult = EXIT_SUCCESS; /* silence compiler */
310 if (options.single_txn)
312 if ((res = PSQLexec("BEGIN")) == NULL)
314 if (pset.on_error_stop)
316 successResult = EXIT_USER;
324 for (cell = options.actions.head; cell; cell = cell->next)
326 if (cell->action == ACT_SINGLE_QUERY)
328 if (pset.echo == PSQL_ECHO_ALL)
331 successResult = SendQuery(cell->val)
332 ? EXIT_SUCCESS : EXIT_FAILURE;
334 else if (cell->action == ACT_SINGLE_SLASH)
336 PsqlScanState scan_state;
337 ConditionalStack cond_stack;
339 if (pset.echo == PSQL_ECHO_ALL)
342 scan_state = psql_scan_create(&psqlscan_callbacks);
343 psql_scan_setup(scan_state,
344 cell->val, strlen(cell->val),
345 pset.encoding, standard_strings());
346 cond_stack = conditional_stack_create();
347 psql_scan_set_passthrough(scan_state, (void *) cond_stack);
349 successResult = HandleSlashCmds(scan_state,
352 NULL) != PSQL_CMD_ERROR
353 ? EXIT_SUCCESS : EXIT_FAILURE;
355 psql_scan_destroy(scan_state);
356 conditional_stack_destroy(cond_stack);
358 else if (cell->action == ACT_FILE)
360 successResult = process_file(cell->val, false);
364 /* should never come here */
368 if (successResult != EXIT_SUCCESS && pset.on_error_stop)
372 if (options.single_txn)
374 if ((res = PSQLexec("COMMIT")) == NULL)
376 if (pset.on_error_stop)
378 successResult = EXIT_USER;
391 * or otherwise enter interactive main loop
395 connection_warnings(true);
397 printf(_("Type \"help\" for help.\n\n"));
398 initializeInput(options.no_readline ? 0 : 1);
399 successResult = MainLoop(stdin);
404 fclose(pset.logfile);
408 return successResult;
413 * Parse command line options
417 parse_psql_options(int argc, char *argv[], struct adhoc_opts *options)
419 static struct option long_options[] =
421 {"echo-all", no_argument, NULL, 'a'},
422 {"no-align", no_argument, NULL, 'A'},
423 {"command", required_argument, NULL, 'c'},
424 {"dbname", required_argument, NULL, 'd'},
425 {"echo-queries", no_argument, NULL, 'e'},
426 {"echo-errors", no_argument, NULL, 'b'},
427 {"echo-hidden", no_argument, NULL, 'E'},
428 {"file", required_argument, NULL, 'f'},
429 {"field-separator", required_argument, NULL, 'F'},
430 {"field-separator-zero", no_argument, NULL, 'z'},
431 {"host", required_argument, NULL, 'h'},
432 {"html", no_argument, NULL, 'H'},
433 {"list", no_argument, NULL, 'l'},
434 {"log-file", required_argument, NULL, 'L'},
435 {"no-readline", no_argument, NULL, 'n'},
436 {"single-transaction", no_argument, NULL, '1'},
437 {"output", required_argument, NULL, 'o'},
438 {"port", required_argument, NULL, 'p'},
439 {"pset", required_argument, NULL, 'P'},
440 {"quiet", no_argument, NULL, 'q'},
441 {"record-separator", required_argument, NULL, 'R'},
442 {"record-separator-zero", no_argument, NULL, '0'},
443 {"single-step", no_argument, NULL, 's'},
444 {"single-line", no_argument, NULL, 'S'},
445 {"tuples-only", no_argument, NULL, 't'},
446 {"table-attr", required_argument, NULL, 'T'},
447 {"username", required_argument, NULL, 'U'},
448 {"set", required_argument, NULL, 'v'},
449 {"variable", required_argument, NULL, 'v'},
450 {"version", no_argument, NULL, 'V'},
451 {"no-password", no_argument, NULL, 'w'},
452 {"password", no_argument, NULL, 'W'},
453 {"expanded", no_argument, NULL, 'x'},
454 {"no-psqlrc", no_argument, NULL, 'X'},
455 {"help", optional_argument, NULL, 1},
462 memset(options, 0, sizeof *options);
464 while ((c = getopt_long(argc, argv, "aAbc:d:eEf:F:h:HlL:no:p:P:qR:sStT:U:v:VwWxXz?01",
465 long_options, &optindex)) != -1)
470 SetVariable(pset.vars, "ECHO", "all");
473 pset.popt.topt.format = PRINT_UNALIGNED;
476 SetVariable(pset.vars, "ECHO", "errors");
479 if (optarg[0] == '\\')
480 simple_action_list_append(&options->actions,
484 simple_action_list_append(&options->actions,
489 options->dbname = pg_strdup(optarg);
492 SetVariable(pset.vars, "ECHO", "queries");
495 SetVariableBool(pset.vars, "ECHO_HIDDEN");
498 simple_action_list_append(&options->actions,
503 pset.popt.topt.fieldSep.separator = pg_strdup(optarg);
504 pset.popt.topt.fieldSep.separator_zero = false;
507 options->host = pg_strdup(optarg);
510 pset.popt.topt.format = PRINT_HTML;
513 options->list_dbs = true;
516 options->logfilename = pg_strdup(optarg);
519 options->no_readline = true;
522 if (!setQFout(optarg))
526 options->port = pg_strdup(optarg);
534 value = pg_strdup(optarg);
535 equal_loc = strchr(value, '=');
537 result = do_pset(value, NULL, &pset.popt, true);
541 result = do_pset(value, equal_loc + 1, &pset.popt, true);
546 fprintf(stderr, _("%s: could not set printing parameter \"%s\"\n"), pset.progname, value);
554 SetVariableBool(pset.vars, "QUIET");
557 pset.popt.topt.recordSep.separator = pg_strdup(optarg);
558 pset.popt.topt.recordSep.separator_zero = false;
561 SetVariableBool(pset.vars, "SINGLESTEP");
564 SetVariableBool(pset.vars, "SINGLELINE");
567 pset.popt.topt.tuples_only = true;
570 pset.popt.topt.tableAttr = pg_strdup(optarg);
573 options->username = pg_strdup(optarg);
580 value = pg_strdup(optarg);
581 equal_loc = strchr(value, '=');
584 if (!DeleteVariable(pset.vars, value))
585 exit(EXIT_FAILURE); /* error already printed */
590 if (!SetVariable(pset.vars, value, equal_loc + 1))
591 exit(EXIT_FAILURE); /* error already printed */
601 pset.getPassword = TRI_NO;
604 pset.getPassword = TRI_YES;
607 pset.popt.topt.expanded = true;
610 options->no_psqlrc = true;
613 pset.popt.topt.fieldSep.separator_zero = true;
616 pset.popt.topt.recordSep.separator_zero = true;
619 options->single_txn = true;
622 /* Actual help option given */
623 if (strcmp(argv[optind - 1], "-?") == 0)
628 /* unknown option reported by getopt */
634 if (!optarg || strcmp(optarg, "options") == 0)
636 else if (optarg && strcmp(optarg, "commands") == 0)
638 else if (optarg && strcmp(optarg, "variables") == 0)
639 helpVariables(NOPAGER);
648 fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
656 * if we still have arguments, use it as the database name and username
658 while (argc - optind >= 1)
660 if (!options->dbname)
661 options->dbname = argv[optind];
662 else if (!options->username)
663 options->username = argv[optind];
664 else if (!pset.quiet)
665 fprintf(stderr, _("%s: warning: extra command-line argument \"%s\" ignored\n"),
666 pset.progname, argv[optind]);
674 * Append a new item to the end of the SimpleActionList.
675 * Note that "val" is copied if it's not NULL.
678 simple_action_list_append(SimpleActionList *list,
679 enum _actions action, const char *val)
681 SimpleActionListCell *cell;
683 cell = (SimpleActionListCell *) pg_malloc(sizeof(SimpleActionListCell));
686 cell->action = action;
688 cell->val = pg_strdup(val);
693 list->tail->next = cell;
701 * Load .psqlrc file, if found.
704 process_psqlrc(char *argv0)
706 char home[MAXPGPATH];
707 char rc_file[MAXPGPATH];
708 char my_exec_path[MAXPGPATH];
709 char etc_path[MAXPGPATH];
710 char *envrc = getenv("PSQLRC");
712 if (find_my_exec(argv0, my_exec_path) < 0)
714 fprintf(stderr, _("%s: could not find own program executable\n"), argv0);
718 get_etc_path(my_exec_path, etc_path);
720 snprintf(rc_file, MAXPGPATH, "%s/%s", etc_path, SYSPSQLRC);
721 process_psqlrc_file(rc_file);
723 if (envrc != NULL && strlen(envrc) > 0)
725 /* might need to free() this */
726 char *envrc_alloc = pstrdup(envrc);
728 expand_tilde(&envrc_alloc);
729 process_psqlrc_file(envrc_alloc);
731 else if (get_home_path(home))
733 snprintf(rc_file, MAXPGPATH, "%s/%s", home, PSQLRC);
734 process_psqlrc_file(rc_file);
741 process_psqlrc_file(char *filename)
746 #if defined(WIN32) && (!defined(__MINGW32__))
750 psqlrc_minor = psprintf("%s-%s", filename, PG_VERSION);
751 psqlrc_major = psprintf("%s-%s", filename, PG_MAJORVERSION);
753 /* check for minor version first, then major, then no version */
754 if (access(psqlrc_minor, R_OK) == 0)
755 (void) process_file(psqlrc_minor, false);
756 else if (access(psqlrc_major, R_OK) == 0)
757 (void) process_file(psqlrc_major, false);
758 else if (access(filename, R_OK) == 0)
759 (void) process_file(filename, false);
769 * This output format is intended to match GNU standards.
774 puts("psql (PostgreSQL) " PG_VERSION);
780 * Substitute hooks and assign hooks for psql variables.
782 * This isn't an amazingly good place for them, but neither is anywhere else.
784 * By policy, every special variable that controls any psql behavior should
785 * have one or both hooks, even if they're just no-ops. This ensures that
786 * the variable will remain present in variables.c's list even when unset,
787 * which ensures that it's known to tab completion.
791 bool_substitute_hook(char *newval)
795 /* "\unset FOO" becomes "\set FOO off" */
796 newval = pg_strdup("off");
798 else if (newval[0] == '\0')
800 /* "\set FOO" becomes "\set FOO on" */
802 newval = pg_strdup("on");
808 autocommit_hook(const char *newval)
810 return ParseVariableBool(newval, "AUTOCOMMIT", &pset.autocommit);
814 on_error_stop_hook(const char *newval)
816 return ParseVariableBool(newval, "ON_ERROR_STOP", &pset.on_error_stop);
820 quiet_hook(const char *newval)
822 return ParseVariableBool(newval, "QUIET", &pset.quiet);
826 singleline_hook(const char *newval)
828 return ParseVariableBool(newval, "SINGLELINE", &pset.singleline);
832 singlestep_hook(const char *newval)
834 return ParseVariableBool(newval, "SINGLESTEP", &pset.singlestep);
838 fetch_count_substitute_hook(char *newval)
841 newval = pg_strdup("0");
846 fetch_count_hook(const char *newval)
848 return ParseVariableNum(newval, "FETCH_COUNT", &pset.fetch_count);
852 histfile_hook(const char *newval)
855 * Someday we might try to validate the filename, but for now, this is
856 * just a placeholder to ensure HISTFILE is known to tab completion.
862 histsize_substitute_hook(char *newval)
865 newval = pg_strdup("500");
870 histsize_hook(const char *newval)
872 return ParseVariableNum(newval, "HISTSIZE", &pset.histsize);
876 ignoreeof_substitute_hook(char *newval)
881 * This tries to mimic the behavior of bash, to wit "If set, the value is
882 * the number of consecutive EOF characters which must be typed as the
883 * first characters on an input line before bash exits. If the variable
884 * exists but does not have a numeric value, or has no value, the default
885 * value is 10. If it does not exist, EOF signifies the end of input to
886 * the shell." Unlike bash, however, we insist on the stored value
887 * actually being a valid integer.
890 newval = pg_strdup("0");
891 else if (!ParseVariableNum(newval, NULL, &dummy))
892 newval = pg_strdup("10");
897 ignoreeof_hook(const char *newval)
899 return ParseVariableNum(newval, "IGNOREEOF", &pset.ignoreeof);
903 echo_substitute_hook(char *newval)
906 newval = pg_strdup("none");
911 echo_hook(const char *newval)
913 Assert(newval != NULL); /* else substitute hook messed up */
914 if (pg_strcasecmp(newval, "queries") == 0)
915 pset.echo = PSQL_ECHO_QUERIES;
916 else if (pg_strcasecmp(newval, "errors") == 0)
917 pset.echo = PSQL_ECHO_ERRORS;
918 else if (pg_strcasecmp(newval, "all") == 0)
919 pset.echo = PSQL_ECHO_ALL;
920 else if (pg_strcasecmp(newval, "none") == 0)
921 pset.echo = PSQL_ECHO_NONE;
924 PsqlVarEnumError("ECHO", newval, "none, errors, queries, all");
931 echo_hidden_hook(const char *newval)
933 Assert(newval != NULL); /* else substitute hook messed up */
934 if (pg_strcasecmp(newval, "noexec") == 0)
935 pset.echo_hidden = PSQL_ECHO_HIDDEN_NOEXEC;
940 if (ParseVariableBool(newval, NULL, &on_off))
941 pset.echo_hidden = on_off ? PSQL_ECHO_HIDDEN_ON : PSQL_ECHO_HIDDEN_OFF;
944 PsqlVarEnumError("ECHO_HIDDEN", newval, "on, off, noexec");
952 on_error_rollback_hook(const char *newval)
954 Assert(newval != NULL); /* else substitute hook messed up */
955 if (pg_strcasecmp(newval, "interactive") == 0)
956 pset.on_error_rollback = PSQL_ERROR_ROLLBACK_INTERACTIVE;
961 if (ParseVariableBool(newval, NULL, &on_off))
962 pset.on_error_rollback = on_off ? PSQL_ERROR_ROLLBACK_ON : PSQL_ERROR_ROLLBACK_OFF;
965 PsqlVarEnumError("ON_ERROR_ROLLBACK", newval, "on, off, interactive");
973 comp_keyword_case_substitute_hook(char *newval)
976 newval = pg_strdup("preserve-upper");
981 comp_keyword_case_hook(const char *newval)
983 Assert(newval != NULL); /* else substitute hook messed up */
984 if (pg_strcasecmp(newval, "preserve-upper") == 0)
985 pset.comp_case = PSQL_COMP_CASE_PRESERVE_UPPER;
986 else if (pg_strcasecmp(newval, "preserve-lower") == 0)
987 pset.comp_case = PSQL_COMP_CASE_PRESERVE_LOWER;
988 else if (pg_strcasecmp(newval, "upper") == 0)
989 pset.comp_case = PSQL_COMP_CASE_UPPER;
990 else if (pg_strcasecmp(newval, "lower") == 0)
991 pset.comp_case = PSQL_COMP_CASE_LOWER;
994 PsqlVarEnumError("COMP_KEYWORD_CASE", newval,
995 "lower, upper, preserve-lower, preserve-upper");
1002 histcontrol_substitute_hook(char *newval)
1005 newval = pg_strdup("none");
1010 histcontrol_hook(const char *newval)
1012 Assert(newval != NULL); /* else substitute hook messed up */
1013 if (pg_strcasecmp(newval, "ignorespace") == 0)
1014 pset.histcontrol = hctl_ignorespace;
1015 else if (pg_strcasecmp(newval, "ignoredups") == 0)
1016 pset.histcontrol = hctl_ignoredups;
1017 else if (pg_strcasecmp(newval, "ignoreboth") == 0)
1018 pset.histcontrol = hctl_ignoreboth;
1019 else if (pg_strcasecmp(newval, "none") == 0)
1020 pset.histcontrol = hctl_none;
1023 PsqlVarEnumError("HISTCONTROL", newval,
1024 "none, ignorespace, ignoredups, ignoreboth");
1031 prompt1_hook(const char *newval)
1033 pset.prompt1 = newval ? newval : "";
1038 prompt2_hook(const char *newval)
1040 pset.prompt2 = newval ? newval : "";
1045 prompt3_hook(const char *newval)
1047 pset.prompt3 = newval ? newval : "";
1052 verbosity_substitute_hook(char *newval)
1055 newval = pg_strdup("default");
1060 verbosity_hook(const char *newval)
1062 Assert(newval != NULL); /* else substitute hook messed up */
1063 if (pg_strcasecmp(newval, "default") == 0)
1064 pset.verbosity = PQERRORS_DEFAULT;
1065 else if (pg_strcasecmp(newval, "terse") == 0)
1066 pset.verbosity = PQERRORS_TERSE;
1067 else if (pg_strcasecmp(newval, "verbose") == 0)
1068 pset.verbosity = PQERRORS_VERBOSE;
1071 PsqlVarEnumError("VERBOSITY", newval, "default, terse, verbose");
1076 PQsetErrorVerbosity(pset.db, pset.verbosity);
1081 show_context_substitute_hook(char *newval)
1084 newval = pg_strdup("errors");
1089 show_context_hook(const char *newval)
1091 Assert(newval != NULL); /* else substitute hook messed up */
1092 if (pg_strcasecmp(newval, "never") == 0)
1093 pset.show_context = PQSHOW_CONTEXT_NEVER;
1094 else if (pg_strcasecmp(newval, "errors") == 0)
1095 pset.show_context = PQSHOW_CONTEXT_ERRORS;
1096 else if (pg_strcasecmp(newval, "always") == 0)
1097 pset.show_context = PQSHOW_CONTEXT_ALWAYS;
1100 PsqlVarEnumError("SHOW_CONTEXT", newval, "never, errors, always");
1105 PQsetErrorContextVisibility(pset.db, pset.show_context);
1111 EstablishVariableSpace(void)
1113 pset.vars = CreateVariableSpace();
1115 SetVariableHooks(pset.vars, "AUTOCOMMIT",
1116 bool_substitute_hook,
1118 SetVariableHooks(pset.vars, "ON_ERROR_STOP",
1119 bool_substitute_hook,
1120 on_error_stop_hook);
1121 SetVariableHooks(pset.vars, "QUIET",
1122 bool_substitute_hook,
1124 SetVariableHooks(pset.vars, "SINGLELINE",
1125 bool_substitute_hook,
1127 SetVariableHooks(pset.vars, "SINGLESTEP",
1128 bool_substitute_hook,
1130 SetVariableHooks(pset.vars, "FETCH_COUNT",
1131 fetch_count_substitute_hook,
1133 SetVariableHooks(pset.vars, "HISTFILE",
1136 SetVariableHooks(pset.vars, "HISTSIZE",
1137 histsize_substitute_hook,
1139 SetVariableHooks(pset.vars, "IGNOREEOF",
1140 ignoreeof_substitute_hook,
1142 SetVariableHooks(pset.vars, "ECHO",
1143 echo_substitute_hook,
1145 SetVariableHooks(pset.vars, "ECHO_HIDDEN",
1146 bool_substitute_hook,
1148 SetVariableHooks(pset.vars, "ON_ERROR_ROLLBACK",
1149 bool_substitute_hook,
1150 on_error_rollback_hook);
1151 SetVariableHooks(pset.vars, "COMP_KEYWORD_CASE",
1152 comp_keyword_case_substitute_hook,
1153 comp_keyword_case_hook);
1154 SetVariableHooks(pset.vars, "HISTCONTROL",
1155 histcontrol_substitute_hook,
1157 SetVariableHooks(pset.vars, "PROMPT1",
1160 SetVariableHooks(pset.vars, "PROMPT2",
1163 SetVariableHooks(pset.vars, "PROMPT3",
1166 SetVariableHooks(pset.vars, "VERBOSITY",
1167 verbosity_substitute_hook,
1169 SetVariableHooks(pset.vars, "SHOW_CONTEXT",
1170 show_context_substitute_hook,