MCPcopy Create free account
hub / github.com/apache/cloudberry / makeAlterConfigCommand

Function makeAlterConfigCommand

src/bin/pg_dump/dumputils.c:973–1036  ·  view source on GitHub ↗

* Helper function for dumping "ALTER DATABASE/ROLE SET ..." commands. * * Parse the contents of configitem (a "name=value" string), wrap it in * a complete ALTER command, and append it to buf. * * type is DATABASE or ROLE, and name is the name of the database or role. * If we need an "IN" clause, type2 and name2 similarly define what to put * there; otherwise they should be NULL. * conn is

Source from the content-addressed store, hash-verified

971 * conn is used only to determine string-literal quoting conventions.
972 */
973void
974makeAlterConfigCommand(PGconn *conn, const char *configitem,
975 const char *type, const char *name,
976 const char *type2, const char *name2,
977 PQExpBuffer buf)
978{
979 char *mine;
980 char *pos;
981
982 /* Parse the configitem. If we can't find an "=", silently do nothing. */
983 mine = pg_strdup(configitem);
984 pos = strchr(mine, '=');
985 if (pos == NULL)
986 {
987 pg_free(mine);
988 return;
989 }
990 *pos++ = '\0';
991
992 /* Build the command, with suitable quoting for everything. */
993 appendPQExpBuffer(buf, "ALTER %s %s ", type, fmtId(name));
994 if (type2 != NULL && name2 != NULL)
995 appendPQExpBuffer(buf, "IN %s %s ", type2, fmtId(name2));
996 appendPQExpBuffer(buf, "SET %s TO ", fmtId(mine));
997
998 /*
999 * Variables that are marked GUC_LIST_QUOTE were already fully quoted by
1000 * flatten_set_variable_args() before they were put into the setconfig
1001 * array. However, because the quoting rules used there aren't exactly
1002 * like SQL's, we have to break the list value apart and then quote the
1003 * elements as string literals. (The elements may be double-quoted as-is,
1004 * but we can't just feed them to the SQL parser; it would do the wrong
1005 * thing with elements that are zero-length or longer than NAMEDATALEN.)
1006 *
1007 * Variables that are not so marked should just be emitted as simple
1008 * string literals. If the variable is not known to
1009 * variable_is_guc_list_quote(), we'll do that; this makes it unsafe to
1010 * use GUC_LIST_QUOTE for extension variables.
1011 */
1012 if (variable_is_guc_list_quote(mine))
1013 {
1014 char **namelist;
1015 char **nameptr;
1016
1017 /* Parse string into list of identifiers */
1018 /* this shouldn't fail really */
1019 if (SplitGUCList(pos, ',', &namelist))
1020 {
1021 for (nameptr = namelist; *nameptr; nameptr++)
1022 {
1023 if (nameptr != namelist)
1024 appendPQExpBufferStr(buf, ", ");
1025 appendStringLiteralConn(buf, *nameptr, conn);
1026 }
1027 }
1028 pg_free(namelist);
1029 }
1030 else

Callers 2

dumpUserConfigFunction · 0.85
dumpDatabaseConfigFunction · 0.85

Calls 8

pg_strdupFunction · 0.85
pg_freeFunction · 0.85
appendPQExpBufferFunction · 0.85
fmtIdFunction · 0.85
appendPQExpBufferStrFunction · 0.85
appendStringLiteralConnFunction · 0.85
SplitGUCListFunction · 0.70

Tested by

no test coverage detected