Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit13fc2e4

Browse files
committed
Fix two error-recovery bugs in describeOneTableDetails(), and make the code
to dump sequence values cope with sequences outside the search path and/orhaving names that need quoting. No back-patch needed because these are newproblems in 8.4.Kris Jurka (also a little bit of code beautification by tgl)
1 parent88dd4b0 commit13fc2e4

File tree

1 file changed

+22
-15
lines changed

1 file changed

+22
-15
lines changed

‎src/bin/psql/describe.c

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
* Copyright (c) 2000-2008, PostgreSQL Global Development Group
1010
*
11-
* $PostgreSQL: pgsql/src/bin/psql/describe.c,v 1.185 2008/09/23 09:20:38 heikki Exp $
11+
* $PostgreSQL: pgsql/src/bin/psql/describe.c,v 1.186 2008/11/03 19:08:56 tgl Exp $
1212
*/
1313
#include"postgres_fe.h"
1414

@@ -826,6 +826,7 @@ describeOneTableDetails(const char *schemaname,
826826
PGresult*res=NULL;
827827
printTableOptmyopt=pset.popt.topt;
828828
printTableContentcont;
829+
boolprintTableInitialized= false;
829830
inti;
830831
char*view_def=NULL;
831832
char*headers[6];
@@ -887,9 +888,10 @@ describeOneTableDetails(const char *schemaname,
887888
tableinfo.tablespace= (pset.sversion >=80000) ?
888889
atooid(PQgetvalue(res,0,6)) :0;
889890
PQclear(res);
891+
res=NULL;
890892

891893
/*
892-
*This is used to get the valuesof a sequenceand storeit in an
894+
*If it's a sequence, fetch its values and storeinto an
893895
* array that will be used later.
894896
*/
895897
if (tableinfo.relkind=='S')
@@ -898,12 +900,14 @@ describeOneTableDetails(const char *schemaname,
898900

899901
#defineSEQ_NUM_COLS 10
900902
printfPQExpBuffer(&buf,
901-
"SELECT sequence_name, last_value, \n"
902-
"start_value, increment_by, \n"
903-
"max_value, min_value, cache_value, \n"
904-
"log_cnt, is_cycled, is_called \n"
905-
"FROM \"%s\"",
906-
relationname);
903+
"SELECT sequence_name, last_value,\n"
904+
" start_value, increment_by,\n"
905+
" max_value, min_value, cache_value,\n"
906+
" log_cnt, is_cycled, is_called\n"
907+
"FROM %s",
908+
fmtId(schemaname));
909+
/* must be separate because fmtId isn't reentrant */
910+
appendPQExpBuffer(&buf,".%s",fmtId(relationname));
907911

908912
result=PSQLexec(buf.data, false);
909913
if (!result)
@@ -1000,6 +1004,7 @@ describeOneTableDetails(const char *schemaname,
10001004
}
10011005

10021006
printTableInit(&cont,&myopt,title.data,cols,numrows);
1007+
printTableInitialized= true;
10031008

10041009
for (i=0;i<cols;i++)
10051010
printTableAddHeader(&cont,headers[i], true,'l');
@@ -1030,12 +1035,8 @@ describeOneTableDetails(const char *schemaname,
10301035

10311036
/* Type */
10321037
printTableAddCell(&cont,PQgetvalue(res,i,1), false);
1033-
1034-
/* A special 'Value' column for sequences */
1035-
if (tableinfo.relkind=='S')
1036-
printTableAddCell(&cont,seq_values[i], false);
1037-
1038-
/* Extra: not null and default */
1038+
1039+
/* Modifiers: not null and default */
10391040
if (show_modifiers)
10401041
{
10411042
resetPQExpBuffer(&tmpbuf);
@@ -1057,10 +1058,15 @@ describeOneTableDetails(const char *schemaname,
10571058
printTableAddCell(&cont,modifiers[i], false);
10581059
}
10591060

1061+
/* Value: for sequences only */
1062+
if (tableinfo.relkind=='S')
1063+
printTableAddCell(&cont,seq_values[i], false);
1064+
10601065
/* Storage and Description */
10611066
if (verbose)
10621067
{
10631068
char*storage=PQgetvalue(res,i,5);
1069+
10641070
/* these strings are literal in our syntax, so not translated. */
10651071
printTableAddCell(&cont, (storage[0]=='p' ?"plain" :
10661072
(storage[0]=='m' ?"main" :
@@ -1593,7 +1599,8 @@ describeOneTableDetails(const char *schemaname,
15931599
error_return:
15941600

15951601
/* clean up */
1596-
printTableCleanup(&cont);
1602+
if (printTableInitialized)
1603+
printTableCleanup(&cont);
15971604
termPQExpBuffer(&buf);
15981605
termPQExpBuffer(&title);
15991606
termPQExpBuffer(&tmpbuf);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp