PostgreSQL Source Code git master
Loading...
Searching...
No Matches
command.h File Reference
Include dependency graph for command.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Typedefs

typedef enum _backslashResult backslashResult
 

Enumerations

enum  _backslashResult {
  PSQL_CMD_UNKNOWN = 0 , PSQL_CMD_SEND , PSQL_CMD_SKIP_LINE , PSQL_CMD_TERMINATE ,
  PSQL_CMD_NEWEDIT , PSQL_CMD_ERROR
}
 

Functions

backslashResult HandleSlashCmds (PsqlScanState scan_state, ConditionalStack cstack, PQExpBuffer query_buf, PQExpBuffer previous_buf)
 
int process_file (char *filename, bool use_relative_path)
 
bool do_pset (const char *param, const char *value, printQueryOpt *popt, bool quiet)
 
printQueryOptsavePsetInfo (const printQueryOpt *popt)
 
void restorePsetInfo (printQueryOpt *popt, printQueryOpt *save)
 
void connection_warnings (bool in_startup)
 
void SyncVariables (void)
 
void UnsyncVariables (void)
 

Typedef Documentation

◆ backslashResult

Enumeration Type Documentation

◆ _backslashResult

Enumerator
PSQL_CMD_UNKNOWN 
PSQL_CMD_SEND 
PSQL_CMD_SKIP_LINE 
PSQL_CMD_TERMINATE 
PSQL_CMD_NEWEDIT 
PSQL_CMD_ERROR 

Definition at line 15 of file command.h.

16{
17 PSQL_CMD_UNKNOWN = 0, /* not done parsing yet (internal only) */
18 PSQL_CMD_SEND, /* query complete; send off */
19 PSQL_CMD_SKIP_LINE, /* keep building query */
20 PSQL_CMD_TERMINATE, /* quit program */
21 PSQL_CMD_NEWEDIT, /* query buffer was changed (e.g., via \e) */
22 PSQL_CMD_ERROR, /* the execution of the backslash command
23 * resulted in an error */
@ PSQL_CMD_TERMINATE
Definition command.h:20
@ PSQL_CMD_UNKNOWN
Definition command.h:17
@ PSQL_CMD_NEWEDIT
Definition command.h:21
@ PSQL_CMD_ERROR
Definition command.h:22
@ PSQL_CMD_SEND
Definition command.h:18
@ PSQL_CMD_SKIP_LINE
Definition command.h:19
enum _backslashResult backslashResult

Function Documentation

◆ connection_warnings()

void connection_warnings ( bool  in_startup)
extern

Definition at line 4443 of file command.c.

4444{
4445 if (!pset.quiet && !pset.notty)
4446 {
4448 char cverbuf[32];
4449 char sverbuf[32];
4450
4451 if (pset.sversion != client_ver)
4452 {
4453 const char *server_version;
4454
4455 /* Try to get full text form, might include "devel" etc */
4456 server_version = PQparameterStatus(pset.db, "server_version");
4457 /* Otherwise fall back on pset.sversion */
4458 if (!server_version)
4459 {
4461 sverbuf, sizeof(sverbuf));
4463 }
4464
4465 printf(_("%s (%s, server %s)\n"),
4467 }
4468 /* For version match, only print psql banner on startup. */
4469 else if (in_startup)
4470 printf("%s (%s)\n", pset.progname, PG_VERSION);
4471
4472 /*
4473 * Warn if server's major version is newer than ours, or if server
4474 * predates our support cutoff (currently 9.2).
4475 */
4476 if (pset.sversion / 100 > client_ver / 100 ||
4477 pset.sversion < 90200)
4478 printf(_("WARNING: %s major version %s, server major version %s.\n"
4479 " Some psql features might not work.\n"),
4480 pset.progname,
4482 cverbuf, sizeof(cverbuf)),
4484 sverbuf, sizeof(sverbuf)));
4485
4486#ifdef WIN32
4487 if (in_startup)
4489#endif
4490 printSSLInfo();
4491 printGSSInfo();
4492 }
4493}
static void printSSLInfo(void)
Definition command.c:4502
static void printGSSInfo(void)
Definition command.c:4530
#define _(x)
Definition elog.c:95
const char * PQparameterStatus(const PGconn *conn, const char *paramName)
static int server_version
Definition pg_dumpall.c:122
#define printf(...)
Definition port.h:266
static int fb(int x)
PsqlSettings pset
Definition startup.c:32
char * formatPGVersionNumber(int version_number, bool include_minor, char *buf, size_t buflen)
PGconn * db
Definition settings.h:103
const char * progname
Definition settings.h:142

References _, _psqlSettings::db, fb(), formatPGVersionNumber(), _psqlSettings::notty, PQparameterStatus(), printf, printGSSInfo(), printSSLInfo(), _psqlSettings::progname, pset, _psqlSettings::quiet, server_version, and _psqlSettings::sversion.

Referenced by CheckConnection(), do_connect(), and main().

◆ do_pset()

bool do_pset ( const char param,
const char value,
printQueryOpt popt,
bool  quiet 
)
extern

Definition at line 5078 of file command.c.

5079{
5080 size_t vallen = 0;
5081
5082 Assert(param != NULL);
5083
5084 if (value)
5085 vallen = strlen(value);
5086
5087 /* set format */
5088 if (strcmp(param, "format") == 0)
5089 {
5090 static const struct fmt
5091 {
5092 const char *name;
5093 enum printFormat number;
5094 } formats[] =
5095 {
5096 /* remember to update error message below when adding more */
5097 {"aligned", PRINT_ALIGNED},
5098 {"asciidoc", PRINT_ASCIIDOC},
5099 {"csv", PRINT_CSV},
5100 {"html", PRINT_HTML},
5101 {"latex", PRINT_LATEX},
5102 {"troff-ms", PRINT_TROFF_MS},
5103 {"unaligned", PRINT_UNALIGNED},
5104 {"wrapped", PRINT_WRAPPED}
5105 };
5106
5107 if (!value)
5108 ;
5109 else
5110 {
5111 int match_pos = -1;
5112
5113 for (int i = 0; i < lengthof(formats); i++)
5114 {
5115 if (pg_strncasecmp(formats[i].name, value, vallen) == 0)
5116 {
5117 if (match_pos < 0)
5118 match_pos = i;
5119 else
5120 {
5121 pg_log_error("\\pset: ambiguous abbreviation \"%s\" matches both \"%s\" and \"%s\"",
5122 value,
5123 formats[match_pos].name, formats[i].name);
5124 return false;
5125 }
5126 }
5127 }
5128 if (match_pos >= 0)
5129 popt->topt.format = formats[match_pos].number;
5130 else if (pg_strncasecmp("latex-longtable", value, vallen) == 0)
5131 {
5132 /*
5133 * We must treat latex-longtable specially because latex is a
5134 * prefix of it; if both were in the table above, we'd think
5135 * "latex" is ambiguous.
5136 */
5138 }
5139 else
5140 {
5141 pg_log_error("\\pset: allowed formats are aligned, asciidoc, csv, html, latex, latex-longtable, troff-ms, unaligned, wrapped");
5142 return false;
5143 }
5144 }
5145 }
5146
5147 /* set table line style */
5148 else if (strcmp(param, "linestyle") == 0)
5149 {
5150 if (!value)
5151 ;
5152 else if (pg_strncasecmp("ascii", value, vallen) == 0)
5154 else if (pg_strncasecmp("old-ascii", value, vallen) == 0)
5156 else if (pg_strncasecmp("unicode", value, vallen) == 0)
5157 popt->topt.line_style = &pg_utf8format;
5158 else
5159 {
5160 pg_log_error("\\pset: allowed line styles are ascii, old-ascii, unicode");
5161 return false;
5162 }
5163 }
5164
5165 /* set unicode border line style */
5166 else if (strcmp(param, "unicode_border_linestyle") == 0)
5167 {
5168 if (!value)
5169 ;
5170 else if (set_unicode_line_style(value, vallen,
5172 refresh_utf8format(&(popt->topt));
5173 else
5174 {
5175 pg_log_error("\\pset: allowed Unicode border line styles are single, double");
5176 return false;
5177 }
5178 }
5179
5180 /* set unicode column line style */
5181 else if (strcmp(param, "unicode_column_linestyle") == 0)
5182 {
5183 if (!value)
5184 ;
5185 else if (set_unicode_line_style(value, vallen,
5187 refresh_utf8format(&(popt->topt));
5188 else
5189 {
5190 pg_log_error("\\pset: allowed Unicode column line styles are single, double");
5191 return false;
5192 }
5193 }
5194
5195 /* set unicode header line style */
5196 else if (strcmp(param, "unicode_header_linestyle") == 0)
5197 {
5198 if (!value)
5199 ;
5200 else if (set_unicode_line_style(value, vallen,
5202 refresh_utf8format(&(popt->topt));
5203 else
5204 {
5205 pg_log_error("\\pset: allowed Unicode header line styles are single, double");
5206 return false;
5207 }
5208 }
5209
5210 /* set border style/width */
5211 else if (strcmp(param, "border") == 0)
5212 {
5213 if (value)
5214 popt->topt.border = atoi(value);
5215 }
5216
5217 /* set expanded/vertical mode */
5218 else if (strcmp(param, "x") == 0 ||
5219 strcmp(param, "expanded") == 0 ||
5220 strcmp(param, "vertical") == 0)
5221 {
5222 if (value && pg_strcasecmp(value, "auto") == 0)
5223 popt->topt.expanded = 2;
5224 else if (value)
5225 {
5226 bool on_off;
5227
5229 popt->topt.expanded = on_off ? 1 : 0;
5230 else
5231 {
5232 PsqlVarEnumError(param, value, "on, off, auto");
5233 return false;
5234 }
5235 }
5236 else
5237 popt->topt.expanded = !popt->topt.expanded;
5238 }
5239
5240 /* header line width in expanded mode */
5241 else if (strcmp(param, "xheader_width") == 0)
5242 {
5243 if (!value)
5244 ;
5245 else if (pg_strcasecmp(value, "full") == 0)
5247 else if (pg_strcasecmp(value, "column") == 0)
5249 else if (pg_strcasecmp(value, "page") == 0)
5251 else
5252 {
5253 int intval = atoi(value);
5254
5255 if (intval == 0)
5256 {
5257 pg_log_error("\\pset: allowed xheader_width values are \"%s\" (default), \"%s\", \"%s\", or a number specifying the exact width", "full", "column", "page");
5258 return false;
5259 }
5260
5262 popt->topt.expanded_header_exact_width = intval;
5263 }
5264 }
5265
5266 /* field separator for CSV format */
5267 else if (strcmp(param, "csv_fieldsep") == 0)
5268 {
5269 if (value)
5270 {
5271 /* CSV separator has to be a one-byte character */
5272 if (strlen(value) != 1)
5273 {
5274 pg_log_error("\\pset: csv_fieldsep must be a single one-byte character");
5275 return false;
5276 }
5277 if (value[0] == '"' || value[0] == '\n' || value[0] == '\r')
5278 {
5279 pg_log_error("\\pset: csv_fieldsep cannot be a double quote, a newline, or a carriage return");
5280 return false;
5281 }
5282 popt->topt.csvFieldSep[0] = value[0];
5283 }
5284 }
5285
5286 /* locale-aware numeric output */
5287 else if (strcmp(param, "numericlocale") == 0)
5288 {
5289 if (value)
5290 return ParseVariableBool(value, param, &popt->topt.numericLocale);
5291 else
5292 popt->topt.numericLocale = !popt->topt.numericLocale;
5293 }
5294
5295 /* null display */
5296 else if (strcmp(param, "null") == 0)
5297 {
5298 if (value)
5299 {
5300 free(popt->nullPrint);
5301 popt->nullPrint = pg_strdup(value);
5302 }
5303 }
5304
5305 /* 'false' display */
5306 else if (strcmp(param, "display_false") == 0)
5307 {
5308 if (value)
5309 {
5310 free(popt->falsePrint);
5311 popt->falsePrint = pg_strdup(value);
5312 }
5313 }
5314
5315 /* 'true' display */
5316 else if (strcmp(param, "display_true") == 0)
5317 {
5318 if (value)
5319 {
5320 free(popt->truePrint);
5321 popt->truePrint = pg_strdup(value);
5322 }
5323 }
5324
5325 /* field separator for unaligned text */
5326 else if (strcmp(param, "fieldsep") == 0)
5327 {
5328 if (value)
5329 {
5330 free(popt->topt.fieldSep.separator);
5332 popt->topt.fieldSep.separator_zero = false;
5333 }
5334 }
5335
5336 else if (strcmp(param, "fieldsep_zero") == 0)
5337 {
5338 free(popt->topt.fieldSep.separator);
5339 popt->topt.fieldSep.separator = NULL;
5340 popt->topt.fieldSep.separator_zero = true;
5341 }
5342
5343 /* record separator for unaligned text */
5344 else if (strcmp(param, "recordsep") == 0)
5345 {
5346 if (value)
5347 {
5350 popt->topt.recordSep.separator_zero = false;
5351 }
5352 }
5353
5354 else if (strcmp(param, "recordsep_zero") == 0)
5355 {
5357 popt->topt.recordSep.separator = NULL;
5358 popt->topt.recordSep.separator_zero = true;
5359 }
5360
5361 /* toggle between full and tuples-only format */
5362 else if (strcmp(param, "t") == 0 || strcmp(param, "tuples_only") == 0)
5363 {
5364 if (value)
5365 return ParseVariableBool(value, param, &popt->topt.tuples_only);
5366 else
5367 popt->topt.tuples_only = !popt->topt.tuples_only;
5368 }
5369
5370 /* set title override */
5371 else if (strcmp(param, "C") == 0 || strcmp(param, "title") == 0)
5372 {
5373 free(popt->title);
5374 if (!value)
5375 popt->title = NULL;
5376 else
5377 popt->title = pg_strdup(value);
5378 }
5379
5380 /* set HTML table tag options */
5381 else if (strcmp(param, "T") == 0 || strcmp(param, "tableattr") == 0)
5382 {
5383 free(popt->topt.tableAttr);
5384 if (!value)
5385 popt->topt.tableAttr = NULL;
5386 else
5387 popt->topt.tableAttr = pg_strdup(value);
5388 }
5389
5390 /* toggle use of pager */
5391 else if (strcmp(param, "pager") == 0)
5392 {
5393 if (value && pg_strcasecmp(value, "always") == 0)
5394 popt->topt.pager = 2;
5395 else if (value)
5396 {
5397 bool on_off;
5398
5400 {
5401 PsqlVarEnumError(param, value, "on, off, always");
5402 return false;
5403 }
5404 popt->topt.pager = on_off ? 1 : 0;
5405 }
5406 else if (popt->topt.pager == 1)
5407 popt->topt.pager = 0;
5408 else
5409 popt->topt.pager = 1;
5410 }
5411
5412 /* set minimum lines for pager use */
5413 else if (strcmp(param, "pager_min_lines") == 0)
5414 {
5415 if (value &&
5416 !ParseVariableNum(value, "pager_min_lines", &popt->topt.pager_min_lines))
5417 return false;
5418 }
5419
5420 /* disable "(x rows)" footer */
5421 else if (strcmp(param, "footer") == 0)
5422 {
5423 if (value)
5424 return ParseVariableBool(value, param, &popt->topt.default_footer);
5425 else
5426 popt->topt.default_footer = !popt->topt.default_footer;
5427 }
5428
5429 /* set border style/width */
5430 else if (strcmp(param, "columns") == 0)
5431 {
5432 if (value)
5433 popt->topt.columns = atoi(value);
5434 }
5435 else
5436 {
5437 pg_log_error("\\pset: unknown option: %s", param);
5438 return false;
5439 }
5440
5441 if (!quiet)
5442 printPsetInfo(param, &pset.popt);
5443
5444 return true;
5445}
#define Assert(condition)
Definition c.h:945
#define lengthof(array)
Definition c.h:875
static bool set_unicode_line_style(const char *value, size_t vallen, unicode_linestyle *linestyle)
Definition command.c:5035
static bool printPsetInfo(const char *param, printQueryOpt *popt)
Definition command.c:5451
char * pg_strdup(const char *in)
Definition fe_memutils.c:85
void refresh_utf8format(const printTableOpt *opt)
Definition print.c:3889
const printTextFormat pg_asciiformat
Definition print.c:61
const printTextFormat pg_asciiformat_old
Definition print.c:82
printTextFormat pg_utf8format
Definition print.c:104
@ PRINT_XHEADER_EXACT_WIDTH
Definition print.h:78
@ PRINT_XHEADER_PAGE
Definition print.h:76
@ PRINT_XHEADER_COLUMN
Definition print.h:74
@ PRINT_XHEADER_FULL
Definition print.h:72
printFormat
Definition print.h:29
@ PRINT_LATEX_LONGTABLE
Definition print.h:36
@ PRINT_CSV
Definition print.h:33
@ PRINT_UNALIGNED
Definition print.h:38
@ PRINT_ALIGNED
Definition print.h:31
@ PRINT_TROFF_MS
Definition print.h:37
@ PRINT_ASCIIDOC
Definition print.h:32
@ PRINT_LATEX
Definition print.h:35
@ PRINT_HTML
Definition print.h:34
@ PRINT_WRAPPED
Definition print.h:39
static struct @174 value
int i
Definition isn.c:77
#define pg_log_error(...)
Definition logging.h:106
int pg_strcasecmp(const char *s1, const char *s2)
int pg_strncasecmp(const char *s1, const char *s2, size_t n)
#define free(a)
printQueryOpt popt
Definition settings.h:112
printTableOpt topt
Definition print.h:185
char * nullPrint
Definition print.h:186
char * falsePrint
Definition print.h:188
char * title
Definition print.h:189
char * truePrint
Definition print.h:187
unsigned short int expanded
Definition print.h:114
unicode_linestyle unicode_border_linestyle
Definition print.h:141
bool tuples_only
Definition print.h:126
int columns
Definition print.h:140
enum printFormat format
Definition print.h:113
struct separator fieldSep
Definition print.h:132
int expanded_header_exact_width
Definition print.h:118
struct separator recordSep
Definition print.h:133
printXheaderWidthType expanded_header_width_type
Definition print.h:116
char csvFieldSep[2]
Definition print.h:134
const printTextFormat * line_style
Definition print.h:131
bool default_footer
Definition print.h:129
int pager_min_lines
Definition print.h:124
unsigned short int pager
Definition print.h:122
char * tableAttr
Definition print.h:137
bool numericLocale
Definition print.h:135
unsigned short int border
Definition print.h:120
unicode_linestyle unicode_header_linestyle
Definition print.h:143
unicode_linestyle unicode_column_linestyle
Definition print.h:142
bool separator_zero
Definition print.h:108
char * separator
Definition print.h:107
void PsqlVarEnumError(const char *name, const char *value, const char *suggestions)
Definition variables.c:486
bool ParseVariableBool(const char *value, const char *name, bool *result)
Definition variables.c:109
bool ParseVariableNum(const char *value, const char *name, int *result)
Definition variables.c:158
const char * name

References Assert, printTableOpt::border, printTableOpt::columns, printTableOpt::csvFieldSep, printTableOpt::default_footer, printTableOpt::expanded, printTableOpt::expanded_header_exact_width, printTableOpt::expanded_header_width_type, printQueryOpt::falsePrint, fb(), printTableOpt::fieldSep, printTableOpt::format, free, i, lengthof, printTableOpt::line_style, name, printQueryOpt::nullPrint, printTableOpt::numericLocale, printTableOpt::pager, printTableOpt::pager_min_lines, ParseVariableBool(), ParseVariableNum(), pg_asciiformat, pg_asciiformat_old, pg_log_error, pg_strcasecmp(), pg_strdup(), pg_strncasecmp(), pg_utf8format, _psqlSettings::popt, PRINT_ALIGNED, PRINT_ASCIIDOC, PRINT_CSV, PRINT_HTML, PRINT_LATEX, PRINT_LATEX_LONGTABLE, PRINT_TROFF_MS, PRINT_UNALIGNED, PRINT_WRAPPED, PRINT_XHEADER_COLUMN, PRINT_XHEADER_EXACT_WIDTH, PRINT_XHEADER_FULL, PRINT_XHEADER_PAGE, printPsetInfo(), pset, PsqlVarEnumError(), printTableOpt::recordSep, refresh_utf8format(), separator::separator, separator::separator_zero, set_unicode_line_style(), printTableOpt::tableAttr, printQueryOpt::title, printQueryOpt::topt, printQueryOpt::truePrint, printTableOpt::tuples_only, printTableOpt::unicode_border_linestyle, printTableOpt::unicode_column_linestyle, printTableOpt::unicode_header_linestyle, and value.

Referenced by exec_command_a(), exec_command_C(), exec_command_f(), exec_command_html(), exec_command_pset(), exec_command_t(), exec_command_T(), exec_command_x(), parse_psql_options(), and process_command_g_options().

◆ HandleSlashCmds()

backslashResult HandleSlashCmds ( PsqlScanState  scan_state,
ConditionalStack  cstack,
PQExpBuffer  query_buf,
PQExpBuffer  previous_buf 
)
extern

Definition at line 231 of file command.c.

235{
236 backslashResult status;
237 char *cmd;
238 char *arg;
239
241 Assert(cstack != NULL);
242
243 /* Parse off the command name */
245
246 /*
247 * And try to execute it.
248 *
249 * If we are in "restricted" mode, the only allowable backslash command is
250 * \unrestrict (to exit restricted mode).
251 */
252 if (restricted && strcmp(cmd, "unrestrict") != 0)
253 {
254 pg_log_error("backslash commands are restricted; only \\unrestrict is allowed");
255 status = PSQL_CMD_ERROR;
256 }
257 else
258 status = exec_command(cmd, scan_state, cstack, query_buf, previous_buf);
259
260 if (status == PSQL_CMD_UNKNOWN)
261 {
262 pg_log_error("invalid command \\%s", cmd);
264 pg_log_error_hint("Try \\? for help.");
265 status = PSQL_CMD_ERROR;
266 }
267
268 if (status != PSQL_CMD_ERROR)
269 {
270 /*
271 * Eat any remaining arguments after a valid command. We want to
272 * suppress evaluation of backticks in this situation, so transiently
273 * push an inactive conditional-stack entry.
274 */
275 bool active_branch = conditional_active(cstack);
276
279 OT_NORMAL, NULL, false)))
280 {
281 if (active_branch)
282 pg_log_warning("\\%s: extra argument \"%s\" ignored", cmd, arg);
283 free(arg);
284 }
285 conditional_stack_pop(cstack);
286 }
287 else
288 {
289 /* silently throw away rest of line after an erroneous command */
291 OT_WHOLE_LINE, NULL, false)))
292 free(arg);
293 }
294
295 /* if there is a trailing \\, swallow it */
297
298 free(cmd);
299
300 /* some commands write to queryFout, so make sure output is sent */
302
303 return status;
304}
static bool restricted
Definition command.c:199
static backslashResult exec_command(const char *cmd, PsqlScanState scan_state, ConditionalStack cstack, PQExpBuffer query_buf, PQExpBuffer previous_buf)
Definition command.c:315
void conditional_stack_push(ConditionalStack cstack, ifState new_state)
Definition conditional.c:53
bool conditional_stack_pop(ConditionalStack cstack)
Definition conditional.c:69
bool conditional_active(ConditionalStack cstack)
@ IFSTATE_IGNORED
Definition conditional.h:37
Datum arg
Definition elog.c:1322
#define pg_log_error_hint(...)
Definition logging.h:112
#define pg_log_warning(...)
Definition pgfnames.c:24
void psql_scan_slash_command_end(PsqlScanState state)
@ OT_NORMAL
@ OT_WHOLE_LINE
char * psql_scan_slash_option(PsqlScanState state, enum slash_option_type type, char *quote, bool semicolon)
char * psql_scan_slash_command(PsqlScanState state)
FILE * queryFout
Definition settings.h:105
bool cur_cmd_interactive
Definition settings.h:140

References arg, Assert, conditional_active(), conditional_stack_pop(), conditional_stack_push(), _psqlSettings::cur_cmd_interactive, exec_command(), fb(), free, IFSTATE_IGNORED, OT_NORMAL, OT_WHOLE_LINE, pg_log_error, pg_log_error_hint, pg_log_warning, pset, PSQL_CMD_ERROR, PSQL_CMD_UNKNOWN, psql_scan_slash_command(), psql_scan_slash_command_end(), psql_scan_slash_option(), _psqlSettings::queryFout, and restricted.

Referenced by main(), and MainLoop().

◆ process_file()

int process_file ( char filename,
bool  use_relative_path 
)
extern

Definition at line 4925 of file command.c.

4926{
4927 FILE *fd;
4928 int result;
4929 char *oldfilename;
4930 char relpath[MAXPGPATH];
4931
4932 if (!filename)
4933 {
4934 fd = stdin;
4935 filename = NULL;
4936 }
4937 else if (strcmp(filename, "-") != 0)
4938 {
4940
4941 /*
4942 * If we were asked to resolve the pathname relative to the location
4943 * of the currently executing script, and there is one, and this is a
4944 * relative pathname, then prepend all but the last pathname component
4945 * of the current script to this pathname.
4946 */
4949 {
4954
4955 filename = relpath;
4956 }
4957
4959
4960 if (!fd)
4961 {
4962 pg_log_error("%s: %m", filename);
4963 return EXIT_FAILURE;
4964 }
4965 }
4966 else
4967 {
4968 fd = stdin;
4969 filename = "<stdin>"; /* for future error messages */
4970 }
4971
4974
4976
4977 result = MainLoop(fd);
4978
4979 if (fd != stdin)
4980 fclose(fd);
4981
4983
4985
4986 return result;
4987}
#define PG_BINARY_R
Definition c.h:1378
void pg_logging_config(int new_flags)
Definition logging.c:166
#define PG_LOG_FLAG_TERSE
Definition logging.h:86
int MainLoop(FILE *source)
Definition mainloop.c:33
#define MAXPGPATH
static char * filename
Definition pg_dumpall.c:133
void join_path_components(char *ret_path, const char *head, const char *tail)
Definition path.c:286
#define is_absolute_path(filename)
Definition port.h:104
void get_parent_directory(char *path)
Definition path.c:1068
void canonicalize_path_enc(char *path, int encoding)
Definition path.c:344
bool has_drive_prefix(const char *path)
Definition path.c:94
size_t strlcpy(char *dst, const char *src, size_t siz)
Definition strlcpy.c:45
static int fd(const char *x, int i)
#define relpath(rlocator, forknum)
Definition relpath.h:150
#define EXIT_FAILURE
Definition settings.h:197
char * inputfile
Definition settings.h:143

References canonicalize_path_enc(), _psqlSettings::encoding, EXIT_FAILURE, fb(), fd(), filename, get_parent_directory(), has_drive_prefix(), _psqlSettings::inputfile, is_absolute_path, join_path_components(), MainLoop(), MAXPGPATH, PG_BINARY_R, pg_log_error, PG_LOG_FLAG_TERSE, pg_logging_config(), pset, relpath, and strlcpy().

Referenced by exec_command_include().

◆ restorePsetInfo()

void restorePsetInfo ( printQueryOpt popt,
printQueryOpt save 
)
extern

Definition at line 5701 of file command.c.

5702{
5703 /* Free all the old data we're about to overwrite the pointers to. */
5704
5705 /* topt.line_style points to const data that need not be duplicated */
5706 free(popt->topt.fieldSep.separator);
5708 free(popt->topt.tableAttr);
5709 free(popt->nullPrint);
5710 free(popt->title);
5711
5712 /*
5713 * footers and translate_columns are never set in psql's print settings,
5714 * so we needn't write code to duplicate them.
5715 */
5716 Assert(popt->footers == NULL);
5717 Assert(popt->translate_columns == NULL);
5718
5719 /* Now we may flat-copy all the fields, including pointers. */
5720 memcpy(popt, save, sizeof(printQueryOpt));
5721
5722 /* Lastly, free "save" ... but its sub-structures now belong to popt. */
5723 free(save);
5724}
const bool * translate_columns
Definition print.h:192
char ** footers
Definition print.h:190

References Assert, fb(), printTableOpt::fieldSep, printQueryOpt::footers, free, printQueryOpt::nullPrint, printTableOpt::recordSep, separator::separator, printTableOpt::tableAttr, printQueryOpt::title, printQueryOpt::topt, and printQueryOpt::translate_columns.

Referenced by process_command_g_options(), and SendQuery().

◆ savePsetInfo()

printQueryOpt * savePsetInfo ( const printQueryOpt popt)
extern

Definition at line 5665 of file command.c.

5666{
5668
5670
5671 /* Flat-copy all the scalar fields, then duplicate sub-structures. */
5672 memcpy(save, popt, sizeof(printQueryOpt));
5673
5674 /* topt.line_style points to const data that need not be duplicated */
5675 if (popt->topt.fieldSep.separator)
5676 save->topt.fieldSep.separator = pg_strdup(popt->topt.fieldSep.separator);
5677 if (popt->topt.recordSep.separator)
5678 save->topt.recordSep.separator = pg_strdup(popt->topt.recordSep.separator);
5679 if (popt->topt.tableAttr)
5680 save->topt.tableAttr = pg_strdup(popt->topt.tableAttr);
5681 if (popt->nullPrint)
5682 save->nullPrint = pg_strdup(popt->nullPrint);
5683 if (popt->title)
5684 save->title = pg_strdup(popt->title);
5685
5686 /*
5687 * footers and translate_columns are never set in psql's print settings,
5688 * so we needn't write code to duplicate them.
5689 */
5690 Assert(popt->footers == NULL);
5691 Assert(popt->translate_columns == NULL);
5692
5693 return save;
5694}
#define pg_malloc_object(type)
Definition fe_memutils.h:50

References Assert, fb(), printTableOpt::fieldSep, printQueryOpt::footers, printQueryOpt::nullPrint, pg_malloc_object, pg_strdup(), printTableOpt::recordSep, separator::separator, printTableOpt::tableAttr, printQueryOpt::title, printQueryOpt::topt, and printQueryOpt::translate_columns.

Referenced by exec_command_g(), and process_command_g_options().

◆ SyncVariables()

void SyncVariables ( void  )
extern

Definition at line 4571 of file command.c.

4572{
4573 char vbuf[32];
4574 const char *server_version;
4575 char *service_name;
4576 char *service_file;
4577
4578 /* get stuff from connection */
4582
4584
4585 SetVariable(pset.vars, "DBNAME", PQdb(pset.db));
4586 SetVariable(pset.vars, "USER", PQuser(pset.db));
4587 SetVariable(pset.vars, "HOST", PQhost(pset.db));
4588 SetVariable(pset.vars, "PORT", PQport(pset.db));
4590
4591 service_name = get_conninfo_value("service");
4592 SetVariable(pset.vars, "SERVICE", service_name);
4593 if (service_name)
4595
4596 service_file = get_conninfo_value("servicefile");
4597 SetVariable(pset.vars, "SERVICEFILE", service_file);
4598 if (service_file)
4600
4601 /* this bit should match connection_warnings(): */
4602 /* Try to get full text form of version, might include "devel" etc */
4603 server_version = PQparameterStatus(pset.db, "server_version");
4604 /* Otherwise fall back on pset.sversion */
4605 if (!server_version)
4606 {
4607 formatPGVersionNumber(pset.sversion, true, vbuf, sizeof(vbuf));
4609 }
4610 SetVariable(pset.vars, "SERVER_VERSION_NAME", server_version);
4611
4612 snprintf(vbuf, sizeof(vbuf), "%d", pset.sversion);
4613 SetVariable(pset.vars, "SERVER_VERSION_NUM", vbuf);
4614
4615 /* send stuff to it, too */
4618}
char * get_conninfo_value(const char *keyword)
Definition common.c:2540
int PQserverVersion(const PGconn *conn)
char * PQdb(const PGconn *conn)
char * PQport(const PGconn *conn)
char * PQhost(const PGconn *conn)
int PQclientEncoding(const PGconn *conn)
PGContextVisibility PQsetErrorContextVisibility(PGconn *conn, PGContextVisibility show_context)
char * PQuser(const PGconn *conn)
PGVerbosity PQsetErrorVerbosity(PGconn *conn, PGVerbosity verbosity)
void pg_free(void *ptr)
#define pg_encoding_to_char
Definition pg_wchar.h:630
#define snprintf
Definition port.h:260
void setFmtEncoding(int encoding)
VariableSpace vars
Definition settings.h:151
PGVerbosity verbosity
Definition settings.h:184
PGContextVisibility show_context
Definition settings.h:186
int encoding
Definition print.h:138
bool SetVariable(VariableSpace space, const char *name, const char *value)
Definition variables.c:281

References _psqlSettings::db, _psqlSettings::encoding, printTableOpt::encoding, fb(), formatPGVersionNumber(), get_conninfo_value(), pg_encoding_to_char, pg_free(), _psqlSettings::popt, PQclientEncoding(), PQdb(), PQhost(), PQparameterStatus(), PQport(), PQserverVersion(), PQsetErrorContextVisibility(), PQsetErrorVerbosity(), PQuser(), pset, server_version, setFmtEncoding(), SetVariable(), _psqlSettings::show_context, snprintf, _psqlSettings::sversion, printQueryOpt::topt, _psqlSettings::vars, and _psqlSettings::verbosity.

Referenced by CheckConnection(), do_connect(), and main().

◆ UnsyncVariables()

void UnsyncVariables ( void  )
extern

Definition at line 4626 of file command.c.

4627{
4628 SetVariable(pset.vars, "DBNAME", NULL);
4629 SetVariable(pset.vars, "SERVICE", NULL);
4630 SetVariable(pset.vars, "SERVICEFILE", NULL);
4631 SetVariable(pset.vars, "USER", NULL);
4632 SetVariable(pset.vars, "HOST", NULL);
4633 SetVariable(pset.vars, "PORT", NULL);
4634 SetVariable(pset.vars, "ENCODING", NULL);
4635 SetVariable(pset.vars, "SERVER_VERSION_NAME", NULL);
4636 SetVariable(pset.vars, "SERVER_VERSION_NUM", NULL);
4637}

References fb(), pset, SetVariable(), and _psqlSettings::vars.

Referenced by CheckConnection(), and do_connect().