* \watch -- execute a query every N seconds */
| 2683 | * \watch -- execute a query every N seconds |
| 2684 | */ |
| 2685 | static backslashResult |
| 2686 | exec_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 |
no test coverage detected