Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ public enum SQLBinaryOperator {
Escape("ESCAPE", 110),
RegExp("REGEXP", 110),
NotRegExp("NOT REGEXP", 110),
MemberOf("MEMBER OF", 110),
Equality("=", 110),
EqEq("==", 110),

Expand Down Expand Up @@ -145,6 +146,7 @@ public boolean isRelational() {
case NotRLike:
case RegExp:
case NotRegExp:
case MemberOf:
case Is:
case IsNot:
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,37 @@ protected void parseIndexOptions(SQLIndexDefinition indexDefinition) {
}
}

@Override
public SQLExpr relationalRest(SQLExpr expr) {
if (lexer.token() == Token.IDENTIFIER && lexer.hashLCase() == FnvHash.Constants.MEMBER) {
Lexer.SavePoint mark = lexer.mark();
lexer.nextToken();

if (lexer.token() == Token.OF || lexer.identifierEquals("OF")) {
lexer.nextToken();

SQLExpr rightExp;
if (lexer.token() == Token.LPAREN) {
lexer.nextToken();
rightExp = expr();
accept(Token.RPAREN);
if (rightExp instanceof SQLExprImpl) {
((SQLExprImpl) rightExp).setParenthesized(true);
}
rightExp = primaryRest(rightExp);
} else {
rightExp = bitOr();
}

expr = new SQLBinaryOpExpr(expr, SQLBinaryOperator.MemberOf, rightExp, dbType);
return super.relationalRest(expr);
}
lexer.reset(mark);
}

return super.relationalRest(expr);
}

@Override
protected SQLExpr parseSelectItemRest(String ident, long hash_lower) {
SQLExpr expr = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
import com.alibaba.druid.wall.spi.MySqlWallProvider;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.*;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

public class MySqlWallTest100 {
@Test
Expand All @@ -31,4 +32,13 @@ public void test_false() throws Exception {

assertFalse(provider.checkValid(sql));
}

@Test
public void test_member_of() {
WallProvider provider = new MySqlWallProvider();

String sql = "select 'ab' member of('[23, \"abc\", 17, \"ab\", 10]')";

assertTrue(provider.checkValid(sql));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,18 @@ public void test_26() throws Exception {
assertEquals("SELECT CAST(LEAST(3600, 9223372036854775808.0) AS SIGNED);", text);
}

@Test
public void test_27() throws Exception {
String sql = "SELECT 'ab' MEMBER OF('[23, \"abc\", 17, \"ab\", 10]')";

SQLStatementParser parser = new MySqlStatementParser(sql);
List<SQLStatement> stmtList = parser.parseStatementList();

String text = output(stmtList);

assertEquals("SELECT 'ab' MEMBER OF '[23, \"abc\", 17, \"ab\", 10]'", text);
}

private String output(List<SQLStatement> stmtList) {
return SQLUtils.toSQLString(stmtList, JdbcConstants.MYSQL);
}
Expand Down