提交 ee3c51d4 编写于 作者: T Tom Lane

Fix a number of places where pg_dump was careless about explicitly

coercing OID literals to OID in its queries.  Depending on the query
and the server version, this could cause failures for OIDs over 2 billion.
上级 b579d461
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.228 2001/09/06 02:07:42 tgl Exp $ * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.229 2001/09/07 01:11:50 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -726,7 +726,7 @@ main(int argc, char **argv) ...@@ -726,7 +726,7 @@ main(int argc, char **argv)
else else
progname = strrchr(argv[0], '/') + 1; progname = strrchr(argv[0], '/') + 1;
/* Set defaulty options based on progname */ /* Set default options based on progname */
if (strcmp(progname, "pg_backup") == 0) if (strcmp(progname, "pg_backup") == 0)
{ {
format = "c"; format = "c";
...@@ -1449,8 +1449,6 @@ getTypes(int *numTypes) ...@@ -1449,8 +1449,6 @@ getTypes(int *numTypes)
* OprInfo* structure * OprInfo* structure
* *
* numOprs is set to the number of operators read in * numOprs is set to the number of operators read in
*
*
*/ */
OprInfo * OprInfo *
getOperators(int *numOprs) getOperators(int *numOprs)
...@@ -1821,8 +1819,6 @@ clearAggInfo(AggInfo *agginfo, int numArgs) ...@@ -1821,8 +1819,6 @@ clearAggInfo(AggInfo *agginfo, int numArgs)
* return them in the AggInfo* structure * return them in the AggInfo* structure
* *
* numAggs is set to the number of aggregates read in * numAggs is set to the number of aggregates read in
*
*
*/ */
AggInfo * AggInfo *
getAggregates(int *numAggs) getAggregates(int *numAggs)
...@@ -2040,8 +2036,6 @@ getFuncs(int *numFuncs) ...@@ -2040,8 +2036,6 @@ getFuncs(int *numFuncs)
* in the system catalogs return them in the TableInfo* structure * in the system catalogs return them in the TableInfo* structure
* *
* numTables is set to the number of tables read in * numTables is set to the number of tables read in
*
*
*/ */
TableInfo * TableInfo *
getTables(int *numTables, FuncInfo *finfo, int numFuncs) getTables(int *numTables, FuncInfo *finfo, int numFuncs)
...@@ -2297,7 +2291,7 @@ getTables(int *numTables, FuncInfo *finfo, int numFuncs) ...@@ -2297,7 +2291,7 @@ getTables(int *numTables, FuncInfo *finfo, int numFuncs)
resetPQExpBuffer(query); resetPQExpBuffer(query);
appendPQExpBuffer(query, appendPQExpBuffer(query,
"SELECT indexrelid FROM pg_index i WHERE i.indisprimary AND i.indrelid = %s ", "SELECT indexrelid FROM pg_index i WHERE i.indisprimary AND i.indrelid = '%s'::oid ",
tblinfo[i].oid); tblinfo[i].oid);
res2 = PQexec(g_conn, query->data); res2 = PQexec(g_conn, query->data);
if (!res2 || PQresultStatus(res2) != PGRES_TUPLES_OK) if (!res2 || PQresultStatus(res2) != PGRES_TUPLES_OK)
...@@ -2335,7 +2329,7 @@ getTables(int *numTables, FuncInfo *finfo, int numFuncs) ...@@ -2335,7 +2329,7 @@ getTables(int *numTables, FuncInfo *finfo, int numFuncs)
resetPQExpBuffer(query); resetPQExpBuffer(query);
appendPQExpBuffer(query, appendPQExpBuffer(query,
"SELECT relname FROM pg_class " "SELECT relname FROM pg_class "
"WHERE oid = %s", "WHERE oid = '%s'::oid",
tblinfo[i].pkIndexOid); tblinfo[i].pkIndexOid);
res2 = PQexec(g_conn, query->data); res2 = PQexec(g_conn, query->data);
...@@ -2656,8 +2650,6 @@ getTables(int *numTables, FuncInfo *finfo, int numFuncs) ...@@ -2656,8 +2650,6 @@ getTables(int *numTables, FuncInfo *finfo, int numFuncs)
* from the system catalogs return them in the InhInfo* structure * from the system catalogs return them in the InhInfo* structure
* *
* numInherits is set to the number of tables read in * numInherits is set to the number of tables read in
*
*
*/ */
InhInfo * InhInfo *
getInherits(int *numInherits) getInherits(int *numInherits)
...@@ -3013,7 +3005,7 @@ dumpComment(Archive *fout, const char *target, const char *oid, ...@@ -3013,7 +3005,7 @@ dumpComment(Archive *fout, const char *target, const char *oid,
if (fout->remoteVersion >= 70200) if (fout->remoteVersion >= 70200)
{ {
appendPQExpBuffer(query, "SELECT description FROM pg_description " appendPQExpBuffer(query, "SELECT description FROM pg_description "
"WHERE objoid = %s and classoid = " "WHERE objoid = '%s'::oid and classoid = "
"(SELECT oid FROM pg_class where relname = '%s') " "(SELECT oid FROM pg_class where relname = '%s') "
"and objsubid = %d", "and objsubid = %d",
oid, classname, subid); oid, classname, subid);
...@@ -3021,7 +3013,7 @@ dumpComment(Archive *fout, const char *target, const char *oid, ...@@ -3021,7 +3013,7 @@ dumpComment(Archive *fout, const char *target, const char *oid,
else else
{ {
/* Note: this will fail to find attribute comments in pre-7.2... */ /* Note: this will fail to find attribute comments in pre-7.2... */
appendPQExpBuffer(query, "SELECT description FROM pg_description WHERE objoid = %s", oid); appendPQExpBuffer(query, "SELECT description FROM pg_description WHERE objoid = '%s'::oid", oid);
} }
/*** Execute query ***/ /*** Execute query ***/
...@@ -3396,7 +3388,7 @@ dumpOneFunc(Archive *fout, FuncInfo *finfo, int i, ...@@ -3396,7 +3388,7 @@ dumpOneFunc(Archive *fout, FuncInfo *finfo, int i,
/* becomeUser(fout, finfo[i].usename); */ /* becomeUser(fout, finfo[i].usename); */
sprintf(query, "SELECT lanname FROM pg_language WHERE oid = %u", sprintf(query, "SELECT lanname FROM pg_language WHERE oid = '%u'::oid",
finfo[i].lang); finfo[i].lang);
res = PQexec(g_conn, query); res = PQexec(g_conn, query);
if (!res || if (!res ||
...@@ -4556,7 +4548,7 @@ dumpIndexes(Archive *fout, IndInfo *indinfo, int numIndexes, ...@@ -4556,7 +4548,7 @@ dumpIndexes(Archive *fout, IndInfo *indinfo, int numIndexes,
int numRows; int numRows;
PQExpBuffer pred = createPQExpBuffer(); PQExpBuffer pred = createPQExpBuffer();
appendPQExpBuffer(pred, "SELECT pg_get_expr(indpred,indrelid) as pred FROM pg_index WHERE indexrelid = %s", appendPQExpBuffer(pred, "SELECT pg_get_expr(indpred,indrelid) as pred FROM pg_index WHERE indexrelid = '%s'::oid",
indinfo[i].indexreloid); indinfo[i].indexreloid);
res = PQexec(g_conn, pred->data); res = PQexec(g_conn, pred->data);
if (!res || PQresultStatus(res) != PGRES_TUPLES_OK) if (!res || PQresultStatus(res) != PGRES_TUPLES_OK)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册