Commit ffb120ec authored by Bruce Momjian's avatar Bruce Momjian

Add new \w write command to psql.

parent 5e490118
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * 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) ...@@ -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 -- 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, " \\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, " \\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, " \\z -- list current grant/revoke permissions\n");
fprintf(fout, " \\! [<cmd>] -- shell escape or command\n"); fprintf(fout, " \\! [<cmd>] -- shell escape or command\n");
...@@ -2135,13 +2136,34 @@ HandleSlashCmds(PsqlSettings *pset, ...@@ -2135,13 +2136,34 @@ HandleSlashCmds(PsqlSettings *pset,
break; break;
} }
case 'H':
if (toggle(pset, &pset->opt.html3, "HTML3.0 tabular output"))
pset->opt.standard = 0;
break;
case 'l': /* \l is list database */ case 'l': /* \l is list database */
listAllDbs(pset); listAllDbs(pset);
break; break;
case 'H': case 'm': /* monitor like type-setting */
if (toggle(pset, &pset->opt.html3, "HTML3.0 tabular output")) if (toggle(pset, &pset->opt.standard, "standard SQL separaters and padding"))
pset->opt.standard = 0; {
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; break;
case 'o': case 'o':
...@@ -2175,31 +2197,6 @@ HandleSlashCmds(PsqlSettings *pset, ...@@ -2175,31 +2197,6 @@ HandleSlashCmds(PsqlSettings *pset,
#endif #endif
break; 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 */ case 't': /* toggle headers */
toggle(pset, &pset->opt.header, "output headings and row count"); toggle(pset, &pset->opt.header, "output headings and row count");
break; break;
...@@ -2216,10 +2213,34 @@ HandleSlashCmds(PsqlSettings *pset, ...@@ -2216,10 +2213,34 @@ HandleSlashCmds(PsqlSettings *pset,
} }
break; 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': case 'x':
toggle(pset, &pset->opt.expanded, "expanded table representation"); toggle(pset, &pset->opt.expanded, "expanded table representation");
break; break;
case 'z': /* list table rights (grant/revoke) */
rightsList(pset);
break;
case '!': case '!':
do_shell(optarg); do_shell(optarg);
break; break;
...@@ -2252,13 +2273,17 @@ MainLoop(PsqlSettings *pset, char *query, FILE *source) ...@@ -2252,13 +2273,17 @@ MainLoop(PsqlSettings *pset, char *query, FILE *source)
int successResult = 1; int successResult = 1;
int slashCmdStatus = CMD_SEND; int slashCmdStatus = CMD_SEND;
/* /*--------------------------------------------------------------
* slashCmdStatus can be: CMD_UNKNOWN - send currently constructed * slashCmdStatus can be:
* query to backend (i.e. we got a \g) CMD_SEND - send * CMD_UNKNOWN - send currently constructed query to backend
* currently constructed query to backend (i.e. we got a \g) * (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 * CMD_SKIP_LINE - skip processing of this line, continue building
* up query CMD_TERMINATE - terminate processing of this query * up query
* entirely CMD_NEWEDIT - new query supplied by edit * CMD_TERMINATE - terminate processing of this query entirely
* CMD_NEWEDIT - new query supplied by edit
*---------------------------------------------------------------
*/ */
bool querySent = false; bool querySent = false;
...@@ -2358,7 +2383,6 @@ MainLoop(PsqlSettings *pset, char *query, FILE *source) ...@@ -2358,7 +2383,6 @@ MainLoop(PsqlSettings *pset, char *query, FILE *source)
* query - pointer to current command query_start - placeholder * query - pointer to current command query_start - placeholder
* for next command * for next command
*/ */
if (line == NULL || (!interactive && *line == '\0')) if (line == NULL || (!interactive && *line == '\0'))
{ /* No more input. Time to quit, or \i { /* No more input. Time to quit, or \i
* done */ * done */
......
.\" This is -*-nroff-*- .\" This is -*-nroff-*-
.\" XXX standard disclaimer belongs here.... .\" 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 .TH PSQL UNIX 1/20/96 PostgreSQL PostgreSQL
.SH NAME .SH NAME
psql - run the interactive query front-end psql - run the interactive query front-end
...@@ -380,6 +380,9 @@ Toggles extended row format mode. When enabled each row will have its column ...@@ -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. 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 This is useful for rows which are otherwise too long to fit into
one screen line. HTML row output mode supports this flag too. one screen line. HTML row output mode supports this flag too.
.IP "\ew [\fIfilename\fR]"
Outputs current query buffer to
.IR filename .
.IP "\ez" .IP "\ez"
Produces a list of all tables in database with their appropriate ACLs Produces a list of all tables in database with their appropriate ACLs
(grant/revoke permissions) listed. (grant/revoke permissions) listed.
......
...@@ -162,7 +162,7 @@ HREF="../../backend/storage/ipc/shmem.c">ShmemInitHash().</A><P> ...@@ -162,7 +162,7 @@ HREF="../../backend/storage/ipc/shmem.c">ShmemInitHash().</A><P>
<ADDRESS> <ADDRESS>
Maintainer: Bruce Momjian (<A Maintainer: Bruce Momjian (<A
HREF="mailto:maillist@candle.pha.pa.us">maillist@candle.pha.pa.us</A>)<BR> 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> </ADDRESS>
</SMALL> </SMALL>
</BODY> </BODY>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment