PostgreSQL Source Code  git master
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)

Definition at line 3614 of file command.c.

3615 {
3616  if (!pset.quiet && !pset.notty)
3617  {
3618  int client_ver = PG_VERSION_NUM;
3619  char cverbuf[32];
3620  char sverbuf[32];
3621 
3622  if (pset.sversion != client_ver)
3623  {
3624  const char *server_version;
3625 
3626  /* Try to get full text form, might include "devel" etc */
3627  server_version = PQparameterStatus(pset.db, "server_version");
3628  /* Otherwise fall back on pset.sversion */
3629  if (!server_version)
3630  {
3632  sverbuf, sizeof(sverbuf));
3633  server_version = sverbuf;
3634  }
3635 
3636  printf(_("%s (%s, server %s)\n"),
3637  pset.progname, PG_VERSION, server_version);
3638  }
3639  /* For version match, only print psql banner on startup. */
3640  else if (in_startup)
3641  printf("%s (%s)\n", pset.progname, PG_VERSION);
3642 
3643  /*
3644  * Warn if server's major version is newer than ours, or if server
3645  * predates our support cutoff (currently 9.2).
3646  */
3647  if (pset.sversion / 100 > client_ver / 100 ||
3648  pset.sversion < 90200)
3649  printf(_("WARNING: %s major version %s, server major version %s.\n"
3650  " Some psql features might not work.\n"),
3651  pset.progname,
3652  formatPGVersionNumber(client_ver, false,
3653  cverbuf, sizeof(cverbuf)),
3655  sverbuf, sizeof(sverbuf)));
3656 
3657 #ifdef WIN32
3658  if (in_startup)
3659  checkWin32Codepage();
3660 #endif
3661  printSSLInfo();
3662  printGSSInfo();
3663  }
3664 }
static void printSSLInfo(void)
Definition: command.c:3673
static void printGSSInfo(void)
Definition: command.c:3698
#define _(x)
Definition: elog.c:89
const char * PQparameterStatus(const PGconn *conn, const char *paramName)
Definition: fe-connect.c:6873
static int server_version
Definition: pg_dumpall.c:85
#define printf(...)
Definition: port.h:231
PsqlSettings pset
Definition: startup.c:32
char * formatPGVersionNumber(int version_number, bool include_minor, char *buf, size_t buflen)
Definition: string_utils.c:177
PGconn * db
Definition: settings.h:82
const char * progname
Definition: settings.h:109

References _, _psqlSettings::db, 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 
)

Definition at line 4229 of file command.c.

4230 {
4231  size_t vallen = 0;
4232 
4233  Assert(param != NULL);
4234 
4235  if (value)
4236  vallen = strlen(value);
4237 
4238  /* set format */
4239  if (strcmp(param, "format") == 0)
4240  {
4241  static const struct fmt
4242  {
4243  const char *name;
4244  enum printFormat number;
4245  } formats[] =
4246  {
4247  /* remember to update error message below when adding more */
4248  {"aligned", PRINT_ALIGNED},
4249  {"asciidoc", PRINT_ASCIIDOC},
4250  {"csv", PRINT_CSV},
4251  {"html", PRINT_HTML},
4252  {"latex", PRINT_LATEX},
4253  {"troff-ms", PRINT_TROFF_MS},
4254  {"unaligned", PRINT_UNALIGNED},
4255  {"wrapped", PRINT_WRAPPED}
4256  };
4257 
4258  if (!value)
4259  ;
4260  else
4261  {
4262  int match_pos = -1;
4263 
4264  for (int i = 0; i < lengthof(formats); i++)
4265  {
4266  if (pg_strncasecmp(formats[i].name, value, vallen) == 0)
4267  {
4268  if (match_pos < 0)
4269  match_pos = i;
4270  else
4271  {
4272  pg_log_error("\\pset: ambiguous abbreviation \"%s\" matches both \"%s\" and \"%s\"",
4273  value,
4274  formats[match_pos].name, formats[i].name);
4275  return false;
4276  }
4277  }
4278  }
4279  if (match_pos >= 0)
4280  popt->topt.format = formats[match_pos].number;
4281  else if (pg_strncasecmp("latex-longtable", value, vallen) == 0)
4282  {
4283  /*
4284  * We must treat latex-longtable specially because latex is a
4285  * prefix of it; if both were in the table above, we'd think
4286  * "latex" is ambiguous.
4287  */
4289  }
4290  else
4291  {
4292  pg_log_error("\\pset: allowed formats are aligned, asciidoc, csv, html, latex, latex-longtable, troff-ms, unaligned, wrapped");
4293  return false;
4294  }
4295  }
4296  }
4297 
4298  /* set table line style */
4299  else if (strcmp(param, "linestyle") == 0)
4300  {
4301  if (!value)
4302  ;
4303  else if (pg_strncasecmp("ascii", value, vallen) == 0)
4304  popt->topt.line_style = &pg_asciiformat;
4305  else if (pg_strncasecmp("old-ascii", value, vallen) == 0)
4307  else if (pg_strncasecmp("unicode", value, vallen) == 0)
4308  popt->topt.line_style = &pg_utf8format;
4309  else
4310  {
4311  pg_log_error("\\pset: allowed line styles are ascii, old-ascii, unicode");
4312  return false;
4313  }
4314  }
4315 
4316  /* set unicode border line style */
4317  else if (strcmp(param, "unicode_border_linestyle") == 0)
4318  {
4319  if (!value)
4320  ;
4321  else if (set_unicode_line_style(value, vallen,
4323  refresh_utf8format(&(popt->topt));
4324  else
4325  {
4326  pg_log_error("\\pset: allowed Unicode border line styles are single, double");
4327  return false;
4328  }
4329  }
4330 
4331  /* set unicode column line style */
4332  else if (strcmp(param, "unicode_column_linestyle") == 0)
4333  {
4334  if (!value)
4335  ;
4336  else if (set_unicode_line_style(value, vallen,
4338  refresh_utf8format(&(popt->topt));
4339  else
4340  {
4341  pg_log_error("\\pset: allowed Unicode column line styles are single, double");
4342  return false;
4343  }
4344  }
4345 
4346  /* set unicode header line style */
4347  else if (strcmp(param, "unicode_header_linestyle") == 0)
4348  {
4349  if (!value)
4350  ;
4351  else if (set_unicode_line_style(value, vallen,
4353  refresh_utf8format(&(popt->topt));
4354  else
4355  {
4356  pg_log_error("\\pset: allowed Unicode header line styles are single, double");
4357  return false;
4358  }
4359  }
4360 
4361  /* set border style/width */
4362  else if (strcmp(param, "border") == 0)
4363  {
4364  if (value)
4365  popt->topt.border = atoi(value);
4366  }
4367 
4368  /* set expanded/vertical mode */
4369  else if (strcmp(param, "x") == 0 ||
4370  strcmp(param, "expanded") == 0 ||
4371  strcmp(param, "vertical") == 0)
4372  {
4373  if (value && pg_strcasecmp(value, "auto") == 0)
4374  popt->topt.expanded = 2;
4375  else if (value)
4376  {
4377  bool on_off;
4378 
4379  if (ParseVariableBool(value, NULL, &on_off))
4380  popt->topt.expanded = on_off ? 1 : 0;
4381  else
4382  {
4383  PsqlVarEnumError(param, value, "on, off, auto");
4384  return false;
4385  }
4386  }
4387  else
4388  popt->topt.expanded = !popt->topt.expanded;
4389  }
4390 
4391  /* field separator for CSV format */
4392  else if (strcmp(param, "csv_fieldsep") == 0)
4393  {
4394  if (value)
4395  {
4396  /* CSV separator has to be a one-byte character */
4397  if (strlen(value) != 1)
4398  {
4399  pg_log_error("\\pset: csv_fieldsep must be a single one-byte character");
4400  return false;
4401  }
4402  if (value[0] == '"' || value[0] == '\n' || value[0] == '\r')
4403  {
4404  pg_log_error("\\pset: csv_fieldsep cannot be a double quote, a newline, or a carriage return");
4405  return false;
4406  }
4407  popt->topt.csvFieldSep[0] = value[0];
4408  }
4409  }
4410 
4411  /* locale-aware numeric output */
4412  else if (strcmp(param, "numericlocale") == 0)
4413  {
4414  if (value)
4415  return ParseVariableBool(value, param, &popt->topt.numericLocale);
4416  else
4417  popt->topt.numericLocale = !popt->topt.numericLocale;
4418  }
4419 
4420  /* null display */
4421  else if (strcmp(param, "null") == 0)
4422  {
4423  if (value)
4424  {
4425  free(popt->nullPrint);
4426  popt->nullPrint = pg_strdup(value);
4427  }
4428  }
4429 
4430  /* field separator for unaligned text */
4431  else if (strcmp(param, "fieldsep") == 0)
4432  {
4433  if (value)
4434  {
4435  free(popt->topt.fieldSep.separator);
4437  popt->topt.fieldSep.separator_zero = false;
4438  }
4439  }
4440 
4441  else if (strcmp(param, "fieldsep_zero") == 0)
4442  {
4443  free(popt->topt.fieldSep.separator);
4444  popt->topt.fieldSep.separator = NULL;
4445  popt->topt.fieldSep.separator_zero = true;
4446  }
4447 
4448  /* record separator for unaligned text */
4449  else if (strcmp(param, "recordsep") == 0)
4450  {
4451  if (value)
4452  {
4453  free(popt->topt.recordSep.separator);
4455  popt->topt.recordSep.separator_zero = false;
4456  }
4457  }
4458 
4459  else if (strcmp(param, "recordsep_zero") == 0)
4460  {
4461  free(popt->topt.recordSep.separator);
4462  popt->topt.recordSep.separator = NULL;
4463  popt->topt.recordSep.separator_zero = true;
4464  }
4465 
4466  /* toggle between full and tuples-only format */
4467  else if (strcmp(param, "t") == 0 || strcmp(param, "tuples_only") == 0)
4468  {
4469  if (value)
4470  return ParseVariableBool(value, param, &popt->topt.tuples_only);
4471  else
4472  popt->topt.tuples_only = !popt->topt.tuples_only;
4473  }
4474 
4475  /* set title override */
4476  else if (strcmp(param, "C") == 0 || strcmp(param, "title") == 0)
4477  {
4478  free(popt->title);
4479  if (!value)
4480  popt->title = NULL;
4481  else
4482  popt->title = pg_strdup(value);
4483  }
4484 
4485  /* set HTML table tag options */
4486  else if (strcmp(param, "T") == 0 || strcmp(param, "tableattr") == 0)
4487  {
4488  free(popt->topt.tableAttr);
4489  if (!value)
4490  popt->topt.tableAttr = NULL;
4491  else
4492  popt->topt.tableAttr = pg_strdup(value);
4493  }
4494 
4495  /* toggle use of pager */
4496  else if (strcmp(param, "pager") == 0)
4497  {
4498  if (value && pg_strcasecmp(value, "always") == 0)
4499  popt->topt.pager = 2;
4500  else if (value)
4501  {
4502  bool on_off;
4503 
4504  if (!ParseVariableBool(value, NULL, &on_off))
4505  {
4506  PsqlVarEnumError(param, value, "on, off, always");
4507  return false;
4508  }
4509  popt->topt.pager = on_off ? 1 : 0;
4510  }
4511  else if (popt->topt.pager == 1)
4512  popt->topt.pager = 0;
4513  else
4514  popt->topt.pager = 1;
4515  }
4516 
4517  /* set minimum lines for pager use */
4518  else if (strcmp(param, "pager_min_lines") == 0)
4519  {
4520  if (value)
4521  popt->topt.pager_min_lines = atoi(value);
4522  }
4523 
4524  /* disable "(x rows)" footer */
4525  else if (strcmp(param, "footer") == 0)
4526  {
4527  if (value)
4528  return ParseVariableBool(value, param, &popt->topt.default_footer);
4529  else
4530  popt->topt.default_footer = !popt->topt.default_footer;
4531  }
4532 
4533  /* set border style/width */
4534  else if (strcmp(param, "columns") == 0)
4535  {
4536  if (value)
4537  popt->topt.columns = atoi(value);
4538  }
4539  else
4540  {
4541  pg_log_error("\\pset: unknown option: %s", param);
4542  return false;
4543  }
4544 
4545  if (!quiet)
4546  printPsetInfo(param, &pset.popt);
4547 
4548  return true;
4549 }
#define lengthof(array)
Definition: c.h:734
static bool set_unicode_line_style(const char *value, size_t vallen, unicode_linestyle *linestyle)
Definition: command.c:4186
static bool printPsetInfo(const char *param, printQueryOpt *popt)
Definition: command.c:4555
const char * name
Definition: encode.c:561
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
void refresh_utf8format(const printTableOpt *opt)
Definition: print.c:3632
const printTextFormat pg_asciiformat
Definition: print.c:56
const printTextFormat pg_asciiformat_old
Definition: print.c:77
printTextFormat pg_utf8format
Definition: print.c:99
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
#define free(a)
Definition: header.h:65
static struct @151 value
int i
Definition: isn.c:73
Assert(fmt[strlen(fmt) - 1] !='\n')
static void const char * fmt
#define pg_log_error(...)
Definition: logging.h:106
int pg_strcasecmp(const char *s1, const char *s2)
Definition: pgstrcasecmp.c:36
int pg_strncasecmp(const char *s1, const char *s2, size_t n)
Definition: pgstrcasecmp.c:69
printQueryOpt popt
Definition: settings.h:91
printTableOpt topt
Definition: print.h:169
char * nullPrint
Definition: print.h:170
char * title
Definition: print.h:171
unsigned short int expanded
Definition: print.h:102
unicode_linestyle unicode_border_linestyle
Definition: print.h:125
bool tuples_only
Definition: print.h:110
int columns
Definition: print.h:124
enum printFormat format
Definition: print.h:101
struct separator fieldSep
Definition: print.h:116
struct separator recordSep
Definition: print.h:117
char csvFieldSep[2]
Definition: print.h:118
const printTextFormat * line_style
Definition: print.h:115
bool default_footer
Definition: print.h:113
int pager_min_lines
Definition: print.h:108
unsigned short int pager
Definition: print.h:106
char * tableAttr
Definition: print.h:121
bool numericLocale
Definition: print.h:119
unsigned short int border
Definition: print.h:104
unicode_linestyle unicode_header_linestyle
Definition: print.h:127
unicode_linestyle unicode_column_linestyle
Definition: print.h:126
bool separator_zero
Definition: print.h:96
char * separator
Definition: print.h:95
void PsqlVarEnumError(const char *name, const char *value, const char *suggestions)
Definition: variables.c:417
bool ParseVariableBool(const char *value, const char *name, bool *result)
Definition: variables.c:107

References Assert(), printTableOpt::border, printTableOpt::columns, printTableOpt::csvFieldSep, printTableOpt::default_footer, printTableOpt::expanded, printTableOpt::fieldSep, fmt, printTableOpt::format, free, i, lengthof, printTableOpt::line_style, name, printQueryOpt::nullPrint, printTableOpt::numericLocale, printTableOpt::pager, printTableOpt::pager_min_lines, ParseVariableBool(), 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, printPsetInfo(), pset, PsqlVarEnumError(), printTableOpt::recordSep, refresh_utf8format(), separator::separator, separator::separator_zero, set_unicode_line_style(), printTableOpt::tableAttr, printQueryOpt::title, printQueryOpt::topt, 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 
)

Definition at line 213 of file command.c.

217 {
219  char *cmd;
220  char *arg;
221 
222  Assert(scan_state != NULL);
223  Assert(cstack != NULL);
224 
225  /* Parse off the command name */
226  cmd = psql_scan_slash_command(scan_state);
227 
228  /* And try to execute it */
229  status = exec_command(cmd, scan_state, cstack, query_buf, previous_buf);
230 
231  if (status == PSQL_CMD_UNKNOWN)
232  {
233  pg_log_error("invalid command \\%s", cmd);
235  pg_log_error_hint("Try \\? for help.");
237  }
238 
239  if (status != PSQL_CMD_ERROR)
240  {
241  /*
242  * Eat any remaining arguments after a valid command. We want to
243  * suppress evaluation of backticks in this situation, so transiently
244  * push an inactive conditional-stack entry.
245  */
246  bool active_branch = conditional_active(cstack);
247 
249  while ((arg = psql_scan_slash_option(scan_state,
250  OT_NORMAL, NULL, false)))
251  {
252  if (active_branch)
253  pg_log_warning("\\%s: extra argument \"%s\" ignored", cmd, arg);
254  free(arg);
255  }
256  conditional_stack_pop(cstack);
257  }
258  else
259  {
260  /* silently throw away rest of line after an erroneous command */
261  while ((arg = psql_scan_slash_option(scan_state,
262  OT_WHOLE_LINE, NULL, false)))
263  free(arg);
264  }
265 
266  /* if there is a trailing \\, swallow it */
267  psql_scan_slash_command_end(scan_state);
268 
269  free(cmd);
270 
271  /* some commands write to queryFout, so make sure output is sent */
273 
274  return status;
275 }
static backslashResult exec_command(const char *cmd, PsqlScanState scan_state, ConditionalStack cstack, PQExpBuffer query_buf, PQExpBuffer previous_buf)
Definition: command.c:286
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)
Definition: conditional.c:140
@ IFSTATE_IGNORED
Definition: conditional.h:37
static void const char fflush(stdout)
#define pg_log_error_hint(...)
Definition: logging.h:112
void * arg
static void static void status(const char *fmt,...) pg_attribute_printf(1
Definition: pg_regress.c:229
#define pg_log_warning(...)
Definition: pgfnames.c:24
char * psql_scan_slash_command(PsqlScanState state)
void psql_scan_slash_command_end(PsqlScanState state)
@ OT_NORMAL
Definition: psqlscanslash.h:17
@ OT_WHOLE_LINE
Definition: psqlscanslash.h:21
char * psql_scan_slash_option(PsqlScanState state, enum slash_option_type type, char *quote, bool semicolon)
FILE * queryFout
Definition: settings.h:84
bool cur_cmd_interactive
Definition: settings.h:107

References arg, Assert(), conditional_active(), conditional_stack_pop(), conditional_stack_push(), _psqlSettings::cur_cmd_interactive, exec_command(), fflush(), 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 status().

Referenced by main(), and MainLoop().

◆ process_file()

int process_file ( char *  filename,
bool  use_relative_path 
)

Definition at line 4076 of file command.c.

4077 {
4078  FILE *fd;
4079  int result;
4080  char *oldfilename;
4081  char relpath[MAXPGPATH];
4082 
4083  if (!filename)
4084  {
4085  fd = stdin;
4086  filename = NULL;
4087  }
4088  else if (strcmp(filename, "-") != 0)
4089  {
4091 
4092  /*
4093  * If we were asked to resolve the pathname relative to the location
4094  * of the currently executing script, and there is one, and this is a
4095  * relative pathname, then prepend all but the last pathname component
4096  * of the current script to this pathname.
4097  */
4098  if (use_relative_path && pset.inputfile &&
4100  {
4101  strlcpy(relpath, pset.inputfile, sizeof(relpath));
4105 
4106  filename = relpath;
4107  }
4108 
4109  fd = fopen(filename, PG_BINARY_R);
4110 
4111  if (!fd)
4112  {
4113  pg_log_error("%s: %m", filename);
4114  return EXIT_FAILURE;
4115  }
4116  }
4117  else
4118  {
4119  fd = stdin;
4120  filename = "<stdin>"; /* for future error messages */
4121  }
4122 
4123  oldfilename = pset.inputfile;
4125 
4127 
4128  result = MainLoop(fd);
4129 
4130  if (fd != stdin)
4131  fclose(fd);
4132 
4133  pset.inputfile = oldfilename;
4134 
4136 
4137  return result;
4138 }
#define PG_BINARY_R
Definition: c.h:1270
void pg_logging_config(int new_flags)
Definition: logging.c:163
#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:94
void join_path_components(char *ret_path, const char *head, const char *tail)
Definition: path.c:219
#define is_absolute_path(filename)
Definition: port.h:89
bool has_drive_prefix(const char *filename)
Definition: path.c:88
void canonicalize_path(char *path)
Definition: path.c:264
void get_parent_directory(char *path)
Definition: path.c:977
size_t strlcpy(char *dst, const char *src, size_t siz)
Definition: strlcpy.c:45
static int fd(const char *x, int i)
Definition: preproc-init.c:105
#define relpath(rnode, forknum)
Definition: relpath.h:87
#define EXIT_FAILURE
Definition: settings.h:163
char * inputfile
Definition: settings.h:110

References canonicalize_path(), EXIT_FAILURE, 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 
)

Definition at line 4778 of file command.c.

4779 {
4780  /* Free all the old data we're about to overwrite the pointers to. */
4781 
4782  /* topt.line_style points to const data that need not be duplicated */
4783  if (popt->topt.fieldSep.separator)
4784  free(popt->topt.fieldSep.separator);
4785  if (popt->topt.recordSep.separator)
4786  free(popt->topt.recordSep.separator);
4787  if (popt->topt.tableAttr)
4788  free(popt->topt.tableAttr);
4789  if (popt->nullPrint)
4790  free(popt->nullPrint);
4791  if (popt->title)
4792  free(popt->title);
4793 
4794  /*
4795  * footers and translate_columns are never set in psql's print settings,
4796  * so we needn't write code to duplicate them.
4797  */
4798  Assert(popt->footers == NULL);
4799  Assert(popt->translate_columns == NULL);
4800 
4801  /* Now we may flat-copy all the fields, including pointers. */
4802  memcpy(popt, save, sizeof(printQueryOpt));
4803 
4804  /* Lastly, free "save" ... but its sub-structures now belong to popt. */
4805  free(save);
4806 }
const bool * translate_columns
Definition: print.h:174
char ** footers
Definition: print.h:172

References Assert(), 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)

Definition at line 4742 of file command.c.

4743 {
4744  printQueryOpt *save;
4745 
4746  save = (printQueryOpt *) pg_malloc(sizeof(printQueryOpt));
4747 
4748  /* Flat-copy all the scalar fields, then duplicate sub-structures. */
4749  memcpy(save, popt, sizeof(printQueryOpt));
4750 
4751  /* topt.line_style points to const data that need not be duplicated */
4752  if (popt->topt.fieldSep.separator)
4754  if (popt->topt.recordSep.separator)
4756  if (popt->topt.tableAttr)
4757  save->topt.tableAttr = pg_strdup(popt->topt.tableAttr);
4758  if (popt->nullPrint)
4759  save->nullPrint = pg_strdup(popt->nullPrint);
4760  if (popt->title)
4761  save->title = pg_strdup(popt->title);
4762 
4763  /*
4764  * footers and translate_columns are never set in psql's print settings,
4765  * so we needn't write code to duplicate them.
4766  */
4767  Assert(popt->footers == NULL);
4768  Assert(popt->translate_columns == NULL);
4769 
4770  return save;
4771 }
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47

References Assert(), printTableOpt::fieldSep, printQueryOpt::footers, printQueryOpt::nullPrint, pg_malloc(), 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  )

Definition at line 3739 of file command.c.

3740 {
3741  char vbuf[32];
3742  const char *server_version;
3743 
3744  /* get stuff from connection */
3748 
3749  SetVariable(pset.vars, "DBNAME", PQdb(pset.db));
3750  SetVariable(pset.vars, "USER", PQuser(pset.db));
3751  SetVariable(pset.vars, "HOST", PQhost(pset.db));
3752  SetVariable(pset.vars, "PORT", PQport(pset.db));
3754 
3755  /* this bit should match connection_warnings(): */
3756  /* Try to get full text form of version, might include "devel" etc */
3757  server_version = PQparameterStatus(pset.db, "server_version");
3758  /* Otherwise fall back on pset.sversion */
3759  if (!server_version)
3760  {
3761  formatPGVersionNumber(pset.sversion, true, vbuf, sizeof(vbuf));
3762  server_version = vbuf;
3763  }
3764  SetVariable(pset.vars, "SERVER_VERSION_NAME", server_version);
3765 
3766  snprintf(vbuf, sizeof(vbuf), "%d", pset.sversion);
3767  SetVariable(pset.vars, "SERVER_VERSION_NUM", vbuf);
3768 
3769  /* send stuff to it, too */
3772 }
const char * pg_encoding_to_char(int encoding)
Definition: encnames.c:588
int PQserverVersion(const PGconn *conn)
Definition: fe-connect.c:6898
char * PQhost(const PGconn *conn)
Definition: fe-connect.c:6787
char * PQdb(const PGconn *conn)
Definition: fe-connect.c:6754
int PQclientEncoding(const PGconn *conn)
Definition: fe-connect.c:6985
PGContextVisibility PQsetErrorContextVisibility(PGconn *conn, PGContextVisibility show_context)
Definition: fe-connect.c:7047
char * PQuser(const PGconn *conn)
Definition: fe-connect.c:6762
char * PQport(const PGconn *conn)
Definition: fe-connect.c:6823
PGVerbosity PQsetErrorVerbosity(PGconn *conn, PGVerbosity verbosity)
Definition: fe-connect.c:7035
#define snprintf
Definition: port.h:225
VariableSpace vars
Definition: settings.h:118
int encoding
Definition: settings.h:83
PGVerbosity verbosity
Definition: settings.h:150
PGContextVisibility show_context
Definition: settings.h:152
int encoding
Definition: print.h:122
bool SetVariable(VariableSpace space, const char *name, const char *value)
Definition: variables.c:211

References _psqlSettings::db, _psqlSettings::encoding, printTableOpt::encoding, formatPGVersionNumber(), pg_encoding_to_char(), _psqlSettings::popt, PQclientEncoding(), PQdb(), PQhost(), PQparameterStatus(), PQport(), PQserverVersion(), PQsetErrorContextVisibility(), PQsetErrorVerbosity(), PQuser(), pset, server_version, 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  )

Definition at line 3780 of file command.c.

3781 {
3782  SetVariable(pset.vars, "DBNAME", NULL);
3783  SetVariable(pset.vars, "USER", NULL);
3784  SetVariable(pset.vars, "HOST", NULL);
3785  SetVariable(pset.vars, "PORT", NULL);
3786  SetVariable(pset.vars, "ENCODING", NULL);
3787  SetVariable(pset.vars, "SERVER_VERSION_NAME", NULL);
3788  SetVariable(pset.vars, "SERVER_VERSION_NUM", NULL);
3789 }

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

Referenced by CheckConnection(), and do_connect().