Skip to content

Commit 1bd08f6

Browse files
committed
Fixup various older misuses of appendPQExpBuffer
Use appendPQExpBufferStr when there are no parameters and appendPQExpBufferChar when the string length is 1. Unlike 3fae25c, which fixed this issue for code that was new to v18, this one fixes up instances which exist in the backbranches. We've historically tried to maintain this standard and if we're going to continue doing that, then we won't be doing that selectively based on when the code was introduced. Now seems like a good time to flush out the existing misuses. Waiting until v19 just prolongs their existence in terms of released versions that the misuses exist in. Author: David Rowley <drowleyml@gmail.com> Discussion: https://postgr.es/m/CAApHDvoARMvPeXTTC0HnpARBHn-WgVstc8XFCyMGOzvgu_1HvQ@mail.gmail.com
1 parent d9e0386 commit 1bd08f6

File tree

7 files changed

+40
-40
lines changed

7 files changed

+40
-40
lines changed

src/bin/initdb/initdb.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1620,9 +1620,9 @@ bootstrap_template1(void)
16201620
printfPQExpBuffer(&cmd, "\"%s\" --boot %s %s", backend_exec, boot_options, extra_options);
16211621
appendPQExpBuffer(&cmd, " -X %d", wal_segment_size_mb * (1024 * 1024));
16221622
if (data_checksums)
1623-
appendPQExpBuffer(&cmd, " -k");
1623+
appendPQExpBufferStr(&cmd, " -k");
16241624
if (debug)
1625-
appendPQExpBuffer(&cmd, " -d 5");
1625+
appendPQExpBufferStr(&cmd, " -d 5");
16261626

16271627

16281628
PG_CMD_OPEN(cmd.data);

src/bin/pg_basebackup/pg_createsubscriber.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1247,20 +1247,20 @@ setup_recovery(const struct LogicalRepInfo *dbinfo, const char *datadir, const c
12471247
* targets (name, time, xid, LSN).
12481248
*/
12491249
recoveryconfcontents = GenerateRecoveryConfig(conn, NULL, NULL);
1250-
appendPQExpBuffer(recoveryconfcontents, "recovery_target = ''\n");
1251-
appendPQExpBuffer(recoveryconfcontents,
1252-
"recovery_target_timeline = 'latest'\n");
1253-
appendPQExpBuffer(recoveryconfcontents,
1254-
"recovery_target_inclusive = true\n");
1255-
appendPQExpBuffer(recoveryconfcontents,
1256-
"recovery_target_action = promote\n");
1257-
appendPQExpBuffer(recoveryconfcontents, "recovery_target_name = ''\n");
1258-
appendPQExpBuffer(recoveryconfcontents, "recovery_target_time = ''\n");
1259-
appendPQExpBuffer(recoveryconfcontents, "recovery_target_xid = ''\n");
1250+
appendPQExpBufferStr(recoveryconfcontents, "recovery_target = ''\n");
1251+
appendPQExpBufferStr(recoveryconfcontents,
1252+
"recovery_target_timeline = 'latest'\n");
1253+
appendPQExpBufferStr(recoveryconfcontents,
1254+
"recovery_target_inclusive = true\n");
1255+
appendPQExpBufferStr(recoveryconfcontents,
1256+
"recovery_target_action = promote\n");
1257+
appendPQExpBufferStr(recoveryconfcontents, "recovery_target_name = ''\n");
1258+
appendPQExpBufferStr(recoveryconfcontents, "recovery_target_time = ''\n");
1259+
appendPQExpBufferStr(recoveryconfcontents, "recovery_target_xid = ''\n");
12601260

12611261
if (dry_run)
12621262
{
1263-
appendPQExpBuffer(recoveryconfcontents, "# dry run mode");
1263+
appendPQExpBufferStr(recoveryconfcontents, "# dry run mode");
12641264
appendPQExpBuffer(recoveryconfcontents,
12651265
"recovery_target_lsn = '%X/%X'\n",
12661266
LSN_FORMAT_ARGS((XLogRecPtr) InvalidXLogRecPtr));
@@ -1484,7 +1484,7 @@ start_standby_server(const struct CreateSubscriberOptions *opt, bool restricted_
14841484

14851485
appendPQExpBuffer(pg_ctl_cmd, "\"%s\" start -D ", pg_ctl_path);
14861486
appendShellString(pg_ctl_cmd, subscriber_dir);
1487-
appendPQExpBuffer(pg_ctl_cmd, " -s -o \"-c sync_replication_slots=off\"");
1487+
appendPQExpBufferStr(pg_ctl_cmd, " -s -o \"-c sync_replication_slots=off\"");
14881488

14891489
/* Prevent unintended slot invalidation */
14901490
appendPQExpBufferStr(pg_ctl_cmd, " -o \"-c idle_replication_slot_timeout=0\"");

src/bin/pg_dump/pg_dump.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1777,7 +1777,7 @@ expand_table_name_patterns(Archive *fout,
17771777
*/
17781778
if (with_child_tables)
17791779
{
1780-
appendPQExpBuffer(query, "WITH RECURSIVE partition_tree (relid) AS (\n");
1780+
appendPQExpBufferStr(query, "WITH RECURSIVE partition_tree (relid) AS (\n");
17811781
}
17821782

17831783
appendPQExpBuffer(query,
@@ -1804,13 +1804,13 @@ expand_table_name_patterns(Archive *fout,
18041804

18051805
if (with_child_tables)
18061806
{
1807-
appendPQExpBuffer(query, "UNION"
1808-
"\nSELECT i.inhrelid"
1809-
"\nFROM partition_tree p"
1810-
"\n JOIN pg_catalog.pg_inherits i"
1811-
"\n ON p.relid OPERATOR(pg_catalog.=) i.inhparent"
1812-
"\n)"
1813-
"\nSELECT relid FROM partition_tree");
1807+
appendPQExpBufferStr(query, "UNION"
1808+
"\nSELECT i.inhrelid"
1809+
"\nFROM partition_tree p"
1810+
"\n JOIN pg_catalog.pg_inherits i"
1811+
"\n ON p.relid OPERATOR(pg_catalog.=) i.inhparent"
1812+
"\n)"
1813+
"\nSELECT relid FROM partition_tree");
18141814
}
18151815

18161816
ExecuteSqlStatement(fout, "RESET search_path");
@@ -5034,8 +5034,8 @@ getSubscriptions(Archive *fout)
50345034
appendPQExpBufferStr(query,
50355035
" s.subfailover\n");
50365036
else
5037-
appendPQExpBuffer(query,
5038-
" false AS subfailover\n");
5037+
appendPQExpBufferStr(query,
5038+
" false AS subfailover\n");
50395039

50405040
appendPQExpBufferStr(query,
50415041
"FROM pg_subscription s\n");
@@ -5257,7 +5257,7 @@ dumpSubscriptionTable(Archive *fout, const SubRelInfo *subrinfo)
52575257
if (subrinfo->srsublsn && subrinfo->srsublsn[0] != '\0')
52585258
appendPQExpBuffer(query, ", '%s'", subrinfo->srsublsn);
52595259
else
5260-
appendPQExpBuffer(query, ", NULL");
5260+
appendPQExpBufferStr(query, ", NULL");
52615261

52625262
appendPQExpBufferStr(query, ");\n");
52635263
}
@@ -5352,7 +5352,7 @@ dumpSubscription(Archive *fout, const SubscriptionInfo *subinfo)
53525352
appendPQExpBufferStr(query, ", disable_on_error = true");
53535353

53545354
if (!subinfo->subpasswordrequired)
5355-
appendPQExpBuffer(query, ", password_required = false");
5355+
appendPQExpBufferStr(query, ", password_required = false");
53565356

53575357
if (subinfo->subrunasowner)
53585358
appendPQExpBufferStr(query, ", run_as_owner = true");

src/bin/pg_dump/pg_dumpall.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1246,7 +1246,7 @@ dumpRoleMembership(PGconn *conn)
12461246
{
12471247
if (optbuf->data[0] != '\0')
12481248
appendPQExpBufferStr(optbuf, ", ");
1249-
appendPQExpBuffer(optbuf, "SET FALSE");
1249+
appendPQExpBufferStr(optbuf, "SET FALSE");
12501250
}
12511251
if (optbuf->data[0] != '\0')
12521252
fprintf(OPF, " WITH %s", optbuf->data);

src/bin/pg_upgrade/pg_upgrade.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -999,11 +999,11 @@ create_logical_replication_slots(void)
999999
LogicalSlotInfo *slot_info = &slot_arr->slots[slotnum];
10001000

10011001
/* Constructs a query for creating logical replication slots */
1002-
appendPQExpBuffer(query,
1003-
"SELECT * FROM "
1004-
"pg_catalog.pg_create_logical_replication_slot(");
1002+
appendPQExpBufferStr(query,
1003+
"SELECT * FROM "
1004+
"pg_catalog.pg_create_logical_replication_slot(");
10051005
appendStringLiteralConn(query, slot_info->slotname, conn);
1006-
appendPQExpBuffer(query, ", ");
1006+
appendPQExpBufferStr(query, ", ");
10071007
appendStringLiteralConn(query, slot_info->plugin, conn);
10081008

10091009
appendPQExpBuffer(query, ", false, %s, %s);",

src/bin/psql/common.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1404,7 +1404,7 @@ DescribeQuery(const char *query, double *elapsed_msec)
14041404
char *escname;
14051405

14061406
if (i > 0)
1407-
appendPQExpBufferStr(&buf, ",");
1407+
appendPQExpBufferChar(&buf, ',');
14081408

14091409
name = PQfname(result, i);
14101410
escname = PQescapeLiteral(pset.db, name, strlen(name));

src/bin/scripts/vacuumdb.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -896,11 +896,11 @@ retrieve_objects(PGconn *conn, vacuumingOptions *vacopts,
896896
if (objects_listed)
897897
{
898898
if (objfilter & OBJFILTER_SCHEMA_EXCLUDE)
899-
appendPQExpBuffer(&catalog_query,
900-
" AND listed_objects.object_oid IS NULL\n");
899+
appendPQExpBufferStr(&catalog_query,
900+
" AND listed_objects.object_oid IS NULL\n");
901901
else
902-
appendPQExpBuffer(&catalog_query,
903-
" AND listed_objects.object_oid IS NOT NULL\n");
902+
appendPQExpBufferStr(&catalog_query,
903+
" AND listed_objects.object_oid IS NOT NULL\n");
904904
}
905905

906906
/*
@@ -911,10 +911,10 @@ retrieve_objects(PGconn *conn, vacuumingOptions *vacopts,
911911
*/
912912
if ((objfilter & OBJFILTER_TABLE) == 0)
913913
{
914-
appendPQExpBuffer(&catalog_query,
915-
" AND c.relkind OPERATOR(pg_catalog.=) ANY (array["
916-
CppAsString2(RELKIND_RELATION) ", "
917-
CppAsString2(RELKIND_MATVIEW) "])\n");
914+
appendPQExpBufferStr(&catalog_query,
915+
" AND c.relkind OPERATOR(pg_catalog.=) ANY (array["
916+
CppAsString2(RELKIND_RELATION) ", "
917+
CppAsString2(RELKIND_MATVIEW) "])\n");
918918
}
919919

920920
/*

0 commit comments

Comments
 (0)