Skip to content

Commit 9e26b76

Browse files
authored
bugfix #720 #991: supporting SELECT "conditions" (#1032)
* bugfix issue #1020: JSON type in MySQL not supported in v3.2 * bugfix issue #720 #991: supporting SELECT "CONDITIONS"
1 parent 8152356 commit 9e26b76

File tree

2 files changed

+33
-8
lines changed

2 files changed

+33
-8
lines changed

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

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
* #L%
99
*/
1010

11-
options{
12-
IGNORE_CASE = true ;
11+
options {
12+
IGNORE_CASE = true;
1313
STATIC = false;
1414
DEBUG_PARSER = false;
1515
DEBUG_LOOKAHEAD = false;
@@ -975,7 +975,7 @@ List<SelectExpressionItem> ListExpressionItem():
975975
}
976976
{
977977
item = SelectExpressionItem() {retval.add(item);}
978-
("," item = SelectExpressionItem() {retval.add(item);} )*
978+
(<K_COMMA> item = SelectExpressionItem() {retval.add(item);} )*
979979
{ return retval; }
980980
}
981981

@@ -1636,7 +1636,7 @@ SelectExpressionItem SelectExpressionItem():
16361636
Alias alias = null;
16371637
}
16381638
{
1639-
expression=SimpleExpression() { selectExpressionItem = new SelectExpressionItem(); selectExpressionItem.setExpression(expression); }
1639+
expression=Condition() { selectExpressionItem = new SelectExpressionItem(); selectExpressionItem.setExpression(expression); }
16401640
[alias=Alias() { selectExpressionItem.setAlias(alias); }] { return selectExpressionItem; }
16411641
}
16421642

@@ -1785,11 +1785,22 @@ List<SelectExpressionItem> PivotSingleInItems():
17851785
SelectExpressionItem item;
17861786
}
17871787
{
1788-
item = SelectExpressionItem() {retval.add(item);}
1789-
("," item = SelectExpressionItem() {retval.add(item);} )*
1788+
item = PivotSelectExprItem() {retval.add(item);}
1789+
("," item = PivotSelectExprItem() {retval.add(item);} )*
17901790
{ return retval; }
17911791
}
17921792

1793+
SelectExpressionItem PivotSelectExprItem():
1794+
{
1795+
SelectExpressionItem selectExpressionItem = null;
1796+
Expression expression = null;
1797+
Alias alias = null;
1798+
}
1799+
{
1800+
expression=SimpleExpression() { selectExpressionItem = new SelectExpressionItem(); selectExpressionItem.setExpression(expression); }
1801+
[alias=Alias() { selectExpressionItem.setAlias(alias); }] { return selectExpressionItem; }
1802+
}
1803+
17931804
ExpressionListItem ExpressionListItem():
17941805
{
17951806
ExpressionListItem expressionListItem = null;
@@ -1957,12 +1968,12 @@ FromItem FromItem():
19571968
(
19581969
indexHint = MySQLIndexHint() {
19591970
if (fromItem instanceof Table)
1960-
((Table) fromItem).setHint(indexHint);
1971+
((Table) fromItem).setHint(indexHint);
19611972
}
19621973
|
19631974
sqlServerHints = SQLServerHints() {
19641975
if (fromItem instanceof Table)
1965-
((Table) fromItem).setSqlServerHints(sqlServerHints);
1976+
((Table) fromItem).setSqlServerHints(sqlServerHints);
19661977
}
19671978
)
19681979
]

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
import net.sf.jsqlparser.statement.*;
2222
import static net.sf.jsqlparser.test.TestUtils.*;
2323
import org.apache.commons.io.IOUtils;
24+
25+
import static net.sf.jsqlparser.test.TestUtils.assertSqlCanBeParsedAndDeparsed;
2426
import static org.assertj.core.api.Assertions.assertThat;
2527
import java.io.IOException;
2628
import java.io.StringReader;
@@ -4272,4 +4274,16 @@ public void testKeyWordOfIssue1029() throws JSQLParserException {
42724274
public void testKeyWordExceptIssue1026() throws JSQLParserException {
42734275
assertSqlCanBeParsedAndDeparsed("SELECT * FROM xxx WHERE exclude = 1");
42744276
}
4277+
4278+
@Test
4279+
public void testSelectConditionsIssue720And991() throws JSQLParserException {
4280+
assertSqlCanBeParsedAndDeparsed("SELECT column IS NOT NULL FROM table");
4281+
assertSqlCanBeParsedAndDeparsed("SELECT 0 IS NULL");
4282+
assertSqlCanBeParsedAndDeparsed("SELECT 1 + 2");
4283+
assertSqlCanBeParsedAndDeparsed("SELECT 1 < 2");
4284+
assertSqlCanBeParsedAndDeparsed("SELECT 1 > 2");
4285+
assertSqlCanBeParsedAndDeparsed("SELECT 1 + 2 AS a, 3 < 4 AS b");
4286+
assertSqlCanBeParsedAndDeparsed("SELECT 1 < 2 AS a, 0 IS NULL AS b");
4287+
// assertSqlCanBeParsedAndDeparsed("SELECT 1 < 2 AS a, (0 IS NULL) AS b");
4288+
}
42754289
}

0 commit comments

Comments
 (0)