From 84bb600be180c53addcbccba69be5134fcbce2dc Mon Sep 17 00:00:00 2001 From: Heikki Linnakangas Date: Wed, 8 Apr 2009 19:02:37 +0000 Subject: [PATCH] Quote string literals correctly in the new CREATE SERVER statements and binary upgrade UPDATE statements. --- src/bin/pg_dump/pg_dump.c | 36 ++++++++++++++++++++++-------------- src/bin/pg_dump/pg_dumpall.c | 8 +++++--- 2 files changed, 27 insertions(+), 17 deletions(-) diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c index f67002bd4f..6aa46ce79e 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -12,7 +12,7 @@ * by PostgreSQL * * IDENTIFICATION - * $PostgreSQL: pgsql/src/bin/pg_dump/pg_dump.c,v 1.534 2009/04/06 08:42:53 heikki Exp $ + * $PostgreSQL: pgsql/src/bin/pg_dump/pg_dump.c,v 1.535 2009/04/08 19:02:37 heikki Exp $ * *------------------------------------------------------------------------- */ @@ -1734,8 +1734,10 @@ dumpDatabase(Archive *AH) appendPQExpBuffer(creaQry, "\n-- For binary upgrade, set datfrozenxid.\n"); appendPQExpBuffer(creaQry, "UPDATE pg_database\n" "SET datfrozenxid = '%u'\n" - "WHERE datname = '%s';\n", - frozenxid, datname); + "WHERE datname = ", + frozenxid); + appendStringLiteralAH(creaQry, datname, AH); + appendPQExpBuffer(creaQry, ";\n"); } appendPQExpBuffer(delQry, "DROP DATABASE %s;\n", @@ -9396,9 +9398,15 @@ dumpForeignServer(Archive *fout, ForeignServerInfo *srvinfo) appendPQExpBuffer(q, "CREATE SERVER %s", fmtId(srvinfo->dobj.name)); if (srvinfo->srvtype && strlen(srvinfo->srvtype) > 0) - appendPQExpBuffer(q, " TYPE '%s'", srvinfo->srvtype); + { + appendPQExpBuffer(q, " TYPE "); + appendStringLiteralAH(q, srvinfo->srvtype, fout); + } if (srvinfo->srvversion && strlen(srvinfo->srvversion) > 0) - appendPQExpBuffer(q, " VERSION '%s'", srvinfo->srvversion); + { + appendPQExpBuffer(q, " VERSION "); + appendStringLiteralAH(q, srvinfo->srvversion, fout); + } appendPQExpBuffer(q, " FOREIGN DATA WRAPPER "); appendPQExpBuffer(q, "%s", fmtId(fdwname)); @@ -9891,23 +9899,23 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo) " WHERE relnamespace = " "(SELECT oid FROM pg_namespace " "WHERE nspname = CURRENT_SCHEMA)\n" - " AND relname = '%s'\n" - " );\n", + " AND relname = ", tbinfo->attlen[j], tbinfo->attalign[j], - tbinfo->attnames[j], - tbinfo->dobj.name); + tbinfo->attnames[j]); + appendStringLiteralAH(q, tbinfo->dobj.name, fout); + appendPQExpBuffer(q, "\n );\n"); } } appendPQExpBuffer(q, "\n-- For binary upgrade, set relfrozenxid.\n"); appendPQExpBuffer(q, "UPDATE pg_class\n" "SET relfrozenxid = '%u'\n" - "WHERE relname = '%s'\n" - " AND relnamespace = " + "WHERE relname = ", + tbinfo->frozenxid); + appendStringLiteralAH(q, tbinfo->dobj.name, fout); + appendPQExpBuffer(q, "\n AND relnamespace = " "(SELECT oid FROM pg_namespace " - "WHERE nspname = CURRENT_SCHEMA);\n", - tbinfo->frozenxid, - tbinfo->dobj.name); + "WHERE nspname = CURRENT_SCHEMA);\n"); } /* Loop dumping statistics and storage statements */ diff --git a/src/bin/pg_dump/pg_dumpall.c b/src/bin/pg_dump/pg_dumpall.c index 019c641135..0d6d1e450c 100644 --- a/src/bin/pg_dump/pg_dumpall.c +++ b/src/bin/pg_dump/pg_dumpall.c @@ -6,7 +6,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * - * $PostgreSQL: pgsql/src/bin/pg_dump/pg_dumpall.c,v 1.122 2009/04/06 08:42:53 heikki Exp $ + * $PostgreSQL: pgsql/src/bin/pg_dump/pg_dumpall.c,v 1.123 2009/04/08 19:02:37 heikki Exp $ * *------------------------------------------------------------------------- */ @@ -1088,8 +1088,10 @@ dumpCreateDB(PGconn *conn) appendPQExpBuffer(buf, "\n-- For binary upgrade, set datfrozenxid.\n"); appendPQExpBuffer(buf, "UPDATE pg_database\n" "SET datfrozenxid = '%u'\n" - "WHERE datname = '%s';\n", - dbfrozenxid, fdbname); + "WHERE datname = ", + dbfrozenxid); + appendStringLiteralConn(buf, dbname, conn); + appendPQExpBuffer(buf, ";\n"); } } -- 2.40.0