Skip to content

Commit 60a7d10

Browse files
Allows CASE ... ELSE ComplexExpression (#1388)
Fixes #1375 Co-authored-by: Tobias <t.warneke@gmx.net>
1 parent c423224 commit 60a7d10

File tree

2 files changed

+6
-16
lines changed

2 files changed

+6
-16
lines changed

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

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4291,7 +4291,7 @@ Expression CaseWhenExpression() #CaseWhenExpression:
42914291
[ switchExp=Condition() ]
42924292
( clause=WhenThenSearchCondition() { whenClauses.add(clause); } )+
42934293
[<K_ELSE> (LOOKAHEAD( ["("] CaseWhenExpression() [")"] ( <K_WHEN> | <K_ELSE> | <K_END> ) ) ["("] elseExp=CaseWhenExpression() [")" { ((CaseExpression) elseExp).setUsingBrackets(true); } ]
4294-
| elseExp=Condition()
4294+
| elseExp=Expression()
42954295
)
42964296
]
42974297
<K_END> { caseCounter--; }
@@ -4323,21 +4323,6 @@ WhenClause WhenThenSearchCondition():
43234323
}
43244324
}
43254325

4326-
/*WhenClause WhenThenValue():
4327-
{
4328-
WhenClause whenThen = new WhenClause();
4329-
Expression whenExp = null;
4330-
Expression thenExp = null;
4331-
}
4332-
{
4333-
<K_WHEN> whenExp=SimpleExpression() <K_THEN> thenExp=SimpleExpression()
4334-
{
4335-
whenThen.setWhenExpression(whenExp);
4336-
whenThen.setThenExpression(thenExp);
4337-
return whenThen;
4338-
}
4339-
}*/
4340-
43414326
RowConstructor RowConstructor(): {
43424327
RowConstructor rowConstructor = new RowConstructor();
43434328
ColumnDefinition columnDefinition = null;

src/test/java/net/sf/jsqlparser/statement/select/SelectTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4891,6 +4891,11 @@ public void testCanCallSubSelectOnWithItemEvenIfNotSetIssue1369() {
48914891
}
48924892

48934893
@Test
4894+
public void testCaseElseExpressionIssue1375() throws JSQLParserException {
4895+
assertSqlCanBeParsedAndDeparsed(
4896+
"SELECT * FROM t1 WHERE CASE WHEN 1 = 1 THEN c1 = 'a' ELSE c2 = 'b' AND c4 = 'd' END", true);
4897+
}
4898+
48944899
public void testComplexInExpressionIssue905() throws JSQLParserException {
48954900
assertSqlCanBeParsedAndDeparsed(
48964901
"select * " +

0 commit comments

Comments
 (0)