Add new \w write command to psql.

This commit is contained in:
Bruce Momjian 1998-08-10 20:31:42 +00:00
parent 5e490118f8
commit ffb120ecc6
3 changed files with 66 additions and 39 deletions

View File

@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/bin/psql/Attic/psql.c,v 1.152 1998/08/06 05:12:55 momjian Exp $
* $Header: /cvsroot/pgsql/src/bin/psql/Attic/psql.c,v 1.153 1998/08/10 20:31:38 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@ -254,6 +254,7 @@ slashUsage(PsqlSettings *pset)
fprintf(fout, " \\t -- toggle table headings and row count (currently %s)\n", on(pset->opt.header));
fprintf(fout, " \\T [<html>] -- set html3.0 <table ...> options (currently '%s')\n", pset->opt.tableOpt ? pset->opt.tableOpt : "");
fprintf(fout, " \\x -- toggle expanded output (currently %s)\n", on(pset->opt.expanded));
fprintf(fout, " \\w <fname> -- output current buffer to a file\n");
fprintf(fout, " \\z -- list current grant/revoke permissions\n");
fprintf(fout, " \\! [<cmd>] -- shell escape or command\n");
@ -2135,13 +2136,34 @@ HandleSlashCmds(PsqlSettings *pset,
break;
}
case 'H':
if (toggle(pset, &pset->opt.html3, "HTML3.0 tabular output"))
pset->opt.standard = 0;
break;
case 'l': /* \l is list database */
listAllDbs(pset);
break;
case 'H':
if (toggle(pset, &pset->opt.html3, "HTML3.0 tabular output"))
pset->opt.standard = 0;
case 'm': /* monitor like type-setting */
if (toggle(pset, &pset->opt.standard, "standard SQL separaters and padding"))
{
pset->opt.html3 = pset->opt.expanded = 0;
pset->opt.align = pset->opt.header = 1;
if (pset->opt.fieldSep)
free(pset->opt.fieldSep);
pset->opt.fieldSep = strdup("|");
if (!pset->quiet)
printf("field separator changed to '%s'\n", pset->opt.fieldSep);
}
else
{
if (pset->opt.fieldSep)
free(pset->opt.fieldSep);
pset->opt.fieldSep = strdup(DEFAULT_FIELD_SEP);
if (!pset->quiet)
printf("field separator changed to '%s'\n", pset->opt.fieldSep);
}
break;
case 'o':
@ -2175,31 +2197,6 @@ HandleSlashCmds(PsqlSettings *pset,
#endif
break;
case 'm': /* monitor like type-setting */
if (toggle(pset, &pset->opt.standard, "standard SQL separaters and padding"))
{
pset->opt.html3 = pset->opt.expanded = 0;
pset->opt.align = pset->opt.header = 1;
if (pset->opt.fieldSep)
free(pset->opt.fieldSep);
pset->opt.fieldSep = strdup("|");
if (!pset->quiet)
printf("field separator changed to '%s'\n", pset->opt.fieldSep);
}
else
{
if (pset->opt.fieldSep)
free(pset->opt.fieldSep);
pset->opt.fieldSep = strdup(DEFAULT_FIELD_SEP);
if (!pset->quiet)
printf("field separator changed to '%s'\n", pset->opt.fieldSep);
}
break;
case 'z': /* list table rights (grant/revoke) */
rightsList(pset);
break;
case 't': /* toggle headers */
toggle(pset, &pset->opt.header, "output headings and row count");
break;
@ -2216,10 +2213,34 @@ HandleSlashCmds(PsqlSettings *pset,
}
break;
case 'w':
{
FILE *fd;
if (!optarg)
{
fprintf(stderr, "\\w must be followed by a file name\n");
break;
}
if ((fd = fopen(optarg, "w")) == NULL)
{
fprintf(stderr, "file named %s could not be opened\n", optarg);
break;
}
fputs(query, fd);
fputs("\n", fd);
fclose(fd);
break;
}
case 'x':
toggle(pset, &pset->opt.expanded, "expanded table representation");
break;
case 'z': /* list table rights (grant/revoke) */
rightsList(pset);
break;
case '!':
do_shell(optarg);
break;
@ -2252,13 +2273,17 @@ MainLoop(PsqlSettings *pset, char *query, FILE *source)
int successResult = 1;
int slashCmdStatus = CMD_SEND;
/*
* slashCmdStatus can be: CMD_UNKNOWN - send currently constructed
* query to backend (i.e. we got a \g) CMD_SEND - send
* currently constructed query to backend (i.e. we got a \g)
* CMD_SKIP_LINE - skip processing of this line, continue building
* up query CMD_TERMINATE - terminate processing of this query
* entirely CMD_NEWEDIT - new query supplied by edit
/*--------------------------------------------------------------
* slashCmdStatus can be:
* CMD_UNKNOWN - send currently constructed query to backend
* (i.e. we got a \g)
* CMD_SEND - send currently constructed query to backend
* (i.e. we got a \g)
* CMD_SKIP_LINE - skip processing of this line, continue building
* up query
* CMD_TERMINATE - terminate processing of this query entirely
* CMD_NEWEDIT - new query supplied by edit
*---------------------------------------------------------------
*/
bool querySent = false;
@ -2358,7 +2383,6 @@ MainLoop(PsqlSettings *pset, char *query, FILE *source)
* query - pointer to current command query_start - placeholder
* for next command
*/
if (line == NULL || (!interactive && *line == '\0'))
{ /* No more input. Time to quit, or \i
* done */

View File

@ -1,6 +1,6 @@
.\" This is -*-nroff-*-
.\" XXX standard disclaimer belongs here....
.\" $Header: /cvsroot/pgsql/src/man/Attic/psql.1,v 1.27 1998/08/03 05:54:30 momjian Exp $
.\" $Header: /cvsroot/pgsql/src/man/Attic/psql.1,v 1.28 1998/08/10 20:31:40 momjian Exp $
.TH PSQL UNIX 1/20/96 PostgreSQL PostgreSQL
.SH NAME
psql - run the interactive query front-end
@ -380,6 +380,9 @@ Toggles extended row format mode. When enabled each row will have its column
names printed on the left with the column values printed on the right.
This is useful for rows which are otherwise too long to fit into
one screen line. HTML row output mode supports this flag too.
.IP "\ew [\fIfilename\fR]"
Outputs current query buffer to
.IR filename .
.IP "\ez"
Produces a list of all tables in database with their appropriate ACLs
(grant/revoke permissions) listed.

View File

@ -162,7 +162,7 @@ HREF="../../backend/storage/ipc/shmem.c">ShmemInitHash().</A><P>
<ADDRESS>
Maintainer: Bruce Momjian (<A
HREF="mailto:maillist@candle.pha.pa.us">maillist@candle.pha.pa.us</A>)<BR>
Last updated: Tue Dec 9 17:56:08 EST 1997
Last updated: Mon Aug 10 10:48:06 EDT 1998
</ADDRESS>
</SMALL>
</BODY>