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

Function exec_command_watch

src/bin/psql/command.c:2685–2719  ·  view source on GitHub ↗

* \watch -- execute a query every N seconds */

Source from the content-addressed store, hash-verified

2683 * \watch -- execute a query every N seconds
2684 */
2685static backslashResult
2686exec_command_watch(PsqlScanState scan_state, bool active_branch,
2687 PQExpBuffer query_buf, PQExpBuffer previous_buf)
2688{
2689 bool success = true;
2690
2691 if (active_branch)
2692 {
2693 char *opt = psql_scan_slash_option(scan_state,
2694 OT_NORMAL, NULL, true);
2695 double sleep = 2;
2696
2697 /* Convert optional sleep-length argument */
2698 if (opt)
2699 {
2700 sleep = strtod(opt, NULL);
2701 if (sleep <= 0)
2702 sleep = 1;
2703 free(opt);
2704 }
2705
2706 /* If query_buf is empty, recall and execute previous query */
2707 (void) copy_previous_query(query_buf, previous_buf);
2708
2709 success = do_watch(query_buf, sleep);
2710
2711 /* Reset the query buffer as though for \r */
2712 resetPQExpBuffer(query_buf);
2713 psql_scan_reset(scan_state);
2714 }
2715 else
2716 ignore_slash_options(scan_state);
2717
2718 return success ? PSQL_CMD_SKIP_LINE : PSQL_CMD_ERROR;
2719}
2720
2721/*
2722 * \x -- set or toggle expanded table representation

Callers 1

exec_commandFunction · 0.85

Calls 4

copy_previous_queryFunction · 0.85
do_watchFunction · 0.85
resetPQExpBufferFunction · 0.85
ignore_slash_optionsFunction · 0.85

Tested by

no test coverage detected