Commit 1cc1b91d authored by Robert Haas's avatar Robert Haas

pg_dump: Miscellaneous tightening based on recent refactorings.

Use exit_horribly() and ExecuteSqlQueryForSingleRow() in various
places where it's equivalent, or nearly equivalent, to the prior
coding. Apart from being more compact, this also makes the error
messages for the wrong-number-of-tuples case more consistent.
parent 689d0eb7
...@@ -532,16 +532,10 @@ main(int argc, char **argv) ...@@ -532,16 +532,10 @@ main(int argc, char **argv)
dump_inserts = 1; dump_inserts = 1;
if (dataOnly && schemaOnly) if (dataOnly && schemaOnly)
{ exit_horribly(NULL, "options -s/--schema-only and -a/--data-only cannot be used together\n");
write_msg(NULL, "options -s/--schema-only and -a/--data-only cannot be used together\n");
exit_nicely(1);
}
if ((dataOnly || schemaOnly) && dumpSections != DUMP_UNSECTIONED) if ((dataOnly || schemaOnly) && dumpSections != DUMP_UNSECTIONED)
{ exit_horribly(NULL, "options -s/--schema-only and -a/--data-only cannot be used with --section\n");
write_msg(NULL, "options -s/--schema-only and -a/--data-only cannot be used with --section\n");
exit_nicely(1);
}
if (dataOnly) if (dataOnly)
dumpSections = DUMP_DATA; dumpSections = DUMP_DATA;
...@@ -554,10 +548,7 @@ main(int argc, char **argv) ...@@ -554,10 +548,7 @@ main(int argc, char **argv)
} }
if (dataOnly && outputClean) if (dataOnly && outputClean)
{ exit_horribly(NULL, "options -c/--clean and -a/--data-only cannot be used together\n");
write_msg(NULL, "options -c/--clean and -a/--data-only cannot be used together\n");
exit_nicely(1);
}
if (dump_inserts && oids) if (dump_inserts && oids)
{ {
...@@ -587,20 +578,14 @@ main(int argc, char **argv) ...@@ -587,20 +578,14 @@ main(int argc, char **argv)
on_exit_nicely(pgdump_cleanup_at_exit, fout); on_exit_nicely(pgdump_cleanup_at_exit, fout);
if (fout == NULL) if (fout == NULL)
{ exit_horribly(NULL, "could not open output file \"%s\" for writing\n", filename);
write_msg(NULL, "could not open output file \"%s\" for writing\n", filename);
exit_nicely(1);
}
/* Let the archiver know how noisy to be */ /* Let the archiver know how noisy to be */
fout->verbose = g_verbose; fout->verbose = g_verbose;
my_version = parse_version(PG_VERSION); my_version = parse_version(PG_VERSION);
if (my_version < 0) if (my_version < 0)
{ exit_horribly(NULL, "could not parse version string \"%s\"\n", PG_VERSION);
write_msg(NULL, "could not parse version string \"%s\"\n", PG_VERSION);
exit_nicely(1);
}
/* /*
* We allow the server to be back to 7.0, and up to any minor release of * We allow the server to be back to 7.0, and up to any minor release of
...@@ -668,10 +653,7 @@ main(int argc, char **argv) ...@@ -668,10 +653,7 @@ main(int argc, char **argv)
expand_schema_name_patterns(fout, &schema_include_patterns, expand_schema_name_patterns(fout, &schema_include_patterns,
&schema_include_oids); &schema_include_oids);
if (schema_include_oids.head == NULL) if (schema_include_oids.head == NULL)
{ exit_horribly(NULL, "No matching schemas were found\n");
write_msg(NULL, "No matching schemas were found\n");
exit_nicely(1);
}
} }
expand_schema_name_patterns(fout, &schema_exclude_patterns, expand_schema_name_patterns(fout, &schema_exclude_patterns,
&schema_exclude_oids); &schema_exclude_oids);
...@@ -683,10 +665,7 @@ main(int argc, char **argv) ...@@ -683,10 +665,7 @@ main(int argc, char **argv)
expand_table_name_patterns(fout, &table_include_patterns, expand_table_name_patterns(fout, &table_include_patterns,
&table_include_oids); &table_include_oids);
if (table_include_oids.head == NULL) if (table_include_oids.head == NULL)
{ exit_horribly(NULL, "No matching tables were found\n");
write_msg(NULL, "No matching tables were found\n");
exit_nicely(1);
}
} }
expand_table_name_patterns(fout, &table_exclude_patterns, expand_table_name_patterns(fout, &table_exclude_patterns,
&table_exclude_oids); &table_exclude_oids);
...@@ -875,11 +854,8 @@ setup_connection(Archive *AH, const char *dumpencoding, char *use_role) ...@@ -875,11 +854,8 @@ setup_connection(Archive *AH, const char *dumpencoding, char *use_role)
if (dumpencoding) if (dumpencoding)
{ {
if (PQsetClientEncoding(conn, dumpencoding) < 0) if (PQsetClientEncoding(conn, dumpencoding) < 0)
{ exit_horribly(NULL, "invalid client encoding \"%s\" specified\n",
write_msg(NULL, "invalid client encoding \"%s\" specified\n", dumpencoding);
dumpencoding);
exit_nicely(1);
}
} }
/* /*
...@@ -974,10 +950,7 @@ parseArchiveFormat(const char *format, ArchiveMode *mode) ...@@ -974,10 +950,7 @@ parseArchiveFormat(const char *format, ArchiveMode *mode)
else if (pg_strcasecmp(format, "tar") == 0) else if (pg_strcasecmp(format, "tar") == 0)
archiveFormat = archTar; archiveFormat = archTar;
else else
{ exit_horribly(NULL, "invalid output format \"%s\" specified\n", format);
write_msg(NULL, "invalid output format \"%s\" specified\n", format);
exit_nicely(1);
}
return archiveFormat; return archiveFormat;
} }
...@@ -999,10 +972,7 @@ expand_schema_name_patterns(Archive *fout, ...@@ -999,10 +972,7 @@ expand_schema_name_patterns(Archive *fout,
return; /* nothing to do */ return; /* nothing to do */
if (fout->remoteVersion < 70300) if (fout->remoteVersion < 70300)
{ exit_horribly(NULL, "server version must be at least 7.3 to use schema selection switches\n");
write_msg(NULL, "server version must be at least 7.3 to use schema selection switches\n");
exit_nicely(1);
}
query = createPQExpBuffer(); query = createPQExpBuffer();
...@@ -1831,7 +1801,6 @@ dumpDatabase(Archive *fout) ...@@ -1831,7 +1801,6 @@ dumpDatabase(Archive *fout)
PQExpBuffer creaQry = createPQExpBuffer(); PQExpBuffer creaQry = createPQExpBuffer();
PGconn *conn = GetConnection(fout); PGconn *conn = GetConnection(fout);
PGresult *res; PGresult *res;
int ntups;
int i_tableoid, int i_tableoid,
i_oid, i_oid,
i_dba, i_dba,
...@@ -1928,23 +1897,7 @@ dumpDatabase(Archive *fout) ...@@ -1928,23 +1897,7 @@ dumpDatabase(Archive *fout)
appendStringLiteralAH(dbQry, datname, fout); appendStringLiteralAH(dbQry, datname, fout);
} }
res = ExecuteSqlQuery(fout, dbQry->data, PGRES_TUPLES_OK); res = ExecuteSqlQueryForSingleRow(fout, dbQry->data);
ntups = PQntuples(res);
if (ntups <= 0)
{
write_msg(NULL, "missing pg_database entry for database \"%s\"\n",
datname);
exit_nicely(1);
}
if (ntups != 1)
{
write_msg(NULL, "query returned more than one (%d) pg_database entry for database \"%s\"\n",
ntups, datname);
exit_nicely(1);
}
i_tableoid = PQfnumber(res, "tableoid"); i_tableoid = PQfnumber(res, "tableoid");
i_oid = PQfnumber(res, "oid"); i_oid = PQfnumber(res, "oid");
...@@ -2040,13 +1993,7 @@ dumpDatabase(Archive *fout) ...@@ -2040,13 +1993,7 @@ dumpDatabase(Archive *fout)
"WHERE oid = %u;\n", "WHERE oid = %u;\n",
LargeObjectRelationId); LargeObjectRelationId);
lo_res = ExecuteSqlQuery(fout, loFrozenQry->data, PGRES_TUPLES_OK); lo_res = ExecuteSqlQueryForSingleRow(fout, loFrozenQry->data);
if (PQntuples(lo_res) != 1)
{
write_msg(NULL, "dumpDatabase(): could not find pg_largeobject.relfrozenxid\n");
exit_nicely(1);
}
i_relfrozenxid = PQfnumber(lo_res, "relfrozenxid"); i_relfrozenxid = PQfnumber(lo_res, "relfrozenxid");
...@@ -2078,13 +2025,7 @@ dumpDatabase(Archive *fout) ...@@ -2078,13 +2025,7 @@ dumpDatabase(Archive *fout)
"WHERE oid = %u;\n", "WHERE oid = %u;\n",
LargeObjectMetadataRelationId); LargeObjectMetadataRelationId);
lo_res = ExecuteSqlQuery(fout, loFrozenQry->data, PGRES_TUPLES_OK); lo_res = ExecuteSqlQueryForSingleRow(fout, loFrozenQry->data);
if (PQntuples(lo_res) != 1)
{
write_msg(NULL, "dumpDatabase(): could not find pg_largeobject_metadata.relfrozenxid\n");
exit_nicely(1);
}
i_relfrozenxid = PQfnumber(lo_res, "relfrozenxid"); i_relfrozenxid = PQfnumber(lo_res, "relfrozenxid");
...@@ -2407,11 +2348,8 @@ dumpBlobs(Archive *fout, void *arg) ...@@ -2407,11 +2348,8 @@ dumpBlobs(Archive *fout, void *arg)
/* Open the BLOB */ /* Open the BLOB */
loFd = lo_open(conn, blobOid, INV_READ); loFd = lo_open(conn, blobOid, INV_READ);
if (loFd == -1) if (loFd == -1)
{ exit_horribly(NULL, "could not open large object %u: %s",
write_msg(NULL, "could not open large object %u: %s", blobOid, PQerrorMessage(conn));
blobOid, PQerrorMessage(conn));
exit_nicely(1);
}
StartBlob(fout, blobOid); StartBlob(fout, blobOid);
...@@ -2420,11 +2358,8 @@ dumpBlobs(Archive *fout, void *arg) ...@@ -2420,11 +2358,8 @@ dumpBlobs(Archive *fout, void *arg)
{ {
cnt = lo_read(conn, loFd, buf, LOBBUFSIZE); cnt = lo_read(conn, loFd, buf, LOBBUFSIZE);
if (cnt < 0) if (cnt < 0)
{ exit_horribly(NULL, "error reading large object %u: %s",
write_msg(NULL, "error reading large object %u: %s", blobOid, PQerrorMessage(conn));
blobOid, PQerrorMessage(conn));
exit_nicely(1);
}
WriteData(fout, buf, cnt); WriteData(fout, buf, cnt);
} while (cnt > 0); } while (cnt > 0);
...@@ -2618,10 +2553,7 @@ binary_upgrade_extension_member(PQExpBuffer upgrade_buffer, ...@@ -2618,10 +2553,7 @@ binary_upgrade_extension_member(PQExpBuffer upgrade_buffer,
extobj = NULL; extobj = NULL;
} }
if (extobj == NULL) if (extobj == NULL)
{ exit_horribly(NULL, "could not find parent extension for %s", objlabel);
write_msg(NULL, "could not find parent extension for %s", objlabel);
exit_nicely(1);
}
appendPQExpBuffer(upgrade_buffer, appendPQExpBuffer(upgrade_buffer,
"\n-- For binary upgrade, handle extension membership the hard way\n"); "\n-- For binary upgrade, handle extension membership the hard way\n");
...@@ -2760,8 +2692,7 @@ findNamespace(Archive *fout, Oid nsoid, Oid objoid) ...@@ -2760,8 +2692,7 @@ findNamespace(Archive *fout, Oid nsoid, Oid objoid)
if (nsoid == nsinfo->dobj.catId.oid) if (nsoid == nsinfo->dobj.catId.oid)
return nsinfo; return nsinfo;
} }
write_msg(NULL, "schema with OID %u does not exist\n", nsoid); exit_horribly(NULL, "schema with OID %u does not exist\n", nsoid);
exit_nicely(1);
} }
else else
{ {
...@@ -5085,12 +5016,8 @@ getRules(Archive *fout, int *numRules) ...@@ -5085,12 +5016,8 @@ getRules(Archive *fout, int *numRules)
ruletableoid = atooid(PQgetvalue(res, i, i_ruletable)); ruletableoid = atooid(PQgetvalue(res, i, i_ruletable));
ruleinfo[i].ruletable = findTableByOid(ruletableoid); ruleinfo[i].ruletable = findTableByOid(ruletableoid);
if (ruleinfo[i].ruletable == NULL) if (ruleinfo[i].ruletable == NULL)
{ exit_horribly(NULL, "failed sanity check, parent table OID %u of pg_rewrite entry OID %u not found\n",
write_msg(NULL, "failed sanity check, parent table OID %u of pg_rewrite entry OID %u not found\n", ruletableoid, ruleinfo[i].dobj.catId.oid);
ruletableoid,
ruleinfo[i].dobj.catId.oid);
exit_nicely(1);
}
ruleinfo[i].dobj.namespace = ruleinfo[i].ruletable->dobj.namespace; ruleinfo[i].dobj.namespace = ruleinfo[i].ruletable->dobj.namespace;
ruleinfo[i].dobj.dump = ruleinfo[i].ruletable->dobj.dump; ruleinfo[i].dobj.dump = ruleinfo[i].ruletable->dobj.dump;
ruleinfo[i].ev_type = *(PQgetvalue(res, i, i_ev_type)); ruleinfo[i].ev_type = *(PQgetvalue(res, i, i_ev_type));
...@@ -5331,12 +5258,10 @@ getTriggers(Archive *fout, TableInfo tblinfo[], int numTables) ...@@ -5331,12 +5258,10 @@ getTriggers(Archive *fout, TableInfo tblinfo[], int numTables)
if (OidIsValid(tginfo[j].tgconstrrelid)) if (OidIsValid(tginfo[j].tgconstrrelid))
{ {
if (PQgetisnull(res, j, i_tgconstrrelname)) if (PQgetisnull(res, j, i_tgconstrrelname))
{ exit_horribly(NULL, "query produced null referenced table name for foreign key trigger \"%s\" on table \"%s\" (OID of table: %u)\n",
write_msg(NULL, "query produced null referenced table name for foreign key trigger \"%s\" on table \"%s\" (OID of table: %u)\n", tginfo[j].dobj.name,
tginfo[j].dobj.name, tbinfo->dobj.name, tbinfo->dobj.name,
tginfo[j].tgconstrrelid); tginfo[j].tgconstrrelid);
exit_nicely(1);
}
tginfo[j].tgconstrrelname = pg_strdup(PQgetvalue(res, j, i_tgconstrrelname)); tginfo[j].tgconstrrelname = pg_strdup(PQgetvalue(res, j, i_tgconstrrelname));
} }
else else
...@@ -5879,11 +5804,9 @@ getTableAttrs(Archive *fout, TableInfo *tblinfo, int numTables) ...@@ -5879,11 +5804,9 @@ getTableAttrs(Archive *fout, TableInfo *tblinfo, int numTables)
for (j = 0; j < ntups; j++) for (j = 0; j < ntups; j++)
{ {
if (j + 1 != atoi(PQgetvalue(res, j, i_attnum))) if (j + 1 != atoi(PQgetvalue(res, j, i_attnum)))
{ exit_horribly(NULL,
write_msg(NULL, "invalid column numbering in table \"%s\"\n", "invalid column numbering in table \"%s\"\n",
tbinfo->dobj.name); tbinfo->dobj.name);
exit_nicely(1);
}
tbinfo->attnames[j] = pg_strdup(PQgetvalue(res, j, i_attname)); tbinfo->attnames[j] = pg_strdup(PQgetvalue(res, j, i_attname));
tbinfo->atttypnames[j] = pg_strdup(PQgetvalue(res, j, i_atttypname)); tbinfo->atttypnames[j] = pg_strdup(PQgetvalue(res, j, i_atttypname));
tbinfo->atttypmod[j] = atoi(PQgetvalue(res, j, i_atttypmod)); tbinfo->atttypmod[j] = atoi(PQgetvalue(res, j, i_atttypmod));
...@@ -5967,11 +5890,9 @@ getTableAttrs(Archive *fout, TableInfo *tblinfo, int numTables) ...@@ -5967,11 +5890,9 @@ getTableAttrs(Archive *fout, TableInfo *tblinfo, int numTables)
adnum = atoi(PQgetvalue(res, j, 2)); adnum = atoi(PQgetvalue(res, j, 2));
if (adnum <= 0 || adnum > ntups) if (adnum <= 0 || adnum > ntups)
{ exit_horribly(NULL,
write_msg(NULL, "invalid adnum value %d for table \"%s\"\n", "invalid adnum value %d for table \"%s\"\n",
adnum, tbinfo->dobj.name); adnum, tbinfo->dobj.name);
exit_nicely(1);
}
/* /*
* dropped columns shouldn't have defaults, but just in case, * dropped columns shouldn't have defaults, but just in case,
...@@ -7666,13 +7587,7 @@ dumpRangeType(Archive *fout, TypeInfo *tyinfo) ...@@ -7666,13 +7587,7 @@ dumpRangeType(Archive *fout, TypeInfo *tyinfo)
"rngtypid = '%u'", "rngtypid = '%u'",
tyinfo->dobj.catId.oid); tyinfo->dobj.catId.oid);
res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); res = ExecuteSqlQueryForSingleRow(fout, query->data);
if (PQntuples(res) != 1)
{
write_msg(NULL, "query returned %d pg_range entries for range type \"%s\"\n",
PQntuples(res), tyinfo->dobj.name);
exit_nicely(1);
}
/* /*
* DROP must be fully qualified in case same name appears in pg_catalog. * DROP must be fully qualified in case same name appears in pg_catalog.
...@@ -9346,11 +9261,8 @@ dumpFunc(Archive *fout, FuncInfo *finfo) ...@@ -9346,11 +9261,8 @@ dumpFunc(Archive *fout, FuncInfo *finfo)
else if (provolatile[0] == PROVOLATILE_STABLE) else if (provolatile[0] == PROVOLATILE_STABLE)
appendPQExpBuffer(q, " STABLE"); appendPQExpBuffer(q, " STABLE");
else if (provolatile[0] != PROVOLATILE_VOLATILE) else if (provolatile[0] != PROVOLATILE_VOLATILE)
{ exit_horribly(NULL, "unrecognized provolatile value for function \"%s\"\n",
write_msg(NULL, "unrecognized provolatile value for function \"%s\"\n", finfo->dobj.name);
finfo->dobj.name);
exit_nicely(1);
}
} }
if (proisstrict[0] == 't') if (proisstrict[0] == 't')
...@@ -11769,9 +11681,9 @@ dumpDefaultACL(Archive *fout, DefaultACLInfo *daclinfo) ...@@ -11769,9 +11681,9 @@ dumpDefaultACL(Archive *fout, DefaultACLInfo *daclinfo)
break; break;
default: default:
/* shouldn't get here */ /* shouldn't get here */
write_msg(NULL, "unknown object type (%d) in default privileges\n", exit_horribly(NULL,
(int) daclinfo->defaclobjtype); "unknown object type (%d) in default privileges\n",
exit_nicely(1); (int) daclinfo->defaclobjtype);
type = ""; /* keep compiler quiet */ type = ""; /* keep compiler quiet */
} }
...@@ -11785,11 +11697,8 @@ dumpDefaultACL(Archive *fout, DefaultACLInfo *daclinfo) ...@@ -11785,11 +11697,8 @@ dumpDefaultACL(Archive *fout, DefaultACLInfo *daclinfo)
daclinfo->defaclrole, daclinfo->defaclrole,
fout->remoteVersion, fout->remoteVersion,
q)) q))
{ exit_horribly(NULL, "could not parse default ACL list (%s)\n",
write_msg(NULL, "could not parse default ACL list (%s)\n", daclinfo->defaclacl);
daclinfo->defaclacl);
exit_nicely(1);
}
ArchiveEntry(fout, daclinfo->dobj.catId, daclinfo->dobj.dumpId, ArchiveEntry(fout, daclinfo->dobj.catId, daclinfo->dobj.dumpId,
tag->data, tag->data,
...@@ -11842,11 +11751,9 @@ dumpACL(Archive *fout, CatalogId objCatId, DumpId objDumpId, ...@@ -11842,11 +11751,9 @@ dumpACL(Archive *fout, CatalogId objCatId, DumpId objDumpId,
if (!buildACLCommands(name, subname, type, acls, owner, if (!buildACLCommands(name, subname, type, acls, owner,
"", fout->remoteVersion, sql)) "", fout->remoteVersion, sql))
{ exit_horribly(NULL,
write_msg(NULL, "could not parse ACL list (%s) for object \"%s\" (%s)\n", "could not parse ACL list (%s) for object \"%s\" (%s)\n",
acls, name, type); acls, name, type);
exit_nicely(1);
}
if (sql->len > 0) if (sql->len > 0)
ArchiveEntry(fout, nilCatalogId, createDumpId(), ArchiveEntry(fout, nilCatalogId, createDumpId(),
...@@ -12286,22 +12193,18 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo) ...@@ -12286,22 +12193,18 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo)
if (PQntuples(res) != 1) if (PQntuples(res) != 1)
{ {
if (PQntuples(res) < 1) if (PQntuples(res) < 1)
write_msg(NULL, "query to obtain definition of view \"%s\" returned no data\n", exit_horribly(NULL, "query to obtain definition of view \"%s\" returned no data\n",
tbinfo->dobj.name); tbinfo->dobj.name);
else else
write_msg(NULL, "query to obtain definition of view \"%s\" returned more than one definition\n", exit_horribly(NULL, "query to obtain definition of view \"%s\" returned more than one definition\n",
tbinfo->dobj.name); tbinfo->dobj.name);
exit_nicely(1);
} }
viewdef = PQgetvalue(res, 0, 0); viewdef = PQgetvalue(res, 0, 0);
if (strlen(viewdef) == 0) if (strlen(viewdef) == 0)
{ exit_horribly(NULL, "definition of view \"%s\" appears to be empty (length zero)\n",
write_msg(NULL, "definition of view \"%s\" appears to be empty (length zero)\n", tbinfo->dobj.name);
tbinfo->dobj.name);
exit_nicely(1);
}
/* /*
* DROP must be fully qualified in case same name appears in * DROP must be fully qualified in case same name appears in
...@@ -12349,15 +12252,7 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo) ...@@ -12349,15 +12252,7 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo)
"ON (fs.oid = ft.ftserver) " "ON (fs.oid = ft.ftserver) "
"WHERE ft.ftrelid = '%u'", "WHERE ft.ftrelid = '%u'",
tbinfo->dobj.catId.oid); tbinfo->dobj.catId.oid);
res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); res = ExecuteSqlQueryForSingleRow(fout, query->data);
if (PQntuples(res) != 1)
{
write_msg(NULL, ngettext("query returned %d foreign server entry for foreign table \"%s\"\n",
"query returned %d foreign server entries for foreign table \"%s\"\n",
PQntuples(res)),
PQntuples(res), tbinfo->dobj.name);
exit_nicely(1);
}
i_srvname = PQfnumber(res, "srvname"); i_srvname = PQfnumber(res, "srvname");
i_ftoptions = PQfnumber(res, "ftoptions"); i_ftoptions = PQfnumber(res, "ftoptions");
srvname = pg_strdup(PQgetvalue(res, 0, i_srvname)); srvname = pg_strdup(PQgetvalue(res, 0, i_srvname));
...@@ -12919,9 +12814,8 @@ getAttrName(int attrnum, TableInfo *tblInfo) ...@@ -12919,9 +12814,8 @@ getAttrName(int attrnum, TableInfo *tblInfo)
case TableOidAttributeNumber: case TableOidAttributeNumber:
return "tableoid"; return "tableoid";
} }
write_msg(NULL, "invalid column number %d for table \"%s\"\n", exit_horribly(NULL, "invalid column number %d for table \"%s\"\n",
attrnum, tblInfo->dobj.name); attrnum, tblInfo->dobj.name);
exit_nicely(1);
return NULL; /* keep compiler quiet */ return NULL; /* keep compiler quiet */
} }
...@@ -13030,11 +12924,8 @@ dumpConstraint(Archive *fout, ConstraintInfo *coninfo) ...@@ -13030,11 +12924,8 @@ dumpConstraint(Archive *fout, ConstraintInfo *coninfo)
indxinfo = (IndxInfo *) findObjectByDumpId(coninfo->conindex); indxinfo = (IndxInfo *) findObjectByDumpId(coninfo->conindex);
if (indxinfo == NULL) if (indxinfo == NULL)
{ exit_horribly(NULL, "missing index for constraint \"%s\"\n",
write_msg(NULL, "missing index for constraint \"%s\"\n", coninfo->dobj.name);
coninfo->dobj.name);
exit_nicely(1);
}
if (binary_upgrade) if (binary_upgrade)
binary_upgrade_set_pg_class_oids(fout, q, binary_upgrade_set_pg_class_oids(fout, q,
...@@ -13220,8 +13111,8 @@ dumpConstraint(Archive *fout, ConstraintInfo *coninfo) ...@@ -13220,8 +13111,8 @@ dumpConstraint(Archive *fout, ConstraintInfo *coninfo)
} }
else else
{ {
write_msg(NULL, "unrecognized constraint type: %c\n", coninfo->contype); exit_horribly(NULL, "unrecognized constraint type: %c\n",
exit_nicely(1); coninfo->contype);
} }
/* Dump Constraint Comments --- only works for table constraints */ /* Dump Constraint Comments --- only works for table constraints */
...@@ -13269,7 +13160,6 @@ static Oid ...@@ -13269,7 +13160,6 @@ static Oid
findLastBuiltinOid_V71(Archive *fout, const char *dbname) findLastBuiltinOid_V71(Archive *fout, const char *dbname)
{ {
PGresult *res; PGresult *res;
int ntups;
Oid last_oid; Oid last_oid;
PQExpBuffer query = createPQExpBuffer(); PQExpBuffer query = createPQExpBuffer();
...@@ -13277,19 +13167,7 @@ findLastBuiltinOid_V71(Archive *fout, const char *dbname) ...@@ -13277,19 +13167,7 @@ findLastBuiltinOid_V71(Archive *fout, const char *dbname)
appendPQExpBuffer(query, "SELECT datlastsysoid from pg_database where datname = "); appendPQExpBuffer(query, "SELECT datlastsysoid from pg_database where datname = ");
appendStringLiteralAH(query, dbname, fout); appendStringLiteralAH(query, dbname, fout);
res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); res = ExecuteSqlQueryForSingleRow(fout, query->data);
ntups = PQntuples(res);
if (ntups < 1)
{
write_msg(NULL, "missing pg_database entry for this database\n");
exit_nicely(1);
}
if (ntups > 1)
{
write_msg(NULL, "found more than one pg_database entry for this database\n");
exit_nicely(1);
}
last_oid = atooid(PQgetvalue(res, 0, PQfnumber(res, "datlastsysoid"))); last_oid = atooid(PQgetvalue(res, 0, PQfnumber(res, "datlastsysoid")));
PQclear(res); PQclear(res);
destroyPQExpBuffer(query); destroyPQExpBuffer(query);
...@@ -13308,23 +13186,10 @@ static Oid ...@@ -13308,23 +13186,10 @@ static Oid
findLastBuiltinOid_V70(Archive *fout) findLastBuiltinOid_V70(Archive *fout)
{ {
PGresult *res; PGresult *res;
int ntups;
int last_oid; int last_oid;
res = ExecuteSqlQuery(fout, res = ExecuteSqlQueryForSingleRow(fout,
"SELECT oid FROM pg_class WHERE relname = 'pg_indexes'", "SELECT oid FROM pg_class WHERE relname = 'pg_indexes'");
PGRES_TUPLES_OK);
ntups = PQntuples(res);
if (ntups < 1)
{
write_msg(NULL, "could not find entry for pg_indexes in pg_class\n");
exit_nicely(1);
}
if (ntups > 1)
{
write_msg(NULL, "found more than one entry for pg_indexes in pg_class\n");
exit_nicely(1);
}
last_oid = atooid(PQgetvalue(res, 0, PQfnumber(res, "oid"))); last_oid = atooid(PQgetvalue(res, 0, PQfnumber(res, "oid")));
PQclear(res); PQclear(res);
return last_oid; return last_oid;
......
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