Debian Codegraph @

src/bin/psql/settings.h

raw ◀ ▶
1 Debian patch touch this file
1 /*
2 * psql - the PostgreSQL interactive terminal
3 *
4 * Copyright (c) 2000-2025, PostgreSQL Global Development Group
5 *
6 * src/bin/psql/settings.h
7 */
8 #ifndef SETTINGS_H
9 #define SETTINGS_H
10
11 #include "fe_utils/print.h"
12 #include "variables.h"
13
14 #define DEFAULT_CSV_FIELD_SEP ','
15 #define DEFAULT_FIELD_SEP "|"
16 #define DEFAULT_RECORD_SEP "\n"
17
18 #if defined(WIN32) || defined(__CYGWIN__)
19 #define DEFAULT_EDITOR "notepad.exe"
20 /* no DEFAULT_EDITOR_LINENUMBER_ARG for Notepad */
21 #else
•22 #define DEFAULT_EDITOR "sensible-editor"
23 /*#define DEFAULT_EDITOR_LINENUMBER_ARG "+"*/
24 #endif
25
26 #define DEFAULT_PROMPT1 "%/%R%x%# "
27 #define DEFAULT_PROMPT2 "%/%R%x%# "
28 #define DEFAULT_PROMPT3 ">> "
29
30 #define DEFAULT_WATCH_INTERVAL "2"
31 /*
32 * Limit the max default setting to a value which should be safe for the
33 * itimer call, yet large enough to cover all realistic usecases.
34 */
35 #define DEFAULT_WATCH_INTERVAL_MAX (1000*1000)
36 /*
37 * Note: these enums should generally be chosen so that zero corresponds
38 * to the default behavior.
39 */
40
41 typedef enum
42 {
43 PSQL_ECHO_NONE,
44 PSQL_ECHO_QUERIES,
45 PSQL_ECHO_ERRORS,
46 PSQL_ECHO_ALL,
47 } PSQL_ECHO;
48
49 typedef enum
50 {
51 PSQL_ECHO_HIDDEN_OFF,
52 PSQL_ECHO_HIDDEN_ON,
53 PSQL_ECHO_HIDDEN_NOEXEC,
54 } PSQL_ECHO_HIDDEN;
55
56 typedef enum
57 {
58 PSQL_ERROR_ROLLBACK_OFF,
59 PSQL_ERROR_ROLLBACK_INTERACTIVE,
60 PSQL_ERROR_ROLLBACK_ON,
61 } PSQL_ERROR_ROLLBACK;
62
63 typedef enum
64 {
65 PSQL_COMP_CASE_PRESERVE_UPPER,
66 PSQL_COMP_CASE_PRESERVE_LOWER,
67 PSQL_COMP_CASE_UPPER,
68 PSQL_COMP_CASE_LOWER,
69 } PSQL_COMP_CASE;
70
71 typedef enum
72 {
73 PSQL_SEND_QUERY,
74 PSQL_SEND_EXTENDED_CLOSE,
75 PSQL_SEND_EXTENDED_PARSE,
76 PSQL_SEND_EXTENDED_QUERY_PARAMS,
77 PSQL_SEND_EXTENDED_QUERY_PREPARED,
78 PSQL_SEND_PIPELINE_SYNC,
79 PSQL_SEND_START_PIPELINE_MODE,
80 PSQL_SEND_END_PIPELINE_MODE,
81 PSQL_SEND_FLUSH,
82 PSQL_SEND_FLUSH_REQUEST,
83 PSQL_SEND_GET_RESULTS,
84 } PSQL_SEND_MODE;
85
86 typedef enum
87 {
88 hctl_none = 0,
89 hctl_ignorespace = 1,
90 hctl_ignoredups = 2,
91 hctl_ignoreboth = hctl_ignorespace | hctl_ignoredups,
92 } HistControl;
93
94 enum trivalue
95 {
96 TRI_DEFAULT,
97 TRI_NO,
98 TRI_YES,
99 };
100
101 typedef struct _psqlSettings
102 {
103 PGconn *db; /* connection to backend */
104 int encoding; /* client_encoding */
105 FILE *queryFout; /* where to send the query results */
106 bool queryFoutPipe; /* queryFout is from a popen() */
107
108 FILE *copyStream; /* Stream to read/write for \copy command */
109
110 PGresult *last_error_result; /* most recent error result, if any */
111
112 printQueryOpt popt; /* The active print format settings */
113
114 char *gfname; /* one-shot file output argument for \g */
115 printQueryOpt *gsavepopt; /* if not null, saved print format settings */
116
117 char *gset_prefix; /* one-shot prefix argument for \gset */
118 bool gdesc_flag; /* one-shot request to describe query result */
119 bool gexec_flag; /* one-shot request to execute query result */
120 PSQL_SEND_MODE send_mode; /* one-shot request to send query with normal
121 * or extended query protocol */
122 int bind_nparams; /* number of parameters */
123 char **bind_params; /* parameters for extended query protocol call */
124 char *stmtName; /* prepared statement name used for extended
125 * query protocol commands */
126 int piped_commands; /* number of piped commands */
127 int piped_syncs; /* number of piped syncs */
128 int available_results; /* number of results available to get */
129 int requested_results; /* number of requested results, including
130 * sync messages. Used to read a limited
131 * subset of the available_results. */
132 bool crosstab_flag; /* one-shot request to crosstab result */
133 char *ctv_args[4]; /* \crosstabview arguments */
134
135 bool notty; /* stdin or stdout is not a tty (as determined
136 * on startup) */
137 enum trivalue getPassword; /* prompt the user for a username and password */
138 FILE *cur_cmd_source; /* describe the status of the current main
139 * loop */
140 bool cur_cmd_interactive;
141 int sversion; /* backend server version */
142 const char *progname; /* in case you renamed psql */
143 char *inputfile; /* file being currently processed, if any */
144 uint64 lineno; /* also for error reporting */
145 uint64 stmt_lineno; /* line number inside the current statement */
146
147 bool timing; /* enable timing of all queries */
148
149 FILE *logfile; /* session log file handle */
150
151 VariableSpace vars; /* "shell variable" repository */
152
153 /*
154 * If we get a connection failure, the now-unusable PGconn is stashed here
155 * until we can successfully reconnect. Never attempt to do anything with
156 * this PGconn except extract parameters for a \connect attempt.
157 */
158 PGconn *dead_conn; /* previous connection to backend */
159
160 /*
161 * The remaining fields are set by assign hooks associated with entries in
162 * "vars". They should not be set directly except by those hook
163 * functions.
164 */
165 bool autocommit;
166 bool on_error_stop;
167 bool quiet;
168 bool singleline;
169 bool singlestep;
170 bool hide_compression;
171 bool hide_tableam;
172 int fetch_count;
173 int histsize;
174 int ignoreeof;
175 double watch_interval;
176 PSQL_ECHO echo;
177 PSQL_ECHO_HIDDEN echo_hidden;
178 PSQL_ERROR_ROLLBACK on_error_rollback;
179 PSQL_COMP_CASE comp_case;
180 HistControl histcontrol;
181 const char *prompt1;
182 const char *prompt2;
183 const char *prompt3;
184 PGVerbosity verbosity; /* current error verbosity level */
185 bool show_all_results;
186 PGContextVisibility show_context; /* current context display level */
187 } PsqlSettings;
188
189 extern PsqlSettings pset;
190
191
192 #ifndef EXIT_SUCCESS
193 #define EXIT_SUCCESS 0
194 #endif
195
196 #ifndef EXIT_FAILURE
197 #define EXIT_FAILURE 1
198 #endif
199
200 #define EXIT_BADCONN 2
201
202 #define EXIT_USER 3
203
204 #endif