Skip to content

Commit

Permalink
Fixes #1381 (#1383)
Browse files Browse the repository at this point in the history
Allow Complex Expressions as SelectItem
  • Loading branch information
manticore-projects authored Nov 19, 2021
1 parent 60a7d10 commit cdf0f09
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/main/jjtree/net/sf/jsqlparser/parser/JSqlParserCC.jjt
Original file line number Diff line number Diff line change
Expand Up @@ -2022,8 +2022,8 @@ SelectExpressionItem SelectExpressionItem():
Alias alias = null;
}
{
expression=Condition() { selectExpressionItem = new SelectExpressionItem(); selectExpressionItem.setExpression(expression); }
[alias=Alias() { selectExpressionItem.setAlias(alias); }] { return selectExpressionItem; }
expression=Expression() { selectExpressionItem = new SelectExpressionItem(); selectExpressionItem.setExpression(expression); }
[alias=Alias() { selectExpressionItem.setAlias(alias); }] { return selectExpressionItem; }
}

SelectItem SelectItem() #SelectItem:
Expand Down
19 changes: 16 additions & 3 deletions src/test/java/net/sf/jsqlparser/statement/select/SelectTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -384,8 +384,6 @@ public void testLimit2() throws JSQLParserException {
offset = ((PlainSelect) select.getSelectBody()).getLimit().getOffset();
rowCount = ((PlainSelect) select.getSelectBody()).getLimit().getRowCount();

System.out.println(rowCount.getClass().getName());

assertNull(offset);
Assertions.assertTrue( rowCount instanceof AllValue);

Expand Down Expand Up @@ -4895,7 +4893,7 @@ public void testCaseElseExpressionIssue1375() throws JSQLParserException {
assertSqlCanBeParsedAndDeparsed(
"SELECT * FROM t1 WHERE CASE WHEN 1 = 1 THEN c1 = 'a' ELSE c2 = 'b' AND c4 = 'd' END", true);
}

public void testComplexInExpressionIssue905() throws JSQLParserException {
assertSqlCanBeParsedAndDeparsed(
"select * " +
Expand All @@ -4922,4 +4920,19 @@ public void testComplexInExpressionIssue905() throws JSQLParserException {
"from table_a " +
"where (a, b, c) in ((1, 2, 3), (3, 4, 5))", true);
}

@Test
public void testLogicalExpressionSelectItemIssue1381() throws JSQLParserException {
assertSqlCanBeParsedAndDeparsed(
"SELECT ( 1 + 1 ) = ( 1 + 2 )", true);

assertSqlCanBeParsedAndDeparsed(
"SELECT ( 1 = 1 ) = ( 1 = 2 )", true);

assertSqlCanBeParsedAndDeparsed(
"SELECT ( ( 1 = 1 ) AND ( 1 = 2 ) )", true);

assertSqlCanBeParsedAndDeparsed(
"SELECT ( 1 = 1 ) AND ( 1 = 2 )", true);
}
}

0 comments on commit cdf0f09

Please sign in to comment.