Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions src/main/jjtree/net/sf/jsqlparser/parser/JSqlParserCC.jjt
Original file line number Diff line number Diff line change
Expand Up @@ -4796,9 +4796,7 @@ Expression CaseWhenExpression() #CaseWhenExpression:
[
<K_ELSE>
(
LOOKAHEAD(3, {!interrupted}) "(" elseExp=CaseWhenExpression() ")" { elseExp = new Parenthesis( elseExp ); }
| LOOKAHEAD(3, {!interrupted}) elseExp=CaseWhenExpression()
| LOOKAHEAD(3, {getAsBoolean(Feature.allowComplexParsing) && !interrupted}) elseExp=Expression()
LOOKAHEAD({getAsBoolean(Feature.allowComplexParsing) && !interrupted}) elseExp=Expression()
| elseExp=SimpleExpression()
)
]
Expand Down
27 changes: 27 additions & 0 deletions src/test/java/net/sf/jsqlparser/expression/CaseExpressionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,33 @@ public void testCaseOrSwitch() throws JSQLParserException {
TestUtils.assertExpressionCanBeParsedAndDeparsed("CASE true OR false WHEN true THEN 1 ELSE 2 END", true);
}

@Test
public void testInnerCaseWithConcatInElsePart() throws JSQLParserException {
String query = "SELECT \n" +
"CASE \n" +
" WHEN 1 = 1 \n" +
" THEN \n" +
" CASE \n" +
" WHEN 2 = 2 \n" +
" THEN '2a' \n" +
" ELSE \n" +
" CASE \n" +
" WHEN 1 = 1 \n" +
" THEN \n" +
" CASE \n" +
" WHEN 2 = 2 \n" +
" THEN '2a' \n" +
" ELSE '' \n" +
" END \n" +
" ELSE 'b' \n" +
" END || 'z'\n" +
" END \n" +
" ELSE 'b' \n" +
"END AS tmp\n" +
"FROM test_table";
TestUtils.assertSqlCanBeParsedAndDeparsed(query, true);
}

@Test
public void testCaseInsideBrackets() throws JSQLParserException {
String sqlStr = "SELECT ( CASE\n"
Expand Down