From 394408763bc0ae96ea4271ad706105c1ee360293 Mon Sep 17 00:00:00 2001 From: David Rowley Date: Mon, 14 Apr 2025 18:46:03 +1200 Subject: [PATCH v1 2/2] Fixup various usages of appendPQExpBuffer Use appendPQExpBufferStr when there are no parameters and appendPQExpBufferChar when the string length is 1. --- src/bin/initdb/initdb.c | 4 +-- src/bin/pg_basebackup/pg_createsubscriber.c | 28 ++++++++++----------- src/bin/pg_dump/pg_dump.c | 28 ++++++++++----------- src/bin/pg_dump/pg_dumpall.c | 2 +- src/bin/pg_upgrade/pg_upgrade.c | 8 +++--- src/bin/psql/common.c | 2 +- src/bin/scripts/vacuumdb.c | 16 ++++++------ src/interfaces/libpq/fe-auth-oauth-curl.c | 2 +- src/test/modules/test_escape/test_escape.c | 15 +++++------ 9 files changed, 51 insertions(+), 54 deletions(-) diff --git a/src/bin/initdb/initdb.c b/src/bin/initdb/initdb.c index c17fda2bc81..2087690449d 100644 --- a/src/bin/initdb/initdb.c +++ b/src/bin/initdb/initdb.c @@ -1620,9 +1620,9 @@ bootstrap_template1(void) printfPQExpBuffer(&cmd, "\"%s\" --boot %s %s", backend_exec, boot_options, extra_options); appendPQExpBuffer(&cmd, " -X %d", wal_segment_size_mb * (1024 * 1024)); if (data_checksums) - appendPQExpBuffer(&cmd, " -k"); + appendPQExpBufferStr(&cmd, " -k"); if (debug) - appendPQExpBuffer(&cmd, " -d 5"); + appendPQExpBufferStr(&cmd, " -d 5"); PG_CMD_OPEN(cmd.data); diff --git a/src/bin/pg_basebackup/pg_createsubscriber.c b/src/bin/pg_basebackup/pg_createsubscriber.c index 42aaa428aed..f65acc7cb11 100644 --- a/src/bin/pg_basebackup/pg_createsubscriber.c +++ b/src/bin/pg_basebackup/pg_createsubscriber.c @@ -1247,20 +1247,20 @@ setup_recovery(const struct LogicalRepInfo *dbinfo, const char *datadir, const c * targets (name, time, xid, LSN). */ recoveryconfcontents = GenerateRecoveryConfig(conn, NULL, NULL); - appendPQExpBuffer(recoveryconfcontents, "recovery_target = ''\n"); - appendPQExpBuffer(recoveryconfcontents, - "recovery_target_timeline = 'latest'\n"); - appendPQExpBuffer(recoveryconfcontents, - "recovery_target_inclusive = true\n"); - appendPQExpBuffer(recoveryconfcontents, - "recovery_target_action = promote\n"); - appendPQExpBuffer(recoveryconfcontents, "recovery_target_name = ''\n"); - appendPQExpBuffer(recoveryconfcontents, "recovery_target_time = ''\n"); - appendPQExpBuffer(recoveryconfcontents, "recovery_target_xid = ''\n"); + appendPQExpBufferStr(recoveryconfcontents, "recovery_target = ''\n"); + appendPQExpBufferStr(recoveryconfcontents, + "recovery_target_timeline = 'latest'\n"); + appendPQExpBufferStr(recoveryconfcontents, + "recovery_target_inclusive = true\n"); + appendPQExpBufferStr(recoveryconfcontents, + "recovery_target_action = promote\n"); + appendPQExpBufferStr(recoveryconfcontents, "recovery_target_name = ''\n"); + appendPQExpBufferStr(recoveryconfcontents, "recovery_target_time = ''\n"); + appendPQExpBufferStr(recoveryconfcontents, "recovery_target_xid = ''\n"); if (dry_run) { - appendPQExpBuffer(recoveryconfcontents, "# dry run mode"); + appendPQExpBufferStr(recoveryconfcontents, "# dry run mode"); appendPQExpBuffer(recoveryconfcontents, "recovery_target_lsn = '%X/%X'\n", LSN_FORMAT_ARGS((XLogRecPtr) InvalidXLogRecPtr)); @@ -1484,10 +1484,10 @@ start_standby_server(const struct CreateSubscriberOptions *opt, bool restricted_ appendPQExpBuffer(pg_ctl_cmd, "\"%s\" start -D ", pg_ctl_path); 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 */ - appendPQExpBuffer(pg_ctl_cmd, " -o \"-c idle_replication_slot_timeout=0\""); + appendPQExpBufferStr(pg_ctl_cmd, " -o \"-c idle_replication_slot_timeout=0\""); if (restricted_access) { @@ -1513,7 +1513,7 @@ start_standby_server(const struct CreateSubscriberOptions *opt, bool restricted_ /* Suppress to start logical replication if requested */ if (restrict_logical_worker) - appendPQExpBuffer(pg_ctl_cmd, " -o \"-c max_logical_replication_workers=0\""); + appendPQExpBufferStr(pg_ctl_cmd, " -o \"-c max_logical_replication_workers=0\""); pg_log_debug("pg_ctl command is: %s", pg_ctl_cmd->data); rc = system(pg_ctl_cmd->data); diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c index c6e6d3b2b86..d9379bf8225 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -1777,7 +1777,7 @@ expand_table_name_patterns(Archive *fout, */ if (with_child_tables) { - appendPQExpBuffer(query, "WITH RECURSIVE partition_tree (relid) AS (\n"); + appendPQExpBufferStr(query, "WITH RECURSIVE partition_tree (relid) AS (\n"); } appendPQExpBuffer(query, @@ -1804,13 +1804,13 @@ expand_table_name_patterns(Archive *fout, if (with_child_tables) { - appendPQExpBuffer(query, "UNION" - "\nSELECT i.inhrelid" - "\nFROM partition_tree p" - "\n JOIN pg_catalog.pg_inherits i" - "\n ON p.relid OPERATOR(pg_catalog.=) i.inhparent" - "\n)" - "\nSELECT relid FROM partition_tree"); + appendPQExpBufferStr(query, "UNION" + "\nSELECT i.inhrelid" + "\nFROM partition_tree p" + "\n JOIN pg_catalog.pg_inherits i" + "\n ON p.relid OPERATOR(pg_catalog.=) i.inhparent" + "\n)" + "\nSELECT relid FROM partition_tree"); } ExecuteSqlStatement(fout, "RESET search_path"); @@ -5034,8 +5034,8 @@ getSubscriptions(Archive *fout) appendPQExpBufferStr(query, " s.subfailover\n"); else - appendPQExpBuffer(query, - " false AS subfailover\n"); + appendPQExpBufferStr(query, + " false AS subfailover\n"); appendPQExpBufferStr(query, "FROM pg_subscription s\n"); @@ -5257,7 +5257,7 @@ dumpSubscriptionTable(Archive *fout, const SubRelInfo *subrinfo) if (subrinfo->srsublsn && subrinfo->srsublsn[0] != '\0') appendPQExpBuffer(query, ", '%s'", subrinfo->srsublsn); else - appendPQExpBuffer(query, ", NULL"); + appendPQExpBufferStr(query, ", NULL"); appendPQExpBufferStr(query, ");\n"); } @@ -5352,7 +5352,7 @@ dumpSubscription(Archive *fout, const SubscriptionInfo *subinfo) appendPQExpBufferStr(query, ", disable_on_error = true"); if (!subinfo->subpasswordrequired) - appendPQExpBuffer(query, ", password_required = false"); + appendPQExpBufferStr(query, ", password_required = false"); if (subinfo->subrunasowner) appendPQExpBufferStr(query, ", run_as_owner = true"); @@ -9751,7 +9751,7 @@ determineNotNullFlags(Archive *fout, PGresult *res, int r, { *invalidnotnulloids = createPQExpBuffer(); appendPQExpBufferChar(*invalidnotnulloids, '{'); - appendPQExpBuffer(*invalidnotnulloids, "%s", constroid); + appendPQExpBufferStr(*invalidnotnulloids, constroid); } else appendPQExpBuffer(*invalidnotnulloids, ",%s", constroid); @@ -10978,7 +10978,7 @@ dumpRelationStats_dumper(Archive *fout, const void *userArg, const TocEntry *te) */ if (rsinfo->nindAttNames == 0) { - appendPQExpBuffer(out, ",\n\t'attname', "); + appendPQExpBufferStr(out, ",\n\t'attname', "); appendStringLiteralAH(out, attname, fout); } else diff --git a/src/bin/pg_dump/pg_dumpall.c b/src/bin/pg_dump/pg_dumpall.c index 3395d559518..946a6d0fafc 100644 --- a/src/bin/pg_dump/pg_dumpall.c +++ b/src/bin/pg_dump/pg_dumpall.c @@ -1246,7 +1246,7 @@ dumpRoleMembership(PGconn *conn) { if (optbuf->data[0] != '\0') appendPQExpBufferStr(optbuf, ", "); - appendPQExpBuffer(optbuf, "SET FALSE"); + appendPQExpBufferStr(optbuf, "SET FALSE"); } if (optbuf->data[0] != '\0') fprintf(OPF, " WITH %s", optbuf->data); diff --git a/src/bin/pg_upgrade/pg_upgrade.c b/src/bin/pg_upgrade/pg_upgrade.c index d9db48dba0d..536e49d2616 100644 --- a/src/bin/pg_upgrade/pg_upgrade.c +++ b/src/bin/pg_upgrade/pg_upgrade.c @@ -999,11 +999,11 @@ create_logical_replication_slots(void) LogicalSlotInfo *slot_info = &slot_arr->slots[slotnum]; /* Constructs a query for creating logical replication slots */ - appendPQExpBuffer(query, - "SELECT * FROM " - "pg_catalog.pg_create_logical_replication_slot("); + appendPQExpBufferStr(query, + "SELECT * FROM " + "pg_catalog.pg_create_logical_replication_slot("); appendStringLiteralConn(query, slot_info->slotname, conn); - appendPQExpBuffer(query, ", "); + appendPQExpBufferStr(query, ", "); appendStringLiteralConn(query, slot_info->plugin, conn); appendPQExpBuffer(query, ", false, %s, %s);", diff --git a/src/bin/psql/common.c b/src/bin/psql/common.c index 5249336bcf2..5382a07b74d 100644 --- a/src/bin/psql/common.c +++ b/src/bin/psql/common.c @@ -1404,7 +1404,7 @@ DescribeQuery(const char *query, double *elapsed_msec) char *escname; if (i > 0) - appendPQExpBufferStr(&buf, ","); + appendPQExpBufferChar(&buf, ','); name = PQfname(result, i); escname = PQescapeLiteral(pset.db, name, strlen(name)); diff --git a/src/bin/scripts/vacuumdb.c b/src/bin/scripts/vacuumdb.c index 935e6da3c17..22067faaf7d 100644 --- a/src/bin/scripts/vacuumdb.c +++ b/src/bin/scripts/vacuumdb.c @@ -896,11 +896,11 @@ retrieve_objects(PGconn *conn, vacuumingOptions *vacopts, if (objects_listed) { if (objfilter & OBJFILTER_SCHEMA_EXCLUDE) - appendPQExpBuffer(&catalog_query, - " AND listed_objects.object_oid IS NULL\n"); + appendPQExpBufferStr(&catalog_query, + " AND listed_objects.object_oid IS NULL\n"); else - appendPQExpBuffer(&catalog_query, - " AND listed_objects.object_oid IS NOT NULL\n"); + appendPQExpBufferStr(&catalog_query, + " AND listed_objects.object_oid IS NOT NULL\n"); } /* @@ -911,10 +911,10 @@ retrieve_objects(PGconn *conn, vacuumingOptions *vacopts, */ if ((objfilter & OBJFILTER_TABLE) == 0) { - appendPQExpBuffer(&catalog_query, - " AND c.relkind OPERATOR(pg_catalog.=) ANY (array[" - CppAsString2(RELKIND_RELATION) ", " - CppAsString2(RELKIND_MATVIEW) "])\n"); + appendPQExpBufferStr(&catalog_query, + " AND c.relkind OPERATOR(pg_catalog.=) ANY (array[" + CppAsString2(RELKIND_RELATION) ", " + CppAsString2(RELKIND_MATVIEW) "])\n"); } /* diff --git a/src/interfaces/libpq/fe-auth-oauth-curl.c b/src/interfaces/libpq/fe-auth-oauth-curl.c index 3f7a476586f..1ed7f34024a 100644 --- a/src/interfaces/libpq/fe-auth-oauth-curl.c +++ b/src/interfaces/libpq/fe-auth-oauth-curl.c @@ -2859,7 +2859,7 @@ error_return: } } - appendPQExpBufferStr(&conn->errorMessage, "\n"); + appendPQExpBufferChar(&conn->errorMessage, '\n'); return PGRES_POLLING_FAILED; } diff --git a/src/test/modules/test_escape/test_escape.c b/src/test/modules/test_escape/test_escape.c index f6b36448977..0b4883cc7c8 100644 --- a/src/test/modules/test_escape/test_escape.c +++ b/src/test/modules/test_escape/test_escape.c @@ -96,8 +96,7 @@ escape_literal(PGconn *conn, PQExpBuffer target, escaped = PQescapeLiteral(conn, unescaped, unescaped_len); if (!escaped) { - appendPQExpBuffer(escape_err, "%s", - PQerrorMessage(conn)); + appendPQExpBufferStr(escape_err, PQerrorMessage(conn)); escape_err->data[escape_err->len - 1] = 0; escape_err->len--; return false; @@ -120,8 +119,7 @@ escape_identifier(PGconn *conn, PQExpBuffer target, escaped = PQescapeIdentifier(conn, unescaped, unescaped_len); if (!escaped) { - appendPQExpBuffer(escape_err, "%s", - PQerrorMessage(conn)); + appendPQExpBufferStr(escape_err, PQerrorMessage(conn)); escape_err->data[escape_err->len - 1] = 0; escape_err->len--; return false; @@ -153,8 +151,7 @@ escape_string_conn(PGconn *conn, PQExpBuffer target, if (error) { - appendPQExpBuffer(escape_err, "%s", - PQerrorMessage(conn)); + appendPQExpBufferStr(escape_err, PQerrorMessage(conn)); escape_err->data[escape_err->len - 1] = 0; escape_err->len--; return false; @@ -514,7 +511,7 @@ test_psql_parse(pe_test_config *tc, PQExpBuffer testname, "#\t\t %d: scan_result: %s prompt: %u, query_buf: ", matches, scan_res_s(scan_result), prompt_status); escapify(details, query_buf->data, query_buf->len); - appendPQExpBuffer(details, "\n"); + appendPQExpBufferChar(details, '\n'); matches++; } @@ -566,7 +563,7 @@ test_one_vector_escape(pe_test_config *tc, const pe_test_vector *tv, const pe_te } /* name to describe the test */ - appendPQExpBuffer(testname, ">"); + appendPQExpBufferChar(testname, '>'); escapify(testname, tv->escape, tv->escape_len); appendPQExpBuffer(testname, "< - %s - %s", tv->client_encoding, ef->name); @@ -575,7 +572,7 @@ test_one_vector_escape(pe_test_config *tc, const pe_test_vector *tv, const pe_te appendPQExpBuffer(details, "#\t input: %zd bytes: ", tv->escape_len); escapify(details, tv->escape, tv->escape_len); - appendPQExpBufferStr(details, "\n"); + appendPQExpBufferChar(details, '\n'); appendPQExpBuffer(details, "#\t encoding: %s\n", tv->client_encoding); -- 2.43.0