Re: \if, \elseif, \else, \endif (was Re: PSQL commands: \quit_if, \quit_unless)
Corey Huinker <corey.huinker@gmail.com>
From: Corey Huinker <corey.huinker@gmail.com>
To: Fabien COELHO <coelho@cri.ensmp.fr>
Cc: Daniel Verite <daniel@manitou-mail.org>, Erik Rijkers <er@xs4all.nl>,
Tom Lane <tgl@sss.pgh.pa.us>, Jim Nasby <Jim.Nasby@bluetreble.com>,
PostgreSQL <pgsql-hackers@postgresql.org>, pgsql-hackers-owner@postgresql.org
Date: 2017-02-06T06:39:49Z
Lists: pgsql-hackers
Attachments
- 0001.if_endif.v7.diff (text/plain) patch v7
> > Hmmm. ISTM that control-c must at least reset the stack, otherwise their > is not easy way to get out. What can be left to another patch is doing a > control-C for contents and then another one for the stack when there is no > content. > And so it shall be. > - put Fabien's tap test in place verbatim >> > > Hmmm. That was really just a POC... I would suggest some more tests, eg: > > # elif error > "\\if false\n\\elif error\n\\endif\n" > > # ignore commands on error (stdout must be empty) > "\\if error\n\\echo NO\n\\else\n\\echo NO\n\\endif\n" > Those are already in the regression (around line 2763 of expected/psql.out), are you saying we should have them in TAP as well? Should we only do TAP tests? Anyway, here's the Ctrl-C behavior: # \if true new \if is true, executing commands # \echo msg msg # ^C escaped \if, executing commands # \if false new \if is false, ignoring commands until next \elif, \else, or \endif # \echo msg inside inactive branch, command ignored. # ^C escaped \if, executing commands # \echo msg msg # \endif encountered un-matched \endif # Ctrl-C exits do the same before/after state checks that \endif does, the lone difference being that it "escaped" the \if rather than "exited" the \if. Thanks to Daniel for pointing out where it should be handled, because I wasn't going to figure that out on my own. v7's only major difference from v6 is the Ctrl-C branch escaping.
Commits
-
Support \if ... \elif ... \else ... \endif in psql scripting.
- e984ef5861df 10.0 landed
-
Add a "void *" passthrough pointer for psqlscan.l's callback functions.
- 895e36bb3f36 10.0 landed