Skip to content

Commit 1cd3c27

Browse files
committed
fixes #850
1 parent 6191ae0 commit 1cd3c27

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2265,14 +2265,15 @@ Expression AndExpression() :
22652265
{
22662266
Expression left, right, result;
22672267
boolean not = false;
2268+
boolean exclamationMarkNot=false;
22682269
}
22692270
{
22702271
(
22712272
LOOKAHEAD(Condition())
22722273
left=Condition()
22732274
|
2274-
[ <K_NOT> { not = true; } ]
2275-
"(" left=OrExpression() ")" {left = new Parenthesis(left); if (not) { left = new NotExpression(left); not = false; } }
2275+
[ <K_NOT> { not=true; } | "!" { not=true; exclamationMarkNot=true; } ]
2276+
"(" left=OrExpression() ")" {left = new Parenthesis(left); if (not) { left = new NotExpression(left, exclamationMarkNot); not = false; } }
22762277
)
22772278
{ result = left; }
22782279

@@ -2282,8 +2283,8 @@ Expression AndExpression() :
22822283
LOOKAHEAD(Condition())
22832284
right=Condition()
22842285
|
2285-
[ <K_NOT> { not = true; } ]
2286-
"(" right=OrExpression() ")" {right = new Parenthesis(right); if (not) { right = new NotExpression(right); not = false; } }
2286+
[ <K_NOT> { not=true; } | "!" { not=true; exclamationMarkNot=true; } ]
2287+
"(" right=OrExpression() ")" {right = new Parenthesis(right); if (not) { right = new NotExpression(right, exclamationMarkNot); not = false; } }
22872288
)
22882289
{
22892290
result = new AndExpression(left, right);
@@ -2300,16 +2301,17 @@ Expression Condition():
23002301
Expression result;
23012302
Token token;
23022303
boolean not = false;
2304+
boolean exclamationMarkNot = false;
23032305
}
23042306
{
2305-
[ LOOKAHEAD(2) <K_NOT> { not = true; }]
2307+
[ LOOKAHEAD(2) (<K_NOT> { not=true; } | "!" { not=true; exclamationMarkNot=true; })]
23062308
(
23072309
LOOKAHEAD(SQLCondition()) result=SQLCondition()
23082310
| LOOKAHEAD(RegularCondition()) result=RegularCondition()
23092311
| result=SimpleExpression()
23102312
)
23112313

2312-
{ return not?new NotExpression(result):result; }
2314+
{ return not?new NotExpression(result, exclamationMarkNot):result; }
23132315
}
23142316

23152317
Expression RegularCondition() #RegularCondition:

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3531,6 +3531,17 @@ public void testNotVariant3() throws JSQLParserException {
35313531
assertSqlCanBeParsedAndDeparsed("SELECT NOT (1 + 1)");
35323532
}
35333533

3534+
@Test
3535+
public void testNotVariant4() throws JSQLParserException {
3536+
assertSqlCanBeParsedAndDeparsed("SELECT * FROM mytable WHERE NOT (1 = 1)");
3537+
assertSqlCanBeParsedAndDeparsed("SELECT * FROM mytable WHERE ! (1 = 1)");
3538+
}
3539+
3540+
@Test
3541+
public void testNotVariantIssue850() throws JSQLParserException {
3542+
assertSqlCanBeParsedAndDeparsed("SELECT * FROM mytable WHERE id = 1 AND ! (id = 1 AND id = 2)");
3543+
}
3544+
35343545
@Test
35353546
public void testDateArithmentic() throws JSQLParserException {
35363547
assertSqlCanBeParsedAndDeparsed("SELECT CURRENT_DATE + (1 DAY) FROM SYSIBM.SYSDUMMY1");

0 commit comments

Comments
 (0)