Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit e6a64bd

Browse files
committed
Fix a bug in the previous patch, which caused the title pointer to be used
before it was actually set.
1 parent 1e9199e commit e6a64bd

File tree

2 files changed

+44
-42
lines changed

2 files changed

+44
-42
lines changed

src/bin/psql/describe.c

+40-40
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright (c) 2000-2008, PostgreSQL Global Development Group
55
*
6-
* $PostgreSQL: pgsql/src/bin/psql/describe.c,v 1.171 2008/05/12 22:59:58 alvherre Exp $
6+
* $PostgreSQL: pgsql/src/bin/psql/describe.c,v 1.172 2008/05/13 00:14:11 alvherre Exp $
77
*/
88
#include "postgres_fe.h"
99

@@ -865,6 +865,45 @@ describeOneTableDetails(const char *schemaname,
865865
goto error_return;
866866
numrows = PQntuples(res);
867867

868+
/* Make title */
869+
switch (tableinfo.relkind)
870+
{
871+
case 'r':
872+
printfPQExpBuffer(&title, _("Table \"%s.%s\""),
873+
schemaname, relationname);
874+
break;
875+
case 'v':
876+
printfPQExpBuffer(&title, _("View \"%s.%s\""),
877+
schemaname, relationname);
878+
break;
879+
case 'S':
880+
printfPQExpBuffer(&title, _("Sequence \"%s.%s\""),
881+
schemaname, relationname);
882+
break;
883+
case 'i':
884+
printfPQExpBuffer(&title, _("Index \"%s.%s\""),
885+
schemaname, relationname);
886+
break;
887+
case 's':
888+
/* not used as of 8.2, but keep it for backwards compatibility */
889+
printfPQExpBuffer(&title, _("Special relation \"%s.%s\""),
890+
schemaname, relationname);
891+
break;
892+
case 't':
893+
printfPQExpBuffer(&title, _("TOAST table \"%s.%s\""),
894+
schemaname, relationname);
895+
break;
896+
case 'c':
897+
printfPQExpBuffer(&title, _("Composite type \"%s.%s\""),
898+
schemaname, relationname);
899+
break;
900+
default:
901+
/* untranslated unknown relkind */
902+
printfPQExpBuffer(&title, "?%c? \"%s.%s\"",
903+
tableinfo.relkind, schemaname, relationname);
904+
break;
905+
}
906+
868907
/* Set the number of columns, and their names */
869908
cols = 2;
870909
headers[0] = "Column";
@@ -937,45 +976,6 @@ describeOneTableDetails(const char *schemaname,
937976
printTableAddCell(&cont, PQgetvalue(res, i, 5), false);
938977
}
939978

940-
/* Make title */
941-
switch (tableinfo.relkind)
942-
{
943-
case 'r':
944-
printfPQExpBuffer(&title, _("Table \"%s.%s\""),
945-
schemaname, relationname);
946-
break;
947-
case 'v':
948-
printfPQExpBuffer(&title, _("View \"%s.%s\""),
949-
schemaname, relationname);
950-
break;
951-
case 'S':
952-
printfPQExpBuffer(&title, _("Sequence \"%s.%s\""),
953-
schemaname, relationname);
954-
break;
955-
case 'i':
956-
printfPQExpBuffer(&title, _("Index \"%s.%s\""),
957-
schemaname, relationname);
958-
break;
959-
case 's':
960-
/* not used as of 8.2, but keep it for backwards compatibility */
961-
printfPQExpBuffer(&title, _("Special relation \"%s.%s\""),
962-
schemaname, relationname);
963-
break;
964-
case 't':
965-
printfPQExpBuffer(&title, _("TOAST table \"%s.%s\""),
966-
schemaname, relationname);
967-
break;
968-
case 'c':
969-
printfPQExpBuffer(&title, _("Composite type \"%s.%s\""),
970-
schemaname, relationname);
971-
break;
972-
default:
973-
/* untranslated unknown relkind */
974-
printfPQExpBuffer(&title, "?%c? \"%s.%s\"",
975-
tableinfo.relkind, schemaname, relationname);
976-
break;
977-
}
978-
979979
/* Make footers */
980980
if (tableinfo.relkind == 'i')
981981
{

src/bin/psql/print.c

+4-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright (c) 2000-2008, PostgreSQL Global Development Group
55
*
6-
* $PostgreSQL: pgsql/src/bin/psql/print.c,v 1.100 2008/05/12 22:59:58 alvherre Exp $
6+
* $PostgreSQL: pgsql/src/bin/psql/print.c,v 1.101 2008/05/13 00:14:11 alvherre Exp $
77
*/
88
#include "postgres_fe.h"
99

@@ -1918,8 +1918,10 @@ ClosePager(FILE *pagerpipe)
19181918

19191919
/*
19201920
* Initialise a table contents struct.
1921+
* Must be called before any other printTable method is used.
19211922
*
1922-
* Must be called before any other printTable method is used.
1923+
* The title is not duplicated; the caller must ensure that the buffer
1924+
* is available for the lifetime of the printTableContent struct.
19231925
*
19241926
* If you call this, you must call printTableCleanup once you're done with the
19251927
* table.

0 commit comments

Comments
 (0)