You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
/*
|
|
|
|
* psql - the PostgreSQL interactive terminal
|
|
|
|
*
|
|
|
|
* Copyright (c) 2000-2017, PostgreSQL Global Development Group
|
|
|
|
*
|
|
|
|
* src/bin/psql/command.h
|
|
|
|
*/
|
|
|
|
#ifndef COMMAND_H
|
|
|
|
#define COMMAND_H
|
|
|
|
|
|
|
|
#include "fe_utils/print.h"
|
|
|
|
#include "fe_utils/psqlscan.h"
|
Support \if ... \elif ... \else ... \endif in psql scripting.
This patch adds nestable conditional blocks to psql. The control
structure feature per se is complete, but the boolean expressions
understood by \if and \elif are pretty primitive; basically, after
variable substitution and backtick expansion, the result has to be
"true" or "false" or one of the other standard spellings of a boolean
value. But that's enough for many purposes, since you can always
do the heavy lifting on the server side; and we can extend it later.
Along the way, pay down some of the technical debt that had built up
around psql/command.c:
* Refactor exec_command() into a function per command, instead of
being a 1500-line monstrosity. This makes the file noticeably longer
because of repetitive function header/trailer overhead, but it seems
much more readable.
* Teach psql_get_variable() and psqlscanslash.l to suppress variable
substitution and backtick expansion on the basis of the conditional
stack state, thereby allowing removal of the OT_NO_EVAL kluge.
* Fix the no-doubt-once-expedient hack of sometimes silently substituting
mainloop.c's previous_buf for query_buf when calling HandleSlashCmds.
(It's a bit remarkable that commands like \r worked at all with that.)
Recall of a previous query is now done explicitly in the slash commands
where that should happen.
Corey Huinker, reviewed by Fabien Coelho, further hacking by me
Discussion: https://postgr.es/m/CADkLM=c94OSRTnat=LX0ivNq4pxDNeoomFfYvBKM5N_xfmLtAA@mail.gmail.com
8 years ago
|
|
|
#include "conditional.h"
|
|
|
|
|
|
|
|
|
|
|
|
typedef enum _backslashResult
|
|
|
|
{
|
|
|
|
PSQL_CMD_UNKNOWN = 0, /* not done parsing yet (internal only) */
|
|
|
|
PSQL_CMD_SEND, /* query complete; send off */
|
|
|
|
PSQL_CMD_SKIP_LINE, /* keep building query */
|
|
|
|
PSQL_CMD_TERMINATE, /* quit program */
|
|
|
|
PSQL_CMD_NEWEDIT, /* query buffer was changed (e.g., via \e) */
|
|
|
|
PSQL_CMD_ERROR /* the execution of the backslash command
|
|
|
|
* resulted in an error */
|
|
|
|
} backslashResult;
|
|
|
|
|
|
|
|
|
|
|
|
extern backslashResult HandleSlashCmds(PsqlScanState scan_state,
|
Support \if ... \elif ... \else ... \endif in psql scripting.
This patch adds nestable conditional blocks to psql. The control
structure feature per se is complete, but the boolean expressions
understood by \if and \elif are pretty primitive; basically, after
variable substitution and backtick expansion, the result has to be
"true" or "false" or one of the other standard spellings of a boolean
value. But that's enough for many purposes, since you can always
do the heavy lifting on the server side; and we can extend it later.
Along the way, pay down some of the technical debt that had built up
around psql/command.c:
* Refactor exec_command() into a function per command, instead of
being a 1500-line monstrosity. This makes the file noticeably longer
because of repetitive function header/trailer overhead, but it seems
much more readable.
* Teach psql_get_variable() and psqlscanslash.l to suppress variable
substitution and backtick expansion on the basis of the conditional
stack state, thereby allowing removal of the OT_NO_EVAL kluge.
* Fix the no-doubt-once-expedient hack of sometimes silently substituting
mainloop.c's previous_buf for query_buf when calling HandleSlashCmds.
(It's a bit remarkable that commands like \r worked at all with that.)
Recall of a previous query is now done explicitly in the slash commands
where that should happen.
Corey Huinker, reviewed by Fabien Coelho, further hacking by me
Discussion: https://postgr.es/m/CADkLM=c94OSRTnat=LX0ivNq4pxDNeoomFfYvBKM5N_xfmLtAA@mail.gmail.com
8 years ago
|
|
|
ConditionalStack cstack,
|
|
|
|
PQExpBuffer query_buf,
|
|
|
|
PQExpBuffer previous_buf);
|
|
|
|
|
|
|
|
extern int process_file(char *filename, bool use_relative_path);
|
|
|
|
|
|
|
|
extern bool do_pset(const char *param,
|
|
|
|
const char *value,
|
|
|
|
printQueryOpt *popt,
|
|
|
|
bool quiet);
|
|
|
|
|
|
|
|
extern void connection_warnings(bool in_startup);
|
|
|
|
|
|
|
|
extern void SyncVariables(void);
|
|
|
|
|
|
|
|
extern void UnsyncVariables(void);
|
|
|
|
|
|
|
|
#endif /* COMMAND_H */
|