27 #include "catalog/pg_class_d.h"
79 bool show_verbose,
bool show_system);
131 const char *cmd,
bool is_func);
163 int lineno,
bool discard_on_quit,
bool *edited);
164 static bool do_shell(
const char *command);
181 static void checkWin32Codepage(
void);
223 Assert(scan_state != NULL);
230 status =
exec_command(cmd, scan_state, cstack, query_buf, previous_buf);
306 pg_log_warning(
"\\%s command ignored; use \\endif or Ctrl-C to exit current \\if block",
310 if (strcmp(cmd,
"a") == 0)
312 else if (strcmp(cmd,
"bind") == 0)
314 else if (strcmp(cmd,
"C") == 0)
316 else if (strcmp(cmd,
"c") == 0 || strcmp(cmd,
"connect") == 0)
318 else if (strcmp(cmd,
"cd") == 0)
320 else if (strcmp(cmd,
"conninfo") == 0)
324 else if (strcmp(cmd,
"copyright") == 0)
326 else if (strcmp(cmd,
"crosstabview") == 0)
328 else if (cmd[0] ==
'd')
330 else if (strcmp(cmd,
"e") == 0 || strcmp(cmd,
"edit") == 0)
332 query_buf, previous_buf);
333 else if (strcmp(cmd,
"ef") == 0)
335 else if (strcmp(cmd,
"ev") == 0)
337 else if (strcmp(cmd,
"echo") == 0 || strcmp(cmd,
"qecho") == 0 ||
338 strcmp(cmd,
"warn") == 0)
340 else if (strcmp(cmd,
"elif") == 0)
342 else if (strcmp(cmd,
"else") == 0)
344 else if (strcmp(cmd,
"endif") == 0)
346 else if (strcmp(cmd,
"encoding") == 0)
348 else if (strcmp(cmd,
"errverbose") == 0)
350 else if (strcmp(cmd,
"f") == 0)
352 else if (strcmp(cmd,
"g") == 0 || strcmp(cmd,
"gx") == 0)
354 else if (strcmp(cmd,
"gdesc") == 0)
356 else if (strcmp(cmd,
"getenv") == 0)
358 else if (strcmp(cmd,
"gexec") == 0)
360 else if (strcmp(cmd,
"gset") == 0)
362 else if (strcmp(cmd,
"h") == 0 || strcmp(cmd,
"help") == 0)
364 else if (strcmp(cmd,
"H") == 0 || strcmp(cmd,
"html") == 0)
366 else if (strcmp(cmd,
"i") == 0 || strcmp(cmd,
"include") == 0 ||
367 strcmp(cmd,
"ir") == 0 || strcmp(cmd,
"include_relative") == 0)
369 else if (strcmp(cmd,
"if") == 0)
371 else if (strcmp(cmd,
"l") == 0 || strcmp(cmd,
"list") == 0 ||
372 strcmp(cmd,
"l+") == 0 || strcmp(cmd,
"list+") == 0)
374 else if (strncmp(cmd,
"lo_", 3) == 0)
376 else if (strcmp(cmd,
"o") == 0 || strcmp(cmd,
"out") == 0)
378 else if (strcmp(cmd,
"p") == 0 || strcmp(cmd,
"print") == 0)
380 query_buf, previous_buf);
381 else if (strcmp(cmd,
"password") == 0)
383 else if (strcmp(cmd,
"prompt") == 0)
385 else if (strcmp(cmd,
"pset") == 0)
387 else if (strcmp(cmd,
"q") == 0 || strcmp(cmd,
"quit") == 0)
389 else if (strcmp(cmd,
"r") == 0 || strcmp(cmd,
"reset") == 0)
391 else if (strcmp(cmd,
"s") == 0)
393 else if (strcmp(cmd,
"set") == 0)
395 else if (strcmp(cmd,
"setenv") == 0)
397 else if (strcmp(cmd,
"sf") == 0 || strcmp(cmd,
"sf+") == 0)
399 else if (strcmp(cmd,
"sv") == 0 || strcmp(cmd,
"sv+") == 0)
401 else if (strcmp(cmd,
"t") == 0)
403 else if (strcmp(cmd,
"T") == 0)
405 else if (strcmp(cmd,
"timing") == 0)
407 else if (strcmp(cmd,
"unset") == 0)
409 else if (strcmp(cmd,
"w") == 0 || strcmp(cmd,
"write") == 0)
411 query_buf, previous_buf);
412 else if (strcmp(cmd,
"watch") == 0)
414 query_buf, previous_buf);
415 else if (strcmp(cmd,
"x") == 0)
417 else if (strcmp(cmd,
"z") == 0 || strcmp(cmd,
"zS") == 0)
419 else if (strcmp(cmd,
"!") == 0)
421 else if (strcmp(cmd,
"?") == 0)
478 if (nparams > nalloc)
480 nalloc = nalloc ? nalloc * 2 : 1;
538 static const char prefix[] =
"-reuse-previous=";
546 if (opt1 != NULL && strncmp(opt1, prefix,
sizeof(prefix) - 1) == 0)
601 dir = getenv(
"HOME");
602 if (dir == NULL || dir[0] ==
'\0')
604 uid_t user_id = geteuid();
608 pw = getpwuid(user_id);
613 pg_log_error(
"could not get home directory for user ID %ld: %s",
615 errno ?
strerror(errno) :
_(
"user does not exist"));
632 pg_log_error(
"\\%s: could not change directory to \"%s\": %m",
656 printf(
_(
"You are currently not connected to a database.\n"));
665 if (hostaddr && *hostaddr)
666 printf(
_(
"You are connected to database \"%s\" as user \"%s\" on address \"%s\" at port \"%s\".\n"),
669 printf(
_(
"You are connected to database \"%s\" as user \"%s\" via socket in \"%s\" at port \"%s\".\n"),
674 if (hostaddr && *hostaddr && strcmp(host, hostaddr) != 0)
675 printf(
_(
"You are connected to database \"%s\" as user \"%s\" on host \"%s\" (address \"%s\") at port \"%s\".\n"),
678 printf(
_(
"You are connected to database \"%s\" as user \"%s\" on host \"%s\" at port \"%s\".\n"),
766 show_verbose = strchr(cmd,
'+') ?
true :
false;
767 show_system = strchr(cmd,
'S') ?
true :
false;
782 char *pattern2 = NULL;
784 if (pattern && cmd[2] !=
'\0' && cmd[2] !=
'+')
820 if (strncmp(cmd,
"dconfig", 7) == 0)
833 if (strncmp(cmd,
"ddp", 3) == 0)
853 show_verbose, show_system);
875 show_verbose, show_system);
912 if (cmd[2] ==
'd' && cmd[3] ==
's')
914 char *pattern2 = NULL;
923 else if (cmd[2] ==
'g')
1018 const char *pattern,
1019 bool show_verbose,
bool show_system)
1023 int num_arg_patterns = 0;
1033 arg_patterns[num_arg_patterns++] = ap;
1041 arg_patterns, num_arg_patterns,
1042 show_verbose, show_system);
1045 arg_patterns, num_arg_patterns,
1046 show_verbose, show_system);
1048 while (--num_arg_patterns >= 0)
1049 free(arg_patterns[num_arg_patterns]);
1088 strspn(fname,
"0123456789") == strlen(fname))
1107 bool discard_on_quit;
1114 discard_on_quit =
true;
1127 if (
do_edit(fname, query_buf, lineno, discard_on_quit, NULL))
1189 "CREATE FUNCTION ( )\n"
1192 " -- common options: IMMUTABLE STABLE STRICT SECURITY DEFINER\n"
1199 " -- something...\n");
1211 else if (is_func && lineno > 0)
1222 const char *lines = query_buf->
data;
1224 while (*lines !=
'\0')
1226 if (strncmp(lines,
"AS ", 3) == 0 ||
1227 strncmp(lines,
"BEGIN ", 6) == 0 ||
1228 strncmp(lines,
"RETURN ", 7) == 0)
1232 lines = strchr(lines,
'\n');
1242 bool edited =
false;
1244 if (!
do_edit(NULL, query_buf, lineno,
true, &edited))
1247 puts(
_(
"No changes"));
1277 bool no_newline =
false;
1281 if (strcmp(cmd,
"qecho") == 0)
1283 else if (strcmp(cmd,
"warn") == 0)
1291 if (first && !no_newline && !quoted && strcmp(
value,
"-n") == 0)
1371 puts(
_(
"out of memory"));
1374 puts(
_(
"There is no previous error."));
1424 if (fname && fname[0] ==
'(')
1428 active_branch, cmd);
1444 if (strcmp(cmd,
"gx") == 0)
1466 bool active_branch,
const char *cmd)
1469 bool found_r_paren =
false;
1496 if (optlen > 0 &&
option[optlen - 1] ==
')')
1499 found_r_paren =
true;
1506 char *valptr = strchr(
option,
'=');
1521 first_option = NULL;
1524 }
while (!found_r_paren);
1569 if (!myvar || !envvar)
1576 char *envval = getenv(envvar);
1695 bool include_relative;
1697 include_relative = (strcmp(cmd,
"ir") == 0
1698 || strcmp(cmd,
"include_relative") == 0);
1959 show_verbose = strchr(cmd,
'+') ?
true :
false;
1990 if (strcmp(cmd + 3,
"export") == 0)
2004 else if (strcmp(cmd + 3,
"import") == 0)
2018 else if (strcmp(cmd + 3,
"list") == 0)
2020 else if (strcmp(cmd + 3,
"list+") == 0)
2023 else if (strcmp(cmd + 3,
"unlink") == 0)
2086 if (query_buf && query_buf->
len > 0)
2087 puts(query_buf->
data);
2088 else if (previous_buf && previous_buf->
len > 0)
2089 puts(previous_buf->
data);
2091 puts(
_(
"Query buffer is empty."));
2145 else if (strcmp(pw1, pw2) != 0)
2186 *prompt_text = NULL;
2224 fputs(prompt_text,
stdout);
2230 pg_log_error(
"\\%s: could not read value for variable",
2271 static const char *
const my_list[] = {
2272 "border",
"columns",
"csv_fieldsep",
"expanded",
"fieldsep",
2273 "fieldsep_zero",
"footer",
"format",
"linestyle",
"null",
2274 "numericlocale",
"pager",
"pager_min_lines",
2275 "recordsep",
"recordsep_zero",
2276 "tableattr",
"title",
"tuples_only",
2277 "unicode_border_linestyle",
2278 "unicode_column_linestyle",
2279 "unicode_header_linestyle",
2284 for (
i = 0; my_list[
i] != NULL;
i++)
2332 puts(
_(
"Query buffer reset (cleared)."));
2354 printf(
_(
"Wrote history to file \"%s\".\n"), fname);
2439 else if (strchr(envvar,
'=') != NULL)
2441 pg_log_error(
"\\%s: environment variable name must not contain \"=\"",
2454 setenv(envvar, envval, 1);
2471 const char *cmd,
bool is_func)
2477 bool show_linenumbers = (strchr(cmd,
'+') != NULL);
2525 if (show_linenumbers)
2613 puts(
_(
"Timing is on."));
2615 puts(
_(
"Timing is off."));
2670 bool is_pipe =
false;
2687 if (fname[0] ==
'|')
2692 fd = popen(&fname[1],
"w");
2697 fd = fopen(fname,
"w");
2717 if (query_buf && query_buf->
len > 0)
2719 else if (previous_buf && previous_buf->
len > 0)
2724 result = pclose(
fd);
2735 result = fclose(
fd);
2768 bool have_sleep =
false;
2769 bool have_iter =
false;
2770 bool have_min_rows =
false;
2790 valptr = strchr(opt,
'=');
2795 if (strncmp(
"i=", opt, strlen(
"i=")) == 0 ||
2796 strncmp(
"interval=", opt, strlen(
"interval=")) == 0)
2800 pg_log_error(
"\\watch: interval value is specified more than once");
2807 sleep = strtod(valptr, &opt_end);
2808 if (sleep < 0 || *opt_end || errno == ERANGE)
2810 pg_log_error(
"\\watch: incorrect interval value \"%s\"", valptr);
2815 else if (strncmp(
"c=", opt, strlen(
"c=")) == 0 ||
2816 strncmp(
"count=", opt, strlen(
"count=")) == 0)
2820 pg_log_error(
"\\watch: iteration count is specified more than once");
2827 iter =
strtoint(valptr, &opt_end, 10);
2828 if (iter <= 0 || *opt_end || errno == ERANGE)
2830 pg_log_error(
"\\watch: incorrect iteration count \"%s\"", valptr);
2835 else if (strncmp(
"m=", opt, strlen(
"m=")) == 0 ||
2836 strncmp(
"min_rows=", opt, strlen(
"min_rows=")) == 0)
2840 pg_log_error(
"\\watch: minimum row count specified more than once");
2845 have_min_rows =
true;
2847 min_rows =
strtoint(valptr, &opt_end, 10);
2848 if (min_rows <= 0 || *opt_end || errno == ERANGE)
2850 pg_log_error(
"\\watch: incorrect minimum row count \"%s\"", valptr);
2857 pg_log_error(
"\\watch: unrecognized parameter \"%s\"", opt);
2866 pg_log_error(
"\\watch: interval value is specified more than once");
2873 sleep = strtod(opt, &opt_end);
2874 if (sleep < 0 || *opt_end || errno == ERANGE)
2876 pg_log_error(
"\\watch: incorrect interval value \"%s\"", opt);
2942 show_system = strchr(cmd,
'S') ?
true :
false;
2987 if (!opt0 || strcmp(opt0,
"commands") == 0)
2989 else if (strcmp(opt0,
"options") == 0)
2991 else if (strcmp(opt0,
"variables") == 0)
3033 if (*result ==
'\0' || strcmp(result,
"-") == 0)
3054 int num_options = 0;
3062 if (num_options > 0)
3165 return (strcmp(cmd,
"if") == 0 ||
3166 strcmp(cmd,
"elif") == 0 ||
3167 strcmp(cmd,
"else") == 0 ||
3168 strcmp(cmd,
"endif") == 0);
3206 Assert(new_len >= 0 && new_len <= query_buf->
len);
3207 query_buf->
len = new_len;
3208 query_buf->
data[new_len] =
'\0';
3227 if (query_buf && query_buf->
len == 0)
3273 if (new_val == NULL)
3276 if (old_val == NULL || strcmp(old_val, new_val) != 0)
3301 bool same_host =
false;
3303 char *client_encoding;
3305 bool keep_password =
true;
3306 bool has_connection_string;
3307 bool reuse_previous;
3309 has_connection_string =
dbname ?
3313 if (has_connection_string && (
user || host ||
port))
3315 pg_log_error(
"Do not give user, host, or port separately when using a connection string");
3319 switch (reuse_previous_specification)
3322 reuse_previous =
true;
3325 reuse_previous =
false;
3328 reuse_previous = !has_connection_string;
3350 pg_log_error(
"No database connection exists to re-use parameters from");
3359 if (has_connection_string)
3370 bool have_password =
false;
3372 for (ci = cinfo, replci = replcinfo;
3385 char *swap = replci->
val;
3397 if (replci->
val == NULL ||
3398 strcmp(ci->
val, replci->
val) != 0)
3400 if (strcmp(replci->
keyword,
"user") == 0 ||
3401 strcmp(replci->
keyword,
"host") == 0 ||
3402 strcmp(replci->
keyword,
"hostaddr") == 0 ||
3403 strcmp(replci->
keyword,
"port") == 0)
3404 keep_password =
false;
3407 if (strcmp(replci->
keyword,
"password") == 0)
3408 have_password =
true;
3410 else if (!reuse_previous)
3433 nconnopts = ci - cinfo;
3443 keep_password =
true;
3478 for (ci = cinfo; ci->
keyword; ci++)
3482 if (!(ci->
val && strcmp(
user, ci->
val) == 0))
3483 keep_password =
false;
3485 else if (host && strcmp(ci->
keyword,
"host") == 0)
3487 if (ci->
val && strcmp(host, ci->
val) == 0)
3490 keep_password =
false;
3492 else if (
port && strcmp(ci->
keyword,
"port") == 0)
3494 if (!(ci->
val && strcmp(
port, ci->
val) == 0))
3495 keep_password =
false;
3500 nconnopts = ci - cinfo;
3522 bool canceled =
false;
3541 if (
pset.
notty || getenv(
"PGCLIENTENCODING"))
3542 client_encoding = NULL;
3544 client_encoding =
"auto";
3549 const char **keywords =
pg_malloc((nconnopts + 1) *
sizeof(*keywords));
3563 for (ci = cinfo; ci->
keyword; ci++)
3565 keywords[paramnum] = ci->
keyword;
3569 else if (
user && strcmp(ci->
keyword,
"user") == 0)
3571 else if (host && strcmp(ci->
keyword,
"host") == 0)
3572 values[paramnum++] = host;
3573 else if (host && !same_host && strcmp(ci->
keyword,
"hostaddr") == 0)
3576 values[paramnum++] = NULL;
3578 else if (
port && strcmp(ci->
keyword,
"port") == 0)
3581 else if ((
password || !keep_password) &&
3582 strcmp(ci->
keyword,
"password") == 0)
3584 else if (strcmp(ci->
keyword,
"fallback_application_name") == 0)
3586 else if (client_encoding &&
3587 strcmp(ci->
keyword,
"client_encoding") == 0)
3588 values[paramnum++] = client_encoding;
3594 keywords[paramnum] = NULL;
3612 bool canceled =
false;
3717 if (hostaddr && *hostaddr)
3718 printf(
_(
"You are now connected to database \"%s\" as user \"%s\" on address \"%s\" at port \"%s\".\n"),
3721 printf(
_(
"You are now connected to database \"%s\" as user \"%s\" via socket in \"%s\" at port \"%s\".\n"),
3726 if (hostaddr && *hostaddr && strcmp(connhost, hostaddr) != 0)
3727 printf(
_(
"You are now connected to database \"%s\" as user \"%s\" on host \"%s\" (address \"%s\") at port \"%s\".\n"),
3730 printf(
_(
"You are now connected to database \"%s\" as user \"%s\" on host \"%s\" at port \"%s\".\n"),
3735 printf(
_(
"You are now connected to database \"%s\" as user \"%s\".\n"),
3757 int client_ver = PG_VERSION_NUM;
3771 sverbuf,
sizeof(sverbuf));
3775 printf(
_(
"%s (%s, server %s)\n"),
3779 else if (in_startup)
3788 printf(
_(
"WARNING: %s major version %s, server major version %s.\n"
3789 " Some psql features might not work.\n"),
3792 cverbuf,
sizeof(cverbuf)),
3794 sverbuf,
sizeof(sverbuf)));
3798 checkWin32Codepage();
3814 const char *protocol;
3816 const char *compression;
3825 printf(
_(
"SSL connection (protocol: %s, cipher: %s, compression: %s)\n"),
3826 protocol ? protocol :
_(
"unknown"),
3827 cipher ? cipher :
_(
"unknown"),
3828 (compression && strcmp(compression,
"off") != 0) ?
_(
"on") :
_(
"off"));
3842 printf(
_(
"GSSAPI-encrypted connection\n"));
3853 checkWin32Codepage(
void)
3859 concp = GetConsoleCP();
3862 printf(
_(
"WARNING: Console code page (%u) differs from Windows code page (%u)\n"
3863 " 8-bit characters might not work correctly. See psql reference\n"
3864 " page \"Notes for Windows users\" for details.\n"),
3941 const char *editorName;
3942 const char *editor_lineno_arg = NULL;
3949 editorName = getenv(
"PSQL_EDITOR");
3951 editorName = getenv(
"EDITOR");
3953 editorName = getenv(
"VISUAL");
3960 editor_lineno_arg = getenv(
"PSQL_EDITOR_LINENUMBER_ARG");
3961 #ifdef DEFAULT_EDITOR_LINENUMBER_ARG
3962 if (!editor_lineno_arg)
3965 if (!editor_lineno_arg)
3967 pg_log_error(
"environment variable PSQL_EDITOR_LINENUMBER_ARG must be set to specify a line number");
3981 sys =
psprintf(
"exec %s %s%d '%s'",
3982 editorName, editor_lineno_arg, lineno, fname);
3988 sys =
psprintf(
"\"%s\" %s%d \"%s\"",
3989 editorName, editor_lineno_arg, lineno, fname);
3995 result = system(sys);
3997 pg_log_error(
"could not start editor \"%s\"", editorName);
3998 else if (result == 127)
4022 int lineno,
bool discard_on_quit,
bool *edited)
4025 FILE *stream = NULL;
4033 fname = filename_arg;
4038 const char *tmpdir = getenv(
"TMPDIR");
4049 pg_log_error(
"could not locate temporary directory: %s",
4061 snprintf(fnametmp,
sizeof(fnametmp),
"%s%spsql.edit.%d.sql", tmpdir,
4062 "/", (
int) getpid());
4064 snprintf(fnametmp,
sizeof(fnametmp),
"%s%spsql.edit.%d.sql", tmpdir,
4065 "" , (
int) getpid());
4068 fname = (
const char *) fnametmp;
4070 fd = open(fname, O_WRONLY | O_CREAT | O_EXCL, 0600);
4072 stream = fdopen(
fd,
"w");
4074 if (
fd == -1 || !stream)
4076 pg_log_error(
"could not open temporary file \"%s\": %m", fname);
4081 unsigned int ql = query_buf->
len;
4084 if (ql > 0 && query_buf->
data[ql - 1] !=
'\n')
4090 if (fwrite(query_buf->
data, 1, ql, stream) != ql)
4094 if (fclose(stream) != 0)
4097 if (remove(fname) != 0)
4102 else if (fclose(stream) != 0)
4105 if (remove(fname) != 0)
4124 ut.modtime = ut.actime = time(NULL) - 2;
4125 (void) utime(fname, &ut);
4163 while (fgets(line,
sizeof(line), stream) != NULL)
4186 if (discard_on_quit)
4193 if (remove(fname) == -1)
4228 else if (strcmp(
filename,
"-") != 0)
4306 return "latex-longtable";
4376 vallen = strlen(
value);
4379 if (strcmp(param,
"format") == 0)
4381 static const struct fmt
4412 pg_log_error(
"\\pset: ambiguous abbreviation \"%s\" matches both \"%s\" and \"%s\"",
4414 formats[match_pos].
name, formats[
i].
name);
4420 popt->
topt.
format = formats[match_pos].number;
4432 pg_log_error(
"\\pset: allowed formats are aligned, asciidoc, csv, html, latex, latex-longtable, troff-ms, unaligned, wrapped");
4439 else if (strcmp(param,
"linestyle") == 0)
4451 pg_log_error(
"\\pset: allowed line styles are ascii, old-ascii, unicode");
4457 else if (strcmp(param,
"unicode_border_linestyle") == 0)
4466 pg_log_error(
"\\pset: allowed Unicode border line styles are single, double");
4472 else if (strcmp(param,
"unicode_column_linestyle") == 0)
4481 pg_log_error(
"\\pset: allowed Unicode column line styles are single, double");
4487 else if (strcmp(param,
"unicode_header_linestyle") == 0)
4496 pg_log_error(
"\\pset: allowed Unicode header line styles are single, double");
4502 else if (strcmp(param,
"border") == 0)
4509 else if (strcmp(param,
"x") == 0 ||
4510 strcmp(param,
"expanded") == 0 ||
4511 strcmp(param,
"vertical") == 0)
4532 else if (strcmp(param,
"xheader_width") == 0)
4544 int intval = atoi(
value);
4548 pg_log_error(
"\\pset: allowed xheader_width values are \"%s\" (default), \"%s\", \"%s\", or a number specifying the exact width",
"full",
"column",
"page");
4558 else if (strcmp(param,
"csv_fieldsep") == 0)
4563 if (strlen(
value) != 1)
4565 pg_log_error(
"\\pset: csv_fieldsep must be a single one-byte character");
4570 pg_log_error(
"\\pset: csv_fieldsep cannot be a double quote, a newline, or a carriage return");
4578 else if (strcmp(param,
"numericlocale") == 0)
4587 else if (strcmp(param,
"null") == 0)
4597 else if (strcmp(param,
"fieldsep") == 0)
4607 else if (strcmp(param,
"fieldsep_zero") == 0)
4615 else if (strcmp(param,
"recordsep") == 0)
4625 else if (strcmp(param,
"recordsep_zero") == 0)
4633 else if (strcmp(param,
"t") == 0 || strcmp(param,
"tuples_only") == 0)
4642 else if (strcmp(param,
"C") == 0 || strcmp(param,
"title") == 0)
4652 else if (strcmp(param,
"T") == 0 || strcmp(param,
"tableattr") == 0)
4662 else if (strcmp(param,
"pager") == 0)
4684 else if (strcmp(param,
"pager_min_lines") == 0)
4692 else if (strcmp(param,
"footer") == 0)
4701 else if (strcmp(param,
"columns") == 0)
4727 if (strcmp(param,
"border") == 0)
4731 else if (strcmp(param,
"columns") == 0)
4734 printf(
_(
"Target width is unset.\n"));
4740 else if (strcmp(param,
"x") == 0 || strcmp(param,
"expanded") == 0 || strcmp(param,
"vertical") == 0)
4743 printf(
_(
"Expanded display is on.\n"));
4745 printf(
_(
"Expanded display is used automatically.\n"));
4747 printf(
_(
"Expanded display is off.\n"));
4751 else if (strcmp(param,
"xheader_width") == 0)
4754 printf(
_(
"Expanded header width is \"%s\".\n"),
"full");
4756 printf(
_(
"Expanded header width is \"%s\".\n"),
"column");
4758 printf(
_(
"Expanded header width is \"%s\".\n"),
"page");
4764 else if (strcmp(param,
"csv_fieldsep") == 0)
4766 printf(
_(
"Field separator for CSV is \"%s\".\n"),
4771 else if (strcmp(param,
"fieldsep") == 0)
4774 printf(
_(
"Field separator is zero byte.\n"));
4776 printf(
_(
"Field separator is \"%s\".\n"),
4780 else if (strcmp(param,
"fieldsep_zero") == 0)
4782 printf(
_(
"Field separator is zero byte.\n"));
4786 else if (strcmp(param,
"footer") == 0)
4789 printf(
_(
"Default footer is on.\n"));
4791 printf(
_(
"Default footer is off.\n"));
4795 else if (strcmp(param,
"format") == 0)
4801 else if (strcmp(param,
"linestyle") == 0)
4803 printf(
_(
"Line style is %s.\n"),
4808 else if (strcmp(param,
"null") == 0)
4810 printf(
_(
"Null display is \"%s\".\n"),
4815 else if (strcmp(param,
"numericlocale") == 0)
4818 printf(
_(
"Locale-adjusted numeric output is on.\n"));
4820 printf(
_(
"Locale-adjusted numeric output is off.\n"));
4824 else if (strcmp(param,
"pager") == 0)
4827 printf(
_(
"Pager is used for long output.\n"));
4829 printf(
_(
"Pager is always used.\n"));
4831 printf(
_(
"Pager usage is off.\n"));
4835 else if (strcmp(param,
"pager_min_lines") == 0)
4838 "Pager won't be used for less than %d lines.\n",
4844 else if (strcmp(param,
"recordsep") == 0)
4847 printf(
_(
"Record separator is zero byte.\n"));
4849 printf(
_(
"Record separator is <newline>.\n"));
4851 printf(
_(
"Record separator is \"%s\".\n"),
4855 else if (strcmp(param,
"recordsep_zero") == 0)
4857 printf(
_(
"Record separator is zero byte.\n"));
4861 else if (strcmp(param,
"T") == 0 || strcmp(param,
"tableattr") == 0)
4864 printf(
_(
"Table attributes are \"%s\".\n"),
4867 printf(
_(
"Table attributes unset.\n"));
4871 else if (strcmp(param,
"C") == 0 || strcmp(param,
"title") == 0)
4876 printf(
_(
"Title is unset.\n"));
4880 else if (strcmp(param,
"t") == 0 || strcmp(param,
"tuples_only") == 0)
4883 printf(
_(
"Tuples only is on.\n"));
4885 printf(
_(
"Tuples only is off.\n"));
4889 else if (strcmp(param,
"unicode_border_linestyle") == 0)
4891 printf(
_(
"Unicode border line style is \"%s\".\n"),
4895 else if (strcmp(param,
"unicode_column_linestyle") == 0)
4897 printf(
_(
"Unicode column line style is \"%s\".\n"),
4901 else if (strcmp(param,
"unicode_header_linestyle") == 0)
4903 printf(
_(
"Unicode header line style is \"%s\".\n"),
4986 return val ?
"on" :
"off";
5005 else if (*
str ==
'\'')
5033 if (strcmp(param,
"border") == 0)
5035 else if (strcmp(param,
"columns") == 0)
5037 else if (strcmp(param,
"csv_fieldsep") == 0)
5039 else if (strcmp(param,
"expanded") == 0)
5043 else if (strcmp(param,
"fieldsep") == 0)
5047 else if (strcmp(param,
"fieldsep_zero") == 0)
5049 else if (strcmp(param,
"footer") == 0)
5051 else if (strcmp(param,
"format") == 0)
5053 else if (strcmp(param,
"linestyle") == 0)
5055 else if (strcmp(param,
"null") == 0)
5059 else if (strcmp(param,
"numericlocale") == 0)
5061 else if (strcmp(param,
"pager") == 0)
5063 else if (strcmp(param,
"pager_min_lines") == 0)
5065 else if (strcmp(param,
"recordsep") == 0)
5069 else if (strcmp(param,
"recordsep_zero") == 0)
5071 else if (strcmp(param,
"tableattr") == 0)
5073 else if (strcmp(param,
"title") == 0)
5075 else if (strcmp(param,
"tuples_only") == 0)
5077 else if (strcmp(param,
"unicode_border_linestyle") == 0)
5079 else if (strcmp(param,
"unicode_column_linestyle") == 0)
5081 else if (strcmp(param,
"unicode_header_linestyle") == 0)
5083 else if (strcmp(param,
"xheader_width") == 0)
5096 snprintf(wbuff,
sizeof(wbuff),
"%d",
5108 #define DEFAULT_SHELL "/bin/sh"
5114 #define DEFAULT_SHELL "cmd.exe"
5126 const char *shellName;
5128 shellName = getenv(
"SHELL");
5130 if (shellName == NULL)
5131 shellName = getenv(
"COMSPEC");
5133 if (shellName == NULL)
5138 sys =
psprintf(
"exec %s", shellName);
5140 sys =
psprintf(
"\"%s\"", shellName);
5142 result = system(sys);
5146 result = system(command);
5150 if (result == 127 || result == -1)
5167 long sleep_ms = (long) (sleep * 1000);
5169 const char *strftime_fmt;
5170 const char *user_title;
5172 const char *pagerprog = NULL;
5173 FILE *pagerpipe = NULL;
5178 sigset_t sigalrm_sigchld_sigint;
5179 sigset_t sigalrm_sigchld;
5184 if (!query_buf || query_buf->
len <= 0)
5186 pg_log_error(
"\\watch cannot be used with an empty query");
5191 sigemptyset(&sigalrm_sigchld_sigint);
5192 sigaddset(&sigalrm_sigchld_sigint,
SIGCHLD);
5193 sigaddset(&sigalrm_sigchld_sigint,
SIGALRM);
5194 sigaddset(&sigalrm_sigchld_sigint, SIGINT);
5196 sigemptyset(&sigalrm_sigchld);
5197 sigaddset(&sigalrm_sigchld,
SIGCHLD);
5198 sigaddset(&sigalrm_sigchld,
SIGALRM);
5200 sigemptyset(&sigint);
5201 sigaddset(&sigint, SIGINT);
5207 sigprocmask(SIG_BLOCK, &sigalrm_sigchld, NULL);
5232 pagerprog = getenv(
"PSQL_WATCH_PAGER");
5234 if (pagerprog && strspn(pagerprog,
" \t\r\n") == strlen(pagerprog))
5238 isatty(fileno(stdin)) && isatty(fileno(
stdout)))
5242 pagerpipe = popen(pagerprog,
"w");
5254 strftime_fmt =
"%c";
5268 user_title = myopt.
title;
5269 title_len = (user_title ? strlen(user_title) : 0) + 256;
5284 strftime(timebuf,
sizeof(timebuf), strftime_fmt, localtime(&timer));
5287 snprintf(title, title_len,
_(
"%s\t%s (every %gs)\n"),
5288 user_title, timebuf, sleep);
5290 snprintf(title, title_len,
_(
"%s (every %gs)\n"),
5292 myopt.
title = title;
5305 if (iter && (--iter <= 0))
5309 if (pagerpipe && ferror(pagerpipe))
5324 long s =
Min(
i, 1000L);
5336 sigprocmask(SIG_BLOCK, &sigint, NULL);
5343 int signal_received;
5345 errno = sigwait(&sigalrm_sigchld_sigint, &signal_received);
5359 if (signal_received == SIGINT || signal_received ==
SIGCHLD)
5366 sigprocmask(SIG_UNBLOCK, &sigint, NULL);
5393 sigprocmask(SIG_UNBLOCK, &sigalrm_sigchld_sigint, NULL);
5409 printf(
_(
"/******** QUERY *********/\n"
5411 "/************************/\n\n"), query);
5416 _(
"/******** QUERY *********/\n"
5418 "/************************/\n\n"), query);
5456 strchr(desc,
'(') ?
"regprocedure" :
"regproc");
5508 "SELECT pg_catalog.pg_get_functiondef(%u)",
5529 "SELECT nspname, relname, relkind, "
5530 "pg_catalog.pg_get_viewdef(c.oid, true), "
5531 "pg_catalog.array_remove(pg_catalog.array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, "
5532 "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text "
5533 "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption "
5534 "FROM pg_catalog.pg_class c "
5535 "LEFT JOIN pg_catalog.pg_namespace n "
5536 "ON c.relnamespace = n.oid WHERE c.oid = %u",
5542 "SELECT nspname, relname, relkind, "
5543 "pg_catalog.pg_get_viewdef(c.oid, true), "
5544 "c.reloptions AS reloptions, "
5545 "NULL AS checkoption "
5546 "FROM pg_catalog.pg_class c "
5547 "LEFT JOIN pg_catalog.pg_namespace n "
5548 "ON c.relnamespace = n.oid WHERE c.oid = %u",
5587 case RELKIND_MATVIEW:
5604 if (reloptions != NULL && strlen(reloptions) > 2)
5621 if (
buf->len > 0 &&
buf->data[
buf->len - 1] ==
';')
5622 buf->data[--(
buf->len)] =
'\0';
5625 if (checkoption && checkoption[0] !=
'\0')
5632 if (
buf->len > 0 &&
buf->data[
buf->len - 1] !=
'\n')
5662 if (!obj || obj[0] ==
'\0')
5665 c = obj + strlen(obj) - 1;
5678 while (
c > obj && isascii((
unsigned char) *
c) && isspace((
unsigned char) *
c))
5682 if (
c == obj || !isascii((
unsigned char) *
c) || !isdigit((
unsigned char) *
c))
5686 while (
c > obj && isascii((
unsigned char) *
c) && isdigit((
unsigned char) *
c))
5691 if (
c == obj || !isascii((
unsigned char) *
c) ||
5692 !(isspace((
unsigned char) *
c) || *
c ==
')'))
5718 const char *lines =
buf->data;
5720 while (*lines !=
'\0')
5724 lines = strchr(lines,
'\n');
5747 bool in_header = is_func;
5750 while (*lines !=
'\0')
5755 (strncmp(lines,
"AS ", 3) == 0 ||
5756 strncmp(lines,
"BEGIN ", 6) == 0 ||
5757 strncmp(lines,
"RETURN ", 7) == 0))
5765 eol = strchr(lines,
'\n');
void expand_tilde(char **filename)
volatile sig_atomic_t sigint_interrupt_enabled
PGresult * PSQLexec(const char *query)
sigjmp_buf sigint_interrupt_jmp
int PSQLexecWatch(const char *query, const printQueryOpt *opt, FILE *printQueryFout, int min_rows)
void SetShellResultVariables(int wait_result)
void NoticeProcessor(void *arg, const char *message)
bool standard_strings(void)
bool setQFout(const char *fname)
bool recognized_connection_string(const char *connstr)
bool do_copy(const char *args)
static Datum values[MAXATTR]
#define ngettext(s, p, n)
void ResetCancelConn(void)
static backslashResult exec_command_endif(PsqlScanState scan_state, ConditionalStack cstack, PQExpBuffer query_buf)
static backslashResult exec_command_copyright(PsqlScanState scan_state, bool active_branch)
static backslashResult exec_command_errverbose(PsqlScanState scan_state, bool active_branch)
int process_file(char *filename, bool use_relative_path)
static backslashResult exec_command_print(PsqlScanState scan_state, bool active_branch, PQExpBuffer query_buf, PQExpBuffer previous_buf)
static bool get_create_object_cmd(EditableObjectType obj_type, Oid oid, PQExpBuffer buf)
static backslashResult exec_command_html(PsqlScanState scan_state, bool active_branch)
static bool copy_previous_query(PQExpBuffer query_buf, PQExpBuffer previous_buf)
static backslashResult exec_command_g(PsqlScanState scan_state, bool active_branch, const char *cmd)
static char * pset_value_string(const char *param, printQueryOpt *popt)
static backslashResult exec_command_T(PsqlScanState scan_state, bool active_branch)
static char * prompt_for_password(const char *username, bool *canceled)
static backslashResult exec_command_gdesc(PsqlScanState scan_state, bool active_branch)
static char * pset_quoted_string(const char *str)
static backslashResult exec_command_help(PsqlScanState scan_state, bool active_branch)
static void discard_query_text(PsqlScanState scan_state, ConditionalStack cstack, PQExpBuffer query_buf)
static bool set_unicode_line_style(const char *value, size_t vallen, unicode_linestyle *linestyle)
void restorePsetInfo(printQueryOpt *popt, printQueryOpt *save)
static backslashResult exec_command_a(PsqlScanState scan_state, bool active_branch)
static void ignore_boolean_expression(PsqlScanState scan_state)
static bool do_watch(PQExpBuffer query_buf, double sleep, int iter, int min_rows)
static backslashResult exec_command_bind(PsqlScanState scan_state, bool active_branch)
static PQExpBuffer gather_boolean_expression(PsqlScanState scan_state)
static backslashResult exec_command_password(PsqlScanState scan_state, bool active_branch)
static bool is_true_boolean_expression(PsqlScanState scan_state, const char *name)
static bool do_edit(const char *filename_arg, PQExpBuffer query_buf, int lineno, bool discard_on_quit, bool *edited)
static backslashResult exec_command_x(PsqlScanState scan_state, bool active_branch)
static backslashResult exec_command_if(PsqlScanState scan_state, ConditionalStack cstack, PQExpBuffer query_buf)
static backslashResult exec_command_elif(PsqlScanState scan_state, ConditionalStack cstack, PQExpBuffer query_buf)
static bool param_is_newly_set(const char *old_val, const char *new_val)
static void ignore_slash_whole_line(PsqlScanState scan_state)
static const char * _align2string(enum printFormat in)
static backslashResult exec_command_f(PsqlScanState scan_state, bool active_branch)
static backslashResult exec_command_reset(PsqlScanState scan_state, bool active_branch, PQExpBuffer query_buf)
static backslashResult exec_command_out(PsqlScanState scan_state, bool active_branch)
static bool do_connect(enum trivalue reuse_previous_specification, char *dbname, char *user, char *host, char *port)
static bool lookup_object_oid(EditableObjectType obj_type, const char *desc, Oid *obj_oid)
static backslashResult exec_command_echo(PsqlScanState scan_state, bool active_branch, const char *cmd)
static backslashResult exec_command_d(PsqlScanState scan_state, bool active_branch, const char *cmd)
static int count_lines_in_buf(PQExpBuffer buf)
static bool echo_hidden_command(const char *query)
static void save_query_text_state(PsqlScanState scan_state, ConditionalStack cstack, PQExpBuffer query_buf)
static backslashResult exec_command_shell_escape(PsqlScanState scan_state, bool active_branch)
bool do_pset(const char *param, const char *value, printQueryOpt *popt, bool quiet)
static backslashResult exec_command_cd(PsqlScanState scan_state, bool active_branch, const char *cmd)
static backslashResult exec_command_gset(PsqlScanState scan_state, bool active_branch)
static void printSSLInfo(void)
static backslashResult exec_command_ef_ev(PsqlScanState scan_state, bool active_branch, PQExpBuffer query_buf, bool is_func)
static backslashResult exec_command_unset(PsqlScanState scan_state, bool active_branch, const char *cmd)
static void ignore_slash_filepipe(PsqlScanState scan_state)
static backslashResult exec_command_set(PsqlScanState scan_state, bool active_branch)
static bool printPsetInfo(const char *param, printQueryOpt *popt)
static char * read_connect_arg(PsqlScanState scan_state)
static const char * pset_bool_string(bool val)
static backslashResult exec_command_s(PsqlScanState scan_state, bool active_branch)
backslashResult HandleSlashCmds(PsqlScanState scan_state, ConditionalStack cstack, PQExpBuffer query_buf, PQExpBuffer previous_buf)
static backslashResult exec_command_prompt(PsqlScanState scan_state, bool active_branch, const char *cmd)
static backslashResult exec_command_watch(PsqlScanState scan_state, bool active_branch, PQExpBuffer query_buf, PQExpBuffer previous_buf)
static backslashResult exec_command_include(PsqlScanState scan_state, bool active_branch, const char *cmd)
static backslashResult exec_command_list(PsqlScanState scan_state, bool active_branch, const char *cmd)
static bool editFile(const char *fname, int lineno)
static backslashResult exec_command_timing(PsqlScanState scan_state, bool active_branch)
static bool exec_command_dfo(PsqlScanState scan_state, const char *cmd, const char *pattern, bool show_verbose, bool show_system)
void UnsyncVariables(void)
static backslashResult exec_command_C(PsqlScanState scan_state, bool active_branch)
static backslashResult exec_command_encoding(PsqlScanState scan_state, bool active_branch)
static backslashResult exec_command_edit(PsqlScanState scan_state, bool active_branch, PQExpBuffer query_buf, PQExpBuffer previous_buf)
static backslashResult exec_command_else(PsqlScanState scan_state, ConditionalStack cstack, PQExpBuffer query_buf)
static backslashResult exec_command_conninfo(PsqlScanState scan_state, bool active_branch)
static bool do_shell(const char *command)
static backslashResult exec_command_copy(PsqlScanState scan_state, bool active_branch)
static backslashResult exec_command_slash_command_help(PsqlScanState scan_state, bool active_branch)
static backslashResult exec_command_crosstabview(PsqlScanState scan_state, bool active_branch)
static backslashResult exec_command_pset(PsqlScanState scan_state, bool active_branch)
static void ignore_slash_options(PsqlScanState scan_state)
static backslashResult exec_command_t(PsqlScanState scan_state, bool active_branch)
static backslashResult exec_command(const char *cmd, PsqlScanState scan_state, ConditionalStack cstack, PQExpBuffer query_buf, PQExpBuffer previous_buf)
void connection_warnings(bool in_startup)
static backslashResult exec_command_write(PsqlScanState scan_state, bool active_branch, const char *cmd, PQExpBuffer query_buf, PQExpBuffer previous_buf)
static void minimal_error_message(PGresult *res)
static backslashResult exec_command_sf_sv(PsqlScanState scan_state, bool active_branch, const char *cmd, bool is_func)
static bool is_branching_command(const char *cmd)
static backslashResult exec_command_connect(PsqlScanState scan_state, bool active_branch)
static void print_with_linenumbers(FILE *output, char *lines, bool is_func)
static const char * _unicode_linestyle2string(int linestyle)
static int strip_lineno_from_objdesc(char *obj)
static backslashResult exec_command_gexec(PsqlScanState scan_state, bool active_branch)
static backslashResult exec_command_z(PsqlScanState scan_state, bool active_branch, const char *cmd)
static backslashResult exec_command_lo(PsqlScanState scan_state, bool active_branch, const char *cmd)
static backslashResult exec_command_getenv(PsqlScanState scan_state, bool active_branch, const char *cmd)
static backslashResult exec_command_quit(PsqlScanState scan_state, bool active_branch)
printQueryOpt * savePsetInfo(const printQueryOpt *popt)
static backslashResult process_command_g_options(char *first_option, PsqlScanState scan_state, bool active_branch, const char *cmd)
static void printGSSInfo(void)
static backslashResult exec_command_setenv(PsqlScanState scan_state, bool active_branch, const char *cmd)
enum _backslashResult backslashResult
void conditional_stack_set_paren_depth(ConditionalStack cstack, int depth)
ifState conditional_stack_peek(ConditionalStack cstack)
void conditional_stack_push(ConditionalStack cstack, ifState new_state)
bool conditional_stack_pop(ConditionalStack cstack)
void conditional_stack_set_query_len(ConditionalStack cstack, int len)
int conditional_stack_get_query_len(ConditionalStack cstack)
bool conditional_active(ConditionalStack cstack)
int conditional_stack_get_paren_depth(ConditionalStack cstack)
bool conditional_stack_poke(ConditionalStack cstack, ifState new_state)
static void PGresult * res
bool listUserMappings(const char *pattern, bool verbose)
bool listTSConfigs(const char *pattern, bool verbose)
bool describeRoles(const char *pattern, bool verbose, bool showSystem)
bool listOpFamilyFunctions(const char *access_method_pattern, const char *family_pattern, bool verbose)
bool listPublications(const char *pattern)
bool listTSParsers(const char *pattern, bool verbose)
bool listExtensionContents(const char *pattern)
bool describeAggregates(const char *pattern, bool verbose, bool showSystem)
bool listForeignDataWrappers(const char *pattern, bool verbose)
bool listPartitionedTables(const char *reltypes, const char *pattern, bool verbose)
bool describeSubscriptions(const char *pattern, bool verbose)
bool describeRoleGrants(const char *pattern, bool showSystem)
bool listExtendedStats(const char *pattern)
bool describeTypes(const char *pattern, bool verbose, bool showSystem)
bool listOperatorFamilies(const char *access_method_pattern, const char *type_pattern, bool verbose)
bool listForeignServers(const char *pattern, bool verbose)
bool describeTableDetails(const char *pattern, bool verbose, bool showSystem)
bool listDomains(const char *pattern, bool verbose, bool showSystem)
bool listTSDictionaries(const char *pattern, bool verbose)
bool listDbRoleSettings(const char *pattern, const char *pattern2)
bool describeFunctions(const char *functypes, const char *func_pattern, char **arg_patterns, int num_arg_patterns, bool verbose, bool showSystem)
bool listCollations(const char *pattern, bool verbose, bool showSystem)
bool listSchemas(const char *pattern, bool verbose, bool showSystem)
bool listExtensions(const char *pattern)
bool listTables(const char *tabtypes, const char *pattern, bool verbose, bool showSystem)
bool listTSTemplates(const char *pattern, bool verbose)
bool describeTablespaces(const char *pattern, bool verbose)
bool listCasts(const char *pattern, bool verbose)
bool listOpFamilyOperators(const char *access_method_pattern, const char *family_pattern, bool verbose)
bool describeOperators(const char *oper_pattern, char **arg_patterns, int num_arg_patterns, bool verbose, bool showSystem)
bool listOperatorClasses(const char *access_method_pattern, const char *type_pattern, bool verbose)
bool listForeignTables(const char *pattern, bool verbose)
bool describeConfigurationParameters(const char *pattern, bool verbose, bool showSystem)
bool listEventTriggers(const char *pattern, bool verbose)
bool listDefaultACLs(const char *pattern)
bool listAllDbs(const char *pattern, bool verbose)
bool listConversions(const char *pattern, bool verbose, bool showSystem)
bool permissionsList(const char *pattern, bool showSystem)
bool describeAccessMethods(const char *pattern, bool verbose)
bool listLargeObjects(bool verbose)
bool listLanguages(const char *pattern, bool verbose, bool showSystem)
bool describePublications(const char *pattern)
bool objectDescription(const char *pattern, bool showSystem)
int errmsg(const char *fmt,...)
PGresult * PQchangePassword(PGconn *conn, const char *user, const char *passwd)
const char * PQparameterStatus(const PGconn *conn, const char *paramName)
int PQserverVersion(const PGconn *conn)
PQconninfoOption * PQconninfoParse(const char *conninfo, char **errmsg)
char * PQhost(const PGconn *conn)
PGconn * PQconnectdbParams(const char *const *keywords, const char *const *values, int expand_dbname)
char * PQdb(const PGconn *conn)
PQconninfoOption * PQconndefaults(void)
char * PQhostaddr(const PGconn *conn)
void PQconninfoFree(PQconninfoOption *connOptions)
PQconninfoOption * PQconninfo(PGconn *conn)
int PQconnectionNeedsPassword(const PGconn *conn)
char * PQerrorMessage(const PGconn *conn)
ConnStatusType PQstatus(const PGconn *conn)
int PQclientEncoding(const PGconn *conn)
void PQfinish(PGconn *conn)
PGContextVisibility PQsetErrorContextVisibility(PGconn *conn, PGContextVisibility show_context)
char * PQuser(const PGconn *conn)
char * PQport(const PGconn *conn)
PGVerbosity PQsetErrorVerbosity(PGconn *conn, PGVerbosity verbosity)
PQnoticeProcessor PQsetNoticeProcessor(PGconn *conn, PQnoticeProcessor proc, void *arg)
int PQsetClientEncoding(PGconn *conn, const char *encoding)
void PQfreemem(void *ptr)
ExecStatusType PQresultStatus(const PGresult *res)
int PQntuples(const PGresult *res)
PGresult * PQexec(PGconn *conn, const char *query)
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
char * PQresultErrorField(const PGresult *res, int fieldcode)
char * PQresultVerboseErrorMessage(const PGresult *res, PGVerbosity verbosity, PGContextVisibility show_context)
int PQgssEncInUse(PGconn *conn)
const char * PQsslAttribute(PGconn *conn, const char *attribute_name)
int PQsslInUse(PGconn *conn)
void * pg_realloc(void *ptr, size_t size)
char * pg_strdup(const char *in)
void * pg_malloc(size_t size)
#define pg_realloc_array(pointer, type, count)
void restore_sigpipe_trap(void)
void refresh_utf8format(const printTableOpt *opt)
const printTextFormat pg_asciiformat
void ClosePager(FILE *pagerpipe)
const printTextFormat pg_asciiformat_old
void disable_sigpipe_trap(void)
FILE * PageOutput(int lines, const printTableOpt *topt)
const printTextFormat * get_line_style(const printTableOpt *opt)
printTextFormat pg_utf8format
volatile sig_atomic_t cancel_pressed
@ PRINT_XHEADER_EXACT_WIDTH
@ UNICODE_LINESTYLE_SINGLE
@ UNICODE_LINESTYLE_DOUBLE
void slashUsage(unsigned short int pager)
void helpVariables(unsigned short int pager)
void helpSQL(const char *topic, unsigned short int pager)
void print_copyright(void)
bool do_lo_export(const char *loid_arg, const char *filename_arg)
bool do_lo_import(const char *filename_arg, const char *comment_arg)
bool do_lo_unlink(const char *loid_arg)
static void const char * fmt
static void const char fflush(stdout)
Assert(fmt[strlen(fmt) - 1] !='\n')
void pg_logging_config(int new_flags)
#define pg_log_error(...)
#define pg_log_error_hint(...)
#define PG_LOG_FLAG_TERSE
int MainLoop(FILE *source)
char * pstrdup(const char *in)
static int server_version
#define pg_encoding_to_char
#define pg_log_warning(...)
void join_path_components(char *ret_path, const char *head, const char *tail)
#define is_absolute_path(filename)
int pg_strcasecmp(const char *s1, const char *s2)
void canonicalize_path(char *path)
void get_parent_directory(char *path)
bool has_drive_prefix(const char *path)
size_t strlcpy(char *dst, const char *src, size_t siz)
int pg_strncasecmp(const char *s1, const char *s2, size_t n)
#define PG_DIAG_MESSAGE_PRIMARY
static bool is_unixsock_path(const char *path)
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
PQExpBuffer createPQExpBuffer(void)
void initPQExpBuffer(PQExpBuffer str)
void resetPQExpBuffer(PQExpBuffer str)
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
void destroyPQExpBuffer(PQExpBuffer str)
void appendPQExpBufferChar(PQExpBuffer str, char ch)
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
void termPQExpBuffer(PQExpBuffer str)
static int fd(const char *x, int i)
char * psprintf(const char *fmt,...)
void psql_scan_reset(PsqlScanState state)
char * psql_scan_slash_command(PsqlScanState state)
void psql_scan_slash_command_end(PsqlScanState state)
void psql_scan_set_paren_depth(PsqlScanState state, int depth)
int psql_scan_get_paren_depth(PsqlScanState state)
char * psql_scan_slash_option(PsqlScanState state, enum slash_option_type type, char *quote, bool semicolon)
static int before(chr x, chr y)
#define relpath(rlocator, forknum)
#define DEFAULT_EDITOR_LINENUMBER_ARG
@ PSQL_ECHO_HIDDEN_NOEXEC
void pg_usleep(long microsec)
char * simple_prompt_extended(const char *prompt, bool echo, PromptInterruptContext *prompt_ctx)
int strtoint(const char *pg_restrict str, char **pg_restrict endptr, int base)
void appendStringLiteralConn(PQExpBuffer buf, const char *str, PGconn *conn)
const char * fmtId(const char *rawid)
bool appendReloptionsArray(PQExpBuffer buffer, const char *reloptions, const char *prefix, int encoding, bool std_strings)
char * formatPGVersionNumber(int version_number, bool include_minor, char *buf, size_t buflen)
volatile sig_atomic_t * enabled
PGresult * last_error_result
enum trivalue getPassword
PGContextVisibility show_context
PSQL_ECHO_HIDDEN echo_hidden
printQueryOpt * gsavepopt
const bool * translate_columns
unsigned short int expanded
unicode_linestyle unicode_border_linestyle
struct separator fieldSep
int expanded_header_exact_width
struct separator recordSep
printXheaderWidthType expanded_header_width_type
const printTextFormat * line_style
unsigned short int border
unicode_linestyle unicode_header_linestyle
unicode_linestyle unicode_column_linestyle
int setitimer(int which, const struct itimerval *value, struct itimerval *ovalue)
static void usage(const char *progname)
void PrintVariables(VariableSpace space)
void PsqlVarEnumError(const char *name, const char *value, const char *suggestions)
bool ParseVariableBool(const char *value, const char *name, bool *result)
bool ParseVariableNum(const char *value, const char *name, int *result)
bool SetVariable(VariableSpace space, const char *name, const char *value)
char * wait_result_to_str(int exitstatus)