mirror of
https://github.com/postgres/postgres.git
synced 2025-07-11 10:01:57 +03:00
psql: Add PAGER for \h and \?,\C fix, indices spell fix.
This commit is contained in:
@ -7,7 +7,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $Header: /cvsroot/pgsql/src/bin/psql/Attic/psql.c,v 1.77 1997/07/14 22:08:56 momjian Exp $
|
* $Header: /cvsroot/pgsql/src/bin/psql/Attic/psql.c,v 1.78 1997/07/24 20:01:33 momjian Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -153,40 +153,52 @@ on(bool f)
|
|||||||
static void
|
static void
|
||||||
slashUsage(PsqlSettings * ps)
|
slashUsage(PsqlSettings * ps)
|
||||||
{
|
{
|
||||||
int ch;
|
int usePipe = 0;
|
||||||
|
char *pagerenv;
|
||||||
fprintf(stderr, " \\? -- help\n");
|
FILE *fout;
|
||||||
fprintf(stderr, " \\a -- toggle field-alignment (currenty %s)\n", on(ps->opt.align));
|
|
||||||
fprintf(stderr, " \\C [<captn>] -- set html3 caption (currently '%s')\n", ps->opt.caption ? ps->opt.caption : "");
|
|
||||||
fprintf(stderr, " \\connect <dbname|-> <user> -- connect to new database (currently '%s')\n", PQdb(ps->db));
|
|
||||||
fprintf(stderr, " \\copy table {from | to} <fname>\n");
|
|
||||||
fprintf(stderr, " \\d [<table>] -- list tables and indicies in database or columns in <table>, * for all\n");
|
|
||||||
fprintf(stderr, " \\di -- list only indicies in database\n");
|
|
||||||
fprintf(stderr, " \\ds -- list only sequences in database\n");
|
|
||||||
fprintf(stderr, " \\dt -- list only tables in database\n");
|
|
||||||
fprintf(stderr, " \\e [<fname>] -- edit the current query buffer or <fname>, \\E execute too\n");
|
|
||||||
fprintf(stderr, " \\f [<sep>] -- change field separater (currently '%s')\n", ps->opt.fieldSep);
|
|
||||||
fprintf(stderr, " \\g [<fname>] [|<cmd>] -- send query to backend [and results in <fname> or pipe]\n");
|
|
||||||
fprintf(stderr, " \\h [<cmd>] -- help on syntax of sql commands, * for all commands\n");
|
|
||||||
fprintf(stderr, " \\H -- toggle html3 output (currently %s)\n", on(ps->opt.html3));
|
|
||||||
fprintf(stderr, " \\i <fname> -- read and execute queries from filename\n");
|
|
||||||
fprintf(stderr, " \\l -- list all databases\n");
|
|
||||||
fprintf(stderr, " \\m -- toggle monitor-like table display (currently %s)\n", on(ps->opt.standard));
|
|
||||||
fprintf(stderr, " \\o [<fname>] [|<cmd>] -- send all query results to stdout, <fname>, or pipe\n");
|
|
||||||
fprintf(stderr, " \\p -- print the current query buffer\n");
|
|
||||||
|
|
||||||
fprintf(stderr, "Press ENTER to continue");
|
if ((pagerenv = getenv("PAGER")) && (pagerenv[0] != '\0') && \
|
||||||
/* eat up any extra characters typed before ENTER */
|
(fout = popen(pagerenv, "w")))
|
||||||
while ((ch = fgetc(stdin)) != '\r' && ch != '\n')
|
{
|
||||||
;
|
usePipe = 1;
|
||||||
fprintf(stderr, " \\q -- quit\n");
|
pqsignal(SIGPIPE, SIG_IGN);
|
||||||
fprintf(stderr, " \\r -- reset(clear) the query buffer\n");
|
}
|
||||||
fprintf(stderr, " \\s [<fname>] -- print history or save it in <fname>\n");
|
else
|
||||||
fprintf(stderr, " \\t -- toggle table headings and row count (currently %s)\n", on(ps->opt.header));
|
fout = stderr;
|
||||||
fprintf(stderr, " \\T [<html>] -- set html3.0 <table ...> options (currently '%s')\n", ps->opt.tableOpt ? ps->opt.tableOpt : "");
|
|
||||||
fprintf(stderr, " \\x -- toggle expanded output (currently %s)\n", on(ps->opt.expanded));
|
fprintf(fout, " \\? -- help\n");
|
||||||
fprintf(stderr, " \\z -- list current grant/revoke permissions\n");
|
fprintf(fout, " \\a -- toggle field-alignment (currenty %s)\n", on(ps->opt.align));
|
||||||
fprintf(stderr, " \\! [<cmd>] -- shell escape or command\n");
|
fprintf(fout, " \\C [<captn>] -- set html3 caption (currently '%s')\n", ps->opt.caption ? ps->opt.caption : "");
|
||||||
|
fprintf(fout, " \\connect <dbname|-> <user> -- connect to new database (currently '%s')\n", PQdb(ps->db));
|
||||||
|
fprintf(fout, " \\copy table {from | to} <fname>\n");
|
||||||
|
fprintf(fout, " \\d [<table>] -- list tables and indices in database or columns in <table>, * for all\n");
|
||||||
|
fprintf(fout, " \\di -- list only indices in database\n");
|
||||||
|
fprintf(fout, " \\ds -- list only sequences in database\n");
|
||||||
|
fprintf(fout, " \\dt -- list only tables in database\n");
|
||||||
|
fprintf(fout, " \\e [<fname>] -- edit the current query buffer or <fname>, \\E execute too\n");
|
||||||
|
fprintf(fout, " \\f [<sep>] -- change field separater (currently '%s')\n", ps->opt.fieldSep);
|
||||||
|
fprintf(fout, " \\g [<fname>] [|<cmd>] -- send query to backend [and results in <fname> or pipe]\n");
|
||||||
|
fprintf(fout, " \\h [<cmd>] -- help on syntax of sql commands, * for all commands\n");
|
||||||
|
fprintf(fout, " \\H -- toggle html3 output (currently %s)\n", on(ps->opt.html3));
|
||||||
|
fprintf(fout, " \\i <fname> -- read and execute queries from filename\n");
|
||||||
|
fprintf(fout, " \\l -- list all databases\n");
|
||||||
|
fprintf(fout, " \\m -- toggle monitor-like table display (currently %s)\n", on(ps->opt.standard));
|
||||||
|
fprintf(fout, " \\o [<fname>] [|<cmd>] -- send all query results to stdout, <fname>, or pipe\n");
|
||||||
|
fprintf(fout, " \\p -- print the current query buffer\n");
|
||||||
|
fprintf(fout, " \\q -- quit\n");
|
||||||
|
fprintf(fout, " \\r -- reset(clear) the query buffer\n");
|
||||||
|
fprintf(fout, " \\s [<fname>] -- print history or save it in <fname>\n");
|
||||||
|
fprintf(fout, " \\t -- toggle table headings and row count (currently %s)\n", on(ps->opt.header));
|
||||||
|
fprintf(fout, " \\T [<html>] -- set html3.0 <table ...> options (currently '%s')\n", ps->opt.tableOpt ? ps->opt.tableOpt : "");
|
||||||
|
fprintf(fout, " \\x -- toggle expanded output (currently %s)\n", on(ps->opt.expanded));
|
||||||
|
fprintf(fout, " \\z -- list current grant/revoke permissions\n");
|
||||||
|
fprintf(fout, " \\! [<cmd>] -- shell escape or command\n");
|
||||||
|
|
||||||
|
if (usePipe)
|
||||||
|
{
|
||||||
|
pclose(fout);
|
||||||
|
pqsignal(SIGPIPE, SIG_DFL);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static PGresult *
|
static PGresult *
|
||||||
@ -326,12 +338,12 @@ tableList(PsqlSettings * ps, bool deep_tablelist, char info_type)
|
|||||||
switch (info_type) {
|
switch (info_type) {
|
||||||
case 't': fprintf(stderr, "Couldn't find any tables!\n");
|
case 't': fprintf(stderr, "Couldn't find any tables!\n");
|
||||||
break;
|
break;
|
||||||
case 'i': fprintf(stderr, "Couldn't find any indicies!\n");
|
case 'i': fprintf(stderr, "Couldn't find any indices!\n");
|
||||||
break;
|
break;
|
||||||
case 'S': fprintf(stderr, "Couldn't find any sequences!\n");
|
case 'S': fprintf(stderr, "Couldn't find any sequences!\n");
|
||||||
break;
|
break;
|
||||||
case 'b':
|
case 'b':
|
||||||
default: fprintf(stderr, "Couldn't find any tables, sequences or indicies!\n");
|
default: fprintf(stderr, "Couldn't find any tables, sequences or indices!\n");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return (-1);
|
return (-1);
|
||||||
@ -1030,18 +1042,38 @@ do_help(const char *topic)
|
|||||||
int i; /* Index into QL_HELP[] */
|
int i; /* Index into QL_HELP[] */
|
||||||
bool help_found; /* We found the help he asked for */
|
bool help_found; /* We found the help he asked for */
|
||||||
|
|
||||||
|
int usePipe = 0;
|
||||||
|
char *pagerenv;
|
||||||
|
FILE *fout;
|
||||||
|
|
||||||
|
if ((pagerenv = getenv("PAGER")) && (pagerenv[0] != '\0') && \
|
||||||
|
(fout = popen(pagerenv, "w")))
|
||||||
|
{
|
||||||
|
usePipe = 1;
|
||||||
|
pqsignal(SIGPIPE, SIG_IGN);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
fout = stderr;
|
||||||
|
|
||||||
help_found = false; /* Haven't found it yet */
|
help_found = false; /* Haven't found it yet */
|
||||||
for (i = 0; QL_HELP[i].cmd; i++) {
|
for (i = 0; QL_HELP[i].cmd; i++) {
|
||||||
if (strcmp(QL_HELP[i].cmd, topic) == 0 ||
|
if (strcmp(QL_HELP[i].cmd, topic) == 0 ||
|
||||||
strcmp(topic, "*") == 0) {
|
strcmp(topic, "*") == 0) {
|
||||||
help_found = true;
|
help_found = true;
|
||||||
printf("Command: %s\n", QL_HELP[i].cmd);
|
fprintf(fout, "Command: %s\n", QL_HELP[i].cmd);
|
||||||
printf("Description: %s\n", QL_HELP[i].help);
|
fprintf(fout, "Description: %s\n", QL_HELP[i].help);
|
||||||
printf("Syntax:\n");
|
fprintf(fout, "Syntax:\n");
|
||||||
printf("%s\n", QL_HELP[i].syntax);
|
fprintf(fout, "%s\n", QL_HELP[i].syntax);
|
||||||
printf("\n");
|
fprintf(fout, "\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (usePipe)
|
||||||
|
{
|
||||||
|
pclose(fout);
|
||||||
|
pqsignal(SIGPIPE, SIG_DFL);
|
||||||
|
}
|
||||||
|
|
||||||
if (!help_found)
|
if (!help_found)
|
||||||
printf("command not found, "
|
printf("command not found, "
|
||||||
"try \\h with no arguments to see available help\n");
|
"try \\h with no arguments to see available help\n");
|
||||||
@ -1145,14 +1177,11 @@ HandleSlashCmds(PsqlSettings * settings,
|
|||||||
break;
|
break;
|
||||||
case 'C': /* define new caption */
|
case 'C': /* define new caption */
|
||||||
if (settings->opt.caption)
|
if (settings->opt.caption)
|
||||||
free(settings->opt.caption);
|
|
||||||
if (!optarg)
|
|
||||||
{
|
{
|
||||||
if (settings->opt.caption)
|
free(settings->opt.caption);
|
||||||
free(settings->opt.caption);
|
|
||||||
settings->opt.caption = NULL;
|
settings->opt.caption = NULL;
|
||||||
}
|
}
|
||||||
else if (!(settings->opt.caption = strdup(optarg))) {
|
if (optarg && !(settings->opt.caption = strdup(optarg))) {
|
||||||
perror("malloc");
|
perror("malloc");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
@ -1198,11 +1227,11 @@ HandleSlashCmds(PsqlSettings * settings,
|
|||||||
case 'd': /* \d describe tables or columns in a table */
|
case 'd': /* \d describe tables or columns in a table */
|
||||||
if (strncmp(cmd, "dt", 2) == 0) { /* only tables */
|
if (strncmp(cmd, "dt", 2) == 0) { /* only tables */
|
||||||
tableList(settings, 0, 't');
|
tableList(settings, 0, 't');
|
||||||
} else if (strncmp(cmd, "di", 2) == 0) { /* only indicies */
|
} else if (strncmp(cmd, "di", 2) == 0) { /* only indices */
|
||||||
tableList(settings, 0, 'i');
|
tableList(settings, 0, 'i');
|
||||||
} else if (strncmp(cmd, "ds", 2) == 0) { /* only sequences */
|
} else if (strncmp(cmd, "ds", 2) == 0) { /* only sequences */
|
||||||
tableList(settings, 0, 'S');
|
tableList(settings, 0, 'S');
|
||||||
} else if (!optarg) { /* show tables, sequences and indicies */
|
} else if (!optarg) { /* show tables, sequences and indices */
|
||||||
tableList(settings, 0, 'b');
|
tableList(settings, 0, 'b');
|
||||||
} else if (strcmp(optarg, "*") == 0) { /* show everything */
|
} else if (strcmp(optarg, "*") == 0) { /* show everything */
|
||||||
tableList(settings, 0, 'b');
|
tableList(settings, 0, 'b');
|
||||||
|
Reference in New Issue
Block a user