Skip to content

Fixing a problem with an OP_CONCAT in WhenExpression #1837

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Aug 20, 2023
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