* \g [(pset-option[=pset-value] ...)] [filename/shell-command] * \gx [(pset-option[=pset-value] ...)] [filename/shell-command] * * Send the current query. If pset options are specified, they are made * active just for this query. If a filename or pipe command is given, * the query output goes there. \gx implicitly sets "expanded=on" along * with any other pset options that are specified.
| 1355 | * with any other pset options that are specified. |
| 1356 | */ |
| 1357 | static backslashResult |
| 1358 | exec_command_g(PsqlScanState scan_state, bool active_branch, const char *cmd) |
| 1359 | { |
| 1360 | backslashResult status = PSQL_CMD_SKIP_LINE; |
| 1361 | char *fname; |
| 1362 | |
| 1363 | /* |
| 1364 | * Because the option processing for this is fairly complicated, we do it |
| 1365 | * and then decide whether the branch is active. |
| 1366 | */ |
| 1367 | fname = psql_scan_slash_option(scan_state, |
| 1368 | OT_FILEPIPE, NULL, false); |
| 1369 | |
| 1370 | if (fname && fname[0] == '(') |
| 1371 | { |
| 1372 | /* Consume pset options through trailing ')' ... */ |
| 1373 | status = process_command_g_options(fname + 1, scan_state, |
| 1374 | active_branch, cmd); |
| 1375 | free(fname); |
| 1376 | /* ... and again attempt to scan the filename. */ |
| 1377 | fname = psql_scan_slash_option(scan_state, |
| 1378 | OT_FILEPIPE, NULL, false); |
| 1379 | } |
| 1380 | |
| 1381 | if (status == PSQL_CMD_SKIP_LINE && active_branch) |
| 1382 | { |
| 1383 | if (!fname) |
| 1384 | pset.gfname = NULL; |
| 1385 | else |
| 1386 | { |
| 1387 | expand_tilde(&fname); |
| 1388 | pset.gfname = pg_strdup(fname); |
| 1389 | } |
| 1390 | if (strcmp(cmd, "gx") == 0) |
| 1391 | { |
| 1392 | /* save settings if not done already, then force expanded=on */ |
| 1393 | if (pset.gsavepopt == NULL) |
| 1394 | pset.gsavepopt = savePsetInfo(&pset.popt); |
| 1395 | pset.popt.topt.expanded = 1; |
| 1396 | } |
| 1397 | status = PSQL_CMD_SEND; |
| 1398 | } |
| 1399 | |
| 1400 | free(fname); |
| 1401 | |
| 1402 | return status; |
| 1403 | } |
| 1404 | |
| 1405 | /* |
| 1406 | * Process parenthesized pset options for \g |
no test coverage detected