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

Commit19b3c55

Browse files
committed
Fixed-size buffer in dumpClasses is not big enough anymore given the
addition of a column list clause to the COPY command. Spotted byMartin Renters.
1 parent5530b0c commit19b3c55

File tree

1 file changed

+24
-19
lines changed

1 file changed

+24
-19
lines changed

‎src/bin/pg_dump/pg_dump.c‎

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
*
2323
*
2424
* IDENTIFICATION
25-
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.289 2002/08/2200:01:45 tgl Exp $
25+
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.290 2002/08/2221:29:34 tgl Exp $
2626
*
2727
*-------------------------------------------------------------------------
2828
*/
@@ -124,7 +124,7 @@ static char *GetPrivileges(Archive *AH, const char *s, const char *type);
124124
staticintdumpBlobs(Archive*AH,char*,void*);
125125
staticintdumpDatabase(Archive*AH);
126126
staticconstchar*getAttrName(intattrnum,TableInfo*tblInfo);
127-
staticconstchar*fmtCopyColumnList(constTableInfo*ti);
127+
staticconstchar*fmtCopyColumnList(constTableInfo*ti);
128128

129129
externchar*optarg;
130130
externintoptind,
@@ -828,7 +828,16 @@ dumpClasses_nodumpData(Archive *fout, char *oid, void *dctxv)
828828
*/
829829
selectSourceSchema(tbinfo->relnamespace->nspname);
830830

831-
column_list=fmtCopyColumnList(tbinfo);
831+
/*
832+
* If possible, specify the column list explicitly so that we have no
833+
* possibility of retrieving data in the wrong column order. (The
834+
* default column ordering of COPY will not be what we want in certain
835+
* corner cases involving ADD COLUMN and inheritance.)
836+
*/
837+
if (g_fout->remoteVersion >=70300)
838+
column_list=fmtCopyColumnList(tbinfo);
839+
else
840+
column_list="";/* can't select columns in COPY */
832841

833842
if (oids&&hasoids)
834843
{
@@ -1123,11 +1132,11 @@ static void
11231132
dumpClasses(constTableInfo*tblinfo,constintnumTables,Archive*fout,
11241133
constbooloids)
11251134
{
1126-
inti;
1135+
PQExpBuffercopyBuf=createPQExpBuffer();
11271136
DataDumperPtrdumpFn;
11281137
DumpContext*dumpCtx;
1129-
charcopyBuf[512];
11301138
char*copyStmt;
1139+
inti;
11311140

11321141
for (i=0;i<numTables;i++)
11331142
{
@@ -1162,11 +1171,12 @@ dumpClasses(const TableInfo *tblinfo, const int numTables, Archive *fout,
11621171

11631172
dumpFn=dumpClasses_nodumpData;
11641173
column_list=fmtCopyColumnList(&(tblinfo[i]));
1165-
sprintf(copyBuf,"COPY %s %s %sFROM stdin;\n",
1166-
fmtId(tblinfo[i].relname),
1167-
column_list,
1168-
(oids&&tblinfo[i].hasoids) ?"WITH OIDS " :"");
1169-
copyStmt=copyBuf;
1174+
resetPQExpBuffer(copyBuf);
1175+
appendPQExpBuffer(copyBuf,"COPY %s %s %sFROM stdin;\n",
1176+
fmtId(tblinfo[i].relname),
1177+
column_list,
1178+
(oids&&tblinfo[i].hasoids) ?"WITH OIDS " :"");
1179+
copyStmt=copyBuf->data;
11701180
}
11711181
else
11721182
{
@@ -1181,6 +1191,8 @@ dumpClasses(const TableInfo *tblinfo, const int numTables, Archive *fout,
11811191
dumpFn,dumpCtx);
11821192
}
11831193
}
1194+
1195+
destroyPQExpBuffer(copyBuf);
11841196
}
11851197

11861198

@@ -6652,11 +6664,9 @@ fmtQualifiedId(const char *schema, const char *id)
66526664

66536665
/*
66546666
* return a column list clause for the given relation.
6655-
* returns an empty string if the remote server is older than
6656-
* 7.3.
66576667
*/
6658-
staticconstchar*
6659-
fmtCopyColumnList(constTableInfo*ti)
6668+
staticconstchar*
6669+
fmtCopyColumnList(constTableInfo*ti)
66606670
{
66616671
staticPQExpBufferq=NULL;
66626672
intnumatts=ti->numatts;
@@ -6665,16 +6675,11 @@ fmtCopyColumnList(const TableInfo* ti)
66656675
boolneedComma;
66666676
inti;
66676677

6668-
if (g_fout->remoteVersion<70300)
6669-
return"";
6670-
66716678
if (q)/* first time through? */
66726679
resetPQExpBuffer(q);
66736680
else
66746681
q=createPQExpBuffer();
66756682

6676-
resetPQExpBuffer(q);
6677-
66786683
appendPQExpBuffer(q,"(");
66796684
needComma= false;
66806685
for (i=0;i<numatts;i++)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp