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)
 
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 */
enum _backslashResult backslashResult

Function Documentation

◆ connection_warnings()

void connection_warnings ( bool  in_startup)

Definition at line 3196 of file command.c.

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().

3197 {
3198  if (!pset.quiet && !pset.notty)
3199  {
3200  int client_ver = PG_VERSION_NUM;
3201  char cverbuf[32];
3202  char sverbuf[32];
3203 
3204  if (pset.sversion != client_ver)
3205  {
3206  const char *server_version;
3207 
3208  /* Try to get full text form, might include "devel" etc */
3209  server_version = PQparameterStatus(pset.db, "server_version");
3210  /* Otherwise fall back on pset.sversion */
3211  if (!server_version)
3212  {
3214  sverbuf, sizeof(sverbuf));
3215  server_version = sverbuf;
3216  }
3217 
3218  printf(_("%s (%s, server %s)\n"),
3219  pset.progname, PG_VERSION, server_version);
3220  }
3221  /* For version match, only print psql banner on startup. */
3222  else if (in_startup)
3223  printf("%s (%s)\n", pset.progname, PG_VERSION);
3224 
3225  if (pset.sversion / 100 > client_ver / 100)
3226  printf(_("WARNING: %s major version %s, server major version %s.\n"
3227  " Some psql features might not work.\n"),
3228  pset.progname,
3229  formatPGVersionNumber(client_ver, false,
3230  cverbuf, sizeof(cverbuf)),
3232  sverbuf, sizeof(sverbuf)));
3233 
3234 #ifdef WIN32
3235  if (in_startup)
3236  checkWin32Codepage();
3237 #endif
3238  printSSLInfo();
3239  printGSSInfo();
3240  }
3241 }
PGconn * db
Definition: settings.h:82
PsqlSettings pset
Definition: startup.c:31
const char * PQparameterStatus(const PGconn *conn, const char *paramName)
Definition: fe-connect.c:6588
#define printf(...)
Definition: port.h:198
static void printGSSInfo(void)
Definition: command.c:3278
const char * progname
Definition: settings.h:108
static int server_version
Definition: pg_dumpall.c:81
static void printSSLInfo(void)
Definition: command.c:3250
#define _(x)
Definition: elog.c:87
char * formatPGVersionNumber(int version_number, bool include_minor, char *buf, size_t buflen)
Definition: string_utils.c:177

◆ do_pset()

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

Definition at line 3754 of file command.c.

References Assert, printTableOpt::border, printTableOpt::columns, printTableOpt::csvFieldSep, printTableOpt::default_footer, printTableOpt::expanded, printTableOpt::fieldSep, 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, and printTableOpt::unicode_header_linestyle.

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(), and parse_psql_options().

3755 {
3756  size_t vallen = 0;
3757 
3758  Assert(param != NULL);
3759 
3760  if (value)
3761  vallen = strlen(value);
3762 
3763  /* set format */
3764  if (strcmp(param, "format") == 0)
3765  {
3766  static const struct fmt
3767  {
3768  const char *name;
3769  enum printFormat number;
3770  } formats[] =
3771  {
3772  /* remember to update error message below when adding more */
3773  {"aligned", PRINT_ALIGNED},
3774  {"asciidoc", PRINT_ASCIIDOC},
3775  {"csv", PRINT_CSV},
3776  {"html", PRINT_HTML},
3777  {"latex", PRINT_LATEX},
3778  {"troff-ms", PRINT_TROFF_MS},
3779  {"unaligned", PRINT_UNALIGNED},
3780  {"wrapped", PRINT_WRAPPED}
3781  };
3782 
3783  if (!value)
3784  ;
3785  else
3786  {
3787  int match_pos = -1;
3788 
3789  for (int i = 0; i < lengthof(formats); i++)
3790  {
3791  if (pg_strncasecmp(formats[i].name, value, vallen) == 0)
3792  {
3793  if (match_pos < 0)
3794  match_pos = i;
3795  else
3796  {
3797  pg_log_error("\\pset: ambiguous abbreviation \"%s\" matches both \"%s\" and \"%s\"",
3798  value,
3799  formats[match_pos].name, formats[i].name);
3800  return false;
3801  }
3802  }
3803  }
3804  if (match_pos >= 0)
3805  popt->topt.format = formats[match_pos].number;
3806  else if (pg_strncasecmp("latex-longtable", value, vallen) == 0)
3807  {
3808  /*
3809  * We must treat latex-longtable specially because latex is a
3810  * prefix of it; if both were in the table above, we'd think
3811  * "latex" is ambiguous.
3812  */
3814  }
3815  else
3816  {
3817  pg_log_error("\\pset: allowed formats are aligned, asciidoc, csv, html, latex, latex-longtable, troff-ms, unaligned, wrapped");
3818  return false;
3819  }
3820  }
3821  }
3822 
3823  /* set table line style */
3824  else if (strcmp(param, "linestyle") == 0)
3825  {
3826  if (!value)
3827  ;
3828  else if (pg_strncasecmp("ascii", value, vallen) == 0)
3829  popt->topt.line_style = &pg_asciiformat;
3830  else if (pg_strncasecmp("old-ascii", value, vallen) == 0)
3832  else if (pg_strncasecmp("unicode", value, vallen) == 0)
3833  popt->topt.line_style = &pg_utf8format;
3834  else
3835  {
3836  pg_log_error("\\pset: allowed line styles are ascii, old-ascii, unicode");
3837  return false;
3838  }
3839  }
3840 
3841  /* set unicode border line style */
3842  else if (strcmp(param, "unicode_border_linestyle") == 0)
3843  {
3844  if (!value)
3845  ;
3846  else if (set_unicode_line_style(value, vallen,
3848  refresh_utf8format(&(popt->topt));
3849  else
3850  {
3851  pg_log_error("\\pset: allowed Unicode border line styles are single, double");
3852  return false;
3853  }
3854  }
3855 
3856  /* set unicode column line style */
3857  else if (strcmp(param, "unicode_column_linestyle") == 0)
3858  {
3859  if (!value)
3860  ;
3861  else if (set_unicode_line_style(value, vallen,
3863  refresh_utf8format(&(popt->topt));
3864  else
3865  {
3866  pg_log_error("\\pset: allowed Unicode column line styles are single, double");
3867  return false;
3868  }
3869  }
3870 
3871  /* set unicode header line style */
3872  else if (strcmp(param, "unicode_header_linestyle") == 0)
3873  {
3874  if (!value)
3875  ;
3876  else if (set_unicode_line_style(value, vallen,
3878  refresh_utf8format(&(popt->topt));
3879  else
3880  {
3881  pg_log_error("\\pset: allowed Unicode header line styles are single, double");
3882  return false;
3883  }
3884  }
3885 
3886  /* set border style/width */
3887  else if (strcmp(param, "border") == 0)
3888  {
3889  if (value)
3890  popt->topt.border = atoi(value);
3891  }
3892 
3893  /* set expanded/vertical mode */
3894  else if (strcmp(param, "x") == 0 ||
3895  strcmp(param, "expanded") == 0 ||
3896  strcmp(param, "vertical") == 0)
3897  {
3898  if (value && pg_strcasecmp(value, "auto") == 0)
3899  popt->topt.expanded = 2;
3900  else if (value)
3901  {
3902  bool on_off;
3903 
3904  if (ParseVariableBool(value, NULL, &on_off))
3905  popt->topt.expanded = on_off ? 1 : 0;
3906  else
3907  {
3908  PsqlVarEnumError(param, value, "on, off, auto");
3909  return false;
3910  }
3911  }
3912  else
3913  popt->topt.expanded = !popt->topt.expanded;
3914  }
3915 
3916  /* field separator for CSV format */
3917  else if (strcmp(param, "csv_fieldsep") == 0)
3918  {
3919  if (value)
3920  {
3921  /* CSV separator has to be a one-byte character */
3922  if (strlen(value) != 1)
3923  {
3924  pg_log_error("\\pset: csv_fieldsep must be a single one-byte character");
3925  return false;
3926  }
3927  if (value[0] == '"' || value[0] == '\n' || value[0] == '\r')
3928  {
3929  pg_log_error("\\pset: csv_fieldsep cannot be a double quote, a newline, or a carriage return");
3930  return false;
3931  }
3932  popt->topt.csvFieldSep[0] = value[0];
3933  }
3934  }
3935 
3936  /* locale-aware numeric output */
3937  else if (strcmp(param, "numericlocale") == 0)
3938  {
3939  if (value)
3940  return ParseVariableBool(value, param, &popt->topt.numericLocale);
3941  else
3942  popt->topt.numericLocale = !popt->topt.numericLocale;
3943  }
3944 
3945  /* null display */
3946  else if (strcmp(param, "null") == 0)
3947  {
3948  if (value)
3949  {
3950  free(popt->nullPrint);
3951  popt->nullPrint = pg_strdup(value);
3952  }
3953  }
3954 
3955  /* field separator for unaligned text */
3956  else if (strcmp(param, "fieldsep") == 0)
3957  {
3958  if (value)
3959  {
3960  free(popt->topt.fieldSep.separator);
3962  popt->topt.fieldSep.separator_zero = false;
3963  }
3964  }
3965 
3966  else if (strcmp(param, "fieldsep_zero") == 0)
3967  {
3968  free(popt->topt.fieldSep.separator);
3969  popt->topt.fieldSep.separator = NULL;
3970  popt->topt.fieldSep.separator_zero = true;
3971  }
3972 
3973  /* record separator for unaligned text */
3974  else if (strcmp(param, "recordsep") == 0)
3975  {
3976  if (value)
3977  {
3978  free(popt->topt.recordSep.separator);
3980  popt->topt.recordSep.separator_zero = false;
3981  }
3982  }
3983 
3984  else if (strcmp(param, "recordsep_zero") == 0)
3985  {
3986  free(popt->topt.recordSep.separator);
3987  popt->topt.recordSep.separator = NULL;
3988  popt->topt.recordSep.separator_zero = true;
3989  }
3990 
3991  /* toggle between full and tuples-only format */
3992  else if (strcmp(param, "t") == 0 || strcmp(param, "tuples_only") == 0)
3993  {
3994  if (value)
3995  return ParseVariableBool(value, param, &popt->topt.tuples_only);
3996  else
3997  popt->topt.tuples_only = !popt->topt.tuples_only;
3998  }
3999 
4000  /* set title override */
4001  else if (strcmp(param, "C") == 0 || strcmp(param, "title") == 0)
4002  {
4003  free(popt->title);
4004  if (!value)
4005  popt->title = NULL;
4006  else
4007  popt->title = pg_strdup(value);
4008  }
4009 
4010  /* set HTML table tag options */
4011  else if (strcmp(param, "T") == 0 || strcmp(param, "tableattr") == 0)
4012  {
4013  free(popt->topt.tableAttr);
4014  if (!value)
4015  popt->topt.tableAttr = NULL;
4016  else
4017  popt->topt.tableAttr = pg_strdup(value);
4018  }
4019 
4020  /* toggle use of pager */
4021  else if (strcmp(param, "pager") == 0)
4022  {
4023  if (value && pg_strcasecmp(value, "always") == 0)
4024  popt->topt.pager = 2;
4025  else if (value)
4026  {
4027  bool on_off;
4028 
4029  if (!ParseVariableBool(value, NULL, &on_off))
4030  {
4031  PsqlVarEnumError(param, value, "on, off, always");
4032  return false;
4033  }
4034  popt->topt.pager = on_off ? 1 : 0;
4035  }
4036  else if (popt->topt.pager == 1)
4037  popt->topt.pager = 0;
4038  else
4039  popt->topt.pager = 1;
4040  }
4041 
4042  /* set minimum lines for pager use */
4043  else if (strcmp(param, "pager_min_lines") == 0)
4044  {
4045  if (value)
4046  popt->topt.pager_min_lines = atoi(value);
4047  }
4048 
4049  /* disable "(x rows)" footer */
4050  else if (strcmp(param, "footer") == 0)
4051  {
4052  if (value)
4053  return ParseVariableBool(value, param, &popt->topt.default_footer);
4054  else
4055  popt->topt.default_footer = !popt->topt.default_footer;
4056  }
4057 
4058  /* set border style/width */
4059  else if (strcmp(param, "columns") == 0)
4060  {
4061  if (value)
4062  popt->topt.columns = atoi(value);
4063  }
4064  else
4065  {
4066  pg_log_error("\\pset: unknown option: %s", param);
4067  return false;
4068  }
4069 
4070  if (!quiet)
4071  printPsetInfo(param, &pset.popt);
4072 
4073  return true;
4074 }
char * nullPrint
Definition: print.h:168
PsqlSettings pset
Definition: startup.c:31
const printTextFormat * line_style
Definition: print.h:113
#define pg_log_error(...)
Definition: logging.h:79
printTextFormat pg_utf8format
Definition: print.c:100
const printTextFormat pg_asciiformat_old
Definition: print.c:78
enum printFormat format
Definition: print.h:99
void PsqlVarEnumError(const char *name, const char *value, const char *suggestions)
Definition: variables.c:391
printTableOpt topt
Definition: print.h:167
static struct @145 value
unicode_linestyle unicode_header_linestyle
Definition: print.h:125
int pg_strcasecmp(const char *s1, const char *s2)
Definition: pgstrcasecmp.c:36
#define lengthof(array)
Definition: c.h:669
bool separator_zero
Definition: print.h:94
unicode_linestyle unicode_border_linestyle
Definition: print.h:123
int pg_strncasecmp(const char *s1, const char *s2, size_t n)
Definition: pgstrcasecmp.c:69
unsigned short int border
Definition: print.h:102
unsigned short int expanded
Definition: print.h:100
static bool printPsetInfo(const char *param, struct printQueryOpt *popt)
Definition: command.c:4078
unicode_linestyle unicode_column_linestyle
Definition: print.h:124
bool tuples_only
Definition: print.h:108
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
char * tableAttr
Definition: print.h:119
char csvFieldSep[2]
Definition: print.h:116
unsigned short int pager
Definition: print.h:104
#define free(a)
Definition: header.h:65
struct separator fieldSep
Definition: print.h:114
char * title
Definition: print.h:169
int pager_min_lines
Definition: print.h:106
bool default_footer
Definition: print.h:111
#define Assert(condition)
Definition: c.h:739
printQueryOpt popt
Definition: settings.h:91
static bool set_unicode_line_style(const char *value, size_t vallen, unicode_linestyle *linestyle)
Definition: command.c:3722
const char * name
Definition: encode.c:521
bool numericLocale
Definition: print.h:117
bool ParseVariableBool(const char *value, const char *name, bool *result)
Definition: variables.c:107
int i
void refresh_utf8format(const printTableOpt *opt)
Definition: print.c:3575
const printTextFormat pg_asciiformat
Definition: print.c:57
char * separator
Definition: print.h:93
printFormat
Definition: print.h:26
struct separator recordSep
Definition: print.h:115
int columns
Definition: print.h:122

◆ HandleSlashCmds()

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

Definition at line 200 of file command.c.

References arg, Assert, conditional_active(), conditional_stack_pop(), conditional_stack_push(), _psqlSettings::cur_cmd_interactive, exec_command(), free, IFSTATE_IGNORED, OT_NORMAL, OT_WHOLE_LINE, pg_log_error, pg_log_info, 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().

204 {
206  char *cmd;
207  char *arg;
208 
209  Assert(scan_state != NULL);
210  Assert(cstack != NULL);
211 
212  /* Parse off the command name */
213  cmd = psql_scan_slash_command(scan_state);
214 
215  /* And try to execute it */
216  status = exec_command(cmd, scan_state, cstack, query_buf, previous_buf);
217 
218  if (status == PSQL_CMD_UNKNOWN)
219  {
220  pg_log_error("invalid command \\%s", cmd);
222  pg_log_info("Try \\? for help.");
223  status = PSQL_CMD_ERROR;
224  }
225 
226  if (status != PSQL_CMD_ERROR)
227  {
228  /*
229  * Eat any remaining arguments after a valid command. We want to
230  * suppress evaluation of backticks in this situation, so transiently
231  * push an inactive conditional-stack entry.
232  */
233  bool active_branch = conditional_active(cstack);
234 
236  while ((arg = psql_scan_slash_option(scan_state,
237  OT_NORMAL, NULL, false)))
238  {
239  if (active_branch)
240  pg_log_warning("\\%s: extra argument \"%s\" ignored", cmd, arg);
241  free(arg);
242  }
243  conditional_stack_pop(cstack);
244  }
245  else
246  {
247  /* silently throw away rest of line after an erroneous command */
248  while ((arg = psql_scan_slash_option(scan_state,
249  OT_WHOLE_LINE, NULL, false)))
250  free(arg);
251  }
252 
253  /* if there is a trailing \\, swallow it */
254  psql_scan_slash_command_end(scan_state);
255 
256  free(cmd);
257 
258  /* some commands write to queryFout, so make sure output is sent */
259  fflush(pset.queryFout);
260 
261  return status;
262 }
void psql_scan_slash_command_end(PsqlScanState state)
bool conditional_active(ConditionalStack cstack)
Definition: conditional.c:128
PsqlSettings pset
Definition: startup.c:31
bool conditional_stack_pop(ConditionalStack cstack)
Definition: conditional.c:57
#define pg_log_error(...)
Definition: logging.h:79
char * psql_scan_slash_command(PsqlScanState state)
void conditional_stack_push(ConditionalStack cstack, ifState new_state)
Definition: conditional.c:41
FILE * queryFout
Definition: settings.h:84
static backslashResult exec_command(const char *cmd, PsqlScanState scan_state, ConditionalStack cstack, PQExpBuffer query_buf, PQExpBuffer previous_buf)
Definition: command.c:273
bool cur_cmd_interactive
Definition: settings.h:106
char * psql_scan_slash_option(PsqlScanState state, enum slash_option_type type, char *quote, bool semicolon)
#define free(a)
Definition: header.h:65
enum _backslashResult backslashResult
#define Assert(condition)
Definition: c.h:739
void * arg
#define pg_log_warning(...)
Definition: pgfnames.c:24
static void static void status(const char *fmt,...) pg_attribute_printf(1
Definition: pg_regress.c:226
#define pg_log_info(...)
Definition: logging.h:87

◆ process_file()

int process_file ( char *  filename,
bool  use_relative_path 
)

Definition at line 3612 of file command.c.

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().

3613 {
3614  FILE *fd;
3615  int result;
3616  char *oldfilename;
3617  char relpath[MAXPGPATH];
3618 
3619  if (!filename)
3620  {
3621  fd = stdin;
3622  filename = NULL;
3623  }
3624  else if (strcmp(filename, "-") != 0)
3625  {
3627 
3628  /*
3629  * If we were asked to resolve the pathname relative to the location
3630  * of the currently executing script, and there is one, and this is a
3631  * relative pathname, then prepend all but the last pathname component
3632  * of the current script to this pathname.
3633  */
3634  if (use_relative_path && pset.inputfile &&
3636  {
3637  strlcpy(relpath, pset.inputfile, sizeof(relpath));
3638  get_parent_directory(relpath);
3639  join_path_components(relpath, relpath, filename);
3640  canonicalize_path(relpath);
3641 
3642  filename = relpath;
3643  }
3644 
3645  fd = fopen(filename, PG_BINARY_R);
3646 
3647  if (!fd)
3648  {
3649  pg_log_error("%s: %m", filename);
3650  return EXIT_FAILURE;
3651  }
3652  }
3653  else
3654  {
3655  fd = stdin;
3656  filename = "<stdin>"; /* for future error messages */
3657  }
3658 
3659  oldfilename = pset.inputfile;
3661 
3663 
3664  result = MainLoop(fd);
3665 
3666  if (fd != stdin)
3667  fclose(fd);
3668 
3669  pset.inputfile = oldfilename;
3670 
3672 
3673  return result;
3674 }
PsqlSettings pset
Definition: startup.c:31
#define pg_log_error(...)
Definition: logging.h:79
void canonicalize_path(char *path)
Definition: path.c:254
char * inputfile
Definition: settings.h:109
#define PG_BINARY_R
Definition: c.h:1224
static int fd(const char *x, int i)
Definition: preproc-init.c:105
bool has_drive_prefix(const char *filename)
Definition: path.c:87
#define MAXPGPATH
#define is_absolute_path(filename)
Definition: port.h:86
void get_parent_directory(char *path)
Definition: path.c:854
size_t strlcpy(char *dst, const char *src, size_t siz)
Definition: strlcpy.c:45
int MainLoop(FILE *source)
Definition: mainloop.c:33
void pg_logging_config(int new_flags)
Definition: logging.c:102
void join_path_components(char *ret_path, const char *head, const char *tail)
Definition: path.c:218
static char * filename
Definition: pg_dumpall.c:90
#define PG_LOG_FLAG_TERSE
Definition: logging.h:64
#define relpath(rnode, forknum)
Definition: relpath.h:87
#define EXIT_FAILURE
Definition: settings.h:153

◆ SyncVariables()

void SyncVariables ( void  )

Definition at line 3319 of file command.c.

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().

3320 {
3321  char vbuf[32];
3322  const char *server_version;
3323 
3324  /* get stuff from connection */
3328 
3329  SetVariable(pset.vars, "DBNAME", PQdb(pset.db));
3330  SetVariable(pset.vars, "USER", PQuser(pset.db));
3331  SetVariable(pset.vars, "HOST", PQhost(pset.db));
3332  SetVariable(pset.vars, "PORT", PQport(pset.db));
3334 
3335  /* this bit should match connection_warnings(): */
3336  /* Try to get full text form of version, might include "devel" etc */
3337  server_version = PQparameterStatus(pset.db, "server_version");
3338  /* Otherwise fall back on pset.sversion */
3339  if (!server_version)
3340  {
3341  formatPGVersionNumber(pset.sversion, true, vbuf, sizeof(vbuf));
3342  server_version = vbuf;
3343  }
3344  SetVariable(pset.vars, "SERVER_VERSION_NAME", server_version);
3345 
3346  snprintf(vbuf, sizeof(vbuf), "%d", pset.sversion);
3347  SetVariable(pset.vars, "SERVER_VERSION_NUM", vbuf);
3348 
3349  /* send stuff to it, too */
3352 }
PGconn * db
Definition: settings.h:82
int encoding
Definition: print.h:120
PsqlSettings pset
Definition: startup.c:31
const char * PQparameterStatus(const PGconn *conn, const char *paramName)
Definition: fe-connect.c:6588
printTableOpt topt
Definition: print.h:167
char * PQport(const PGconn *conn)
Definition: fe-connect.c:6542
int PQserverVersion(const PGconn *conn)
Definition: fe-connect.c:6613
int PQclientEncoding(const PGconn *conn)
Definition: fe-connect.c:6683
char * PQuser(const PGconn *conn)
Definition: fe-connect.c:6481
PGContextVisibility show_context
Definition: settings.h:142
PGContextVisibility PQsetErrorContextVisibility(PGconn *conn, PGContextVisibility show_context)
Definition: fe-connect.c:6749
PGVerbosity verbosity
Definition: settings.h:141
char * PQhost(const PGconn *conn)
Definition: fe-connect.c:6506
const char * pg_encoding_to_char(int encoding)
Definition: encnames.c:607
char * PQdb(const PGconn *conn)
Definition: fe-connect.c:6473
bool SetVariable(VariableSpace space, const char *name, const char *value)
Definition: variables.c:211
printQueryOpt popt
Definition: settings.h:91
static int server_version
Definition: pg_dumpall.c:81
int encoding
Definition: settings.h:83
#define snprintf
Definition: port.h:192
PGVerbosity PQsetErrorVerbosity(PGconn *conn, PGVerbosity verbosity)
Definition: fe-connect.c:6737
char * formatPGVersionNumber(int version_number, bool include_minor, char *buf, size_t buflen)
Definition: string_utils.c:177
VariableSpace vars
Definition: settings.h:117

◆ UnsyncVariables()

void UnsyncVariables ( void  )

Definition at line 3360 of file command.c.

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

Referenced by CheckConnection(), and do_connect().

3361 {
3362  SetVariable(pset.vars, "DBNAME", NULL);
3363  SetVariable(pset.vars, "USER", NULL);
3364  SetVariable(pset.vars, "HOST", NULL);
3365  SetVariable(pset.vars, "PORT", NULL);
3366  SetVariable(pset.vars, "ENCODING", NULL);
3367  SetVariable(pset.vars, "SERVER_VERSION_NAME", NULL);
3368  SetVariable(pset.vars, "SERVER_VERSION_NUM", NULL);
3369 }
PsqlSettings pset
Definition: startup.c:31
bool SetVariable(VariableSpace space, const char *name, const char *value)
Definition: variables.c:211
VariableSpace vars
Definition: settings.h:117