Skip to content

Commit f05cb7f

Browse files
authored
Fixing a problem with an OP_CONCAT in WhenExpression (#1837)
* fix: Concatenation in inner ELSE statement (Second level of Case Expression) * fix: broken tests * fix: Delete lookahead(3)
1 parent 3cae390 commit f05cb7f

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

src/main/jjtree/net/sf/jsqlparser/parser/JSqlParserCC.jjt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4796,9 +4796,7 @@ Expression CaseWhenExpression() #CaseWhenExpression:
47964796
[
47974797
<K_ELSE>
47984798
(
4799-
LOOKAHEAD(3, {!interrupted}) "(" elseExp=CaseWhenExpression() ")" { elseExp = new Parenthesis( elseExp ); }
4800-
| LOOKAHEAD(3, {!interrupted}) elseExp=CaseWhenExpression()
4801-
| LOOKAHEAD(3, {getAsBoolean(Feature.allowComplexParsing) && !interrupted}) elseExp=Expression()
4799+
LOOKAHEAD({getAsBoolean(Feature.allowComplexParsing) && !interrupted}) elseExp=Expression()
48024800
| elseExp=SimpleExpression()
48034801
)
48044802
]

src/test/java/net/sf/jsqlparser/expression/CaseExpressionTest.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,33 @@ public void testCaseOrSwitch() throws JSQLParserException {
8282
TestUtils.assertExpressionCanBeParsedAndDeparsed("CASE true OR false WHEN true THEN 1 ELSE 2 END", true);
8383
}
8484

85+
@Test
86+
public void testInnerCaseWithConcatInElsePart() throws JSQLParserException {
87+
String query = "SELECT \n" +
88+
"CASE \n" +
89+
" WHEN 1 = 1 \n" +
90+
" THEN \n" +
91+
" CASE \n" +
92+
" WHEN 2 = 2 \n" +
93+
" THEN '2a' \n" +
94+
" ELSE \n" +
95+
" CASE \n" +
96+
" WHEN 1 = 1 \n" +
97+
" THEN \n" +
98+
" CASE \n" +
99+
" WHEN 2 = 2 \n" +
100+
" THEN '2a' \n" +
101+
" ELSE '' \n" +
102+
" END \n" +
103+
" ELSE 'b' \n" +
104+
" END || 'z'\n" +
105+
" END \n" +
106+
" ELSE 'b' \n" +
107+
"END AS tmp\n" +
108+
"FROM test_table";
109+
TestUtils.assertSqlCanBeParsedAndDeparsed(query, true);
110+
}
111+
85112
@Test
86113
public void testCaseInsideBrackets() throws JSQLParserException {
87114
String sqlStr = "SELECT ( CASE\n"

0 commit comments

Comments
 (0)