48 bool line_saved_in_history;
52 volatile int count_eof = 0;
53 volatile bool die_on_error =
false;
54 FILE *prev_cmd_source;
55 bool prev_cmd_interactive;
155 if (query_buf->
len == 0)
163 if (!line && ferror(source))
198 memmove(line, line + 3, strlen(line + 3) + 1);
202 strncmp(line,
"PGDMP", 5) == 0)
205 puts(
_(
"The input is a PostgreSQL custom-format dump.\n" 206 "Use the pg_restore command-line client to restore this dump to a database.\n"));
222 char *first_word = line;
223 char *rest_of_line = NULL;
224 bool found_help =
false;
225 bool found_exit_or_quit =
false;
226 bool found_q =
false;
231 rest_of_line = first_word + 4;
237 rest_of_line = first_word + 4;
238 found_exit_or_quit =
true;
241 else if (strncmp(first_word,
"\\q", 2) == 0)
243 rest_of_line = first_word + 2;
254 if (rest_of_line != NULL)
260 while (isspace((
unsigned char) *rest_of_line))
262 if (*rest_of_line ==
';')
264 while (isspace((
unsigned char) *rest_of_line))
266 if (*rest_of_line !=
'\0')
269 found_exit_or_quit =
false;
281 if (query_buf->
len != 0)
283 puts(
_(
"Use \\? for help or press control-C to clear the input buffer."));
285 puts(
_(
"Use \\? for help."));
289 puts(
_(
"You are using psql, the command-line interface to PostgreSQL."));
290 printf(
_(
"Type: \\copyright for distribution terms\n" 291 " \\h for help with SQL commands\n" 292 " \\? for help with psql commands\n" 293 " \\g or terminate with semicolon to execute query\n" 307 if (found_exit_or_quit)
309 if (query_buf->
len != 0)
314 puts(
_(
"Use \\q to quit."));
317 puts(
_(
"Use control-D to quit."));
319 puts(
_(
"Use control-C to quit."));
337 if (found_q && query_buf->
len != 0 &&
342 puts(
_(
"Use control-D to quit."));
344 puts(
_(
"Use control-C to quit."));
356 if (query_buf->
len > 0)
359 added_nl_pos = query_buf->
len;
373 line_saved_in_history =
false;
375 while (success || !die_on_error)
382 pos_in_query = query_buf->
len;
383 scan_result =
psql_scan(scan_state, query_buf, &prompt_tmp);
384 prompt_status = prompt_tmp;
398 tmp_line = query_buf->
data + pos_in_query;
399 while (*tmp_line !=
'\0')
401 if (*(tmp_line++) ==
'\n')
425 line_saved_in_history =
true;
439 previous_buf = query_buf;
440 query_buf = swap_buf;
451 psql_error(
"query ignored; use \\endif or Ctrl-C to exit current \\if block\n");
472 if (query_buf->
len == added_nl_pos)
474 query_buf->
data[--query_buf->
len] =
'\0';
484 line_saved_in_history =
true;
513 previous_buf = query_buf;
514 query_buf = swap_buf;
534 line_saved_in_history =
false;
562 if (!success && die_on_error)
593 psql_error(
"query ignored; use \\endif or Ctrl-C to exit current \\if block\n");
597 if (!success && die_on_error)
611 psql_error(
"reached EOF without finding closing \\endif(s)\n");
636 return successResult;
bool conditional_active(ConditionalStack cstack)
volatile bool sigint_interrupt_enabled
bool conditional_stack_pop(ConditionalStack cstack)
PsqlScanState psql_scan_create(const PsqlScanCallbacks *callbacks)
char * get_prompt(promptStatus_t status, ConditionalStack cstack)
sigjmp_buf sigint_interrupt_jmp
volatile bool cancel_pressed
int pg_strncasecmp(const char *s1, const char *s2, size_t n)
void destroyPQExpBuffer(PQExpBuffer str)
const PsqlScanCallbacks psqlscan_callbacks
void psql_scan_reset(PsqlScanState state)
char * pg_strdup(const char *in)
ConditionalStack conditional_stack_create(void)
void psql_error(const char *fmt,...)
PQExpBuffer createPQExpBuffer(void)
void appendPQExpBufferChar(PQExpBuffer str, char ch)
void psql_scan_destroy(PsqlScanState state)
bool standard_strings(void)
enum _backslashResult backslashResult
#define Assert(condition)
enum _promptStatus promptStatus_t
#define PQExpBufferBroken(str)
PsqlScanResult psql_scan(PsqlScanState state, PQExpBuffer query_buf, promptStatus_t *prompt)
void conditional_stack_destroy(ConditionalStack cstack)
void psql_scan_set_passthrough(PsqlScanState state, void *passthrough)
bool conditional_stack_empty(ConditionalStack cstack)
void psql_scan_setup(PsqlScanState state, const char *line, int line_len, int encoding, bool std_strings)
bool SendQuery(const char *query)
bool psql_scan_in_quote(PsqlScanState state)
void psql_scan_finish(PsqlScanState state)
backslashResult HandleSlashCmds(PsqlScanState scan_state, ConditionalStack cstack, PQExpBuffer query_buf, PQExpBuffer previous_buf)
void resetPQExpBuffer(PQExpBuffer str)