8000 Back-patch fixes for dumping user-defined types and dumping comments · danielcode/postgres@7df68bd · GitHub
[go: up one dir, main page]

Skip to content

Commit 7df68bd

Browse files
committed
Back-patch fixes for dumping user-defined types and dumping comments
on views.
1 parent a1e17cd commit 7df68bd

File tree

2 files changed

+83
-30
lines changed

2 files changed

+83
-30
lines changed

src/bin/pg_dump/pg_dump.c

Lines changed: 79 additions & 29 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.205.2.3 2001/07/29 22:12:49 tgl Exp $
25+
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.205.2.4 2001/08/03 20:14:06 tgl Exp $
2626
*
2727
* Modifications - 6/10/96 - dave@bensoft.com - version 1.13.dhb
2828
*
@@ -180,7 +180,8 @@ typedef enum _formatLiteralOptions
180180
/* only checks for 'opts == CONV_ALL' anyway. */
181181
} formatLiteralOptions;
182182

183-
static void dumpComment(Archive *outfile, const char *target, const char *oid);
183+
static void dumpComment(Archive *outfile, const char *target, const char *oid,
184+
const char *((*deps)[]));
184185
static void dumpSequence(Archive *fout, TableInfo tbinfo, const bool schemaOnly, const bool dataOnly);
185186
static void dumpACL(Archive *fout, TableInfo tbinfo);
186187
static void dumpTriggers(Archive *fout, const char *tablename,
@@ -1329,7 +1330,10 @@ getTypes(int *numTypes)
13291330
int i_typdelim;
13301331
int i_typdefault;
13311332
int i_typrelid;
1333+
int i_typalign;
1334+
int i_typstorage;
13321335
int i_typbyval;
1336+
int i_typisdefined;
13331337
int i_usename;
13341338
int i_typedefn;
13351339

@@ -1348,14 +1352,14 @@ getTypes(int *numTypes)
13481352
{
13491353
appendPQExpBuffer(query, "SELECT pg_type.oid, typowner, typname, typlen, typprtlen, "
13501354
"typinput, typoutput, typreceive, typsend, typelem, typdelim, "
1351-
"typdefault, typrelid, typbyval, "
1355+
"typdefault, typrelid, typalign, 'p'::char as typstorage, typbyval, typisdefined, "
13521356
"(select usename from pg_user where typowner = usesysid) as usename, "
13531357
"typname as typedefn "
13541358
"from pg_type");
13551359
} else {
13561360
appendPQExpBuffer(query, "SELECT pg_type.oid, typowner, typname, typlen, typprtlen, "
13571361
"typinput, typoutput, typreceive, typsend, typelem, typdelim, "
1358-
"typdefault, typrelid, typbyval, "
1362+
"typdefault, typrelid, typalign, typstorage, typbyval, typisdefined, "
13591363
"(select usename from pg_user where typowner = usesysid) as usename, "
13601364
"format_type(pg_type.oid, NULL) as typedefn "
13611365
"from pg_type");
@@ -1386,7 +1390,10 @@ getTypes(int *numTypes)
13861390
i_typdelim = PQfnumber(res, "typdelim");
13871391
i_typdefault = PQfnumber(res, "typdefault");
13881392
i_typrelid = PQfnumber(res, "typrelid");
1393+
i_typalign = PQfnumber(res, "typalign");
1394+
i_typstorage = PQfnumber(res, "typstorage");
13891395
i_typbyval = PQfnumber(res, "typbyval");
1396+
i_typisdefined = PQfnumber(res, "typisdefined");
13901397
i_usename = PQfnumber(res, "usename");
13911398
i_typedefn = PQfnumber(res, "typedefn");
13921399

@@ -1405,6 +1412,8 @@ getTypes(int *numTypes)
14051412
tinfo[i].typdelim = strdup(PQgetvalue(res, i, i_typdelim));
14061413
tinfo[i].typdefault = strdup(PQgetvalue(res, i, i_typdefault));
14071414
tinfo[i].typrelid = strdup(PQgetvalue(res, i, i_typrelid));
1415+
tinfo[i].typalign = strdup(PQgetvalue(res, i, i_typalign));
1416+
tinfo[i].typstorage = strdup(PQgetvalue(res, i, i_typstorage));
14081417
tinfo[i].usename = strdup(PQgetvalue(res, i, i_usename));
14091418
tinfo[i].typedefn = strdup(PQgetvalue(res, i, i_typedefn));
14101419

@@ -1424,12 +1433,19 @@ getTypes(int *numTypes)
14241433
tinfo[i].isArray = 1;
14251434
else
14261435
tinfo[i].isArray = 0;
1436+
1437+
if (strcmp(PQgetvalue(res, i, i_typisdefined), "f") == 0)
1438+
tinfo[i].isDefined = 0;
1439+
else
1440+
tinfo[i].isDefined = 1;
14271441
}
14281442

14291443
*numTypes = ntups;
14301444

14311445
PQclear(res);
14321446

1447+
destroyPQExpBuffer(query);
1448+
14331449
return tinfo;
14341450
}
14351451

@@ -1567,8 +1583,14 @@ clearTypeInfo(TypeInfo *tp, int numTypes)
15671583
free(tp[i].typdefault);
15681584
if (tp[i].typrelid)
15691585
free(tp[i].typrelid);
1586+
if (tp[i].typalign)
1587+
free(tp[i].typalign);
1588+
if (tp[i].typstorage)
1589+
free(tp[i].typstorage);
15701590
if (tp[i].usename)
15711591
free(tp[i].usename);
1592+
if (tp[i].typedefn)
1593+
free(tp[i].typedefn);
15721594
}
15731595
free(tp);
15741596
}
@@ -2989,16 +3011,17 @@ getIndices(int *numIndices)
29893011
* oid handed to this routine. The routine takes a constant character
29903012
* string for the target part of the object and the oid of the object
29913013
* whose comments are to be dumped. It is perfectly acceptable
2992-
* to hand an oid to this routine which has not been commented. In
2993-
* addition, the routine takes the stdio FILE handle to which the
2994-
* output should be written.
3014+
* to hand an oid to this routine which has not been commented. Additional
3015+
* dependencies can be passed for the comment, too --- this is needed for
3016+
* VIEWs, whose comments are filed under the table OID but which are dumped
3017+
* in order by their rule OID.
29953018
*------------------------------------------------------------------
29963019
*/
29973020

29983021
static void
2999-
dumpComment(Archive *fout, const char *target, const char *oid)
3022+
dumpComment(Archive *fout, const char *target, const char *oid,
3023+
const char *((*deps)[]))
30003024
{
3001-
30023025
PGresult *res;
30033026
PQExpBuffer query;
30043027
int i_description;
@@ -3033,7 +3056,8 @@ dumpComment(Archive *fout, const char *target, const char *oid)
30333056
formatStringLiteral(query, PQgetvalue(res, 0, i_description), PASS_LFTAB);
30343057
appendPQExpBuffer(query, ";\n");
30353058

3036-
ArchiveEntry(fout, oid, target, "COMMENT", NULL, query->data, "" /* Del */ ,
3059+
ArchiveEntry(fout, oid, target, "COMMENT", deps,
3060+
query->data, "" /* Del */ ,
30373061
"" /* Copy */ , "" /* Owner */ , NULL, NULL);
30383062

30393063
}
@@ -3085,13 +3109,13 @@ dumpDBComment(Archive *fout)
30853109
i_oid = PQfnumber(res, "oid");
30863110
resetPQExpBuffer(query);
30873111
appendPQExpBuffer(query, "DATABASE %s", fmtId(PQdb(g_conn), force_quotes));
3088-
dumpComment(fout, query->data, PQgetvalue(res, 0, i_oid));
3112+
dumpComment(fout, query->data, PQgetvalue(res, 0, i_oid), NULL);
30893113
}
30903114

30913115
/*** Clear the statement buffer and return ***/
30923116

30933117
PQclear(res);
3094-
3118+
destroyPQExpBuffer(query);
30953119
}
30963120

30973121
/*
@@ -3108,13 +3132,10 @@ dumpTypes(Archive *fout, FuncInfo *finfo, int numFuncs,
31083132
PQExpBuffer delq = createPQExpBuffer();
31093133
int funcInd;
31103134
const char *((*deps)[]);
3111-
int depIdx = 0;
3112-
3113-
deps = malloc(sizeof(char*) * 10);
3135+
int depIdx;
31143136

31153137
for (i = 0; i < numTypes; i++)
31163138
{
3117-
31183139
/* skip all the builtin types */
31193140
if (atooid(tinfo[i].oid) <= g_last_builtin_oid)
31203141
continue;
@@ -3123,11 +3144,18 @@ dumpTypes(Archive *fout, FuncInfo *finfo, int numFuncs,
31233144
if (atoi(tinfo[i].typrelid) != 0)
31243145
continue;
31253146

3147+
/* skip undefined placeholder types */
3148+
if (!tinfo[i].isDefined)
3149+
continue;
3150+
31263151
/* skip all array types that start w/ underscore */
31273152
if ((tinfo[i].typname[0] == '_') &&
31283153
(strcmp(tinfo[i].typinput, "array_in") == 0))
31293154
continue;
31303155

3156+
deps = malloc(sizeof(char*) * 10);
3157+
depIdx = 0;
3158+
31313159
/*
31323160
* before we create a type, we need to create the input and output
31333161
* functions for it, if they haven't been created already
@@ -3146,6 +3174,7 @@ dumpTypes(Archive *fout, FuncInfo *finfo, int numFuncs,
31463174
dumpOneFunc(fout, finfo, funcInd, tinfo, numTypes);
31473175
}
31483176

3177+
resetPQExpBuffer(delq);
31493178
appendPQExpBuffer(delq, "DROP TYPE %s;\n", fmtId(tinfo[i].typname, force_quotes));
31503179

31513180
resetPQExpBuffer(q);
@@ -3175,8 +3204,6 @@ dumpTypes(Archive *fout, FuncInfo *finfo, int numFuncs,
31753204
{
31763205
fprintf(stderr, "Notice: array type %s - type for elements (oid %s) is not dumped.\n",
31773206
tinfo[i].typname, tinfo[i].typelem);
3178-
resetPQExpBuffer(q);
3179-
resetPQExpBuffer(delq);
31803207
continue;
31813208
}
31823209

@@ -3185,8 +3212,24 @@ dumpTypes(Archive *fout, FuncInfo *finfo, int numFuncs,
31853212

31863213
(*deps)[depIdx++] = strdup(tinfo[i].typelem);
31873214
}
3215+
3216+
/* XXX these are all the aligns currently handled by DefineType */
3217+
if (strcmp(tinfo[i].typalign, "i") == 0)
3218+
appendPQExpBuffer(q, ", alignment = int4");
3219+
else if (strcmp(tinfo[i].typalign, "d") == 0)
3220+
appendPQExpBuffer(q, ", alignment = double");
3221+
3222+
if (strcmp(tinfo[i].typstorage, "p") == 0)
3223+
appendPQExpBuffer(q, ", storage = plain");
3224+
if (strcmp(tinfo[i].typstorage, "e") == 0)
3225+
appendPQExpBuffer(q, ", storage = external");
3226+
if (strcmp(tinfo[i].typstorage, "x") == 0)
3227+
appendPQExpBuffer(q, ", storage = extended");
3228+
if (strcmp(tinfo[i].typstorage, "m") == 0)
3229+
appendPQExpBuffer(q, ", storage = main");
3230+
31883231
if (tinfo[i].passedbyvalue)
3189-
appendPQExpBuffer(q, ",passedbyvalue);\n");
3232+
appendPQExpBuffer(q, ", passedbyvalue);\n");
31903233
else
31913234
appendPQExpBuffer(q, ");\n");
31923235

@@ -3201,7 +3244,7 @@ dumpTypes(Archive *fout, FuncInfo *finfo, int numFuncs,
32013244
resetPQExpBuffer(delq);
32023245

32033246
appendPQExpBuffer(q, "TYPE %s", fmtId(tinfo[i].typname, force_quotes));
3204-
dumpComment(fout, q->data, tinfo[i].oid);
3247+
dumpComment(fout, q->data, tinfo[i].oid, NULL);
32053248

32063249
resetPQExpBuffer(q);
32073250
}
@@ -3486,7 +3529,7 @@ dumpOneFunc(Archive *fout, FuncInfo *finfo, int i,
34863529
appendPQExpBuffer(q, "FUNCTION %s ",
34873530
fmtId(finfo[i].proname, force_quotes));
34883531
appendPQExpBuffer(q, "( %s )", fnlist->data);
3489-
dumpComment(fout, q->data, finfo[i].oid);
3532+
dumpComment(fout, q->data, finfo[i].oid, NULL);
34903533

34913534
}
34923535

@@ -3743,7 +3786,7 @@ dumpAggs(Archive *fout, AggInfo *agginfo, int numAggs,
37433786
resetPQExpBuffer(q);
37443787
appendPQExpBuffer(q, "AGGREGATE %s %s", agginfo[i].aggname,
37453788
findTypeByOid(tinfo, numTypes, agginfo[i].aggbasetype, zeroAsOpaque + useBaseTypeName));
3746-
dumpComment(fout, q->data, agginfo[i].oid);
3789+
dumpComment(fout, q->data, agginfo[i].oid, NULL);
37473790

37483791
}
37493792
}
@@ -4001,6 +4044,7 @@ dumpTables(Archive *fout, TableInfo *tblinfo, int numTables,
40014044
int actual_atts; /* number of attrs in this CREATE statment */
40024045
char *reltypename;
40034046
char *objoid;
4047+
const char *((*commentDeps)[]);
40044048

40054049
/* First - dump SEQUENCEs */
40064050
if (tablename && strlen(tablename) > 0)
@@ -4043,12 +4087,15 @@ dumpTables(Archive *fout, TableInfo *tblinfo, int numTables,
40434087
objoid = tblinfo[i].viewoid;
40444088
appendPQExpBuffer(delq, "DROP VIEW %s;\n", fmtId(tblinfo[i].relname, force_quotes));
40454089
appendPQExpBuffer(q, "CREATE VIEW %s as %s\n", fmtId(tblinfo[i].relname, force_quotes), tblinfo[i].viewdef);
4046-
4090+
commentDeps = malloc(sizeof(char*) * 2);
4091+
(*commentDeps)[0] = strdup(objoid);
4092+
(*commentDeps)[1] = NULL; /* end of list */
40474093
}
40484094
else
40494095
{
40504096
reltypename = "TABLE";
40514097
objoid = tblinfo[i].oid;
4098+
commentDeps = NULL;
40524099
parentRels = tblinfo[i].parentRels;
40534100
numParents = tblinfo[i].numParents;
40544101

@@ -4167,17 +4214,20 @@ dumpTables(Archive *fout, TableInfo *tblinfo, int numTables,
41674214
appendPQExpBuffer(q, "COLUMN %s", fmtId(tblinfo[i].relname, force_quotes));
41684215
appendPQExpBuffer(q, ".");
41694216
appendPQExpBuffer(q, "%s", fmtId(tblinfo[i].attnames[j], force_quotes));
4170-
dumpComment(fout, q->data, tblinfo[i].attoids[j]);
4217+
dumpComment(fout, q->data, tblinfo[i].attoids[j], NULL);
41714218
}
41724219

41734220
/* Dump Table Comments */
41744221

41754222
resetPQExpBuffer(q);
41764223
appendPQExpBuffer(q, "%s %s", reltypename, fmtId(tblinfo[i].relname, force_quotes));
4177-
dumpComment(fout, q->data, tblinfo[i].oid);
4224+
dumpComment(fout, q->data, tblinfo[i].oid, commentDeps);
41784225

41794226
}
41804227
}
4228+
4229+
destroyPQExpBuffer(q);
4230+
destroyPQExpBuffer(delq);
41814231
}
41824232

41834233
static PQExpBuffer
@@ -4461,7 +4511,7 @@ dumpIndices(Archive *fout, IndInfo *indinfo, int numIndices,
44614511
/* Dump Index Comments */
44624512
resetPQExpBuffer(q);
44634513
appendPQExpBuffer(q, "INDEX %s", id1->data);
4464-
dumpComment(fout, q->data, indinfo[i].indoid);
4514+
dumpComment(fout, q->data, indinfo[i].indoid, NULL);
44654515

44664516
}
44674517
}
@@ -4776,7 +4826,7 @@ dumpSequence(Archive *fout, TableInfo tbinfo, const bool schemaOnly, const bool
47764826

47774827
resetPQExpBuffer(query);
47784828
appendPQExpBuffer(query, "SEQUENCE %s", fmtId(tbinfo.relname, force_quotes));
4779-
dumpComment(fout, query->data, tbinfo.oid);
4829+
dumpComment(fout, query->data, tbinfo.oid, NULL);
47804830
}
47814831
}
47824832

@@ -4802,7 +4852,7 @@ dumpTriggers(Archive *fout, const char *tablename,
48024852
ArchiveEntry(fout, tblinfo[i].triggers[j].oid, tblinfo[i].triggers[j].tgname,
48034853
"TRIGGER", NULL, tblinfo[i].triggers[j].tgsrc, "", "",
48044854
tblinfo[i].usename, NULL, NULL);
4805-
dumpComment(fout, tblinfo[i].triggers[j].tgcomment, tblinfo[i].triggers[j].oid);
4855+
dumpComment(fout, tblinfo[i].triggers[j].tgcomment, tblinfo[i].triggers[j].oid, NULL);
48064856
}
48074857
}
48084858
}
@@ -4882,7 +4932,7 @@ dumpRules(Archive *fout, const char *tablename,
48824932

48834933
resetPQExpBuffer(query);
48844934
appendPQExpBuffer(query, "RULE %s", fmtId(PQgetvalue(res, i, i_rulename), force_quotes));
4885-
dumpComment(fout, query->data, PQgetvalue(res, i, i_oid));
4935+
dumpComment(fout, query->data, PQgetvalue(res, i, i_oid), NULL);
48864936

48874937
}
48884938

src/bin/pg_dump/pg_dump.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
77
* Portions Copyright (c) 1994, Regents of the University of California
88
*
9-
* $Id: pg_dump.h,v 1.63 2001/04/25 07:03:20 pjw Exp $
9+
* $Id: pg_dump.h,v 1.63.2.1 2001/08/03 20:14:07 tgl Exp $
1010
*
1111
* Modifications - 6/12/96 - dave@bensoft.com - version 1.13.dhb.2
1212
*
@@ -49,10 +49,13 @@ typedef struct _typeInfo
4949
char *typdelim;
5050
char *typdefault;
5151
char *typrelid;
52+
char *typalign;
53+
char *typstorage;
5254
char *usename;
5355
char *typedefn;
5456
int passedbyvalue;
5557
int isArray;
58+
int isDefined;
5659
} TypeInfo;
5760

5861
typedef struct _funcInfo

0 commit comments

Comments
 (0)
0