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

Function MainLoop

src/bin/psql/mainloop.c:32–657  ·  view source on GitHub ↗

* Main processing loop for reading lines of input * and sending them to the backend. * * This loop is re-entrant. May be called by \i command * which reads input from a file. */

Source from the content-addressed store, hash-verified

30 * which reads input from a file.
31 */
32int
33MainLoop(FILE *source)
34{
35 PsqlScanState scan_state; /* lexer working state */
36 ConditionalStack cond_stack; /* \if status stack */
37 volatile PQExpBuffer query_buf; /* buffer for query being accumulated */
38 volatile PQExpBuffer previous_buf; /* if there isn't anything in the new
39 * buffer yet, use this one for \e,
40 * etc. */
41 PQExpBuffer history_buf; /* earlier lines of a multi-line command, not
42 * yet saved to readline history */
43 char *line; /* current line of input */
44 int added_nl_pos;
45 bool success;
46 bool line_saved_in_history;
47 volatile int successResult = EXIT_SUCCESS;
48 volatile backslashResult slashCmdStatus = PSQL_CMD_UNKNOWN;
49 volatile promptStatus_t prompt_status = PROMPT_READY;
50 volatile bool need_redisplay = false;
51 volatile int count_eof = 0;
52 volatile bool die_on_error = false;
53 FILE *prev_cmd_source;
54 bool prev_cmd_interactive;
55 uint64 prev_lineno;
56
57 /* Save the prior command source */
58 prev_cmd_source = pset.cur_cmd_source;
59 prev_cmd_interactive = pset.cur_cmd_interactive;
60 prev_lineno = pset.lineno;
61 /* pset.stmt_lineno does not need to be saved and restored */
62
63 /* Establish new source */
64 pset.cur_cmd_source = source;
65 pset.cur_cmd_interactive = ((source == stdin) && !pset.notty);
66 pset.lineno = 0;
67 pset.stmt_lineno = 1;
68
69 /* Create working state */
70 scan_state = psql_scan_create(&psqlscan_callbacks);
71 cond_stack = conditional_stack_create();
72 psql_scan_set_passthrough(scan_state, (void *) cond_stack);
73
74 query_buf = createPQExpBuffer();
75 previous_buf = createPQExpBuffer();
76 history_buf = createPQExpBuffer();
77 if (PQExpBufferBroken(query_buf) ||
78 PQExpBufferBroken(previous_buf) ||
79 PQExpBufferBroken(history_buf))
80 {
81 pg_log_error("out of memory");
82 exit(EXIT_FAILURE);
83 }
84
85 /* main loop to get queries and execute them */
86 while (successResult == EXIT_SUCCESS)
87 {
88 /*
89 * Clean up after a previous Control-C

Callers 2

mainFunction · 0.85
process_fileFunction · 0.85

Calls 15

conditional_stack_createFunction · 0.85
createPQExpBufferFunction · 0.85
resetPQExpBufferFunction · 0.85
conditional_stack_emptyFunction · 0.85
conditional_stack_popFunction · 0.85
get_promptFunction · 0.85
gets_interactiveFunction · 0.85
gets_fromFileFunction · 0.85
pg_strncasecmpFunction · 0.85
appendPQExpBufferCharFunction · 0.85
standard_stringsFunction · 0.85
pg_append_historyFunction · 0.85

Tested by

no test coverage detected