提交 07781160 编写于 作者: N Neil Conway

Per discussion on -hackers, this patch changes psql's "expanded" output

mode to only affect the presentation of normal query results, not the
output of psql slash commands. Documentation updated. I also made
some unrelated minor psql cleanup. Per suggestion from Stuart Cooper.
上级 8c05ca77
<!-- <!--
$PostgreSQL: pgsql/doc/src/sgml/ref/psql-ref.sgml,v 1.143 2005/06/13 02:40:08 neilc Exp $ $PostgreSQL: pgsql/doc/src/sgml/ref/psql-ref.sgml,v 1.144 2005/06/13 06:36:22 neilc Exp $
PostgreSQL documentation PostgreSQL documentation
--> -->
...@@ -433,8 +433,8 @@ PostgreSQL documentation ...@@ -433,8 +433,8 @@ PostgreSQL documentation
<term><option>--expanded</></term> <term><option>--expanded</></term>
<listitem> <listitem>
<para> <para>
Turn on the extended table formatting mode. This is equivalent to the Turn on the expanded table formatting mode. This is equivalent to the
command <command>\x</command>. <command>\x</command> command.
</para> </para>
</listitem> </listitem>
</varlistentry> </varlistentry>
...@@ -1389,7 +1389,7 @@ lo_import 152801 ...@@ -1389,7 +1389,7 @@ lo_import 152801
<literal>aligned</literal>, <literal>html</literal>, <literal>aligned</literal>, <literal>html</literal>,
<literal>latex</literal>, or <literal>troff-ms</literal>. <literal>latex</literal>, or <literal>troff-ms</literal>.
Unique abbreviations are allowed. (That would mean one letter Unique abbreviations are allowed. (That would mean one letter
is enough.) is enough.)
</para> </para>
<para> <para>
...@@ -1429,10 +1429,13 @@ lo_import 152801 ...@@ -1429,10 +1429,13 @@ lo_import 152801
<listitem> <listitem>
<para> <para>
Toggles between regular and expanded format. When expanded Toggles between regular and expanded format. When expanded
format is enabled, all output has two columns with the column format is enabled, query results are displayed in two
name on the left and the data on the right. This mode is columns, with the column name on the left and the data on
useful if the data wouldn't fit on the screen in the normal the right. This option only affects how normal query results
<quote>horizontal</quote> mode. are displayed; the output of <application>psql</application>
meta-commands is always presented using the regular
format. This mode is useful if the data wouldn't fit on the
screen in the normal <quote>horizontal</quote> mode.
</para> </para>
<para> <para>
...@@ -1722,7 +1725,7 @@ lo_import 152801 ...@@ -1722,7 +1725,7 @@ lo_import 152801
<term><literal>\x</literal></term> <term><literal>\x</literal></term>
<listitem> <listitem>
<para> <para>
Toggles extended table formatting mode. As such it is equivalent to Toggles expanded table formatting mode. As such it is equivalent to
<literal>\pset expanded</literal>. <literal>\pset expanded</literal>.
</para> </para>
</listitem> </listitem>
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
* *
* Copyright (c) 2000-2005, PostgreSQL Global Development Group * Copyright (c) 2000-2005, PostgreSQL Global Development Group
* *
* $PostgreSQL: pgsql/src/bin/psql/command.c,v 1.145 2005/06/09 23:28:09 momjian Exp $ * $PostgreSQL: pgsql/src/bin/psql/command.c,v 1.146 2005/06/13 06:36:22 neilc Exp $
*/ */
#include "postgres_fe.h" #include "postgres_fe.h"
#include "command.h" #include "command.h"
...@@ -114,11 +114,6 @@ HandleSlashCmds(PsqlScanState scan_state, ...@@ -114,11 +114,6 @@ HandleSlashCmds(PsqlScanState scan_state,
{ {
/* adjust cmd for possible messages below */ /* adjust cmd for possible messages below */
cmd[1] = '\0'; cmd[1] = '\0';
#if 0 /* turned out to be too annoying */
if (isalpha((unsigned char) cmd[0]))
psql_error("Warning: This syntax is deprecated.\n");
#endif
} }
} }
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
* *
* Copyright (c) 2000-2005, PostgreSQL Global Development Group * Copyright (c) 2000-2005, PostgreSQL Global Development Group
* *
* $PostgreSQL: pgsql/src/bin/psql/common.c,v 1.100 2005/06/10 14:49:31 momjian Exp $ * $PostgreSQL: pgsql/src/bin/psql/common.c,v 1.101 2005/06/13 06:36:22 neilc Exp $
*/ */
#include "postgres_fe.h" #include "postgres_fe.h"
#include "common.h" #include "common.h"
...@@ -64,7 +64,6 @@ extern bool prompt_state; ...@@ -64,7 +64,6 @@ extern bool prompt_state;
static bool command_no_begin(const char *query); static bool command_no_begin(const char *query);
/* /*
* "Safe" wrapper around strdup() * "Safe" wrapper around strdup()
*/ */
...@@ -189,7 +188,7 @@ setQFout(const char *fname) ...@@ -189,7 +188,7 @@ setQFout(const char *fname)
* *
*/ */
void void
psql_error(const char *fmt,...) psql_error(const char *fmt, ...)
{ {
va_list ap; va_list ap;
...@@ -784,6 +783,10 @@ PrintNotifications(void) ...@@ -784,6 +783,10 @@ PrintNotifications(void)
static bool static bool
PrintQueryTuples(const PGresult *results) PrintQueryTuples(const PGresult *results)
{ {
printQueryOpt my_popt = pset.popt;
my_popt.topt.normal_query = true;
/* write output to \g argument, if any */ /* write output to \g argument, if any */
if (pset.gfname) if (pset.gfname)
{ {
...@@ -800,7 +803,7 @@ PrintQueryTuples(const PGresult *results) ...@@ -800,7 +803,7 @@ PrintQueryTuples(const PGresult *results)
return false; return false;
} }
printQuery(results, &pset.popt, pset.queryFout); printQuery(results, &my_popt, pset.queryFout);
/* close file/pipe, restore old setting */ /* close file/pipe, restore old setting */
setQFout(NULL); setQFout(NULL);
...@@ -812,7 +815,7 @@ PrintQueryTuples(const PGresult *results) ...@@ -812,7 +815,7 @@ PrintQueryTuples(const PGresult *results)
pset.gfname = NULL; pset.gfname = NULL;
} }
else else
printQuery(results, &pset.popt, pset.queryFout); printQuery(results, &my_popt, pset.queryFout);
return true; return true;
} }
...@@ -1001,7 +1004,7 @@ SendQuery(const char *query) ...@@ -1001,7 +1004,7 @@ SendQuery(const char *query)
if (on_error_rollback_warning == false && pset.sversion < 80000) if (on_error_rollback_warning == false && pset.sversion < 80000)
{ {
fprintf(stderr, _("The server version (%d) does not support savepoints for ON_ERROR_ROLLBACK.\n"), fprintf(stderr, _("The server version (%d) does not support savepoints for ON_ERROR_ROLLBACK.\n"),
pset.sversion); pset.sversion);
on_error_rollback_warning = true; on_error_rollback_warning = true;
} }
else else
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
* *
* Copyright (c) 2000-2005, PostgreSQL Global Development Group * Copyright (c) 2000-2005, PostgreSQL Global Development Group
* *
* $PostgreSQL: pgsql/src/bin/psql/common.h,v 1.43 2005/05/30 18:28:11 momjian Exp $ * $PostgreSQL: pgsql/src/bin/psql/common.h,v 1.44 2005/06/13 06:36:22 neilc Exp $
*/ */
#ifndef COMMON_H #ifndef COMMON_H
#define COMMON_H #define COMMON_H
...@@ -22,7 +22,6 @@ ...@@ -22,7 +22,6 @@
#define atooid(x) ((Oid) strtoul((x), NULL, 10)) #define atooid(x) ((Oid) strtoul((x), NULL, 10))
/* /*
* Safer versions of some standard C library functions. If an * Safer versions of some standard C library functions. If an
* out-of-memory condition occurs, these functions will bail out * out-of-memory condition occurs, these functions will bail out
...@@ -36,7 +35,7 @@ extern void *pg_calloc(size_t nmemb, size_t size); ...@@ -36,7 +35,7 @@ extern void *pg_calloc(size_t nmemb, size_t size);
extern bool setQFout(const char *fname); extern bool setQFout(const char *fname);
extern void extern void
psql_error(const char *fmt,...) psql_error(const char *fmt, ...)
/* This lets gcc check the format string for consistency. */ /* This lets gcc check the format string for consistency. */
__attribute__((format(printf, 1, 2))); __attribute__((format(printf, 1, 2)));
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
* *
* Copyright (c) 2000-2005, PostgreSQL Global Development Group * Copyright (c) 2000-2005, PostgreSQL Global Development Group
* *
* $PostgreSQL: pgsql/src/bin/psql/print.c,v 1.57 2005/06/09 18:40:06 momjian Exp $ * $PostgreSQL: pgsql/src/bin/psql/print.c,v 1.58 2005/06/13 06:36:22 neilc Exp $
*/ */
#include "postgres_fe.h" #include "postgres_fe.h"
#include "common.h" #include "common.h"
...@@ -29,7 +29,6 @@ ...@@ -29,7 +29,6 @@
#include "mbprint.h" #include "mbprint.h"
/*************************/ /*************************/
/* Unaligned text */ /* Unaligned text */
/*************************/ /*************************/
...@@ -1261,6 +1260,7 @@ printTable(const char *title, ...@@ -1261,6 +1260,7 @@ printTable(const char *title,
const char *default_footer[] = {NULL}; const char *default_footer[] = {NULL};
unsigned short int border = opt->border; unsigned short int border = opt->border;
FILE *output; FILE *output;
bool use_expanded;
if (opt->format == PRINT_NOTHING) if (opt->format == PRINT_NOTHING)
return; return;
...@@ -1271,6 +1271,16 @@ printTable(const char *title, ...@@ -1271,6 +1271,16 @@ printTable(const char *title,
if (opt->format != PRINT_HTML && border > 2) if (opt->format != PRINT_HTML && border > 2)
border = 2; border = 2;
/*
* We only want to display the results in "expanded" format if
* this is a normal (user-submitted) query, not a table we're
* printing for a slash command.
*/
if (opt->expanded && opt->normal_query)
use_expanded = true;
else
use_expanded = false;
if (fout == stdout) if (fout == stdout)
{ {
int col_count = 0, int col_count = 0,
...@@ -1305,37 +1315,56 @@ printTable(const char *title, ...@@ -1305,37 +1315,56 @@ printTable(const char *title,
switch (opt->format) switch (opt->format)
{ {
case PRINT_UNALIGNED: case PRINT_UNALIGNED:
if (opt->expanded) if (use_expanded)
print_unaligned_vertical(title, headers, cells, footers, opt->fieldSep, opt->recordSep, opt->tuples_only, output); print_unaligned_vertical(title, headers, cells, footers,
opt->fieldSep, opt->recordSep,
opt->tuples_only, output);
else else
print_unaligned_text(title, headers, cells, footers, opt->fieldSep, opt->recordSep, opt->tuples_only, output); print_unaligned_text(title, headers, cells, footers,
opt->fieldSep, opt->recordSep,
opt->tuples_only, output);
break; break;
case PRINT_ALIGNED: case PRINT_ALIGNED:
if (opt->expanded) if (use_expanded)
print_aligned_vertical(title, headers, cells, footers, opt->tuples_only, border, opt->encoding, output); print_aligned_vertical(title, headers, cells, footers,
opt->tuples_only, border,
opt->encoding, output);
else else
print_aligned_text(title, headers, cells, footers, align, opt->tuples_only, border, opt->encoding, output); print_aligned_text(title, headers, cells, footers,
align, opt->tuples_only,
border, opt->encoding, output);
break; break;
case PRINT_HTML: case PRINT_HTML:
if (opt->expanded) if (use_expanded)
print_html_vertical(title, headers, cells, footers, align, opt->tuples_only, border, opt->tableAttr, output); print_html_vertical(title, headers, cells, footers,
align, opt->tuples_only,
border, opt->tableAttr, output);
else else
print_html_text(title, headers, cells, footers, align, opt->tuples_only, border, opt->tableAttr, output); print_html_text(title, headers, cells, footers,
align, opt->tuples_only, border,
opt->tableAttr, output);
break; break;
case PRINT_LATEX: case PRINT_LATEX:
if (opt->expanded) if (use_expanded)
print_latex_vertical(title, headers, cells, footers, align, opt->tuples_only, border, output); print_latex_vertical(title, headers, cells, footers, align,
opt->tuples_only, border, output);
else else
print_latex_text(title, headers, cells, footers, align, opt->tuples_only, border, output); print_latex_text(title, headers, cells, footers, align,
opt->tuples_only, border, output);
break; break;
case PRINT_TROFF_MS: case PRINT_TROFF_MS:
if (opt->expanded) if (use_expanded)
print_troff_ms_vertical(title, headers, cells, footers, align, opt->tuples_only, border, output); print_troff_ms_vertical(title, headers, cells, footers,
align, opt->tuples_only,
border, output);
else else
print_troff_ms_text(title, headers, cells, footers, align, opt->tuples_only, border, output); print_troff_ms_text(title, headers, cells, footers,
align, opt->tuples_only,
border, output);
break; break;
default: default:
fprintf(stderr, "+ Oops, you shouldn't see this!\n"); fprintf(stderr, _("illegal output format: %d"), opt->format);
exit(EXIT_FAILURE);
} }
/* Only close if we used the pager */ /* Only close if we used the pager */
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
* *
* Copyright (c) 2000-2005, PostgreSQL Global Development Group * Copyright (c) 2000-2005, PostgreSQL Global Development Group
* *
* $PostgreSQL: pgsql/src/bin/psql/print.h,v 1.23 2005/06/09 15:27:27 momjian Exp $ * $PostgreSQL: pgsql/src/bin/psql/print.h,v 1.24 2005/06/13 06:36:22 neilc Exp $
*/ */
#ifndef PRINT_H #ifndef PRINT_H
#define PRINT_H #define PRINT_H
...@@ -42,6 +42,9 @@ typedef struct _printTableOpt ...@@ -42,6 +42,9 @@ typedef struct _printTableOpt
* mode */ * mode */
char *tableAttr; /* attributes for HTML <table ...> */ char *tableAttr; /* attributes for HTML <table ...> */
int encoding; /* character encoding */ int encoding; /* character encoding */
bool normal_query; /* are we presenting the results of a
* "normal" query, or a slash
* command? */
} printTableOpt; } printTableOpt;
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
* *
* Copyright (c) 2000-2005, PostgreSQL Global Development Group * Copyright (c) 2000-2005, PostgreSQL Global Development Group
* *
* $PostgreSQL: pgsql/src/bin/psql/startup.c,v 1.115 2005/04/29 14:30:11 momjian Exp $ * $PostgreSQL: pgsql/src/bin/psql/startup.c,v 1.116 2005/06/13 06:36:22 neilc Exp $
*/ */
#include "postgres_fe.h" #include "postgres_fe.h"
...@@ -143,6 +143,7 @@ main(int argc, char *argv[]) ...@@ -143,6 +143,7 @@ main(int argc, char *argv[])
pset.queryFout = stdout; pset.queryFout = stdout;
pset.popt.topt.border = 1; pset.popt.topt.border = 1;
pset.popt.topt.pager = 1; pset.popt.topt.pager = 1;
pset.popt.topt.normal_query = false;
pset.popt.default_footer = true; pset.popt.default_footer = true;
SetVariable(pset.vars, "VERSION", PG_VERSION_STR); SetVariable(pset.vars, "VERSION", PG_VERSION_STR);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册