PostgreSQL Source Code git master
settings.h
Go to the documentation of 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 "vi"
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/*
31 * Note: these enums should generally be chosen so that zero corresponds
32 * to the default behavior.
33 */
34
35typedef enum
36{
41} PSQL_ECHO;
42
43typedef enum
44{
49
50typedef enum
51{
56
57typedef enum
58{
64
65typedef enum
66{
79
80typedef enum
81{
87
89{
93};
94
95typedef struct _psqlSettings
96{
97 PGconn *db; /* connection to backend */
98 int encoding; /* client_encoding */
99 FILE *queryFout; /* where to send the query results */
100 bool queryFoutPipe; /* queryFout is from a popen() */
101
102 FILE *copyStream; /* Stream to read/write for \copy command */
103
104 PGresult *last_error_result; /* most recent error result, if any */
105
106 printQueryOpt popt; /* The active print format settings */
107
108 char *gfname; /* one-shot file output argument for \g */
109 printQueryOpt *gsavepopt; /* if not null, saved print format settings */
110
111 char *gset_prefix; /* one-shot prefix argument for \gset */
112 bool gdesc_flag; /* one-shot request to describe query result */
113 bool gexec_flag; /* one-shot request to execute query result */
114 PSQL_SEND_MODE send_mode; /* one-shot request to send query with normal
115 * or extended query protocol */
116 int bind_nparams; /* number of parameters */
117 char **bind_params; /* parameters for extended query protocol call */
118 char *stmtName; /* prepared statement name used for extended
119 * query protocol commands */
120 int piped_commands; /* number of piped commands */
121 int piped_syncs; /* number of piped syncs */
122 int available_results; /* number of results available to get */
123 int requested_results; /* number of requested results, including
124 * sync messages. Used to read a limited
125 * subset of the available_results. */
126 bool crosstab_flag; /* one-shot request to crosstab result */
127 char *ctv_args[4]; /* \crosstabview arguments */
128
129 bool notty; /* stdin or stdout is not a tty (as determined
130 * on startup) */
131 enum trivalue getPassword; /* prompt the user for a username and password */
132 FILE *cur_cmd_source; /* describe the status of the current main
133 * loop */
135 int sversion; /* backend server version */
136 const char *progname; /* in case you renamed psql */
137 char *inputfile; /* file being currently processed, if any */
138 uint64 lineno; /* also for error reporting */
139 uint64 stmt_lineno; /* line number inside the current statement */
140
141 bool timing; /* enable timing of all queries */
142
143 FILE *logfile; /* session log file handle */
144
145 VariableSpace vars; /* "shell variable" repository */
146
147 /*
148 * If we get a connection failure, the now-unusable PGconn is stashed here
149 * until we can successfully reconnect. Never attempt to do anything with
150 * this PGconn except extract parameters for a \connect attempt.
151 */
152 PGconn *dead_conn; /* previous connection to backend */
153
154 /*
155 * The remaining fields are set by assign hooks associated with entries in
156 * "vars". They should not be set directly except by those hook
157 * functions.
158 */
161 bool quiet;
174 const char *prompt1;
175 const char *prompt2;
176 const char *prompt3;
177 PGVerbosity verbosity; /* current error verbosity level */
179 PGContextVisibility show_context; /* current context display level */
181
182extern PsqlSettings pset;
183
184
185#ifndef EXIT_SUCCESS
186#define EXIT_SUCCESS 0
187#endif
188
189#ifndef EXIT_FAILURE
190#define EXIT_FAILURE 1
191#endif
192
193#define EXIT_BADCONN 2
194
195#define EXIT_USER 3
196
197#endif
uint64_t uint64
Definition: c.h:503
PGContextVisibility
Definition: libpq-fe.h:162
PGVerbosity
Definition: libpq-fe.h:154
PSQL_ERROR_ROLLBACK
Definition: settings.h:51
@ PSQL_ERROR_ROLLBACK_INTERACTIVE
Definition: settings.h:53
@ PSQL_ERROR_ROLLBACK_ON
Definition: settings.h:54
@ PSQL_ERROR_ROLLBACK_OFF
Definition: settings.h:52
HistControl
Definition: settings.h:81
@ hctl_ignoredups
Definition: settings.h:84
@ hctl_ignoreboth
Definition: settings.h:85
@ hctl_none
Definition: settings.h:82
@ hctl_ignorespace
Definition: settings.h:83
PSQL_ECHO
Definition: settings.h:36
@ PSQL_ECHO_ALL
Definition: settings.h:40
@ PSQL_ECHO_ERRORS
Definition: settings.h:39
@ PSQL_ECHO_NONE
Definition: settings.h:37
@ PSQL_ECHO_QUERIES
Definition: settings.h:38
struct _psqlSettings PsqlSettings
PSQL_ECHO_HIDDEN
Definition: settings.h:44
@ PSQL_ECHO_HIDDEN_NOEXEC
Definition: settings.h:47
@ PSQL_ECHO_HIDDEN_OFF
Definition: settings.h:45
@ PSQL_ECHO_HIDDEN_ON
Definition: settings.h:46
@ TRI_YES
Definition: settings.h:92
@ TRI_DEFAULT
Definition: settings.h:90
@ TRI_NO
Definition: settings.h:91
PsqlSettings pset
Definition: startup.c:32
PSQL_SEND_MODE
Definition: settings.h:66
@ PSQL_SEND_PIPELINE_SYNC
Definition: settings.h:72
@ PSQL_SEND_FLUSH
Definition: settings.h:75
@ PSQL_SEND_FLUSH_REQUEST
Definition: settings.h:76
@ PSQL_SEND_START_PIPELINE_MODE
Definition: settings.h:73
@ PSQL_SEND_QUERY
Definition: settings.h:67
@ PSQL_SEND_EXTENDED_QUERY_PARAMS
Definition: settings.h:70
@ PSQL_SEND_EXTENDED_PARSE
Definition: settings.h:69
@ PSQL_SEND_END_PIPELINE_MODE
Definition: settings.h:74
@ PSQL_SEND_GET_RESULTS
Definition: settings.h:77
@ PSQL_SEND_EXTENDED_CLOSE
Definition: settings.h:68
@ PSQL_SEND_EXTENDED_QUERY_PREPARED
Definition: settings.h:71
PSQL_COMP_CASE
Definition: settings.h:58
@ PSQL_COMP_CASE_PRESERVE_LOWER
Definition: settings.h:60
@ PSQL_COMP_CASE_LOWER
Definition: settings.h:62
@ PSQL_COMP_CASE_PRESERVE_UPPER
Definition: settings.h:59
@ PSQL_COMP_CASE_UPPER
Definition: settings.h:61
uint64 lineno
Definition: settings.h:138
printQueryOpt popt
Definition: settings.h:106
char * gset_prefix
Definition: settings.h:111
PSQL_ERROR_ROLLBACK on_error_rollback
Definition: settings.h:171
bool hide_tableam
Definition: settings.h:165
VariableSpace vars
Definition: settings.h:145
PSQL_COMP_CASE comp_case
Definition: settings.h:172
int encoding
Definition: settings.h:98
char * inputfile
Definition: settings.h:137
PGVerbosity verbosity
Definition: settings.h:177
bool hide_compression
Definition: settings.h:164
FILE * logfile
Definition: settings.h:143
char * stmtName
Definition: settings.h:118
bool on_error_stop
Definition: settings.h:160
PGconn * dead_conn
Definition: settings.h:152
bool autocommit
Definition: settings.h:159
char * ctv_args[4]
Definition: settings.h:127
int available_results
Definition: settings.h:122
PGresult * last_error_result
Definition: settings.h:104
int piped_syncs
Definition: settings.h:121
bool show_all_results
Definition: settings.h:178
const char * prompt2
Definition: settings.h:175
const char * prompt3
Definition: settings.h:176
FILE * copyStream
Definition: settings.h:102
int piped_commands
Definition: settings.h:120
char ** bind_params
Definition: settings.h:117
PGconn * db
Definition: settings.h:97
FILE * queryFout
Definition: settings.h:99
PSQL_SEND_MODE send_mode
Definition: settings.h:114
bool queryFoutPipe
Definition: settings.h:100
PSQL_ECHO echo
Definition: settings.h:169
bool singlestep
Definition: settings.h:163
enum trivalue getPassword
Definition: settings.h:131
uint64 stmt_lineno
Definition: settings.h:139
bool singleline
Definition: settings.h:162
int requested_results
Definition: settings.h:123
PGContextVisibility show_context
Definition: settings.h:179
const char * prompt1
Definition: settings.h:174
PSQL_ECHO_HIDDEN echo_hidden
Definition: settings.h:170
printQueryOpt * gsavepopt
Definition: settings.h:109
char * gfname
Definition: settings.h:108
int fetch_count
Definition: settings.h:166
bool cur_cmd_interactive
Definition: settings.h:134
bool gexec_flag
Definition: settings.h:113
bool crosstab_flag
Definition: settings.h:126
FILE * cur_cmd_source
Definition: settings.h:132
HistControl histcontrol
Definition: settings.h:173
const char * progname
Definition: settings.h:136
bool gdesc_flag
Definition: settings.h:112
int bind_nparams
Definition: settings.h:116
trivalue
Definition: vacuumlo.c:35