Skip to content

Commit

Permalink
Merge 3fcf5e4 into 346eea5
Browse files Browse the repository at this point in the history
  • Loading branch information
manticore-projects committed Aug 25, 2021
2 parents 346eea5 + 3fcf5e4 commit fe3efa7
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 4 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ jacocoTestCoverageVerification {
violationRules {
rule {
limit {
minimum = 0.840
minimum = 0.837
}
}
}
Expand Down
8 changes: 5 additions & 3 deletions src/main/jjtree/net/sf/jsqlparser/parser/JSqlParserCC.jjt
Original file line number Diff line number Diff line change
Expand Up @@ -4264,7 +4264,7 @@ Expression CaseWhenExpression() #CaseWhenExpression:
<K_CASE> { caseCounter++; }
[ switchExp=Condition() ]
( clause=WhenThenSearchCondition() { whenClauses.add(clause); } )+
[<K_ELSE> (LOOKAHEAD( ["("] CaseWhenExpression() [")"] ) ["("] elseExp=CaseWhenExpression() [")" { ((CaseExpression) elseExp).setUsingBrackets(true); } ]
[<K_ELSE> (LOOKAHEAD( ["("] CaseWhenExpression() [")"] ( <K_WHEN> | <K_ELSE> | <K_END> ) ) ["("] elseExp=CaseWhenExpression() [")" { ((CaseExpression) elseExp).setUsingBrackets(true); } ]
| elseExp=Condition()
)
]
Expand All @@ -4285,8 +4285,10 @@ WhenClause WhenThenSearchCondition():
}
{
<K_WHEN> whenExp=Expression()
<K_THEN> (LOOKAHEAD( ["("] CaseWhenExpression() [")"] ) ["("] thenExp=CaseWhenExpression() [")" { ((CaseExpression) thenExp).setUsingBrackets(true); }]
| thenExp=Expression()
<K_THEN> (
LOOKAHEAD( ["("] CaseWhenExpression() [")"] ( <K_WHEN> | <K_ELSE> | <K_END> ) ) ["("] thenExp=CaseWhenExpression() [")" { ((CaseExpression) thenExp).setUsingBrackets(true); }]
|
thenExp=Expression()
)
{
whenThen.setWhenExpression(whenExp);
Expand Down
40 changes: 40 additions & 0 deletions src/test/java/net/sf/jsqlparser/statement/select/SelectTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4701,6 +4701,7 @@ public void testCastToRowConstructorIssue1267() throws JSQLParserException {
assertSqlCanBeParsedAndDeparsed(sqlStr, true);
}

@Test
public void testCollisionWithSpecialStringFunctionsIssue1284() throws JSQLParserException {
assertSqlCanBeParsedAndDeparsed(
"SELECT test( a in (1) AND 2=2) ", true);
Expand All @@ -4715,4 +4716,43 @@ public void testCollisionWithSpecialStringFunctionsIssue1284() throws JSQLParser
"recv_time >= toDateTime('2021-07-20 00:00:00')\n" +
"and recv_time < toDateTime('2021-07-21 00:00:00')", true);
}

@Test
public void testNestedCaseComplexExpressionIssue1306() throws JSQLParserException {
// with extra brackets
assertSqlCanBeParsedAndDeparsed(
"SELECT CASE\n" +
"WHEN 'USD' = 'USD'\n" +
"THEN 0\n" +
"ELSE CASE\n" +
"WHEN 'USD' = 'EURO'\n" +
"THEN ( CASE\n" +
"WHEN 'A' = 'B'\n" +
"THEN 0\n" +
"ELSE 1\n" +
"END * 100 )\n" +
"ELSE 2\n" +
"END\n" +
"END AS \"column1\"\n" +
"FROM test_schema.table_name\n" +
"", true);

// without brackets
assertSqlCanBeParsedAndDeparsed(
"SELECT CASE\n" +
"WHEN 'USD' = 'USD'\n" +
"THEN 0\n" +
"ELSE CASE\n" +
"WHEN 'USD' = 'EURO'\n" +
"THEN CASE\n" +
"WHEN 'A' = 'B'\n" +
"THEN 0\n" +
"ELSE 1\n" +
"END * 100 \n" +
"ELSE 2\n" +
"END\n" +
"END AS \"column1\"\n" +
"FROM test_schema.table_name\n" +
"", true);
}
}

0 comments on commit fe3efa7

Please sign in to comment.