mirror of
https://github.com/postgres/postgres.git
synced 2026-07-15 04:40:58 -04:00
pg_dumpall: simplify coding of dropDBs()
There's no need for a StringInfo when all you want is a string being constructed in a single pass. Author: Álvaro Herrera <alvherre@kurilemu.de> Reported-by: Ranier Vilela <ranier.vf@gmail.com> Reviewed-by: Yang Yuanzhuo <1197620467@qq.com> Reviewed-by: Michael Paquier <michael@paquier.xyz> Reviewed-by: Andrew Dunstan <andrew@dunslane.net> Discussion: https://postgr.es/m/CAEudQAq2wyXZRdsh+wVHcOrungPU+_aQeQU12wbcgrmE0bQovA@mail.gmail.com
This commit is contained in:
parent
59bae23435
commit
a198c26ded
1 changed files with 7 additions and 10 deletions
|
|
@ -1833,7 +1833,6 @@ dropDBs(PGconn *conn)
|
||||||
for (i = 0; i < PQntuples(res); i++)
|
for (i = 0; i < PQntuples(res); i++)
|
||||||
{
|
{
|
||||||
char *dbname = PQgetvalue(res, i, 0);
|
char *dbname = PQgetvalue(res, i, 0);
|
||||||
PQExpBuffer delQry = createPQExpBuffer();
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Skip "postgres" and "template1"; dumpDatabases() will deal with
|
* Skip "postgres" and "template1"; dumpDatabases() will deal with
|
||||||
|
|
@ -1846,15 +1845,14 @@ dropDBs(PGconn *conn)
|
||||||
{
|
{
|
||||||
if (archDumpFormat == archNull)
|
if (archDumpFormat == archNull)
|
||||||
{
|
{
|
||||||
appendPQExpBuffer(delQry, "DROP DATABASE %s%s;\n",
|
fprintf(OPF, "DROP DATABASE %s%s;\n",
|
||||||
if_exists ? "IF EXISTS " : "",
|
if_exists ? "IF EXISTS " : "",
|
||||||
fmtId(dbname));
|
fmtId(dbname));
|
||||||
fprintf(OPF, "%s", delQry->data);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
appendPQExpBuffer(delQry, "DROP DATABASE IF EXISTS %s;\n",
|
char *stmt = psprintf("DROP DATABASE IF EXISTS %s;\n",
|
||||||
fmtId(dbname));
|
fmtId(dbname));
|
||||||
|
|
||||||
ArchiveEntry(fout,
|
ArchiveEntry(fout,
|
||||||
nilCatalogId, /* catalog ID */
|
nilCatalogId, /* catalog ID */
|
||||||
|
|
@ -1862,10 +1860,9 @@ dropDBs(PGconn *conn)
|
||||||
ARCHIVE_OPTS(.tag = psprintf("DATABASE %s", fmtId(dbname)),
|
ARCHIVE_OPTS(.tag = psprintf("DATABASE %s", fmtId(dbname)),
|
||||||
.description = "DROP_GLOBAL",
|
.description = "DROP_GLOBAL",
|
||||||
.section = SECTION_PRE_DATA,
|
.section = SECTION_PRE_DATA,
|
||||||
.createStmt = delQry->data));
|
.createStmt = stmt));
|
||||||
|
pg_free(stmt);
|
||||||
}
|
}
|
||||||
|
|
||||||
destroyPQExpBuffer(delQry);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue