git.postgresql.org Git - postgresql.git/commit

git projects / postgresql.git / commit
? search:
summary | shortlog | log | commit | commitdiff | tree
(parent: ffae673) | patch
Support \if ... \elif ... \else ... \endif in psql scripting.
2017年3月30日 16:59:11 +0000 (12:59 -0400)
2017年3月30日 16:59:24 +0000 (12:59 -0400)
commit e984ef5861df4bc9733b36271d05763e82de7c04
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
17 files changed:
doc/src/sgml/ref/psql-ref.sgml diff | blob | blame | history
src/bin/psql/Makefile diff | blob | blame | history
src/bin/psql/command.c diff | blob | blame | history
src/bin/psql/command.h diff | blob | blame | history
src/bin/psql/common.c diff | blob | blame | history
src/bin/psql/conditional.c [new file with mode: 0644] blob
src/bin/psql/conditional.h [new file with mode: 0644] blob
src/bin/psql/copy.c diff | blob | blame | history
src/bin/psql/help.c diff | blob | blame | history
src/bin/psql/mainloop.c diff | blob | blame | history
src/bin/psql/prompt.c diff | blob | blame | history
src/bin/psql/prompt.h diff | blob | blame | history
src/bin/psql/psqlscanslash.h diff | blob | blame | history
src/bin/psql/psqlscanslash.l diff | blob | blame | history
src/bin/psql/startup.c diff | blob | blame | history
src/test/regress/expected/psql.out diff | blob | blame | history
src/test/regress/sql/psql.sql diff | blob | blame | history
This is the main PostgreSQL git repository.
RSS Atom

AltStyle によって変換されたページ (->オリジナル) /