v1-0001-ensure-fetchAttributeStats-subroutine-handle-single-quote.patch
text/x-patch
Filename: v1-0001-ensure-fetchAttributeStats-subroutine-handle-single-quote.patch
Type: text/x-patch
Part: 0
Patch
Same data as JSON:
GET /api/v1/attachments/:id/patch
the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes.
API reference →
Format: format-patch
Series: patch v1-0001
Subject: ensure fetchAttributeStats subroutine handle single quote properly
| File | + | − |
|---|---|---|
| src/bin/pg_dump/pg_dump.c | 10 | 6 |
| src/fe_utils/string_utils.c | 14 | 1 |
From 5f79c94fb659f47c7c88d5e9779b6523f211d830 Mon Sep 17 00:00:00 2001
From: jian he <jian.universality@gmail.com>
Date: Tue, 13 May 2025 19:29:34 +0800
Subject: [PATCH v1 1/1] ensure fetchAttributeStats subroutine handle single
quote properly
---
src/bin/pg_dump/pg_dump.c | 16 ++++++++++------
src/fe_utils/string_utils.c | 15 ++++++++++++++-
2 files changed, 24 insertions(+), 7 deletions(-)
diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c
index e2e7975b34e..446d7856f29 100644
--- a/src/bin/pg_dump/pg_dump.c
+++ b/src/bin/pg_dump/pg_dump.c
@@ -10738,6 +10738,9 @@ fetchAttributeStats(Archive *fout)
static bool restarted;
int max_rels = MAX_ATTR_STATS_RELS;
+ appendPQExpBufferChar(nspnames, '{');
+ appendPQExpBufferChar(relnames, '{');
+
/*
* Our query for retrieving statistics for multiple relations uses WITH
* ORDINALITY and multi-argument UNNEST(), both of which were introduced
@@ -10776,10 +10779,8 @@ fetchAttributeStats(Archive *fout)
if ((te->reqs & REQ_STATS) != 0 &&
strcmp(te->desc, "STATISTICS DATA") == 0)
{
- appendPQExpBuffer(nspnames, "%s%s", count ? "," : "",
- fmtId(te->namespace));
- appendPQExpBuffer(relnames, "%s%s", count ? "," : "",
- fmtId(te->tag));
+ appendPGArray(nspnames, fmtId(te->namespace));
+ appendPGArray(relnames, fmtId(te->tag));
count++;
}
}
@@ -10789,9 +10790,12 @@ fetchAttributeStats(Archive *fout)
{
PQExpBuffer query = createPQExpBuffer();
+ appendPQExpBufferChar(nspnames, '}');
+ appendPQExpBufferChar(relnames, '}');
+
appendPQExpBuffer(query, "EXECUTE getAttributeStats("
- "'{%s}'::pg_catalog.name[],"
- "'{%s}'::pg_catalog.name[])",
+ "'%s'::pg_catalog.name[],"
+ "'%s'::pg_catalog.name[])",
nspnames->data, relnames->data);
res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
destroyPQExpBuffer(query);
diff --git a/src/fe_utils/string_utils.c b/src/fe_utils/string_utils.c
index 130d1020d50..fa63b8c88e1 100644
--- a/src/fe_utils/string_utils.c
+++ b/src/fe_utils/string_utils.c
@@ -942,12 +942,25 @@ appendPGArray(PQExpBuffer buffer, const char *value)
if (ch == '"' || ch == '\\')
appendPQExpBufferChar(buffer, '\\');
+
+ if (ch == '\'')
+ appendPQExpBufferChar(buffer, '\'');
+
appendPQExpBufferChar(buffer, ch);
}
appendPQExpBufferChar(buffer, '"');
}
else
- appendPQExpBufferStr(buffer, value);
+ {
+ for (tmp = value; *tmp; tmp++)
+ {
+ char ch = *tmp;
+
+ if (ch == '\'')
+ appendPQExpBufferChar(buffer, '\'');
+ appendPQExpBufferChar(buffer, ch);
+ }
+ }
}
--
2.34.1