Commit 7e8c25c6 authored by Heikki Linnakangas's avatar Heikki Linnakangas

Initialize tableoid field correctly when dumping foreign data wrappers and

servers. AFAICT it's harmless at the moment because nothing can depend on
either, but as soon as we introduce an object type with such dependencies,
tableoid needs to be set or pg_dump will fail to interpret the dependencies
correctly. In theory, I guess the uninitialized garbage in tableoid could
cause the object to be mistaken for some other object with same OID as well.
parent 9aae8152
...@@ -5851,6 +5851,7 @@ getForeignDataWrappers(int *numForeignDataWrappers) ...@@ -5851,6 +5851,7 @@ getForeignDataWrappers(int *numForeignDataWrappers)
int i; int i;
PQExpBuffer query = createPQExpBuffer(); PQExpBuffer query = createPQExpBuffer();
FdwInfo *fdwinfo; FdwInfo *fdwinfo;
int i_tableoid;
int i_oid; int i_oid;
int i_fdwname; int i_fdwname;
int i_rolname; int i_rolname;
...@@ -5868,7 +5869,7 @@ getForeignDataWrappers(int *numForeignDataWrappers) ...@@ -5868,7 +5869,7 @@ getForeignDataWrappers(int *numForeignDataWrappers)
/* Make sure we are in proper schema */ /* Make sure we are in proper schema */
selectSourceSchema("pg_catalog"); selectSourceSchema("pg_catalog");
appendPQExpBuffer(query, "SELECT oid, fdwname, " appendPQExpBuffer(query, "SELECT tableoid, oid, fdwname, "
"(%s fdwowner) AS rolname, fdwvalidator::pg_catalog.regproc, fdwacl," "(%s fdwowner) AS rolname, fdwvalidator::pg_catalog.regproc, fdwacl,"
"array_to_string(ARRAY(" "array_to_string(ARRAY("
" SELECT option_name || ' ' || quote_literal(option_value) " " SELECT option_name || ' ' || quote_literal(option_value) "
...@@ -5884,6 +5885,7 @@ getForeignDataWrappers(int *numForeignDataWrappers) ...@@ -5884,6 +5885,7 @@ getForeignDataWrappers(int *numForeignDataWrappers)
fdwinfo = (FdwInfo *) malloc(ntups * sizeof(FdwInfo)); fdwinfo = (FdwInfo *) malloc(ntups * sizeof(FdwInfo));
i_tableoid = PQfnumber(res, "tableoid");
i_oid = PQfnumber(res, "oid"); i_oid = PQfnumber(res, "oid");
i_fdwname = PQfnumber(res, "fdwname"); i_fdwname = PQfnumber(res, "fdwname");
i_rolname = PQfnumber(res, "rolname"); i_rolname = PQfnumber(res, "rolname");
...@@ -5894,6 +5896,7 @@ getForeignDataWrappers(int *numForeignDataWrappers) ...@@ -5894,6 +5896,7 @@ getForeignDataWrappers(int *numForeignDataWrappers)
for (i = 0; i < ntups; i++) for (i = 0; i < ntups; i++)
{ {
fdwinfo[i].dobj.objType = DO_FDW; fdwinfo[i].dobj.objType = DO_FDW;
fdwinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
fdwinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid)); fdwinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
AssignDumpId(&fdwinfo[i].dobj); AssignDumpId(&fdwinfo[i].dobj);
fdwinfo[i].dobj.name = strdup(PQgetvalue(res, i, i_fdwname)); fdwinfo[i].dobj.name = strdup(PQgetvalue(res, i, i_fdwname));
...@@ -5930,6 +5933,7 @@ getForeignServers(int *numForeignServers) ...@@ -5930,6 +5933,7 @@ getForeignServers(int *numForeignServers)
int i; int i;
PQExpBuffer query = createPQExpBuffer(); PQExpBuffer query = createPQExpBuffer();
ForeignServerInfo *srvinfo; ForeignServerInfo *srvinfo;
int i_tableoid;
int i_oid; int i_oid;
int i_srvname; int i_srvname;
int i_rolname; int i_rolname;
...@@ -5949,7 +5953,7 @@ getForeignServers(int *numForeignServers) ...@@ -5949,7 +5953,7 @@ getForeignServers(int *numForeignServers)
/* Make sure we are in proper schema */ /* Make sure we are in proper schema */
selectSourceSchema("pg_catalog"); selectSourceSchema("pg_catalog");
appendPQExpBuffer(query, "SELECT oid, srvname, " appendPQExpBuffer(query, "SELECT tableoid, oid, srvname, "
"(%s srvowner) AS rolname, " "(%s srvowner) AS rolname, "
"srvfdw, srvtype, srvversion, srvacl," "srvfdw, srvtype, srvversion, srvacl,"
"array_to_string(ARRAY(" "array_to_string(ARRAY("
...@@ -5966,6 +5970,7 @@ getForeignServers(int *numForeignServers) ...@@ -5966,6 +5970,7 @@ getForeignServers(int *numForeignServers)
srvinfo = (ForeignServerInfo *) malloc(ntups * sizeof(ForeignServerInfo)); srvinfo = (ForeignServerInfo *) malloc(ntups * sizeof(ForeignServerInfo));
i_tableoid = PQfnumber(res, "tableoid");
i_oid = PQfnumber(res, "oid"); i_oid = PQfnumber(res, "oid");
i_srvname = PQfnumber(res, "srvname"); i_srvname = PQfnumber(res, "srvname");
i_rolname = PQfnumber(res, "rolname"); i_rolname = PQfnumber(res, "rolname");
...@@ -5978,6 +5983,7 @@ getForeignServers(int *numForeignServers) ...@@ -5978,6 +5983,7 @@ getForeignServers(int *numForeignServers)
for (i = 0; i < ntups; i++) for (i = 0; i < ntups; i++)
{ {
srvinfo[i].dobj.objType = DO_FOREIGN_SERVER; srvinfo[i].dobj.objType = DO_FOREIGN_SERVER;
srvinfo[i].dobj.catId.tableoid = atooid(PQgetvalue(res, i, i_tableoid));
srvinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid)); srvinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
AssignDumpId(&srvinfo[i].dobj); AssignDumpId(&srvinfo[i].dobj);
srvinfo[i].dobj.name = strdup(PQgetvalue(res, i, i_srvname)); srvinfo[i].dobj.name = strdup(PQgetvalue(res, i, i_srvname));
......
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