Commit 565afb88 authored by Philip Warner's avatar Philip Warner

Uses column select expressions to get object object owners and tests for blank names

parent aef7a0c8
...@@ -62,7 +62,7 @@ typedef z_stream *z_streamp; ...@@ -62,7 +62,7 @@ typedef z_stream *z_streamp;
#define K_VERS_MAJOR 1 #define K_VERS_MAJOR 1
#define K_VERS_MINOR 4 #define K_VERS_MINOR 4
#define K_VERS_REV 14 #define K_VERS_REV 15
/* Data block types */ /* Data block types */
#define BLK_DATA 1 #define BLK_DATA 1
......
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.166 2000/09/17 20:01:28 tgl Exp $ * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.167 2000/09/18 03:24:03 pjw Exp $
* *
* Modifications - 6/10/96 - dave@bensoft.com - version 1.13.dhb * Modifications - 6/10/96 - dave@bensoft.com - version 1.13.dhb
* *
...@@ -1004,7 +1004,7 @@ dumpDatabase(Archive *AH) ...@@ -1004,7 +1004,7 @@ dumpDatabase(Archive *AH)
fprintf(stderr, "%s saving database definition\n", g_comment_start); fprintf(stderr, "%s saving database definition\n", g_comment_start);
/* Get the dba */ /* Get the dba */
appendPQExpBuffer(dbQry, "select pg_get_userbyid(datdba) as dba from pg_database" appendPQExpBuffer(dbQry, "select (select usename from pg_user where datdba = usesysid) as dba from pg_database"
" where datname = '%s'", PQdb(g_conn)); " where datname = '%s'", PQdb(g_conn));
res = PQexec(g_conn, dbQry->data); res = PQexec(g_conn, dbQry->data);
...@@ -1172,11 +1172,11 @@ getTypes(int *numTypes) ...@@ -1172,11 +1172,11 @@ 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, usename, " "typdefault, typrelid, typbyval, "
"format_type(pg_type.oid, NULL) as typedefn " "(select usename from pg_user where typowner = usesysid) as usename, "
"from pg_type, pg_user " "format_type(pg_type.oid, NULL) as typedefn "
"where typowner = usesysid"); "from pg_type" );
res = PQexec(g_conn, query->data); res = PQexec(g_conn, query->data);
if (!res || if (!res ||
...@@ -1225,6 +1225,9 @@ getTypes(int *numTypes) ...@@ -1225,6 +1225,9 @@ getTypes(int *numTypes)
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));
if (strlen(tinfo[i].usename) == 0)
fprintf(stderr, "WARNING: owner of type '%s' appears to be invalid\n",tinfo[i].typname);
if (strcmp(PQgetvalue(res, i, i_typbyval), "f") == 0) if (strcmp(PQgetvalue(res, i, i_typbyval), "f") == 0)
tinfo[i].passedbyvalue = 0; tinfo[i].passedbyvalue = 0;
else else
...@@ -1288,9 +1291,9 @@ getOperators(int *numOprs) ...@@ -1288,9 +1291,9 @@ getOperators(int *numOprs)
appendPQExpBuffer(query, "SELECT pg_operator.oid, oprname, oprkind, oprcode, " appendPQExpBuffer(query, "SELECT pg_operator.oid, oprname, oprkind, oprcode, "
"oprleft, oprright, oprcom, oprnegate, oprrest, oprjoin, " "oprleft, oprright, oprcom, oprnegate, oprrest, oprjoin, "
"oprcanhash, oprlsortop, oprrsortop, usename " "oprcanhash, oprlsortop, oprrsortop, "
"from pg_operator, pg_user " "(select usename from pg_user where oprowner = usesysid) as usename "
"where oprowner = usesysid"); "from pg_operator");
res = PQexec(g_conn, query->data); res = PQexec(g_conn, query->data);
if (!res || if (!res ||
...@@ -1336,6 +1339,11 @@ getOperators(int *numOprs) ...@@ -1336,6 +1339,11 @@ getOperators(int *numOprs)
oprinfo[i].oprlsortop = strdup(PQgetvalue(res, i, i_oprlsortop)); oprinfo[i].oprlsortop = strdup(PQgetvalue(res, i, i_oprlsortop));
oprinfo[i].oprrsortop = strdup(PQgetvalue(res, i, i_oprrsortop)); oprinfo[i].oprrsortop = strdup(PQgetvalue(res, i, i_oprrsortop));
oprinfo[i].usename = strdup(PQgetvalue(res, i, i_usename)); oprinfo[i].usename = strdup(PQgetvalue(res, i, i_usename));
if (strlen(oprinfo[i].usename) == 0)
fprintf(stderr, "WARNING: owner of operator '%s' appears to be invalid\n",
oprinfo[i].oprname);
} }
PQclear(res); PQclear(res);
...@@ -1627,10 +1635,11 @@ getAggregates(int *numAggs) ...@@ -1627,10 +1635,11 @@ getAggregates(int *numAggs)
/* find all user-defined aggregates */ /* find all user-defined aggregates */
appendPQExpBuffer(query, appendPQExpBuffer(query,
"SELECT pg_aggregate.oid, aggname, aggtransfn, " "SELECT pg_aggregate.oid, aggname, aggtransfn, "
"aggfinalfn, aggtranstype, aggbasetype, " "aggfinalfn, aggtranstype, aggbasetype, "
"agginitval, usename from pg_aggregate, pg_user " "agginitval, "
"where aggowner = usesysid"); "(select usename from pg_user where aggowner = usesysid) as usename "
"from pg_aggregate" );
res = PQexec(g_conn, query->data); res = PQexec(g_conn, query->data);
if (!res || if (!res ||
...@@ -1665,6 +1674,10 @@ getAggregates(int *numAggs) ...@@ -1665,6 +1674,10 @@ getAggregates(int *numAggs)
agginfo[i].aggbasetype = strdup(PQgetvalue(res, i, i_aggbasetype)); agginfo[i].aggbasetype = strdup(PQgetvalue(res, i, i_aggbasetype));
agginfo[i].agginitval = strdup(PQgetvalue(res, i, i_agginitval)); agginfo[i].agginitval = strdup(PQgetvalue(res, i, i_agginitval));
agginfo[i].usename = strdup(PQgetvalue(res, i, i_usename)); agginfo[i].usename = strdup(PQgetvalue(res, i, i_usename));
if (strlen(agginfo[i].usename) == 0)
fprintf(stderr, "WARNING: owner of aggregate '%s' appears to be invalid\n",
agginfo[i].aggname);
} }
PQclear(res); PQclear(res);
...@@ -1706,10 +1719,11 @@ getFuncs(int *numFuncs) ...@@ -1706,10 +1719,11 @@ getFuncs(int *numFuncs)
appendPQExpBuffer(query, appendPQExpBuffer(query,
"SELECT pg_proc.oid, proname, prolang, pronargs, prorettype, " "SELECT pg_proc.oid, proname, prolang, pronargs, prorettype, "
"proretset, proargtypes, prosrc, probin, usename, " "proretset, proargtypes, prosrc, probin, "
"(select usename from pg_user where proowner = usesysid) as usename, "
"proiscachable " "proiscachable "
"from pg_proc, pg_user " "from pg_proc "
"where pg_proc.oid > '%u'::oid and proowner = usesysid", "where pg_proc.oid > '%u'::oid",
g_last_builtin_oid); g_last_builtin_oid);
res = PQexec(g_conn, query->data); res = PQexec(g_conn, query->data);
...@@ -1755,6 +1769,11 @@ getFuncs(int *numFuncs) ...@@ -1755,6 +1769,11 @@ getFuncs(int *numFuncs)
finfo[i].lang = atoi(PQgetvalue(res, i, i_prolang)); finfo[i].lang = atoi(PQgetvalue(res, i, i_prolang));
finfo[i].usename = strdup(PQgetvalue(res, i, i_usename)); finfo[i].usename = strdup(PQgetvalue(res, i, i_usename));
finfo[i].iscachable = (strcmp(PQgetvalue(res, i, i_iscachable),"t") == 0); finfo[i].iscachable = (strcmp(PQgetvalue(res, i, i_iscachable),"t") == 0);
if (strlen(finfo[i].usename) == 0)
fprintf(stderr, "WARNING: owner of function '%s' appears to be invalid\n",
finfo[i].proname);
if (finfo[i].nargs < 0 || finfo[i].nargs > FUNC_MAX_ARGS) if (finfo[i].nargs < 0 || finfo[i].nargs > FUNC_MAX_ARGS)
{ {
fprintf(stderr, "failed sanity check: %s has %d args\n", fprintf(stderr, "failed sanity check: %s has %d args\n",
...@@ -1818,10 +1837,11 @@ getTables(int *numTables, FuncInfo *finfo, int numFuncs) ...@@ -1818,10 +1837,11 @@ getTables(int *numTables, FuncInfo *finfo, int numFuncs)
*/ */
appendPQExpBuffer(query, appendPQExpBuffer(query,
"SELECT pg_class.oid, relname, relkind, relacl, usename, " "SELECT pg_class.oid, relname, relkind, relacl, "
"(select usename from pg_user where relowner = usesysid) as usename, "
"relchecks, reltriggers, relhasindex, pg_get_viewdef(relname) as viewdef " "relchecks, reltriggers, relhasindex, pg_get_viewdef(relname) as viewdef "
"from pg_class, pg_user " "from pg_class "
"where relowner = usesysid and relname !~ '^pg_' " "where relname !~ '^pg_' "
"and relkind in ('%c', '%c', '%c') " "and relkind in ('%c', '%c', '%c') "
"order by oid", "order by oid",
RELKIND_RELATION, RELKIND_SEQUENCE, RELKIND_VIEW); RELKIND_RELATION, RELKIND_SEQUENCE, RELKIND_VIEW);
...@@ -1866,6 +1886,10 @@ getTables(int *numTables, FuncInfo *finfo, int numFuncs) ...@@ -1866,6 +1886,10 @@ getTables(int *numTables, FuncInfo *finfo, int numFuncs)
tblinfo[i].viewdef = NULL; tblinfo[i].viewdef = NULL;
} }
if (strlen(tblinfo[i].usename) == 0)
fprintf(stderr, "WARNING: owner of table '%s' appears to be invalid\n",
tblinfo[i].relname);
/* /*
* Exclude inherited CHECKs from CHECK constraints total. If a * Exclude inherited CHECKs from CHECK constraints total. If a
* constraint matches by name and condition with a constraint * constraint matches by name and condition with a constraint
...@@ -3981,7 +4005,7 @@ dumpRules(Archive *fout, const char *tablename, ...@@ -3981,7 +4005,7 @@ dumpRules(Archive *fout, const char *tablename,
*/ */
resetPQExpBuffer(query); resetPQExpBuffer(query);
appendPQExpBuffer(query, "SELECT definition," appendPQExpBuffer(query, "SELECT definition,"
" pg_get_userbyid(pg_class.relowner) AS viewowner, " " (select usename from pg_user where pg_class.relowner = usesysid) AS viewowner, "
" pg_rewrite.oid, pg_rewrite.rulename " " pg_rewrite.oid, pg_rewrite.rulename "
"FROM pg_rewrite, pg_class, pg_rules " "FROM pg_rewrite, pg_class, pg_rules "
"WHERE pg_class.relname = '%s' " "WHERE pg_class.relname = '%s' "
......
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