Commit 2f9bdffc authored by Philip Warner's avatar Philip Warner

Applied (slightly modified) patches from Tatsuo:

Ok. I have made patches for fixing some of pg_dump problems(see
attached patches). The patches address the problem with user defined
functions, operators and aggregates.
parent d7f0b7ef
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/bin/pg_dump/common.c,v 1.50 2001/01/24 19:43:18 momjian Exp $ * $Header: /cvsroot/pgsql/src/bin/pg_dump/common.c,v 1.51 2001/01/28 02:57:06 pjw 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
* *
...@@ -86,10 +86,8 @@ findTypeByOid(TypeInfo *tinfo, int numTypes, const char *oid, OidOptions opts) ...@@ -86,10 +86,8 @@ findTypeByOid(TypeInfo *tinfo, int numTypes, const char *oid, OidOptions opts)
} }
} }
/* should never get here */ /* no suitable type name was found */
fprintf(stderr, "failed sanity check, type with oid %s was not found\n", return(NULL);
oid);
exit(2);
} }
/* /*
...@@ -114,7 +112,9 @@ findOprByOid(OprInfo *oprinfo, int numOprs, const char *oid) ...@@ -114,7 +112,9 @@ findOprByOid(OprInfo *oprinfo, int numOprs, const char *oid)
/* should never get here */ /* should never get here */
fprintf(stderr, "failed sanity check, opr with oid %s was not found\n", fprintf(stderr, "failed sanity check, opr with oid %s was not found\n",
oid); oid);
exit(2);
/* no suitable operator name was found */
return(NULL);
} }
......
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.188 2001/01/24 19:43:18 momjian Exp $ * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.189 2001/01/28 02:57:06 pjw Exp $
* *
* Modifications - 6/10/96 - dave@bensoft.com - version 1.13.dhb * Modifications - 6/10/96 - dave@bensoft.com - version 1.13.dhb
* *
...@@ -2928,6 +2928,15 @@ dumpTypes(Archive *fout, FuncInfo *finfo, int numFuncs, ...@@ -2928,6 +2928,15 @@ dumpTypes(Archive *fout, FuncInfo *finfo, int numFuncs,
char *elemType; char *elemType;
elemType = findTypeByOid(tinfo, numTypes, tinfo[i].typelem, zeroAsOpaque); elemType = findTypeByOid(tinfo, numTypes, tinfo[i].typelem, zeroAsOpaque);
if (elemType == NULL)
{
fprintf(stderr, "Notice: array type %s - type for elements (oid %s) is not dumped.\n",
tinfo[i].typname, tinfo[i].typelem);
resetPQExpBuffer(q);
resetPQExpBuffer(delq);
continue;
}
appendPQExpBuffer(q, ", element = %s, delimiter = ", elemType); appendPQExpBuffer(q, ", element = %s, delimiter = ", elemType);
formatStringLiteral(q, tinfo[i].typdelim); formatStringLiteral(q, tinfo[i].typdelim);
} }
...@@ -3086,6 +3095,7 @@ dumpOneFunc(Archive *fout, FuncInfo *finfo, int i, ...@@ -3086,6 +3095,7 @@ dumpOneFunc(Archive *fout, FuncInfo *finfo, int i,
char *listSep; char *listSep;
char *listSepComma = ","; char *listSepComma = ",";
char *listSepNone = ""; char *listSepNone = "";
char *rettypename;
if (finfo[i].dumped) if (finfo[i].dumped)
return; return;
...@@ -3147,6 +3157,21 @@ dumpOneFunc(Archive *fout, FuncInfo *finfo, int i, ...@@ -3147,6 +3157,21 @@ dumpOneFunc(Archive *fout, FuncInfo *finfo, int i,
char *typname; char *typname;
typname = findTypeByOid(tinfo, numTypes, finfo[i].argtypes[j], zeroAsOpaque); typname = findTypeByOid(tinfo, numTypes, finfo[i].argtypes[j], zeroAsOpaque);
if (typname == NULL)
{
fprintf(stderr, "Notice: function \"%s\" is not dumped.\n",
finfo[i].proname);
fprintf(stderr, "Reason: the %d th argument type name (oid %s) not found.\n",
j, finfo[i].argtypes[j]);
resetPQExpBuffer(q);
resetPQExpBuffer(fn);
resetPQExpBuffer(delqry);
resetPQExpBuffer(fnlist);
resetPQExpBuffer(asPart);
return;
}
appendPQExpBuffer(fn, "%s%s", appendPQExpBuffer(fn, "%s%s",
(j > 0) ? "," : "", (j > 0) ? "," : "",
typname); typname);
...@@ -3159,11 +3184,28 @@ dumpOneFunc(Archive *fout, FuncInfo *finfo, int i, ...@@ -3159,11 +3184,28 @@ dumpOneFunc(Archive *fout, FuncInfo *finfo, int i,
resetPQExpBuffer(delqry); resetPQExpBuffer(delqry);
appendPQExpBuffer(delqry, "DROP FUNCTION %s;\n", fn->data ); appendPQExpBuffer(delqry, "DROP FUNCTION %s;\n", fn->data );
rettypename = findTypeByOid(tinfo, numTypes, finfo[i].prorettype, zeroAsOpaque);
if (rettypename == NULL)
{
fprintf(stderr, "Notice: function \"%s\" is not dumped.\n",
finfo[i].proname);
fprintf(stderr, "Reason: return type name (oid %s) not found.\n",
finfo[i].prorettype);
resetPQExpBuffer(q);
resetPQExpBuffer(fn);
resetPQExpBuffer(delqry);
resetPQExpBuffer(fnlist);
resetPQExpBuffer(asPart);
return;
}
resetPQExpBuffer(q); resetPQExpBuffer(q);
appendPQExpBuffer(q, "CREATE FUNCTION %s ", fn->data ); appendPQExpBuffer(q, "CREATE FUNCTION %s ", fn->data );
appendPQExpBuffer(q, "RETURNS %s%s %s LANGUAGE ", appendPQExpBuffer(q, "RETURNS %s%s %s LANGUAGE ",
(finfo[i].retset) ? "SETOF " : "", (finfo[i].retset) ? "SETOF " : "",
findTypeByOid(tinfo, numTypes, finfo[i].prorettype, zeroAsOpaque), rettypename,
asPart->data); asPart->data);
formatStringLiteral(q, func_lang); formatStringLiteral(q, func_lang);
...@@ -3208,6 +3250,12 @@ void ...@@ -3208,6 +3250,12 @@ void
dumpOprs(Archive *fout, OprInfo *oprinfo, int numOperators, dumpOprs(Archive *fout, OprInfo *oprinfo, int numOperators,
TypeInfo *tinfo, int numTypes) TypeInfo *tinfo, int numTypes)
{ {
#define OPR_NOTICE(arg) {\
fprintf(stderr, "Notice: operator \"%s\"(oid %s) is not dumped.\n",oprinfo[i].oprname, oprinfo[i].oid);\
fprintf(stderr, "Reason: " CppAsString(arg));\
fprintf (stderr, " (oid %s) not found.\n",oprinfo[i].arg);\
}
int i; int i;
PQExpBuffer q = createPQExpBuffer(); PQExpBuffer q = createPQExpBuffer();
PQExpBuffer delq = createPQExpBuffer(); PQExpBuffer delq = createPQExpBuffer();
...@@ -3222,6 +3270,7 @@ dumpOprs(Archive *fout, OprInfo *oprinfo, int numOperators, ...@@ -3222,6 +3270,7 @@ dumpOprs(Archive *fout, OprInfo *oprinfo, int numOperators,
for (i = 0; i < numOperators; i++) for (i = 0; i < numOperators; i++)
{ {
char *name;
resetPQExpBuffer(leftarg); resetPQExpBuffer(leftarg);
resetPQExpBuffer(rightarg); resetPQExpBuffer(rightarg);
...@@ -3250,22 +3299,50 @@ dumpOprs(Archive *fout, OprInfo *oprinfo, int numOperators, ...@@ -3250,22 +3299,50 @@ dumpOprs(Archive *fout, OprInfo *oprinfo, int numOperators,
if (strcmp(oprinfo[i].oprkind, "r") == 0 || if (strcmp(oprinfo[i].oprkind, "r") == 0 ||
strcmp(oprinfo[i].oprkind, "b") == 0) strcmp(oprinfo[i].oprkind, "b") == 0)
{ {
appendPQExpBuffer(leftarg, ",\n\tLEFTARG = %s ", name = findTypeByOid(tinfo, numTypes,
findTypeByOid(tinfo, numTypes, oprinfo[i].oprleft, zeroAsOpaque) ); oprinfo[i].oprleft, zeroAsOpaque);
if (name == NULL)
{
OPR_NOTICE(oprleft);
continue;
} }
appendPQExpBuffer(leftarg, ",\n\tLEFTARG = %s ",name);
}
if (strcmp(oprinfo[i].oprkind, "l") == 0 || if (strcmp(oprinfo[i].oprkind, "l") == 0 ||
strcmp(oprinfo[i].oprkind, "b") == 0) strcmp(oprinfo[i].oprkind, "b") == 0)
{ {
appendPQExpBuffer(rightarg, ",\n\tRIGHTARG = %s ", name = findTypeByOid(tinfo, numTypes,
findTypeByOid(tinfo, numTypes, oprinfo[i].oprright, zeroAsOpaque) ); oprinfo[i].oprright, zeroAsOpaque);
if (name == NULL)
{
OPR_NOTICE(oprright);
continue;
}
appendPQExpBuffer(rightarg, ",\n\tRIGHTARG = %s ", name);
} }
if (!(strcmp(oprinfo[i].oprcom, "0") == 0)) if (!(strcmp(oprinfo[i].oprcom, "0") == 0))
appendPQExpBuffer(commutator, ",\n\tCOMMUTATOR = %s ", {
findOprByOid(oprinfo, numOperators, oprinfo[i].oprcom)); name = findOprByOid(oprinfo, numOperators, oprinfo[i].oprcom);
if (name == NULL)
{
OPR_NOTICE(oprcom);
continue;
}
appendPQExpBuffer(commutator, ",\n\tCOMMUTATOR = %s ", name);
}
if (!(strcmp(oprinfo[i].oprnegate, "0") == 0)) if (!(strcmp(oprinfo[i].oprnegate, "0") == 0))
appendPQExpBuffer(negator, ",\n\tNEGATOR = %s ", {
findOprByOid(oprinfo, numOperators, oprinfo[i].oprnegate)); name = findOprByOid(oprinfo, numOperators, oprinfo[i].oprnegate);
if (name == NULL)
{
OPR_NOTICE(oprnegate);
continue;
}
appendPQExpBuffer(negator, ",\n\tNEGATOR = %s ", name);
}
if (!(strcmp(oprinfo[i].oprrest, "-") == 0)) if (!(strcmp(oprinfo[i].oprrest, "-") == 0))
appendPQExpBuffer(restrictor, ",\n\tRESTRICT = %s ", oprinfo[i].oprrest); appendPQExpBuffer(restrictor, ",\n\tRESTRICT = %s ", oprinfo[i].oprrest);
...@@ -3274,12 +3351,26 @@ dumpOprs(Archive *fout, OprInfo *oprinfo, int numOperators, ...@@ -3274,12 +3351,26 @@ dumpOprs(Archive *fout, OprInfo *oprinfo, int numOperators,
appendPQExpBuffer(join, ",\n\tJOIN = %s ", oprinfo[i].oprjoin); appendPQExpBuffer(join, ",\n\tJOIN = %s ", oprinfo[i].oprjoin);
if (!(strcmp(oprinfo[i].oprlsortop, "0") == 0)) if (!(strcmp(oprinfo[i].oprlsortop, "0") == 0))
appendPQExpBuffer(sort1, ",\n\tSORT1 = %s ", {
findOprByOid(oprinfo, numOperators, oprinfo[i].oprlsortop)); name = findOprByOid(oprinfo, numOperators, oprinfo[i].oprlsortop);
if (name == NULL)
{
OPR_NOTICE(oprlsortop);
continue;
}
appendPQExpBuffer(sort1, ",\n\tSORT1 = %s ", name);
}
if (!(strcmp(oprinfo[i].oprrsortop, "0") == 0)) if (!(strcmp(oprinfo[i].oprrsortop, "0") == 0))
appendPQExpBuffer(sort2, ",\n\tSORT2 = %s ", {
findOprByOid(oprinfo, numOperators, oprinfo[i].oprrsortop)); name = findOprByOid(oprinfo, numOperators, oprinfo[i].oprrsortop);
if (name == NULL)
{
OPR_NOTICE(oprrsortop);
continue;
}
appendPQExpBuffer(sort2, ",\n\tSORT2 = %s ", name);
}
resetPQExpBuffer(delq); resetPQExpBuffer(delq);
appendPQExpBuffer(delq, "DROP OPERATOR %s (%s", oprinfo[i].oprname, appendPQExpBuffer(delq, "DROP OPERATOR %s (%s", oprinfo[i].oprname,
...@@ -3317,6 +3408,12 @@ void ...@@ -3317,6 +3408,12 @@ void
dumpAggs(Archive *fout, AggInfo *agginfo, int numAggs, dumpAggs(Archive *fout, AggInfo *agginfo, int numAggs,
TypeInfo *tinfo, int numTypes) TypeInfo *tinfo, int numTypes)
{ {
#define AGG_NOTICE(arg) {\
fprintf(stderr, "Notice: aggregate \"%s\"(oid %s) is not dumped.\n",agginfo[i].aggname, agginfo[i].oid);\
fprintf(stderr, "Reason: " CppAsString(arg) );\
fprintf (stderr, " (oid %s) not found.\n",agginfo[i].arg);\
}
int i; int i;
PQExpBuffer q = createPQExpBuffer(); PQExpBuffer q = createPQExpBuffer();
PQExpBuffer delq = createPQExpBuffer(); PQExpBuffer delq = createPQExpBuffer();
...@@ -3325,20 +3422,31 @@ dumpAggs(Archive *fout, AggInfo *agginfo, int numAggs, ...@@ -3325,20 +3422,31 @@ dumpAggs(Archive *fout, AggInfo *agginfo, int numAggs,
for (i = 0; i < numAggs; i++) for (i = 0; i < numAggs; i++)
{ {
char *name;
resetPQExpBuffer(details); resetPQExpBuffer(details);
/* skip all the builtin oids */ /* skip all the builtin oids */
if (atooid(agginfo[i].oid) <= g_last_builtin_oid) if (atooid(agginfo[i].oid) <= g_last_builtin_oid)
continue; continue;
appendPQExpBuffer(details, name = findTypeByOid(tinfo, numTypes, agginfo[i].aggbasetype, zeroAsAny + useBaseTypeName);
"BASETYPE = %s, ", if (name == NULL)
findTypeByOid(tinfo, numTypes, agginfo[i].aggbasetype, zeroAsAny + useBaseTypeName)); {
AGG_NOTICE(aggbasetype);
continue;
}
appendPQExpBuffer(details, "BASETYPE = %s, ", name);
name = findTypeByOid(tinfo, numTypes, agginfo[i].aggtranstype, zeroAsOpaque + useBaseTypeName);
if (name == NULL)
{
AGG_NOTICE(aggtranstype);
continue;
}
appendPQExpBuffer(details, appendPQExpBuffer(details,
"SFUNC = %s, STYPE = %s", "SFUNC = %s, STYPE = %s",
agginfo[i].aggtransfn, agginfo[i].aggtransfn, name);
findTypeByOid(tinfo, numTypes, agginfo[i].aggtranstype, zeroAsOpaque + useBaseTypeName));
if (agginfo[i].agginitval) if (agginfo[i].agginitval)
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment