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

Function PSQLexecWatch

src/bin/psql/common.c:594–678  ·  view source on GitHub ↗

* PSQLexecWatch * * This function is used for \watch command to send the query to * the server and print out the results. * * Returns 1 if the query executed successfully, 0 if it cannot be repeated, * e.g., because of the interrupt, -1 on error. */

Source from the content-addressed store, hash-verified

592 * e.g., because of the interrupt, -1 on error.
593 */
594int
595PSQLexecWatch(const char *query, const printQueryOpt *opt)
596{
597 PGresult *res;
598 double elapsed_msec = 0;
599 instr_time before;
600 instr_time after;
601
602 if (!pset.db)
603 {
604 pg_log_error("You are currently not connected to a database.");
605 return 0;
606 }
607
608 SetCancelConn(pset.db);
609
610 if (pset.timing)
611 INSTR_TIME_SET_CURRENT(before);
612
613 res = PQexec(pset.db, query);
614
615 ResetCancelConn();
616
617 if (!AcceptResult(res))
618 {
619 ClearOrSaveResult(res);
620 return 0;
621 }
622
623 if (pset.timing)
624 {
625 INSTR_TIME_SET_CURRENT(after);
626 INSTR_TIME_SUBTRACT(after, before);
627 elapsed_msec = INSTR_TIME_GET_MILLISEC(after);
628 }
629
630 /*
631 * If SIGINT is sent while the query is processing, the interrupt will be
632 * consumed. The user's intention, though, is to cancel the entire watch
633 * process, so detect a sent cancellation request and exit in this case.
634 */
635 if (cancel_pressed)
636 {
637 PQclear(res);
638 return 0;
639 }
640
641 switch (PQresultStatus(res))
642 {
643 case PGRES_TUPLES_OK:
644 printQuery(res, opt, pset.queryFout, false, pset.logfile);
645 break;
646
647 case PGRES_COMMAND_OK:
648 fprintf(pset.queryFout, "%s\n%s\n\n", opt->title, PQcmdStatus(res));
649 break;
650
651 case PGRES_EMPTY_QUERY:

Callers 1

do_watchFunction · 0.85

Calls 10

SetCancelConnFunction · 0.85
PQexecFunction · 0.85
ResetCancelConnFunction · 0.85
AcceptResultFunction · 0.85
ClearOrSaveResultFunction · 0.85
PQclearFunction · 0.85
PQresultStatusFunction · 0.85
printQueryFunction · 0.85
PQcmdStatusFunction · 0.85
PrintTimingFunction · 0.85

Tested by

no test coverage detected