Fix two error-recovery bugs in describeOneTableDetails(), and make the code
to dump sequence values cope with sequences outside the search path and/or having names that need quoting. No back-patch needed because these are new problems in 8.4. Kris Jurka (also a little bit of code beautification by tgl)
This commit is contained in:
parent
88dd4b0a0d
commit
13fc2e4df8
@ -8,7 +8,7 @@
|
|||||||
*
|
*
|
||||||
* Copyright (c) 2000-2008, PostgreSQL Global Development Group
|
* Copyright (c) 2000-2008, PostgreSQL Global Development Group
|
||||||
*
|
*
|
||||||
* $PostgreSQL: pgsql/src/bin/psql/describe.c,v 1.185 2008/09/23 09:20:38 heikki Exp $
|
* $PostgreSQL: pgsql/src/bin/psql/describe.c,v 1.186 2008/11/03 19:08:56 tgl Exp $
|
||||||
*/
|
*/
|
||||||
#include "postgres_fe.h"
|
#include "postgres_fe.h"
|
||||||
|
|
||||||
@ -826,6 +826,7 @@ describeOneTableDetails(const char *schemaname,
|
|||||||
PGresult *res = NULL;
|
PGresult *res = NULL;
|
||||||
printTableOpt myopt = pset.popt.topt;
|
printTableOpt myopt = pset.popt.topt;
|
||||||
printTableContent cont;
|
printTableContent cont;
|
||||||
|
bool printTableInitialized = false;
|
||||||
int i;
|
int i;
|
||||||
char *view_def = NULL;
|
char *view_def = NULL;
|
||||||
char *headers[6];
|
char *headers[6];
|
||||||
@ -887,9 +888,10 @@ describeOneTableDetails(const char *schemaname,
|
|||||||
tableinfo.tablespace = (pset.sversion >= 80000) ?
|
tableinfo.tablespace = (pset.sversion >= 80000) ?
|
||||||
atooid(PQgetvalue(res, 0, 6)) : 0;
|
atooid(PQgetvalue(res, 0, 6)) : 0;
|
||||||
PQclear(res);
|
PQclear(res);
|
||||||
|
res = NULL;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This is used to get the values of a sequence and store it in an
|
* If it's a sequence, fetch its values and store into an
|
||||||
* array that will be used later.
|
* array that will be used later.
|
||||||
*/
|
*/
|
||||||
if (tableinfo.relkind == 'S')
|
if (tableinfo.relkind == 'S')
|
||||||
@ -902,8 +904,10 @@ describeOneTableDetails(const char *schemaname,
|
|||||||
" start_value, increment_by,\n"
|
" start_value, increment_by,\n"
|
||||||
" max_value, min_value, cache_value,\n"
|
" max_value, min_value, cache_value,\n"
|
||||||
" log_cnt, is_cycled, is_called\n"
|
" log_cnt, is_cycled, is_called\n"
|
||||||
"FROM \"%s\"",
|
"FROM %s",
|
||||||
relationname);
|
fmtId(schemaname));
|
||||||
|
/* must be separate because fmtId isn't reentrant */
|
||||||
|
appendPQExpBuffer(&buf, ".%s", fmtId(relationname));
|
||||||
|
|
||||||
result = PSQLexec(buf.data, false);
|
result = PSQLexec(buf.data, false);
|
||||||
if (!result)
|
if (!result)
|
||||||
@ -1000,6 +1004,7 @@ describeOneTableDetails(const char *schemaname,
|
|||||||
}
|
}
|
||||||
|
|
||||||
printTableInit(&cont, &myopt, title.data, cols, numrows);
|
printTableInit(&cont, &myopt, title.data, cols, numrows);
|
||||||
|
printTableInitialized = true;
|
||||||
|
|
||||||
for (i = 0; i < cols; i++)
|
for (i = 0; i < cols; i++)
|
||||||
printTableAddHeader(&cont, headers[i], true, 'l');
|
printTableAddHeader(&cont, headers[i], true, 'l');
|
||||||
@ -1031,11 +1036,7 @@ describeOneTableDetails(const char *schemaname,
|
|||||||
/* Type */
|
/* Type */
|
||||||
printTableAddCell(&cont, PQgetvalue(res, i, 1), false);
|
printTableAddCell(&cont, PQgetvalue(res, i, 1), false);
|
||||||
|
|
||||||
/* A special 'Value' column for sequences */
|
/* Modifiers: not null and default */
|
||||||
if (tableinfo.relkind == 'S')
|
|
||||||
printTableAddCell(&cont, seq_values[i], false);
|
|
||||||
|
|
||||||
/* Extra: not null and default */
|
|
||||||
if (show_modifiers)
|
if (show_modifiers)
|
||||||
{
|
{
|
||||||
resetPQExpBuffer(&tmpbuf);
|
resetPQExpBuffer(&tmpbuf);
|
||||||
@ -1057,10 +1058,15 @@ describeOneTableDetails(const char *schemaname,
|
|||||||
printTableAddCell(&cont, modifiers[i], false);
|
printTableAddCell(&cont, modifiers[i], false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Value: for sequences only */
|
||||||
|
if (tableinfo.relkind == 'S')
|
||||||
|
printTableAddCell(&cont, seq_values[i], false);
|
||||||
|
|
||||||
/* Storage and Description */
|
/* Storage and Description */
|
||||||
if (verbose)
|
if (verbose)
|
||||||
{
|
{
|
||||||
char *storage = PQgetvalue(res, i, 5);
|
char *storage = PQgetvalue(res, i, 5);
|
||||||
|
|
||||||
/* these strings are literal in our syntax, so not translated. */
|
/* these strings are literal in our syntax, so not translated. */
|
||||||
printTableAddCell(&cont, (storage[0]=='p' ? "plain" :
|
printTableAddCell(&cont, (storage[0]=='p' ? "plain" :
|
||||||
(storage[0]=='m' ? "main" :
|
(storage[0]=='m' ? "main" :
|
||||||
@ -1593,6 +1599,7 @@ describeOneTableDetails(const char *schemaname,
|
|||||||
error_return:
|
error_return:
|
||||||
|
|
||||||
/* clean up */
|
/* clean up */
|
||||||
|
if (printTableInitialized)
|
||||||
printTableCleanup(&cont);
|
printTableCleanup(&cont);
|
||||||
termPQExpBuffer(&buf);
|
termPQExpBuffer(&buf);
|
||||||
termPQExpBuffer(&title);
|
termPQExpBuffer(&title);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user