1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-21 16:02:15 +03:00

Fixup various older misuses of appendPQExpBuffer

Use appendPQExpBufferStr when there are no parameters and
appendPQExpBufferChar when the string length is 1.

Unlike 3fae25cbb, 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
This commit is contained in:
David Rowley
2025-04-18 12:15:08 +12:00
parent d9e03864b6
commit 1bd08f6ba5
7 changed files with 40 additions and 40 deletions

View File

@ -1620,9 +1620,9 @@ bootstrap_template1(void)
printfPQExpBuffer(&cmd, "\"%s\" --boot %s %s", backend_exec, boot_options, extra_options); printfPQExpBuffer(&cmd, "\"%s\" --boot %s %s", backend_exec, boot_options, extra_options);
appendPQExpBuffer(&cmd, " -X %d", wal_segment_size_mb * (1024 * 1024)); appendPQExpBuffer(&cmd, " -X %d", wal_segment_size_mb * (1024 * 1024));
if (data_checksums) if (data_checksums)
appendPQExpBuffer(&cmd, " -k"); appendPQExpBufferStr(&cmd, " -k");
if (debug) if (debug)
appendPQExpBuffer(&cmd, " -d 5"); appendPQExpBufferStr(&cmd, " -d 5");
PG_CMD_OPEN(cmd.data); PG_CMD_OPEN(cmd.data);

View File

@ -1247,20 +1247,20 @@ setup_recovery(const struct LogicalRepInfo *dbinfo, const char *datadir, const c
* targets (name, time, xid, LSN). * targets (name, time, xid, LSN).
*/ */
recoveryconfcontents = GenerateRecoveryConfig(conn, NULL, NULL); recoveryconfcontents = GenerateRecoveryConfig(conn, NULL, NULL);
appendPQExpBuffer(recoveryconfcontents, "recovery_target = ''\n"); appendPQExpBufferStr(recoveryconfcontents, "recovery_target = ''\n");
appendPQExpBuffer(recoveryconfcontents, appendPQExpBufferStr(recoveryconfcontents,
"recovery_target_timeline = 'latest'\n"); "recovery_target_timeline = 'latest'\n");
appendPQExpBuffer(recoveryconfcontents, appendPQExpBufferStr(recoveryconfcontents,
"recovery_target_inclusive = true\n"); "recovery_target_inclusive = true\n");
appendPQExpBuffer(recoveryconfcontents, appendPQExpBufferStr(recoveryconfcontents,
"recovery_target_action = promote\n"); "recovery_target_action = promote\n");
appendPQExpBuffer(recoveryconfcontents, "recovery_target_name = ''\n"); appendPQExpBufferStr(recoveryconfcontents, "recovery_target_name = ''\n");
appendPQExpBuffer(recoveryconfcontents, "recovery_target_time = ''\n"); appendPQExpBufferStr(recoveryconfcontents, "recovery_target_time = ''\n");
appendPQExpBuffer(recoveryconfcontents, "recovery_target_xid = ''\n"); appendPQExpBufferStr(recoveryconfcontents, "recovery_target_xid = ''\n");
if (dry_run) if (dry_run)
{ {
appendPQExpBuffer(recoveryconfcontents, "# dry run mode"); appendPQExpBufferStr(recoveryconfcontents, "# dry run mode");
appendPQExpBuffer(recoveryconfcontents, appendPQExpBuffer(recoveryconfcontents,
"recovery_target_lsn = '%X/%X'\n", "recovery_target_lsn = '%X/%X'\n",
LSN_FORMAT_ARGS((XLogRecPtr) InvalidXLogRecPtr)); LSN_FORMAT_ARGS((XLogRecPtr) InvalidXLogRecPtr));
@ -1484,7 +1484,7 @@ start_standby_server(const struct CreateSubscriberOptions *opt, bool restricted_
appendPQExpBuffer(pg_ctl_cmd, "\"%s\" start -D ", pg_ctl_path); appendPQExpBuffer(pg_ctl_cmd, "\"%s\" start -D ", pg_ctl_path);
appendShellString(pg_ctl_cmd, subscriber_dir); appendShellString(pg_ctl_cmd, subscriber_dir);
appendPQExpBuffer(pg_ctl_cmd, " -s -o \"-c sync_replication_slots=off\""); appendPQExpBufferStr(pg_ctl_cmd, " -s -o \"-c sync_replication_slots=off\"");
/* Prevent unintended slot invalidation */ /* Prevent unintended slot invalidation */
appendPQExpBufferStr(pg_ctl_cmd, " -o \"-c idle_replication_slot_timeout=0\""); appendPQExpBufferStr(pg_ctl_cmd, " -o \"-c idle_replication_slot_timeout=0\"");

View File

@ -1777,7 +1777,7 @@ expand_table_name_patterns(Archive *fout,
*/ */
if (with_child_tables) if (with_child_tables)
{ {
appendPQExpBuffer(query, "WITH RECURSIVE partition_tree (relid) AS (\n"); appendPQExpBufferStr(query, "WITH RECURSIVE partition_tree (relid) AS (\n");
} }
appendPQExpBuffer(query, appendPQExpBuffer(query,
@ -1804,7 +1804,7 @@ expand_table_name_patterns(Archive *fout,
if (with_child_tables) if (with_child_tables)
{ {
appendPQExpBuffer(query, "UNION" appendPQExpBufferStr(query, "UNION"
"\nSELECT i.inhrelid" "\nSELECT i.inhrelid"
"\nFROM partition_tree p" "\nFROM partition_tree p"
"\n JOIN pg_catalog.pg_inherits i" "\n JOIN pg_catalog.pg_inherits i"
@ -5034,7 +5034,7 @@ getSubscriptions(Archive *fout)
appendPQExpBufferStr(query, appendPQExpBufferStr(query,
" s.subfailover\n"); " s.subfailover\n");
else else
appendPQExpBuffer(query, appendPQExpBufferStr(query,
" false AS subfailover\n"); " false AS subfailover\n");
appendPQExpBufferStr(query, appendPQExpBufferStr(query,
@ -5257,7 +5257,7 @@ dumpSubscriptionTable(Archive *fout, const SubRelInfo *subrinfo)
if (subrinfo->srsublsn && subrinfo->srsublsn[0] != '\0') if (subrinfo->srsublsn && subrinfo->srsublsn[0] != '\0')
appendPQExpBuffer(query, ", '%s'", subrinfo->srsublsn); appendPQExpBuffer(query, ", '%s'", subrinfo->srsublsn);
else else
appendPQExpBuffer(query, ", NULL"); appendPQExpBufferStr(query, ", NULL");
appendPQExpBufferStr(query, ");\n"); appendPQExpBufferStr(query, ");\n");
} }
@ -5352,7 +5352,7 @@ dumpSubscription(Archive *fout, const SubscriptionInfo *subinfo)
appendPQExpBufferStr(query, ", disable_on_error = true"); appendPQExpBufferStr(query, ", disable_on_error = true");
if (!subinfo->subpasswordrequired) if (!subinfo->subpasswordrequired)
appendPQExpBuffer(query, ", password_required = false"); appendPQExpBufferStr(query, ", password_required = false");
if (subinfo->subrunasowner) if (subinfo->subrunasowner)
appendPQExpBufferStr(query, ", run_as_owner = true"); appendPQExpBufferStr(query, ", run_as_owner = true");

View File

@ -1246,7 +1246,7 @@ dumpRoleMembership(PGconn *conn)
{ {
if (optbuf->data[0] != '\0') if (optbuf->data[0] != '\0')
appendPQExpBufferStr(optbuf, ", "); appendPQExpBufferStr(optbuf, ", ");
appendPQExpBuffer(optbuf, "SET FALSE"); appendPQExpBufferStr(optbuf, "SET FALSE");
} }
if (optbuf->data[0] != '\0') if (optbuf->data[0] != '\0')
fprintf(OPF, " WITH %s", optbuf->data); fprintf(OPF, " WITH %s", optbuf->data);

View File

@ -999,11 +999,11 @@ create_logical_replication_slots(void)
LogicalSlotInfo *slot_info = &slot_arr->slots[slotnum]; LogicalSlotInfo *slot_info = &slot_arr->slots[slotnum];
/* Constructs a query for creating logical replication slots */ /* Constructs a query for creating logical replication slots */
appendPQExpBuffer(query, appendPQExpBufferStr(query,
"SELECT * FROM " "SELECT * FROM "
"pg_catalog.pg_create_logical_replication_slot("); "pg_catalog.pg_create_logical_replication_slot(");
appendStringLiteralConn(query, slot_info->slotname, conn); appendStringLiteralConn(query, slot_info->slotname, conn);
appendPQExpBuffer(query, ", "); appendPQExpBufferStr(query, ", ");
appendStringLiteralConn(query, slot_info->plugin, conn); appendStringLiteralConn(query, slot_info->plugin, conn);
appendPQExpBuffer(query, ", false, %s, %s);", appendPQExpBuffer(query, ", false, %s, %s);",

View File

@ -1404,7 +1404,7 @@ DescribeQuery(const char *query, double *elapsed_msec)
char *escname; char *escname;
if (i > 0) if (i > 0)
appendPQExpBufferStr(&buf, ","); appendPQExpBufferChar(&buf, ',');
name = PQfname(result, i); name = PQfname(result, i);
escname = PQescapeLiteral(pset.db, name, strlen(name)); escname = PQescapeLiteral(pset.db, name, strlen(name));

View File

@ -896,10 +896,10 @@ retrieve_objects(PGconn *conn, vacuumingOptions *vacopts,
if (objects_listed) if (objects_listed)
{ {
if (objfilter & OBJFILTER_SCHEMA_EXCLUDE) if (objfilter & OBJFILTER_SCHEMA_EXCLUDE)
appendPQExpBuffer(&catalog_query, appendPQExpBufferStr(&catalog_query,
" AND listed_objects.object_oid IS NULL\n"); " AND listed_objects.object_oid IS NULL\n");
else else
appendPQExpBuffer(&catalog_query, appendPQExpBufferStr(&catalog_query,
" AND listed_objects.object_oid IS NOT NULL\n"); " AND listed_objects.object_oid IS NOT NULL\n");
} }
@ -911,7 +911,7 @@ retrieve_objects(PGconn *conn, vacuumingOptions *vacopts,
*/ */
if ((objfilter & OBJFILTER_TABLE) == 0) if ((objfilter & OBJFILTER_TABLE) == 0)
{ {
appendPQExpBuffer(&catalog_query, appendPQExpBufferStr(&catalog_query,
" AND c.relkind OPERATOR(pg_catalog.=) ANY (array[" " AND c.relkind OPERATOR(pg_catalog.=) ANY (array["
CppAsString2(RELKIND_RELATION) ", " CppAsString2(RELKIND_RELATION) ", "
CppAsString2(RELKIND_MATVIEW) "])\n"); CppAsString2(RELKIND_MATVIEW) "])\n");