2 * psql - the PostgreSQL interactive terminal
4 * Copyright (c) 2000-2025, 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
,
68 PSQL_SEND_EXTENDED_CLOSE
,
69 PSQL_SEND_EXTENDED_PARSE
,
70 PSQL_SEND_EXTENDED_QUERY_PARAMS
,
71 PSQL_SEND_EXTENDED_QUERY_PREPARED
,
79 hctl_ignoreboth
= hctl_ignorespace
| hctl_ignoredups
,
89 typedef struct _psqlSettings
91 PGconn
*db
; /* connection to backend */
92 int encoding
; /* client_encoding */
93 FILE *queryFout
; /* where to send the query results */
94 bool queryFoutPipe
; /* queryFout is from a popen() */
96 FILE *copyStream
; /* Stream to read/write for \copy command */
98 PGresult
*last_error_result
; /* most recent error result, if any */
100 printQueryOpt popt
; /* The active print format settings */
102 char *gfname
; /* one-shot file output argument for \g */
103 printQueryOpt
*gsavepopt
; /* if not null, saved print format settings */
105 char *gset_prefix
; /* one-shot prefix argument for \gset */
106 bool gdesc_flag
; /* one-shot request to describe query result */
107 bool gexec_flag
; /* one-shot request to execute query result */
108 PSQL_SEND_MODE send_mode
; /* one-shot request to send query with normal
109 * or extended query protocol */
110 int bind_nparams
; /* number of parameters */
111 char **bind_params
; /* parameters for extended query protocol call */
112 char *stmtName
; /* prepared statement name used for extended
113 * query protocol commands */
114 bool crosstab_flag
; /* one-shot request to crosstab result */
115 char *ctv_args
[4]; /* \crosstabview arguments */
117 bool notty
; /* stdin or stdout is not a tty (as determined
119 enum trivalue getPassword
; /* prompt the user for a username and password */
120 FILE *cur_cmd_source
; /* describe the status of the current main
122 bool cur_cmd_interactive
;
123 int sversion
; /* backend server version */
124 const char *progname
; /* in case you renamed psql */
125 char *inputfile
; /* file being currently processed, if any */
126 uint64 lineno
; /* also for error reporting */
127 uint64 stmt_lineno
; /* line number inside the current statement */
129 bool timing
; /* enable timing of all queries */
131 FILE *logfile
; /* session log file handle */
133 VariableSpace vars
; /* "shell variable" repository */
136 * If we get a connection failure, the now-unusable PGconn is stashed here
137 * until we can successfully reconnect. Never attempt to do anything with
138 * this PGconn except extract parameters for a \connect attempt.
140 PGconn
*dead_conn
; /* previous connection to backend */
143 * The remaining fields are set by assign hooks associated with entries in
144 * "vars". They should not be set directly except by those hook
152 bool hide_compression
;
158 PSQL_ECHO_HIDDEN echo_hidden
;
159 PSQL_ERROR_ROLLBACK on_error_rollback
;
160 PSQL_COMP_CASE comp_case
;
161 HistControl histcontrol
;
165 PGVerbosity verbosity
; /* current error verbosity level */
166 bool show_all_results
;
167 PGContextVisibility show_context
; /* current context display level */
170 extern PsqlSettings pset
;
174 #define EXIT_SUCCESS 0
178 #define EXIT_FAILURE 1
181 #define EXIT_BADCONN 2