* \if -- beginning of an \if..\endif block * * is parsed as a boolean expression. Invalid expressions will emit a * warning and be treated as false. Statements that follow a false expression * will be parsed but ignored. Note that in the case where an \if statement * is itself within an inactive section of a block, then the entire inner * \if..\endif block will be parsed but
| 1637 | * \if..\endif block will be parsed but ignored. |
| 1638 | */ |
| 1639 | static backslashResult |
| 1640 | exec_command_if(PsqlScanState scan_state, ConditionalStack cstack, |
| 1641 | PQExpBuffer query_buf) |
| 1642 | { |
| 1643 | if (conditional_active(cstack)) |
| 1644 | { |
| 1645 | /* |
| 1646 | * First, push a new active stack entry; this ensures that the lexer |
| 1647 | * will perform variable substitution and backtick evaluation while |
| 1648 | * scanning the expression. (That should happen anyway, since we know |
| 1649 | * we're in an active outer branch, but let's be sure.) |
| 1650 | */ |
| 1651 | conditional_stack_push(cstack, IFSTATE_TRUE); |
| 1652 | |
| 1653 | /* Remember current query state in case we need to restore later */ |
| 1654 | save_query_text_state(scan_state, cstack, query_buf); |
| 1655 | |
| 1656 | /* |
| 1657 | * Evaluate the expression; if it's false, change to inactive state. |
| 1658 | */ |
| 1659 | if (!is_true_boolean_expression(scan_state, "\\if expression")) |
| 1660 | conditional_stack_poke(cstack, IFSTATE_FALSE); |
| 1661 | } |
| 1662 | else |
| 1663 | { |
| 1664 | /* |
| 1665 | * We're within an inactive outer branch, so this entire \if block |
| 1666 | * will be ignored. We don't want to evaluate the expression, so push |
| 1667 | * the "ignored" stack state before scanning it. |
| 1668 | */ |
| 1669 | conditional_stack_push(cstack, IFSTATE_IGNORED); |
| 1670 | |
| 1671 | /* Remember current query state in case we need to restore later */ |
| 1672 | save_query_text_state(scan_state, cstack, query_buf); |
| 1673 | |
| 1674 | ignore_boolean_expression(scan_state); |
| 1675 | } |
| 1676 | |
| 1677 | return PSQL_CMD_SKIP_LINE; |
| 1678 | } |
| 1679 | |
| 1680 | /* |
| 1681 | * \elif <expr> -- alternative branch in an \if..\endif block |
no test coverage detected