* \else -- final alternative in an \if..\endif block * * Statements within an \else branch will only be executed if * all previous \if and \elif expressions evaluated to false * and the block was not itself being ignored. */
| 1759 | * and the block was not itself being ignored. |
| 1760 | */ |
| 1761 | static backslashResult |
| 1762 | exec_command_else(PsqlScanState scan_state, ConditionalStack cstack, |
| 1763 | PQExpBuffer query_buf) |
| 1764 | { |
| 1765 | bool success = true; |
| 1766 | |
| 1767 | switch (conditional_stack_peek(cstack)) |
| 1768 | { |
| 1769 | case IFSTATE_TRUE: |
| 1770 | |
| 1771 | /* |
| 1772 | * Just finished active branch of this \if block. Update saved |
| 1773 | * state so we will keep whatever data was put in query_buf by the |
| 1774 | * active branch. |
| 1775 | */ |
| 1776 | save_query_text_state(scan_state, cstack, query_buf); |
| 1777 | |
| 1778 | /* Now skip the \else branch */ |
| 1779 | conditional_stack_poke(cstack, IFSTATE_ELSE_FALSE); |
| 1780 | break; |
| 1781 | case IFSTATE_FALSE: |
| 1782 | |
| 1783 | /* |
| 1784 | * Discard any query text added by the just-skipped branch. |
| 1785 | */ |
| 1786 | discard_query_text(scan_state, cstack, query_buf); |
| 1787 | |
| 1788 | /* |
| 1789 | * We've not found any true \if or \elif expression, so execute |
| 1790 | * the \else branch. |
| 1791 | */ |
| 1792 | conditional_stack_poke(cstack, IFSTATE_ELSE_TRUE); |
| 1793 | break; |
| 1794 | case IFSTATE_IGNORED: |
| 1795 | |
| 1796 | /* |
| 1797 | * Discard any query text added by the just-skipped branch. |
| 1798 | */ |
| 1799 | discard_query_text(scan_state, cstack, query_buf); |
| 1800 | |
| 1801 | /* |
| 1802 | * Either we previously processed the active branch of this \if, |
| 1803 | * or the whole \if block is being skipped. Either way, skip the |
| 1804 | * \else branch. |
| 1805 | */ |
| 1806 | conditional_stack_poke(cstack, IFSTATE_ELSE_FALSE); |
| 1807 | break; |
| 1808 | case IFSTATE_ELSE_TRUE: |
| 1809 | case IFSTATE_ELSE_FALSE: |
| 1810 | pg_log_error("\\else: cannot occur after \\else"); |
| 1811 | success = false; |
| 1812 | break; |
| 1813 | case IFSTATE_NONE: |
| 1814 | /* no \if to else from */ |
| 1815 | pg_log_error("\\else: no matching \\if"); |
| 1816 | success = false; |
| 1817 | break; |
| 1818 | } |
no test coverage detected