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

Function appendReloptionsArray

src/fe_utils/string_utils.c:923–981  ·  view source on GitHub ↗

* Format a reloptions array and append it to the given buffer. * * "prefix" is prepended to the option names; typically it's "" or "toast.". * * Returns false if the reloptions array could not be parsed (in which case * nothing will have been appended to the buffer), or true on success. * * Note: this logic should generally match the backend's flatten_reloptions() * (in adt/ruleutils.c).

Source from the content-addressed store, hash-verified

921 * (in adt/ruleutils.c).
922 */
923bool
924appendReloptionsArray(PQExpBuffer buffer, const char *reloptions,
925 const char *prefix, int encoding, bool std_strings)
926{
927 char **options;
928 int noptions;
929 int i;
930
931 if (!parsePGArray(reloptions, &options, &noptions))
932 {
933 if (options)
934 free(options);
935 return false;
936 }
937
938 for (i = 0; i < noptions; i++)
939 {
940 char *option = options[i];
941 char *name;
942 char *separator;
943 char *value;
944
945 /*
946 * Each array element should have the form name=value. If the "=" is
947 * missing for some reason, treat it like an empty value.
948 */
949 name = option;
950 separator = strchr(option, '=');
951 if (separator)
952 {
953 *separator = '\0';
954 value = separator + 1;
955 }
956 else
957 value = "";
958
959 if (i > 0)
960 appendPQExpBufferStr(buffer, ", ");
961 appendPQExpBuffer(buffer, "%s%s=", prefix, fmtId(name));
962
963 /*
964 * In general we need to quote the value; but to avoid unnecessary
965 * clutter, do not quote if it is an identifier that would not need
966 * quoting. (We could also allow numbers, but that is a bit trickier
967 * than it looks --- for example, are leading zeroes significant? We
968 * don't want to assume very much here about what custom reloptions
969 * might mean.)
970 */
971 if (strcmp(fmtId(value), value) == 0)
972 appendPQExpBufferStr(buffer, value);
973 else
974 appendStringLiteral(buffer, value, encoding, std_strings);
975 }
976
977 if (options)
978 free(options);
979
980 return true;

Callers 2

get_create_object_cmdFunction · 0.85
appendReloptionsArrayAHFunction · 0.85

Calls 5

parsePGArrayFunction · 0.85
appendPQExpBufferStrFunction · 0.85
appendPQExpBufferFunction · 0.85
fmtIdFunction · 0.85
appendStringLiteralFunction · 0.85

Tested by

no test coverage detected