Re: \if, \elseif, \else, \endif (was Re: [HACKERS] PSQL commands:\quit_if, \quit_unless)

Поиск
Список
Период
Сортировка
От Corey Huinker
Тема Re: \if, \elseif, \else, \endif (was Re: [HACKERS] PSQL commands:\quit_if, \quit_unless)
Дата
Msg-id CADkLM=fxWZtCLdxcnVK3R8_-9V49WhzgfNiyEZXXaxLm2x01BA@mail.gmail.com
обсуждение исходный текст
Ответ на Re: \if, \elseif, \else, \endif (was Re: [HACKERS] PSQL commands:\quit_if, \quit_unless)  (Corey Huinker <corey.huinker@gmail.com>)
Список pgsql-hackers


On Mon, Feb 6, 2017 at 11:21 AM, Corey Huinker <corey.huinker@gmail.com> wrote:

Find attached a small patch to improve tap tests, which also checks that psql really exited by checking that nothing is printed afterwards.


Do you think the TAP tests would benefit from having the input described in a q(...) block rather than a string?

q(\if false
\echo a
\elif invalid
\echo b
\endif
\echo c
)

It's a lot more lines, obviously, but it might make what is being tested clearer.


It occurred to me that the part of this patch most important to casual users would be the printed messages at various states. I've enumerated those below, along with the circumstances under which the user would see them.

The following messages are for interactive and script users. They are also errors which respect ON_ERROR_STOP.
-------------------

\if statement which had an invalid boolean expression:
new \if is invalid, ignoring commands until next \endif

\elif was in a proper \if block, and not after the true block, but boolean expression was invalid: 
\elif is invalid, ignoring commands until next \endif

\elif statement after an \else
encountered \elif after \else

\elif statement outside of an \if block [*]
encountered un-matched \elif

\else outside of an \if
encountered un-matched \else

\else after an \else
encountered \else after \else

\endif statement outside of an \if block
encountered un-matched \endif

Input file ends with unresolved \if blocks
found EOF before closing \endif(s)

The following are interactive-only non-error informational messages.
-------------

\if statement which parsed to true:
new \if is true, executing commands

\if statement which parsed to false:
new \if is false, ignoring commands until next \elif, \else, or \endif

\if statement while already in a false/invalid block:
new \if is inside ignored block, ignoring commands until next \endif

\elif statement immediately after the true \if or \elif
\elif is after true block, ignoring commands until next \endif

\elif statement within a false block or subsequent elif after the first ignored elif
\elif is inside ignored block, ignoring commands until next \endif

\elif was evaluated, was true
\elif is true, executing commands

\elif was evaluated, was false
\elif is false, ignoring commands until next \elif, \else, or \endif

\else statement in an ignored block or after the true block was found:
\else after true condition or in ignored block, ignoring commands until next \endif

\else statement and all previous blocks were false
\else after all previous conditions false, executing commands

\endif statement ending only \if on the stack
exited \if, executing commands

\endif statement where last block was false but parent block is also false:
exited \\if to false parent branch, ignoring commands until next \endif

\endif statement where last block was true and parent is true
exited \\if to true parent branch, continuing executing commands

\endif statement where last block was false but parent is true
exited \\if to true parent branch, resuming executing commands

Script is currently in a false (or invalid) branch, and user entered a command other than if/elif/endif:
inside inactive branch, command ignored.

Script currently in a false branch, and user entered a query:
inside inactive branch, query ignored. use \endif to exit current branch.

User in an \if branch and pressed ^C, with no more branches remaining:
escaped \\if, executing commands

User in an \if branch and pressed ^C, but parent branch was false:
escaped \\if to false parent branch, ignoring commands until next \endif

User in a true \if branch and pressed ^C, parent branch true
escaped \\if to true parent branch, continuing executing commands

User in a false \if branch and pressed ^C, parent branch true
escaped \if to true parent branch, resuming executing commands


Notes:
--------

The text for ignored commands vs ignored queries is different.

The text for all the Ctrl-C messages re-uses the \endif messages, but are "escaped" instead of "exited".

В списке pgsql-hackers по дате отправления:

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: [HACKERS] Index corruption with CREATE INDEX CONCURRENTLY
Следующее
От: Pavel Stehule
Дата:
Сообщение: Re: [HACKERS] proposal: session server side variables