MCPcopy Create free account
hub / github.com/apache/cloudberry / exec_command_elif

Function exec_command_elif

src/bin/psql/command.c:1685–1752  ·  view source on GitHub ↗

* \elif -- alternative branch in an \if..\endif block * * is evaluated the same as in \if . */

Source from the content-addressed store, hash-verified

1683 * <expr> is evaluated the same as in \if <expr>.
1684 */
1685static backslashResult
1686exec_command_elif(PsqlScanState scan_state, ConditionalStack cstack,
1687 PQExpBuffer query_buf)
1688{
1689 bool success = true;
1690
1691 switch (conditional_stack_peek(cstack))
1692 {
1693 case IFSTATE_TRUE:
1694
1695 /*
1696 * Just finished active branch of this \if block. Update saved
1697 * state so we will keep whatever data was put in query_buf by the
1698 * active branch.
1699 */
1700 save_query_text_state(scan_state, cstack, query_buf);
1701
1702 /*
1703 * Discard \elif expression and ignore the rest until \endif.
1704 * Switch state before reading expression to ensure proper lexer
1705 * behavior.
1706 */
1707 conditional_stack_poke(cstack, IFSTATE_IGNORED);
1708 ignore_boolean_expression(scan_state);
1709 break;
1710 case IFSTATE_FALSE:
1711
1712 /*
1713 * Discard any query text added by the just-skipped branch.
1714 */
1715 discard_query_text(scan_state, cstack, query_buf);
1716
1717 /*
1718 * Have not yet found a true expression in this \if block, so this
1719 * might be the first. We have to change state before examining
1720 * the expression, or the lexer won't do the right thing.
1721 */
1722 conditional_stack_poke(cstack, IFSTATE_TRUE);
1723 if (!is_true_boolean_expression(scan_state, "\\elif expression"))
1724 conditional_stack_poke(cstack, IFSTATE_FALSE);
1725 break;
1726 case IFSTATE_IGNORED:
1727
1728 /*
1729 * Discard any query text added by the just-skipped branch.
1730 */
1731 discard_query_text(scan_state, cstack, query_buf);
1732
1733 /*
1734 * Skip expression and move on. Either the \if block already had
1735 * an active section, or whole block is being skipped.
1736 */
1737 ignore_boolean_expression(scan_state);
1738 break;
1739 case IFSTATE_ELSE_TRUE:
1740 case IFSTATE_ELSE_FALSE:
1741 pg_log_error("\\elif: cannot occur after \\else");
1742 success = false;

Callers 1

exec_commandFunction · 0.85

Calls 6

conditional_stack_peekFunction · 0.85
save_query_text_stateFunction · 0.85
conditional_stack_pokeFunction · 0.85
discard_query_textFunction · 0.85

Tested by

no test coverage detected