2 * psql - the PostgreSQL interactive terminal
4 * Copyright (c) 2000-2021, PostgreSQL Global Development Group
6 * src/bin/psql/settings.h
11 #include "fe_utils/print.h"
12 #include "variables.h"
14 #define DEFAULT_CSV_FIELD_SEP ','
15 #define DEFAULT_FIELD_SEP "|"
16 #define DEFAULT_RECORD_SEP "\n"
18 #if defined(WIN32) || defined(__CYGWIN__)
19 #define DEFAULT_EDITOR "notepad.exe"
20 /* no DEFAULT_EDITOR_LINENUMBER_ARG for Notepad */
22 #define DEFAULT_EDITOR "vi"
23 #define DEFAULT_EDITOR_LINENUMBER_ARG "+"
26 #define DEFAULT_PROMPT1 "%/%R%x%# "
27 #define DEFAULT_PROMPT2 "%/%R%x%# "
28 #define DEFAULT_PROMPT3 ">> "
31 * Note: these enums should generally be chosen so that zero corresponds
32 * to the default behavior.
47 PSQL_ECHO_HIDDEN_NOEXEC
52 PSQL_ERROR_ROLLBACK_OFF
,
53 PSQL_ERROR_ROLLBACK_INTERACTIVE
,
54 PSQL_ERROR_ROLLBACK_ON
55 } PSQL_ERROR_ROLLBACK
;
59 PSQL_COMP_CASE_PRESERVE_UPPER
,
60 PSQL_COMP_CASE_PRESERVE_LOWER
,
70 hctl_ignoreboth
= hctl_ignorespace
| hctl_ignoredups
80 typedef struct _psqlSettings
82 PGconn
*db
; /* connection to backend */
83 int encoding
; /* client_encoding */
84 FILE *queryFout
; /* where to send the query results */
85 bool queryFoutPipe
; /* queryFout is from a popen() */
87 FILE *copyStream
; /* Stream to read/write for \copy command */
89 PGresult
*last_error_result
; /* most recent error result, if any */
91 printQueryOpt popt
; /* The active print format settings */
93 char *gfname
; /* one-shot file output argument for \g */
94 printQueryOpt
*gsavepopt
; /* if not null, saved print format settings */
96 char *gset_prefix
; /* one-shot prefix argument for \gset */
97 bool gdesc_flag
; /* one-shot request to describe query results */
98 bool gexec_flag
; /* one-shot request to execute query results */
99 bool crosstab_flag
; /* one-shot request to crosstab results */
100 char *ctv_args
[4]; /* \crosstabview arguments */
102 bool notty
; /* stdin or stdout is not a tty (as determined
104 enum trivalue getPassword
; /* prompt the user for a username and password */
105 FILE *cur_cmd_source
; /* describe the status of the current main
107 bool cur_cmd_interactive
;
108 int sversion
; /* backend server version */
109 const char *progname
; /* in case you renamed psql */
110 char *inputfile
; /* file being currently processed, if any */
111 uint64 lineno
; /* also for error reporting */
112 uint64 stmt_lineno
; /* line number inside the current statement */
114 bool timing
; /* enable timing of all queries */
116 FILE *logfile
; /* session log file handle */
118 VariableSpace vars
; /* "shell variable" repository */
121 * If we get a connection failure, the now-unusable PGconn is stashed here
122 * until we can successfully reconnect. Never attempt to do anything with
123 * this PGconn except extract parameters for a \connect attempt.
125 PGconn
*dead_conn
; /* previous connection to backend */
128 * The remaining fields are set by assign hooks associated with entries in
129 * "vars". They should not be set directly except by those hook
137 bool hide_compression
;
143 PSQL_ECHO_HIDDEN echo_hidden
;
144 PSQL_ERROR_ROLLBACK on_error_rollback
;
145 PSQL_COMP_CASE comp_case
;
146 HistControl histcontrol
;
150 PGVerbosity verbosity
; /* current error verbosity level */
151 PGContextVisibility show_context
; /* current context display level */
154 extern PsqlSettings pset
;
158 #define EXIT_SUCCESS 0
162 #define EXIT_FAILURE 1
165 #define EXIT_BADCONN 2