From 47b4e26288c5fd04acce05670c401ed4da82587d Mon Sep 17 00:00:00 2001 From: Andrei Lisouski Date: Wed, 2 Nov 2022 23:32:14 +0100 Subject: [PATCH] Fix parsing statements with multidimensional array --- .../net/sf/jsqlparser/parser/JSqlParserCC.jjt | 14 +++++++++++++- .../sf/jsqlparser/statement/select/SelectTest.java | 5 +++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/main/jjtree/net/sf/jsqlparser/parser/JSqlParserCC.jjt b/src/main/jjtree/net/sf/jsqlparser/parser/JSqlParserCC.jjt index e4975684d..225b59d61 100644 --- a/src/main/jjtree/net/sf/jsqlparser/parser/JSqlParserCC.jjt +++ b/src/main/jjtree/net/sf/jsqlparser/parser/JSqlParserCC.jjt @@ -3895,6 +3895,7 @@ Expression BitwiseXor(): } Expression ArrayExpression(Expression obj): { + Expression expr; Expression idxExpr = null; Expression startExpr = null; Expression stopExpr = null; @@ -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: diff --git a/src/test/java/net/sf/jsqlparser/statement/select/SelectTest.java b/src/test/java/net/sf/jsqlparser/statement/select/SelectTest.java index efac92ff3..dd7090fc3 100644 --- a/src/test/java/net/sf/jsqlparser/statement/select/SelectTest.java +++ b/src/test/java/net/sf/jsqlparser/statement/select/SelectTest.java @@ -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"); + } }