Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix parsing statements with multidimensional array #1656 #1657

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/main/jjtree/net/sf/jsqlparser/parser/JSqlParserCC.jjt
Original file line number Diff line number Diff line change
Expand Up @@ -3895,6 +3895,7 @@ Expression BitwiseXor():
}

Expression ArrayExpression(Expression obj): {
Expression expr;
Expression idxExpr = null;
Expression startExpr = null;
Expression stopExpr = null;
Expand All @@ -3906,7 +3907,18 @@ Expression ArrayExpression(Expression obj): {
[stopExpr = SimpleExpression()]
]
"]"
{ return new ArrayExpression(obj, idxExpr, startExpr, stopExpr); }
{ expr = new ArrayExpression(obj, idxExpr, startExpr, stopExpr); }
(
"["
[LOOKAHEAD(3) idxExpr = SimpleExpression()]
[
(":" { startExpr=idxExpr; idxExpr=null; })
[stopExpr = SimpleExpression()]
]
"]"
{ expr = new ArrayExpression(expr, idxExpr, startExpr, stopExpr); }
)*
{ return expr; }
}

Expression PrimaryExpression() #PrimaryExpression:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5294,4 +5294,9 @@ public void testSelectStatementWithoutForUpdateAndSkipLockedTokens() throws JSQL
assertFalse(plainSelect.isForUpdate());
assertFalse(plainSelect.isSkipLocked());
}

@Test
public void testSelectMultidimensionalArrayStatement() throws JSQLParserException {
assertSqlCanBeParsedAndDeparsed("SELECT f1, f2[1][1], f3[1][2][3] FROM test");
}
}