Skip to content

Commit 0f9e477

Browse files
fix: precedence of the InExpression
- fixes #2244 Signed-off-by: Andreas Reichel <[email protected]>
1 parent 7f068f6 commit 0f9e477

File tree

3 files changed

+22
-14
lines changed

3 files changed

+22
-14
lines changed

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,14 +104,14 @@ dependencies {
104104
testImplementation 'org.junit.jupiter:junit-jupiter-params:5.11.4'
105105

106106
// https://mvnrepository.com/artifact/org.mockito/mockito-junit-jupiter
107-
testImplementation 'org.mockito:mockito-junit-jupiter:+'
107+
testImplementation 'org.mockito:mockito-junit-jupiter:5.18.0'
108108

109109
// Performance Benchmark
110110
testImplementation 'org.openjdk.jmh:jmh-core:+'
111111
testImplementation 'org.openjdk.jmh:jmh-generator-annprocess:+'
112112

113113
// Java Doc in XML Format
114-
xmlDoclet 'com.manticore-projects.tools:xml-doclet:+'
114+
xmlDoclet 'com.manticore-projects.tools:xml-doclet:2.+'
115115

116116
// enforce latest version of JavaCC
117117
testImplementation 'net.java.dev.javacc:javacc:+'

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

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4366,13 +4366,9 @@ WithIsolation WithIsolation():
43664366
JdbcParameter jdbc;
43674367
}
43684368
{
4369-
(
4370-
//with (ur | cs | rs | rr)
4371-
<K_WITH>
4372-
token=<K_ISOLATION> { withIsolation.setIsolation(token.image); }
4373-
4374-
)
4375-
{
4369+
<K_WITH>
4370+
token=<K_ISOLATION>
4371+
{ withIsolation.setIsolation(token.image);
43764372
return withIsolation;
43774373
}
43784374
}
@@ -4434,10 +4430,11 @@ Skip Skip():
44344430
{
44354431
<K_SKIP>
44364432
(
4437-
token=<S_LONG> { skip.setRowCount(Long.parseLong(token.image)); }
4438-
| token=<S_IDENTIFIER> { skip.setVariable(token.image); }
4439-
| jdbc = JdbcParameter() { skip.setJdbcParameter(jdbc); }
4440-
/* "?" { skip.setJdbcParameter(new JdbcParameter(++jdbcParameterIndex, false)); } [ LOOKAHEAD(2) token = <S_LONG> { skip.getJdbcParameter().setUseFixedIndex(true); skip.getJdbcParameter().setIndex(Integer.valueOf(token.image)); } ] */
4433+
token=<S_LONG> { skip.setRowCount(Long.parseLong(token.image)); }
4434+
|
4435+
token=<S_IDENTIFIER> { skip.setVariable(token.image); }
4436+
|
4437+
jdbc = JdbcParameter() { skip.setJdbcParameter(jdbc); }
44414438
)
44424439
{
44434440
return skip;
@@ -4733,7 +4730,7 @@ Expression InExpression(Expression leftExpression) #InExpression :
47334730
(
47344731
LOOKAHEAD(2) token=<S_CHAR_LITERAL> { rightExpression = new StringValue(token.image); }
47354732
|
4736-
rightExpression = Expression()
4733+
rightExpression = PrimaryExpression()
47374734
)
47384735
{
47394736
InExpression inExpression = new InExpression(leftExpression, rightExpression)

src/test/java/net/sf/jsqlparser/expression/operators/relational/InExpressionTest.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@
1010
package net.sf.jsqlparser.expression.operators.relational;
1111

1212
import net.sf.jsqlparser.JSQLParserException;
13+
import net.sf.jsqlparser.expression.operators.conditional.OrExpression;
14+
import net.sf.jsqlparser.statement.select.PlainSelect;
1315
import net.sf.jsqlparser.test.TestUtils;
16+
import org.junit.jupiter.api.Assertions;
1417
import org.junit.jupiter.api.Test;
1518

1619
import static org.junit.jupiter.api.Assertions.*;
@@ -30,4 +33,12 @@ void testOracleInWithBrackets() throws JSQLParserException {
3033
TestUtils.assertSqlCanBeParsedAndDeparsed(sqlStr, true);
3134
}
3235

36+
@Test
37+
void testPrecedenceIssue2244() throws JSQLParserException {
38+
String sqlStr = "select * from `T_DEMO` where a in (1,3,2) or b = 2";
39+
PlainSelect select = (PlainSelect) TestUtils.assertSqlCanBeParsedAndDeparsed(sqlStr, true);
40+
41+
Assertions.assertInstanceOf(OrExpression.class, select.getWhere());
42+
}
43+
3344
}

0 commit comments

Comments
 (0)