1/*
2 * psql - the PostgreSQL interactive terminal
3 *
4 * Copyright (c) 2000-2019, PostgreSQL Global Development Group
5 *
6 * src/bin/psql/settings.h
7 */
8#ifndef SETTINGS_H
9#define SETTINGS_H
10
11
12#include "variables.h"
13#include "fe_utils/print.h"
14
15#define DEFAULT_CSV_FIELD_SEP ','
16#define DEFAULT_FIELD_SEP "|"
17#define DEFAULT_RECORD_SEP "\n"
18
19#if defined(WIN32) || defined(__CYGWIN__)
20#define DEFAULT_EDITOR "notepad.exe"
21/* no DEFAULT_EDITOR_LINENUMBER_ARG for Notepad */
22#else
23#define DEFAULT_EDITOR "vi"
24#define DEFAULT_EDITOR_LINENUMBER_ARG "+"
25#endif
26
27#define DEFAULT_PROMPT1 "%/%R%# "
28#define DEFAULT_PROMPT2 "%/%R%# "
29#define DEFAULT_PROMPT3 ">> "
30
31/*
32 * Note: these enums should generally be chosen so that zero corresponds
33 * to the default behavior.
34 */
35
36typedef enum
37{
38 PSQL_ECHO_NONE,
39 PSQL_ECHO_QUERIES,
40 PSQL_ECHO_ERRORS,
41 PSQL_ECHO_ALL
42} PSQL_ECHO;
43
44typedef enum
45{
46 PSQL_ECHO_HIDDEN_OFF,
47 PSQL_ECHO_HIDDEN_ON,
48 PSQL_ECHO_HIDDEN_NOEXEC
49} PSQL_ECHO_HIDDEN;
50
51typedef enum
52{
53 PSQL_ERROR_ROLLBACK_OFF,
54 PSQL_ERROR_ROLLBACK_INTERACTIVE,
55 PSQL_ERROR_ROLLBACK_ON
56} PSQL_ERROR_ROLLBACK;
57
58typedef enum
59{
60 PSQL_COMP_CASE_PRESERVE_UPPER,
61 PSQL_COMP_CASE_PRESERVE_LOWER,
62 PSQL_COMP_CASE_UPPER,
63 PSQL_COMP_CASE_LOWER
64} PSQL_COMP_CASE;
65
66typedef enum
67{
68 hctl_none = 0,
69 hctl_ignorespace = 1,
70 hctl_ignoredups = 2,
71 hctl_ignoreboth = hctl_ignorespace | hctl_ignoredups
72} HistControl;
73
74enum trivalue
75{
76 TRI_DEFAULT,
77 TRI_NO,
78 TRI_YES
79};
80
81typedef struct _psqlSettings
82{
83 PGconn *db; /* connection to backend */
84 int encoding; /* client_encoding */
85 FILE *queryFout; /* where to send the query results */
86 bool queryFoutPipe; /* queryFout is from a popen() */
87
88 FILE *copyStream; /* Stream to read/write for \copy command */
89
90 PGresult *last_error_result; /* most recent error result, if any */
91
92 printQueryOpt popt;
93
94 char *gfname; /* one-shot file output argument for \g */
95 bool g_expanded; /* one-shot expanded output requested via \gx */
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 */
101
102 bool notty; /* stdin or stdout is not a tty (as determined
103 * on startup) */
104 enum trivalue getPassword; /* prompt the user for a username and password */
105 FILE *cur_cmd_source; /* describe the status of the current main
106 * loop */
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 */
113
114 bool timing; /* enable timing of all queries */
115
116 FILE *logfile; /* session log file handle */
117
118 VariableSpace vars; /* "shell variable" repository */
119
120 /*
121 * The remaining fields are set by assign hooks associated with entries in
122 * "vars". They should not be set directly except by those hook
123 * functions.
124 */
125 bool autocommit;
126 bool on_error_stop;
127 bool quiet;
128 bool singleline;
129 bool singlestep;
130 bool hide_tableam;
131 int fetch_count;
132 int histsize;
133 int ignoreeof;
134 PSQL_ECHO echo;
135 PSQL_ECHO_HIDDEN echo_hidden;
136 PSQL_ERROR_ROLLBACK on_error_rollback;
137 PSQL_COMP_CASE comp_case;
138 HistControl histcontrol;
139 const char *prompt1;
140 const char *prompt2;
141 const char *prompt3;
142 PGVerbosity verbosity; /* current error verbosity level */
143 PGContextVisibility show_context; /* current context display level */
144} PsqlSettings;
145
146extern PsqlSettings pset;
147
148
149#ifndef EXIT_SUCCESS
150#define EXIT_SUCCESS 0
151#endif
152
153#ifndef EXIT_FAILURE
154#define EXIT_FAILURE 1
155#endif
156
157#define EXIT_BADCONN 2
158
159#define EXIT_USER 3
160
161#endif
162