myopt.title = _("List of aggregate functions");
myopt.translate_header = true;
- printQuery(res, &myopt, pset.queryFout, pset.logfile);
+ printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
PQclear(res);
return true;
myopt.title = _("List of tablespaces");
myopt.translate_header = true;
- printQuery(res, &myopt, pset.queryFout, pset.logfile);
+ printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
PQclear(res);
return true;
myopt.translate_columns = translate_columns;
myopt.n_translate_columns = lengthof(translate_columns);
- printQuery(res, &myopt, pset.queryFout, pset.logfile);
+ printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
PQclear(res);
return true;
myopt.title = _("List of data types");
myopt.translate_header = true;
- printQuery(res, &myopt, pset.queryFout, pset.logfile);
+ printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
PQclear(res);
return true;
myopt.title = _("List of operators");
myopt.translate_header = true;
- printQuery(res, &myopt, pset.queryFout, pset.logfile);
+ printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
PQclear(res);
return true;
myopt.title = _("List of databases");
myopt.translate_header = true;
- printQuery(res, &myopt, pset.queryFout, pset.logfile);
+ printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
PQclear(res);
return true;
myopt.translate_columns = translate_columns;
myopt.n_translate_columns = lengthof(translate_columns);
- printQuery(res, &myopt, pset.queryFout, pset.logfile);
+ printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
termPQExpBuffer(&buf);
PQclear(res);
myopt.translate_columns = translate_columns;
myopt.n_translate_columns = lengthof(translate_columns);
- printQuery(res, &myopt, pset.queryFout, pset.logfile);
+ printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
termPQExpBuffer(&buf);
PQclear(res);
myopt.translate_columns = translate_columns;
myopt.n_translate_columns = lengthof(translate_columns);
- printQuery(res, &myopt, pset.queryFout, pset.logfile);
+ printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
PQclear(res);
return true;
{
printfPQExpBuffer(&buf,
"SELECT c.relchecks, c.relkind, c.relhasindex, c.relhasrules, "
- "c.relhastriggers, c.relrowsecurity, c.relforcerowsecurity, "
+ "c.relhastriggers, c.relrowsecurity, c.relforcerowsecurity, "
"c.relhasoids, %s, c.reltablespace, "
"CASE WHEN c.reloftype = 0 THEN '' ELSE c.reloftype::pg_catalog.regtype::pg_catalog.text END, "
"c.relpersistence, c.relreplident\n"
printTableAddFooter(&cont, buf.data);
}
- printTable(&cont, pset.queryFout, pset.logfile);
- printTableCleanup(&cont);
+ printTable(&cont, pset.queryFout, false, pset.logfile);
retval = true;
}
termPQExpBuffer(&buf);
- printTable(&cont, pset.queryFout, pset.logfile);
+ printTable(&cont, pset.queryFout, false, pset.logfile);
printTableCleanup(&cont);
for (i = 0; i < nrows; i++)
myopt.title = _("List of settings");
myopt.translate_header = true;
- printQuery(res, &myopt, pset.queryFout, pset.logfile);
+ printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
}
PQclear(res);
myopt.translate_columns = translate_columns;
myopt.n_translate_columns = lengthof(translate_columns);
- printQuery(res, &myopt, pset.queryFout, pset.logfile);
+ printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
}
PQclear(res);
myopt.title = _("List of languages");
myopt.translate_header = true;
- printQuery(res, &myopt, pset.queryFout, pset.logfile);
+ printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
PQclear(res);
return true;
myopt.title = _("List of domains");
myopt.translate_header = true;
- printQuery(res, &myopt, pset.queryFout, pset.logfile);
+ printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
PQclear(res);
return true;
myopt.translate_columns = translate_columns;
myopt.n_translate_columns = lengthof(translate_columns);
- printQuery(res, &myopt, pset.queryFout, pset.logfile);
+ printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
PQclear(res);
return true;
myopt.translate_columns = translate_columns;
myopt.n_translate_columns = lengthof(translate_columns);
- printQuery(res, &myopt, pset.queryFout, pset.logfile);
+ printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
PQclear(res);
return true;
myopt.translate_columns = translate_columns;
myopt.n_translate_columns = lengthof(translate_columns);
- printQuery(res, &myopt, pset.queryFout, pset.logfile);
+ printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
PQclear(res);
return true;
myopt.translate_columns = translate_columns;
myopt.n_translate_columns = lengthof(translate_columns);
- printQuery(res, &myopt, pset.queryFout, pset.logfile);
+ printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
PQclear(res);
return true;
myopt.title = _("List of schemas");
myopt.translate_header = true;
- printQuery(res, &myopt, pset.queryFout, pset.logfile);
+ printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
PQclear(res);
return true;
myopt.title = _("List of text search parsers");
myopt.translate_header = true;
- printQuery(res, &myopt, pset.queryFout, pset.logfile);
+ printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
PQclear(res);
return true;
myopt.translate_columns = translate_columns;
myopt.n_translate_columns = lengthof(translate_columns);
- printQuery(res, &myopt, pset.queryFout, pset.logfile);
+ printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
PQclear(res);
myopt.translate_columns = NULL;
myopt.n_translate_columns = 0;
- printQuery(res, &myopt, pset.queryFout, pset.logfile);
+ printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
PQclear(res);
return true;
myopt.title = _("List of text search dictionaries");
myopt.translate_header = true;
- printQuery(res, &myopt, pset.queryFout, pset.logfile);
+ printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
PQclear(res);
return true;
myopt.title = _("List of text search templates");
myopt.translate_header = true;
- printQuery(res, &myopt, pset.queryFout, pset.logfile);
+ printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
PQclear(res);
return true;
myopt.title = _("List of text search configurations");
myopt.translate_header = true;
- printQuery(res, &myopt, pset.queryFout, pset.logfile);
+ printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
PQclear(res);
return true;
myopt.topt.default_footer = false;
myopt.translate_header = true;
- printQuery(res, &myopt, pset.queryFout, pset.logfile);
+ printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
termPQExpBuffer(&title);
myopt.title = _("List of foreign-data wrappers");
myopt.translate_header = true;
- printQuery(res, &myopt, pset.queryFout, pset.logfile);
+ printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
PQclear(res);
return true;
myopt.title = _("List of foreign servers");
myopt.translate_header = true;
- printQuery(res, &myopt, pset.queryFout, pset.logfile);
+ printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
PQclear(res);
return true;
myopt.title = _("List of user mappings");
myopt.translate_header = true;
- printQuery(res, &myopt, pset.queryFout, pset.logfile);
+ printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
PQclear(res);
return true;
myopt.title = _("List of foreign tables");
myopt.translate_header = true;
- printQuery(res, &myopt, pset.queryFout, pset.logfile);
+ printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
PQclear(res);
return true;
myopt.title = _("List of installed extensions");
myopt.translate_header = true;
- printQuery(res, &myopt, pset.queryFout, pset.logfile);
+ printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
PQclear(res);
return true;
myopt.title = title;
myopt.translate_header = true;
- printQuery(res, &myopt, pset.queryFout, pset.logfile);
+ printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
PQclear(res);
return true;
/* Local functions */
static int strlen_max_width(unsigned char *str, int *target_width, int encoding);
-static void IsPagerNeeded(const printTableContent *cont, const int extra_lines, bool expanded,
+static void IsPagerNeeded(const printTableContent *cont, int extra_lines, bool expanded,
FILE **fout, bool *is_pager);
-static void print_aligned_vertical(const printTableContent *cont, FILE *fout);
+static void print_aligned_vertical(const printTableContent *cont,
+ FILE *fout, bool is_pager);
/* Count number of digits in integral part of number */
* Print pretty boxes around cells.
*/
static void
-print_aligned_text(const printTableContent *cont, FILE *fout)
+print_aligned_text(const printTableContent *cont, FILE *fout, bool is_pager)
{
bool opt_tuples_only = cont->opt->tuples_only;
int encoding = cont->opt->encoding;
int *bytes_output; /* Bytes output for column value */
printTextLineWrap *wrap; /* Wrap status for each column */
int output_columns = 0; /* Width of interactive console */
- bool is_pager = false;
+ bool is_local_pager = false;
if (cancel_pressed)
return;
if (cont->opt->expanded == 2 && output_columns > 0 &&
(output_columns < total_header_width || output_columns < width_total))
{
- print_aligned_vertical(cont, fout);
+ print_aligned_vertical(cont, fout, is_pager);
goto cleanup;
}
(output_columns < total_header_width || output_columns < width_total))
{
fout = PageOutput(INT_MAX, cont->opt); /* force pager */
- is_pager = true;
+ is_pager = is_local_pager = true;
}
/* Check if newlines or our wrapping now need the pager */
- if (!is_pager)
+ if (!is_pager && fout == stdout)
{
/* scan all cells, find maximum width, compute cell_count */
for (i = 0, ptr = cont->cells; *ptr; ptr++, cell_count++)
}
}
IsPagerNeeded(cont, extra_output_lines, false, &fout, &is_pager);
+ is_local_pager = is_pager;
}
/* time to output */
free(bytes_output);
free(wrap);
- if (is_pager)
+ if (is_local_pager)
ClosePager(fout);
}
}
static void
-print_aligned_vertical(const printTableContent *cont, FILE *fout)
+print_aligned_vertical(const printTableContent *cont,
+ FILE *fout, bool is_pager)
{
bool opt_tuples_only = cont->opt->tuples_only;
unsigned short opt_border = cont->opt->border;
dformatsize = 0;
struct lineptr *hlineptr,
*dlineptr;
- bool is_pager = false,
+ bool is_local_pager = false,
hmultiline = false,
dmultiline = false;
int output_columns = 0; /* Width of interactive console */
* get here via print_aligned_text() in expanded auto mode, and so we have
* to recalculate the pager requirement based on vertical output.
*/
- IsPagerNeeded(cont, 0, true, &fout, &is_pager);
+ if (!is_pager)
+ {
+ IsPagerNeeded(cont, 0, true, &fout, &is_pager);
+ is_local_pager = is_pager;
+ }
/* Find the maximum dimensions for the headers */
for (i = 0; i < cont->ncolumns; i++)
free(hlineptr);
free(dlineptr);
- if (is_pager)
+ if (is_local_pager)
ClosePager(fout);
}
* Setup pager if required
*/
static void
-IsPagerNeeded(const printTableContent *cont, const int extra_lines, bool expanded, FILE **fout,
- bool *is_pager)
+IsPagerNeeded(const printTableContent *cont, int extra_lines, bool expanded,
+ FILE **fout, bool *is_pager)
{
if (*fout == stdout)
{
}
/*
- * Use this to print just any table in the supported formats.
+ * Use this to print any table in the supported formats.
+ *
+ * cont: table data and formatting options
+ * fout: where to print to
+ * is_pager: true if caller has already redirected fout to be a pager pipe
+ * flog: if not null, also print the table there (for --log-file option)
*/
void
-printTable(const printTableContent *cont, FILE *fout, FILE *flog)
+printTable(const printTableContent *cont,
+ FILE *fout, bool is_pager, FILE *flog)
{
- bool is_pager = false;
+ bool is_local_pager = false;
if (cancel_pressed)
return;
if (cont->opt->format == PRINT_NOTHING)
return;
- /* print_aligned_*() handles the pager themselves */
- if (cont->opt->format != PRINT_ALIGNED &&
+ /* print_aligned_*() handle the pager themselves */
+ if (!is_pager &&
+ cont->opt->format != PRINT_ALIGNED &&
cont->opt->format != PRINT_WRAPPED)
+ {
IsPagerNeeded(cont, 0, (cont->opt->expanded == 1), &fout, &is_pager);
+ is_local_pager = is_pager;
+ }
/* print the stuff */
if (flog)
- print_aligned_text(cont, flog);
+ print_aligned_text(cont, flog, false);
switch (cont->opt->format)
{
break;
case PRINT_ALIGNED:
case PRINT_WRAPPED:
- if (cont->opt->expanded == 1)
- print_aligned_vertical(cont, fout);
+
+ /*
+ * In expanded-auto mode, force vertical if a pager is passed in;
+ * else we may make different decisions for different hunks of the
+ * query result.
+ */
+ if (cont->opt->expanded == 1 ||
+ (cont->opt->expanded == 2 && is_pager))
+ print_aligned_vertical(cont, fout, is_pager);
else
- print_aligned_text(cont, fout);
+ print_aligned_text(cont, fout, is_pager);
break;
case PRINT_HTML:
if (cont->opt->expanded == 1)
exit(EXIT_FAILURE);
}
- if (is_pager)
+ if (is_local_pager)
ClosePager(fout);
}
/*
* Use this to print query results
*
- * It calls printTable with all the things set straight.
+ * result: result of a successful query
+ * opt: formatting options
+ * fout: where to print to
+ * is_pager: true if caller has already redirected fout to be a pager pipe
+ * flog: if not null, also print the data there (for --log-file option)
*/
void
-printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, FILE *flog)
+printQuery(const PGresult *result, const printQueryOpt *opt,
+ FILE *fout, bool is_pager, FILE *flog)
{
printTableContent cont;
int i,
printTableAddFooter(&cont, *footer);
}
- printTable(&cont, fout, flog);
+ printTable(&cont, fout, is_pager, flog);
printTableCleanup(&cont);
}