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-2024, 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 
35 typedef enum
36 {
41 } PSQL_ECHO;
42 
43 typedef enum
44 {
49 
50 typedef enum
51 {
56 
57 typedef enum
58 {
64 
65 typedef enum
66 {
73 
74 typedef enum
75 {
76  hctl_none = 0,
80 } HistControl;
81 
83 {
87 };
88 
89 typedef struct _psqlSettings
90 {
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() */
95 
96  FILE *copyStream; /* Stream to read/write for \copy command */
97 
98  PGresult *last_error_result; /* most recent error result, if any */
99 
100  printQueryOpt popt; /* The active print format settings */
101 
102  char *gfname; /* one-shot file output argument for \g */
103  printQueryOpt *gsavepopt; /* if not null, saved print format settings */
104 
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 */
116 
117  bool notty; /* stdin or stdout is not a tty (as determined
118  * on startup) */
119  enum trivalue getPassword; /* prompt the user for a username and password */
120  FILE *cur_cmd_source; /* describe the status of the current main
121  * loop */
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 */
128 
129  bool timing; /* enable timing of all queries */
130 
131  FILE *logfile; /* session log file handle */
132 
133  VariableSpace vars; /* "shell variable" repository */
134 
135  /*
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.
139  */
140  PGconn *dead_conn; /* previous connection to backend */
141 
142  /*
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
145  * functions.
146  */
149  bool quiet;
155  int histsize;
162  const char *prompt1;
163  const char *prompt2;
164  const char *prompt3;
165  PGVerbosity verbosity; /* current error verbosity level */
167  PGContextVisibility show_context; /* current context display level */
169 
170 extern PsqlSettings pset;
171 
172 
173 #ifndef EXIT_SUCCESS
174 #define EXIT_SUCCESS 0
175 #endif
176 
177 #ifndef EXIT_FAILURE
178 #define EXIT_FAILURE 1
179 #endif
180 
181 #define EXIT_BADCONN 2
182 
183 #define EXIT_USER 3
184 
185 #endif
uint64_t uint64
Definition: c.h:486
PGContextVisibility
Definition: libpq-fe.h:158
PGVerbosity
Definition: libpq-fe.h:150
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:75
@ hctl_ignoredups
Definition: settings.h:78
@ hctl_ignoreboth
Definition: settings.h:79
@ hctl_none
Definition: settings.h:76
@ hctl_ignorespace
Definition: settings.h:77
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:86
@ TRI_DEFAULT
Definition: settings.h:84
@ TRI_NO
Definition: settings.h:85
PsqlSettings pset
Definition: startup.c:32
PSQL_SEND_MODE
Definition: settings.h:66
@ 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_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:126
printQueryOpt popt
Definition: settings.h:100
char * gset_prefix
Definition: settings.h:105
PSQL_ERROR_ROLLBACK on_error_rollback
Definition: settings.h:159
bool hide_tableam
Definition: settings.h:153
VariableSpace vars
Definition: settings.h:133
PSQL_COMP_CASE comp_case
Definition: settings.h:160
int encoding
Definition: settings.h:92
char * inputfile
Definition: settings.h:125
PGVerbosity verbosity
Definition: settings.h:165
bool hide_compression
Definition: settings.h:152
FILE * logfile
Definition: settings.h:131
char * stmtName
Definition: settings.h:112
bool on_error_stop
Definition: settings.h:148
PGconn * dead_conn
Definition: settings.h:140
bool autocommit
Definition: settings.h:147
char * ctv_args[4]
Definition: settings.h:115
PGresult * last_error_result
Definition: settings.h:98
bool show_all_results
Definition: settings.h:166
const char * prompt2
Definition: settings.h:163
const char * prompt3
Definition: settings.h:164
FILE * copyStream
Definition: settings.h:96
char ** bind_params
Definition: settings.h:111
PGconn * db
Definition: settings.h:91
FILE * queryFout
Definition: settings.h:93
PSQL_SEND_MODE send_mode
Definition: settings.h:108
bool queryFoutPipe
Definition: settings.h:94
PSQL_ECHO echo
Definition: settings.h:157
bool singlestep
Definition: settings.h:151
enum trivalue getPassword
Definition: settings.h:119
uint64 stmt_lineno
Definition: settings.h:127
bool singleline
Definition: settings.h:150
PGContextVisibility show_context
Definition: settings.h:167
const char * prompt1
Definition: settings.h:162
PSQL_ECHO_HIDDEN echo_hidden
Definition: settings.h:158
printQueryOpt * gsavepopt
Definition: settings.h:103
char * gfname
Definition: settings.h:102
int fetch_count
Definition: settings.h:154
bool cur_cmd_interactive
Definition: settings.h:122
bool gexec_flag
Definition: settings.h:107
bool crosstab_flag
Definition: settings.h:114
FILE * cur_cmd_source
Definition: settings.h:120
HistControl histcontrol
Definition: settings.h:161
const char * progname
Definition: settings.h:124
bool gdesc_flag
Definition: settings.h:106
int bind_nparams
Definition: settings.h:110
trivalue
Definition: vacuumlo.c:35