* \set -- set variable */
| 2282 | * \set -- set variable |
| 2283 | */ |
| 2284 | static backslashResult |
| 2285 | exec_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 |
no test coverage detected