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

Function exec_command_set

src/bin/psql/command.c:2284–2332  ·  view source on GitHub ↗

* \set -- set variable */

Source from the content-addressed store, hash-verified

2282 * \set -- set variable
2283 */
2284static backslashResult
2285exec_command_set(PsqlScanState scan_state, bool active_branch)
2286{
2287 bool success = true;
2288
2289 if (active_branch)
2290 {
2291 char *opt0 = psql_scan_slash_option(scan_state,
2292 OT_NORMAL, NULL, false);
2293
2294 if (!opt0)
2295 {
2296 /* list all variables */
2297 PrintVariables(pset.vars);
2298 success = true;
2299 }
2300 else
2301 {
2302 /*
2303 * Set variable to the concatenation of the arguments.
2304 */
2305 char *newval;
2306 char *opt;
2307
2308 opt = psql_scan_slash_option(scan_state,
2309 OT_NORMAL, NULL, false);
2310 newval = pg_strdup(opt ? opt : "");
2311 free(opt);
2312
2313 while ((opt = psql_scan_slash_option(scan_state,
2314 OT_NORMAL, NULL, false)))
2315 {
2316 newval = pg_realloc(newval, strlen(newval) + strlen(opt) + 1);
2317 strcat(newval, opt);
2318 free(opt);
2319 }
2320
2321 if (!SetVariable(pset.vars, opt0, newval))
2322 success = false;
2323
2324 free(newval);
2325 }
2326 free(opt0);
2327 }
2328 else
2329 ignore_slash_options(scan_state);
2330
2331 return success ? PSQL_CMD_SKIP_LINE : PSQL_CMD_ERROR;
2332}
2333
2334/*
2335 * \setenv -- set environment variable

Callers 1

exec_commandFunction · 0.85

Calls 5

PrintVariablesFunction · 0.85
pg_strdupFunction · 0.85
pg_reallocFunction · 0.85
SetVariableFunction · 0.85
ignore_slash_optionsFunction · 0.85

Tested by

no test coverage detected