Fix pg_dump so that comments on views are dumped in the proper sequence.

Dump the alignment and storage information for user-defined types (how'd
that manage to slip through the cracks?), and don't dump 'shell' types
that don't have typisdefined set.  Fix badly broken logic for dependencies
of type definitions (did not work for more than one user-defined type...).
Avoid memory leakage within pg_dump by being more careful to release
storage used by PQExpBuffer objects.
This commit is contained in:
Tom Lane 2001-08-03 19:43:05 +00:00
parent 42fbb6dbe7
commit 8f0ee46dcb
3 changed files with 179 additions and 70 deletions

View File

@ -5,7 +5,7 @@
* Implements the basic DB functions used by the archiver. * Implements the basic DB functions used by the archiver.
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_db.c,v 1.21 2001/07/03 20:21:48 petere Exp $ * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_db.c,v 1.22 2001/08/03 19:43:05 tgl Exp $
* *
* NOTES * NOTES
* *
@ -207,6 +207,8 @@ UserIsSuperuser(ArchiveHandle *AH, char *user)
} }
PQclear(res); PQclear(res);
destroyPQExpBuffer(qry);
return isSuper; return isSuper;
} }
@ -678,7 +680,7 @@ ExecuteSqlCommandBuf(ArchiveHandle *AH, void *qryv, int bufLen)
void void
FixupBlobRefs(ArchiveHandle *AH, char *tablename) FixupBlobRefs(ArchiveHandle *AH, char *tablename)
{ {
PQExpBuffer tblQry = createPQExpBuffer(); PQExpBuffer tblQry;
PGresult *res, PGresult *res,
*uRes; *uRes;
int i, int i,
@ -688,6 +690,8 @@ FixupBlobRefs(ArchiveHandle *AH, char *tablename)
if (strcmp(tablename, BLOB_XREF_TABLE) == 0) if (strcmp(tablename, BLOB_XREF_TABLE) == 0)
return; return;
tblQry = createPQExpBuffer();
appendPQExpBuffer(tblQry, "SELECT a.attname FROM pg_class c, pg_attribute a, pg_type t " appendPQExpBuffer(tblQry, "SELECT a.attname FROM pg_class c, pg_attribute a, pg_type t "
" WHERE a.attnum > 0 AND a.attrelid = c.oid AND a.atttypid = t.oid " " WHERE a.attnum > 0 AND a.attrelid = c.oid AND a.atttypid = t.oid "
" AND t.typname = 'oid' AND c.relname = '%s';", tablename); " AND t.typname = 'oid' AND c.relname = '%s';", tablename);
@ -699,10 +703,8 @@ FixupBlobRefs(ArchiveHandle *AH, char *tablename)
if ((n = PQntuples(res)) == 0) if ((n = PQntuples(res)) == 0)
{ {
/* We're done */ /* nothing to do */
ahlog(AH, 1, "no OID type columns in table %s\n", tablename); ahlog(AH, 1, "no OID type columns in table %s\n", tablename);
PQclear(res);
return;
} }
for (i = 0; i < n; i++) for (i = 0; i < n; i++)
@ -741,7 +743,7 @@ FixupBlobRefs(ArchiveHandle *AH, char *tablename)
} }
PQclear(res); PQclear(res);
destroyPQExpBuffer(tblQry);
} }
/********** /**********
@ -766,6 +768,8 @@ CreateBlobXrefTable(ArchiveHandle *AH)
appendPQExpBuffer(qry, "Create Unique Index %s_ix on %s(oldOid)", BLOB_XREF_TABLE, BLOB_XREF_TABLE); appendPQExpBuffer(qry, "Create Unique Index %s_ix on %s(oldOid)", BLOB_XREF_TABLE, BLOB_XREF_TABLE);
ExecuteSqlCommand(AH, qry, "could not create index on BLOB cross reference table", true); ExecuteSqlCommand(AH, qry, "could not create index on BLOB cross reference table", true);
destroyPQExpBuffer(qry);
} }
void void
@ -776,6 +780,8 @@ InsertBlobXref(ArchiveHandle *AH, int old, int new)
appendPQExpBuffer(qry, "Insert Into %s(oldOid, newOid) Values (%d, %d);", BLOB_XREF_TABLE, old, new); appendPQExpBuffer(qry, "Insert Into %s(oldOid, newOid) Values (%d, %d);", BLOB_XREF_TABLE, old, new);
ExecuteSqlCommand(AH, qry, "could not create BLOB cross reference entry", true); ExecuteSqlCommand(AH, qry, "could not create BLOB cross reference entry", true);
destroyPQExpBuffer(qry);
} }
void void
@ -787,6 +793,8 @@ StartTransaction(ArchiveHandle *AH)
ExecuteSqlCommand(AH, qry, "could not start database transaction", false); ExecuteSqlCommand(AH, qry, "could not start database transaction", false);
AH->txActive = true; AH->txActive = true;
destroyPQExpBuffer(qry);
} }
void void
@ -799,6 +807,8 @@ StartTransactionXref(ArchiveHandle *AH)
ExecuteSqlCommand(AH, qry, ExecuteSqlCommand(AH, qry,
"could not start transaction for BLOB cross references", true); "could not start transaction for BLOB cross references", true);
AH->blobTxActive = true; AH->blobTxActive = true;
destroyPQExpBuffer(qry);
} }
void void
@ -810,6 +820,8 @@ CommitTransaction(ArchiveHandle *AH)
ExecuteSqlCommand(AH, qry, "could not commit database transaction", false); ExecuteSqlCommand(AH, qry, "could not commit database transaction", false);
AH->txActive = false; AH->txActive = false;
destroyPQExpBuffer(qry);
} }
void void
@ -821,4 +833,6 @@ CommitTransactionXref(ArchiveHandle *AH)
ExecuteSqlCommand(AH, qry, "could not commit transaction for BLOB cross references", true); ExecuteSqlCommand(AH, qry, "could not commit transaction for BLOB cross references", true);
AH->blobTxActive = false; AH->blobTxActive = false;
destroyPQExpBuffer(qry);
} }

View File

@ -22,7 +22,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.216 2001/07/29 22:12:23 tgl Exp $ * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.217 2001/08/03 19:43:05 tgl Exp $
* *
* Modifications - 6/10/96 - dave@bensoft.com - version 1.13.dhb * Modifications - 6/10/96 - dave@bensoft.com - version 1.13.dhb
* *
@ -182,7 +182,8 @@ typedef enum _formatLiteralOptions
/* only checks for 'opts == CONV_ALL' anyway. */ /* only checks for 'opts == CONV_ALL' anyway. */
} formatLiteralOptions; } formatLiteralOptions;
static void dumpComment(Archive *outfile, const char *target, const char *oid); static void dumpComment(Archive *outfile, const char *target, const char *oid,
const char *((*deps)[]));
static void dumpSequence(Archive *fout, TableInfo tbinfo, const bool schemaOnly, const bool dataOnly); static void dumpSequence(Archive *fout, TableInfo tbinfo, const bool schemaOnly, const bool dataOnly);
static void dumpACL(Archive *fout, TableInfo tbinfo); static void dumpACL(Archive *fout, TableInfo tbinfo);
static void dumpTriggers(Archive *fout, const char *tablename, static void dumpTriggers(Archive *fout, const char *tablename,
@ -571,6 +572,7 @@ dumpClasses_dumpData(Archive *fout, char *oid, void *dctxv)
archprintf(fout, ");\n"); archprintf(fout, ");\n");
} }
PQclear(res); PQclear(res);
destroyPQExpBuffer(q);
return 1; return 1;
} }
@ -1202,6 +1204,10 @@ dumpDatabase(Archive *AH)
PQclear(res); PQclear(res);
destroyPQExpBuffer(dbQry);
destroyPQExpBuffer(delQry);
destroyPQExpBuffer(creaQry);
return 1; return 1;
} }
@ -1298,6 +1304,9 @@ dumpBlobs(Archive *AH, char *junkOid, void *junkVal)
} }
} while (PQntuples(res) > 0); } while (PQntuples(res) > 0);
destroyPQExpBuffer(oidQry);
destroyPQExpBuffer(oidFetchQry);
return 1; return 1;
} }
@ -1331,7 +1340,10 @@ getTypes(int *numTypes)
int i_typdelim; int i_typdelim;
int i_typdefault; int i_typdefault;
int i_typrelid; int i_typrelid;
int i_typalign;
int i_typstorage;
int i_typbyval; int i_typbyval;
int i_typisdefined;
int i_usename; int i_usename;
int i_typedefn; int i_typedefn;
@ -1340,9 +1352,7 @@ getTypes(int *numTypes)
/* /*
* we include even the built-in types because those may be used as * we include even the built-in types because those may be used as
* array elements by user-defined types * array elements by user-defined types
*/ *
/*
* we filter out the built-in types when we dump out the types * we filter out the built-in types when we dump out the types
*/ */
@ -1350,14 +1360,14 @@ getTypes(int *numTypes)
{ {
appendPQExpBuffer(query, "SELECT pg_type.oid, typowner, typname, typlen, typprtlen, " appendPQExpBuffer(query, "SELECT pg_type.oid, typowner, typname, typlen, typprtlen, "
"typinput, typoutput, typreceive, typsend, typelem, typdelim, " "typinput, typoutput, typreceive, typsend, typelem, typdelim, "
"typdefault, typrelid, typbyval, " "typdefault, typrelid, typalign, 'p'::char as typstorage, typbyval, typisdefined, "
"(select usename from pg_user where typowner = usesysid) as usename, " "(select usename from pg_user where typowner = usesysid) as usename, "
"typname as typedefn " "typname as typedefn "
"from pg_type"); "from pg_type");
} else { } else {
appendPQExpBuffer(query, "SELECT pg_type.oid, typowner, typname, typlen, typprtlen, " appendPQExpBuffer(query, "SELECT pg_type.oid, typowner, typname, typlen, typprtlen, "
"typinput, typoutput, typreceive, typsend, typelem, typdelim, " "typinput, typoutput, typreceive, typsend, typelem, typdelim, "
"typdefault, typrelid, typbyval, " "typdefault, typrelid, typalign, typstorage, typbyval, typisdefined, "
"(select usename from pg_user where typowner = usesysid) as usename, " "(select usename from pg_user where typowner = usesysid) as usename, "
"format_type(pg_type.oid, NULL) as typedefn " "format_type(pg_type.oid, NULL) as typedefn "
"from pg_type"); "from pg_type");
@ -1388,7 +1398,10 @@ getTypes(int *numTypes)
i_typdelim = PQfnumber(res, "typdelim"); i_typdelim = PQfnumber(res, "typdelim");
i_typdefault = PQfnumber(res, "typdefault"); i_typdefault = PQfnumber(res, "typdefault");
i_typrelid = PQfnumber(res, "typrelid"); i_typrelid = PQfnumber(res, "typrelid");
i_typalign = PQfnumber(res, "typalign");
i_typstorage = PQfnumber(res, "typstorage");
i_typbyval = PQfnumber(res, "typbyval"); i_typbyval = PQfnumber(res, "typbyval");
i_typisdefined = PQfnumber(res, "typisdefined");
i_usename = PQfnumber(res, "usename"); i_usename = PQfnumber(res, "usename");
i_typedefn = PQfnumber(res, "typedefn"); i_typedefn = PQfnumber(res, "typedefn");
@ -1407,6 +1420,8 @@ getTypes(int *numTypes)
tinfo[i].typdelim = strdup(PQgetvalue(res, i, i_typdelim)); tinfo[i].typdelim = strdup(PQgetvalue(res, i, i_typdelim));
tinfo[i].typdefault = strdup(PQgetvalue(res, i, i_typdefault)); tinfo[i].typdefault = strdup(PQgetvalue(res, i, i_typdefault));
tinfo[i].typrelid = strdup(PQgetvalue(res, i, i_typrelid)); tinfo[i].typrelid = strdup(PQgetvalue(res, i, i_typrelid));
tinfo[i].typalign = strdup(PQgetvalue(res, i, i_typalign));
tinfo[i].typstorage = strdup(PQgetvalue(res, i, i_typstorage));
tinfo[i].usename = strdup(PQgetvalue(res, i, i_usename)); tinfo[i].usename = strdup(PQgetvalue(res, i, i_usename));
tinfo[i].typedefn = strdup(PQgetvalue(res, i, i_typedefn)); tinfo[i].typedefn = strdup(PQgetvalue(res, i, i_typedefn));
@ -1427,12 +1442,19 @@ getTypes(int *numTypes)
tinfo[i].isArray = 1; tinfo[i].isArray = 1;
else else
tinfo[i].isArray = 0; tinfo[i].isArray = 0;
if (strcmp(PQgetvalue(res, i, i_typisdefined), "f") == 0)
tinfo[i].isDefined = 0;
else
tinfo[i].isDefined = 1;
} }
*numTypes = ntups; *numTypes = ntups;
PQclear(res); PQclear(res);
destroyPQExpBuffer(query);
return tinfo; return tinfo;
} }
@ -1534,6 +1556,8 @@ getOperators(int *numOprs)
PQclear(res); PQclear(res);
destroyPQExpBuffer(query);
return oprinfo; return oprinfo;
} }
@ -1570,8 +1594,14 @@ clearTypeInfo(TypeInfo *tp, int numTypes)
free(tp[i].typdefault); free(tp[i].typdefault);
if (tp[i].typrelid) if (tp[i].typrelid)
free(tp[i].typrelid); free(tp[i].typrelid);
if (tp[i].typalign)
free(tp[i].typalign);
if (tp[i].typstorage)
free(tp[i].typstorage);
if (tp[i].usename) if (tp[i].usename)
free(tp[i].usename); free(tp[i].usename);
if (tp[i].typedefn)
free(tp[i].typedefn);
} }
free(tp); free(tp);
} }
@ -1893,6 +1923,8 @@ getAggregates(int *numAggs)
PQclear(res); PQclear(res);
destroyPQExpBuffer(query);
return agginfo; return agginfo;
} }
@ -2014,8 +2046,9 @@ getFuncs(int *numFuncs)
PQclear(res); PQclear(res);
return finfo; destroyPQExpBuffer(query);
return finfo;
} }
/* /*
@ -2610,8 +2643,10 @@ getTables(int *numTables, FuncInfo *finfo, int numFuncs)
PQclear(res); PQclear(res);
return tblinfo; destroyPQExpBuffer(query);
destroyPQExpBuffer(delqry);
return tblinfo;
} }
/* /*
@ -2664,6 +2699,9 @@ getInherits(int *numInherits)
} }
PQclear(res); PQclear(res);
destroyPQExpBuffer(query);
return inhinfo; return inhinfo;
} }
@ -2695,7 +2733,6 @@ getTableAttrs(TableInfo *tblinfo, int numTables)
for (i = 0; i < numTables; i++) for (i = 0; i < numTables; i++)
{ {
if (tblinfo[i].sequence) if (tblinfo[i].sequence)
continue; continue;
@ -2831,6 +2868,8 @@ getTableAttrs(TableInfo *tblinfo, int numTables)
} }
PQclear(res); PQclear(res);
} }
destroyPQExpBuffer(q);
} }
@ -2937,6 +2976,9 @@ getIndexes(int *numIndexes)
indinfo[i].indhaspred = strdup(PQgetvalue(res, i, i_indhaspred)); indinfo[i].indhaspred = strdup(PQgetvalue(res, i, i_indhaspred));
} }
PQclear(res); PQclear(res);
destroyPQExpBuffer(query);
return indinfo; return indinfo;
} }
@ -2947,16 +2989,17 @@ getIndexes(int *numIndexes)
* oid handed to this routine. The routine takes a constant character * oid handed to this routine. The routine takes a constant character
* string for the target part of the object and the oid of the object * string for the target part of the object and the oid of the object
* whose comments are to be dumped. It is perfectly acceptable * whose comments are to be dumped. It is perfectly acceptable
* to hand an oid to this routine which has not been commented. In * to hand an oid to this routine which has not been commented. Additional
* addition, the routine takes the stdio FILE handle to which the * dependencies can be passed for the comment, too --- this is needed for
* output should be written. * VIEWs, whose comments are filed under the table OID but which are dumped
* in order by their rule OID.
*------------------------------------------------------------------ *------------------------------------------------------------------
*/ */
static void static void
dumpComment(Archive *fout, const char *target, const char *oid) dumpComment(Archive *fout, const char *target, const char *oid,
const char *((*deps)[]))
{ {
PGresult *res; PGresult *res;
PQExpBuffer query; PQExpBuffer query;
int i_description; int i_description;
@ -2991,7 +3034,8 @@ dumpComment(Archive *fout, const char *target, const char *oid)
formatStringLiteral(query, PQgetvalue(res, 0, i_description), PASS_LFTAB); formatStringLiteral(query, PQgetvalue(res, 0, i_description), PASS_LFTAB);
appendPQExpBuffer(query, ";\n"); appendPQExpBuffer(query, ";\n");
ArchiveEntry(fout, oid, target, "COMMENT", NULL, query->data, "" /* Del */ , ArchiveEntry(fout, oid, target, "COMMENT", deps,
query->data, "" /* Del */ ,
"" /* Copy */ , "" /* Owner */ , NULL, NULL); "" /* Copy */ , "" /* Owner */ , NULL, NULL);
} }
@ -2999,7 +3043,7 @@ dumpComment(Archive *fout, const char *target, const char *oid)
/*** Clear the statement buffer and return ***/ /*** Clear the statement buffer and return ***/
PQclear(res); PQclear(res);
destroyPQExpBuffer(query);
} }
/*------------------------------------------------------------------ /*------------------------------------------------------------------
@ -3015,7 +3059,6 @@ dumpComment(Archive *fout, const char *target, const char *oid)
void void
dumpDBComment(Archive *fout) dumpDBComment(Archive *fout)
{ {
PGresult *res; PGresult *res;
PQExpBuffer query; PQExpBuffer query;
int i_oid; int i_oid;
@ -3043,13 +3086,13 @@ dumpDBComment(Archive *fout)
i_oid = PQfnumber(res, "oid"); i_oid = PQfnumber(res, "oid");
resetPQExpBuffer(query); resetPQExpBuffer(query);
appendPQExpBuffer(query, "DATABASE %s", fmtId(PQdb(g_conn), force_quotes)); appendPQExpBuffer(query, "DATABASE %s", fmtId(PQdb(g_conn), force_quotes));
dumpComment(fout, query->data, PQgetvalue(res, 0, i_oid)); dumpComment(fout, query->data, PQgetvalue(res, 0, i_oid), NULL);
} }
/*** Clear the statement buffer and return ***/ /*** Clear the statement buffer and return ***/
PQclear(res); PQclear(res);
destroyPQExpBuffer(query);
} }
/* /*
@ -3066,13 +3109,10 @@ dumpTypes(Archive *fout, FuncInfo *finfo, int numFuncs,
PQExpBuffer delq = createPQExpBuffer(); PQExpBuffer delq = createPQExpBuffer();
int funcInd; int funcInd;
const char *((*deps)[]); const char *((*deps)[]);
int depIdx = 0; int depIdx;
deps = malloc(sizeof(char*) * 10);
for (i = 0; i < numTypes; i++) for (i = 0; i < numTypes; i++)
{ {
/* skip all the builtin types */ /* skip all the builtin types */
if (atooid(tinfo[i].oid) <= g_last_builtin_oid) if (atooid(tinfo[i].oid) <= g_last_builtin_oid)
continue; continue;
@ -3081,11 +3121,18 @@ dumpTypes(Archive *fout, FuncInfo *finfo, int numFuncs,
if (atoi(tinfo[i].typrelid) != 0) if (atoi(tinfo[i].typrelid) != 0)
continue; continue;
/* skip undefined placeholder types */
if (!tinfo[i].isDefined)
continue;
/* skip all array types that start w/ underscore */ /* skip all array types that start w/ underscore */
if ((tinfo[i].typname[0] == '_') && if ((tinfo[i].typname[0] == '_') &&
(strcmp(tinfo[i].typinput, "array_in") == 0)) (strcmp(tinfo[i].typinput, "array_in") == 0))
continue; continue;
deps = malloc(sizeof(char*) * 10);
depIdx = 0;
/* /*
* before we create a type, we need to create the input and output * before we create a type, we need to create the input and output
* functions for it, if they haven't been created already * functions for it, if they haven't been created already
@ -3104,6 +3151,7 @@ dumpTypes(Archive *fout, FuncInfo *finfo, int numFuncs,
dumpOneFunc(fout, finfo, funcInd, tinfo, numTypes); dumpOneFunc(fout, finfo, funcInd, tinfo, numTypes);
} }
resetPQExpBuffer(delq);
appendPQExpBuffer(delq, "DROP TYPE %s;\n", fmtId(tinfo[i].typname, force_quotes)); appendPQExpBuffer(delq, "DROP TYPE %s;\n", fmtId(tinfo[i].typname, force_quotes));
resetPQExpBuffer(q); resetPQExpBuffer(q);
@ -3133,8 +3181,6 @@ dumpTypes(Archive *fout, FuncInfo *finfo, int numFuncs,
{ {
write_msg(NULL, "notice: array type %s - type for elements (oid %s) is not dumped\n", write_msg(NULL, "notice: array type %s - type for elements (oid %s) is not dumped\n",
tinfo[i].typname, tinfo[i].typelem); tinfo[i].typname, tinfo[i].typelem);
resetPQExpBuffer(q);
resetPQExpBuffer(delq);
continue; continue;
} }
@ -3143,6 +3189,22 @@ dumpTypes(Archive *fout, FuncInfo *finfo, int numFuncs,
(*deps)[depIdx++] = strdup(tinfo[i].typelem); (*deps)[depIdx++] = strdup(tinfo[i].typelem);
} }
/* XXX these are all the aligns currently handled by DefineType */
if (strcmp(tinfo[i].typalign, "i") == 0)
appendPQExpBuffer(q, ", alignment = int4");
else if (strcmp(tinfo[i].typalign, "d") == 0)
appendPQExpBuffer(q, ", alignment = double");
if (strcmp(tinfo[i].typstorage, "p") == 0)
appendPQExpBuffer(q, ", storage = plain");
if (strcmp(tinfo[i].typstorage, "e") == 0)
appendPQExpBuffer(q, ", storage = external");
if (strcmp(tinfo[i].typstorage, "x") == 0)
appendPQExpBuffer(q, ", storage = extended");
if (strcmp(tinfo[i].typstorage, "m") == 0)
appendPQExpBuffer(q, ", storage = main");
if (tinfo[i].passedbyvalue) if (tinfo[i].passedbyvalue)
appendPQExpBuffer(q, ", passedbyvalue);\n"); appendPQExpBuffer(q, ", passedbyvalue);\n");
else else
@ -3156,13 +3218,13 @@ dumpTypes(Archive *fout, FuncInfo *finfo, int numFuncs,
/*** Dump Type Comments ***/ /*** Dump Type Comments ***/
resetPQExpBuffer(q); resetPQExpBuffer(q);
resetPQExpBuffer(delq);
appendPQExpBuffer(q, "TYPE %s", fmtId(tinfo[i].typname, force_quotes)); appendPQExpBuffer(q, "TYPE %s", fmtId(tinfo[i].typname, force_quotes));
dumpComment(fout, q->data, tinfo[i].oid); dumpComment(fout, q->data, tinfo[i].oid, NULL);
resetPQExpBuffer(q);
} }
destroyPQExpBuffer(q);
destroyPQExpBuffer(delq);
} }
/* /*
@ -3258,6 +3320,9 @@ dumpProcLangs(Archive *fout, FuncInfo *finfo, int numFuncs,
PQclear(res); PQclear(res);
destroyPQExpBuffer(query);
destroyPQExpBuffer(defqry);
destroyPQExpBuffer(delqry);
} }
/* /*
@ -3290,11 +3355,11 @@ dumpOneFunc(Archive *fout, FuncInfo *finfo, int i,
PQExpBuffer fn = createPQExpBuffer(); PQExpBuffer fn = createPQExpBuffer();
PQExpBuffer delqry = createPQExpBuffer(); PQExpBuffer delqry = createPQExpBuffer();
PQExpBuffer fnlist = createPQExpBuffer(); PQExpBuffer fnlist = createPQExpBuffer();
int j;
PQExpBuffer asPart = createPQExpBuffer(); PQExpBuffer asPart = createPQExpBuffer();
char func_lang[NAMEDATALEN + 1]; char func_lang[NAMEDATALEN + 1];
PGresult *res; PGresult *res;
int nlangs; int nlangs;
int j;
int i_lanname; int i_lanname;
char query[256]; char query[256];
@ -3304,8 +3369,8 @@ dumpOneFunc(Archive *fout, FuncInfo *finfo, int i,
char *rettypename; char *rettypename;
if (finfo[i].dumped) if (finfo[i].dumped)
return; goto done;
else
finfo[i].dumped = 1; finfo[i].dumped = 1;
/* becomeUser(fout, finfo[i].usename); */ /* becomeUser(fout, finfo[i].usename); */
@ -3370,12 +3435,7 @@ dumpOneFunc(Archive *fout, FuncInfo *finfo, int i,
write_msg(NULL, "reason: data type name of argument %d (oid %s) not found\n", write_msg(NULL, "reason: data type name of argument %d (oid %s) not found\n",
j, finfo[i].argtypes[j]); j, finfo[i].argtypes[j]);
resetPQExpBuffer(q); goto done;
resetPQExpBuffer(fn);
resetPQExpBuffer(delqry);
resetPQExpBuffer(fnlist);
resetPQExpBuffer(asPart);
return;
} }
appendPQExpBuffer(fn, "%s%s", appendPQExpBuffer(fn, "%s%s",
@ -3399,12 +3459,7 @@ dumpOneFunc(Archive *fout, FuncInfo *finfo, int i,
write_msg(NULL, "reason: name of return data type (oid %s) not found\n", write_msg(NULL, "reason: name of return data type (oid %s) not found\n",
finfo[i].prorettype); finfo[i].prorettype);
resetPQExpBuffer(q); goto done;
resetPQExpBuffer(fn);
resetPQExpBuffer(delqry);
resetPQExpBuffer(fnlist);
resetPQExpBuffer(asPart);
return;
} }
resetPQExpBuffer(q); resetPQExpBuffer(q);
@ -3445,8 +3500,14 @@ dumpOneFunc(Archive *fout, FuncInfo *finfo, int i,
appendPQExpBuffer(q, "FUNCTION %s ", appendPQExpBuffer(q, "FUNCTION %s ",
fmtId(finfo[i].proname, force_quotes)); fmtId(finfo[i].proname, force_quotes));
appendPQExpBuffer(q, "( %s )", fnlist->data); appendPQExpBuffer(q, "( %s )", fnlist->data);
dumpComment(fout, q->data, finfo[i].oid); dumpComment(fout, q->data, finfo[i].oid, NULL);
done:
destroyPQExpBuffer(q);
destroyPQExpBuffer(fn);
destroyPQExpBuffer(delqry);
destroyPQExpBuffer(fnlist);
destroyPQExpBuffer(asPart);
} }
/* /*
@ -3617,6 +3678,17 @@ dumpOprs(Archive *fout, OprInfo *oprinfo, int numOperators,
ArchiveEntry(fout, oprinfo[i].oid, oprinfo[i].oprname, "OPERATOR", NULL, ArchiveEntry(fout, oprinfo[i].oid, oprinfo[i].oprname, "OPERATOR", NULL,
q->data, delq->data, "", oprinfo[i].usename, NULL, NULL); q->data, delq->data, "", oprinfo[i].usename, NULL, NULL);
} }
destroyPQExpBuffer(q);
destroyPQExpBuffer(delq);
destroyPQExpBuffer(leftarg);
destroyPQExpBuffer(rightarg);
destroyPQExpBuffer(commutator);
destroyPQExpBuffer(negator);
destroyPQExpBuffer(restrictor);
destroyPQExpBuffer(join);
destroyPQExpBuffer(sort1);
destroyPQExpBuffer(sort2);
} }
/* /*
@ -3723,9 +3795,13 @@ dumpAggs(Archive *fout, AggInfo *agginfo, int numAggs,
resetPQExpBuffer(q); resetPQExpBuffer(q);
appendPQExpBuffer(q, "AGGREGATE %s %s", agginfo[i].aggname, appendPQExpBuffer(q, "AGGREGATE %s %s", agginfo[i].aggname,
findTypeByOid(tinfo, numTypes, agginfo[i].aggbasetype, zeroAsOpaque + useBaseTypeName)); findTypeByOid(tinfo, numTypes, agginfo[i].aggbasetype, zeroAsOpaque + useBaseTypeName));
dumpComment(fout, q->data, agginfo[i].oid); dumpComment(fout, q->data, agginfo[i].oid, NULL);
} }
destroyPQExpBuffer(q);
destroyPQExpBuffer(delq);
destroyPQExpBuffer(aggSig);
destroyPQExpBuffer(details);
} }
/* /*
@ -3981,6 +4057,7 @@ dumpTables(Archive *fout, TableInfo *tblinfo, int numTables,
int actual_atts; /* number of attrs in this CREATE statment */ int actual_atts; /* number of attrs in this CREATE statment */
char *reltypename; char *reltypename;
char *objoid; char *objoid;
const char *((*commentDeps)[]);
/* First - dump SEQUENCEs */ /* First - dump SEQUENCEs */
if (tablename && strlen(tablename) > 0) if (tablename && strlen(tablename) > 0)
@ -4023,12 +4100,15 @@ dumpTables(Archive *fout, TableInfo *tblinfo, int numTables,
objoid = tblinfo[i].viewoid; objoid = tblinfo[i].viewoid;
appendPQExpBuffer(delq, "DROP VIEW %s;\n", fmtId(tblinfo[i].relname, force_quotes)); appendPQExpBuffer(delq, "DROP VIEW %s;\n", fmtId(tblinfo[i].relname, force_quotes));
appendPQExpBuffer(q, "CREATE VIEW %s as %s\n", fmtId(tblinfo[i].relname, force_quotes), tblinfo[i].viewdef); appendPQExpBuffer(q, "CREATE VIEW %s as %s\n", fmtId(tblinfo[i].relname, force_quotes), tblinfo[i].viewdef);
commentDeps = malloc(sizeof(char*) * 2);
(*commentDeps)[0] = strdup(objoid);
(*commentDeps)[1] = NULL; /* end of list */
} }
else else
{ {
reltypename = "TABLE"; reltypename = "TABLE";
objoid = tblinfo[i].oid; objoid = tblinfo[i].oid;
commentDeps = NULL;
parentRels = tblinfo[i].parentRels; parentRels = tblinfo[i].parentRels;
numParents = tblinfo[i].numParents; numParents = tblinfo[i].numParents;
@ -4148,17 +4228,20 @@ dumpTables(Archive *fout, TableInfo *tblinfo, int numTables,
appendPQExpBuffer(q, "COLUMN %s", fmtId(tblinfo[i].relname, force_quotes)); appendPQExpBuffer(q, "COLUMN %s", fmtId(tblinfo[i].relname, force_quotes));
appendPQExpBuffer(q, "."); appendPQExpBuffer(q, ".");
appendPQExpBuffer(q, "%s", fmtId(tblinfo[i].attnames[j], force_quotes)); appendPQExpBuffer(q, "%s", fmtId(tblinfo[i].attnames[j], force_quotes));
dumpComment(fout, q->data, tblinfo[i].attoids[j]); dumpComment(fout, q->data, tblinfo[i].attoids[j], NULL);
} }
/* Dump Table Comments */ /* Dump Table Comments */
resetPQExpBuffer(q); resetPQExpBuffer(q);
appendPQExpBuffer(q, "%s %s", reltypename, fmtId(tblinfo[i].relname, force_quotes)); appendPQExpBuffer(q, "%s %s", reltypename, fmtId(tblinfo[i].relname, force_quotes));
dumpComment(fout, q->data, tblinfo[i].oid); dumpComment(fout, q->data, tblinfo[i].oid, commentDeps);
} }
} }
destroyPQExpBuffer(q);
destroyPQExpBuffer(delq);
} }
static PQExpBuffer static PQExpBuffer
@ -4237,16 +4320,15 @@ dumpIndexes(Archive *fout, IndInfo *indinfo, int numIndexes,
k; k;
int tableInd; int tableInd;
PQExpBuffer attlist = createPQExpBuffer(); PQExpBuffer attlist = createPQExpBuffer();
PQExpBuffer q = createPQExpBuffer();
PQExpBuffer delq = createPQExpBuffer();
PQExpBuffer id1 = createPQExpBuffer();
PQExpBuffer id2 = createPQExpBuffer();
char *classname[INDEX_MAX_KEYS]; char *classname[INDEX_MAX_KEYS];
char *funcname; /* the name of the function to comput the char *funcname; /* the name of the function to comput the
* index key from */ * index key from */
int indclass; int indclass;
int nclass; int nclass;
PQExpBuffer q = createPQExpBuffer(),
delq = createPQExpBuffer(),
id1 = createPQExpBuffer(),
id2 = createPQExpBuffer();
PGresult *res; PGresult *res;
for (i = 0; i < numIndexes; i++) for (i = 0; i < numIndexes; i++)
@ -4475,11 +4557,16 @@ dumpIndexes(Archive *fout, IndInfo *indinfo, int numIndexes,
/* Dump Index Comments */ /* Dump Index Comments */
resetPQExpBuffer(q); resetPQExpBuffer(q);
appendPQExpBuffer(q, "INDEX %s", id1->data); appendPQExpBuffer(q, "INDEX %s", id1->data);
dumpComment(fout, q->data, indinfo[i].indexreloid); dumpComment(fout, q->data, indinfo[i].indexreloid, NULL);
} }
} }
destroyPQExpBuffer(attlist);
destroyPQExpBuffer(q);
destroyPQExpBuffer(delq);
destroyPQExpBuffer(id1);
destroyPQExpBuffer(id2);
} }
/* /*
@ -4640,6 +4727,7 @@ findLastBuiltinOid_V71(const char *dbname)
} }
last_oid = atooid(PQgetvalue(res, 0, PQfnumber(res, "datlastsysoid"))); last_oid = atooid(PQgetvalue(res, 0, PQfnumber(res, "datlastsysoid")));
PQclear(res); PQclear(res);
destroyPQExpBuffer(query);
return last_oid; return last_oid;
} }
@ -4722,7 +4810,6 @@ dumpSequence(Archive *fout, TableInfo tbinfo, const bool schemaOnly, const bool
exit_nicely(); exit_nicely();
} }
last = atoi(PQgetvalue(res, 0, 1)); last = atoi(PQgetvalue(res, 0, 1));
incby = atoi(PQgetvalue(res, 0, 2)); incby = atoi(PQgetvalue(res, 0, 2));
maxv = atoi(PQgetvalue(res, 0, 3)); maxv = atoi(PQgetvalue(res, 0, 3));
@ -4779,8 +4866,11 @@ dumpSequence(Archive *fout, TableInfo tbinfo, const bool schemaOnly, const bool
resetPQExpBuffer(query); resetPQExpBuffer(query);
appendPQExpBuffer(query, "SEQUENCE %s", fmtId(tbinfo.relname, force_quotes)); appendPQExpBuffer(query, "SEQUENCE %s", fmtId(tbinfo.relname, force_quotes));
dumpComment(fout, query->data, tbinfo.oid); dumpComment(fout, query->data, tbinfo.oid, NULL);
} }
destroyPQExpBuffer(query);
destroyPQExpBuffer(delqry);
} }
@ -4804,7 +4894,7 @@ dumpTriggers(Archive *fout, const char *tablename,
ArchiveEntry(fout, tblinfo[i].triggers[j].oid, tblinfo[i].triggers[j].tgname, ArchiveEntry(fout, tblinfo[i].triggers[j].oid, tblinfo[i].triggers[j].tgname,
"TRIGGER", NULL, tblinfo[i].triggers[j].tgsrc, "", "", "TRIGGER", NULL, tblinfo[i].triggers[j].tgsrc, "", "",
tblinfo[i].usename, NULL, NULL); tblinfo[i].usename, NULL, NULL);
dumpComment(fout, tblinfo[i].triggers[j].tgcomment, tblinfo[i].triggers[j].oid); dumpComment(fout, tblinfo[i].triggers[j].tgcomment, tblinfo[i].triggers[j].oid, NULL);
} }
} }
} }
@ -4883,10 +4973,12 @@ dumpRules(Archive *fout, const char *tablename,
resetPQExpBuffer(query); resetPQExpBuffer(query);
appendPQExpBuffer(query, "RULE %s", fmtId(PQgetvalue(res, i, i_rulename), force_quotes)); appendPQExpBuffer(query, "RULE %s", fmtId(PQgetvalue(res, i, i_rulename), force_quotes));
dumpComment(fout, query->data, PQgetvalue(res, i, i_oid)); dumpComment(fout, query->data, PQgetvalue(res, i, i_oid), NULL);
} }
PQclear(res); PQclear(res);
} }
destroyPQExpBuffer(query);
} }

View File

@ -6,7 +6,7 @@
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $Id: pg_dump.h,v 1.67 2001/07/17 00:30:35 tgl Exp $ * $Id: pg_dump.h,v 1.68 2001/08/03 19:43:05 tgl Exp $
* *
* Modifications - 6/12/96 - dave@bensoft.com - version 1.13.dhb.2 * Modifications - 6/12/96 - dave@bensoft.com - version 1.13.dhb.2
* *
@ -49,10 +49,13 @@ typedef struct _typeInfo
char *typdelim; char *typdelim;
char *typdefault; char *typdefault;
char *typrelid; char *typrelid;
char *typalign;
char *typstorage;
char *usename; char *usename;
char *typedefn; char *typedefn;
int passedbyvalue; int passedbyvalue;
int isArray; int isArray;
int isDefined;
} TypeInfo; } TypeInfo;
typedef struct _funcInfo typedef struct _funcInfo