Skip to content

Commit 8a950b3

Browse files
tomershaywumpz
authored andcommitted
Added support for RLIKE expressions (#544)
RLIKE is a synonym of REGEXP, therefore should be treated the same.
1 parent 79a887a commit 8a950b3

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ TOKEN: /* SQL Keywords. prefixed with K_ to avoid name clashes */
245245
| <K_RECURSIVE:"RECURSIVE">
246246
| <K_REFERENCES:"REFERENCES">
247247
| <K_REGEXP: "REGEXP">
248+
| <K_RLIKE: "RLIKE">
248249
| <K_REPLACE:"REPLACE">
249250
| <K_RESTRICT: "RESTRICT">
250251
| <K_RETURNING: "RETURNING">
@@ -1997,6 +1998,7 @@ Expression RegularCondition() #RegularCondition:
19971998
| "@@" { result = new Matches(); }
19981999
| "~" { result = new RegExpMatchOperator(RegExpMatchOperatorType.MATCH_CASESENSITIVE); }
19992000
| <K_REGEXP> [ <K_BINARY> { binary=true; } ] { result = new RegExpMySQLOperator(binary?RegExpMatchOperatorType.MATCH_CASESENSITIVE:RegExpMatchOperatorType.MATCH_CASEINSENSITIVE); }
2001+
| <K_RLIKE> [ <K_BINARY> { binary=true; } ] { result = new RegExpMySQLOperator(binary?RegExpMatchOperatorType.MATCH_CASESENSITIVE:RegExpMatchOperatorType.MATCH_CASEINSENSITIVE); }
20002002
| "~*" { result = new RegExpMatchOperator(RegExpMatchOperatorType.MATCH_CASEINSENSITIVE); }
20012003
| "!~" { result = new RegExpMatchOperator(RegExpMatchOperatorType.NOT_MATCH_CASESENSITIVE); }
20022004
| "!~*" { result = new RegExpMatchOperator(RegExpMatchOperatorType.NOT_MATCH_CASEINSENSITIVE); }

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1992,6 +1992,12 @@ public void testRegexpBinaryMySQL() throws JSQLParserException {
19921992
assertSqlCanBeParsedAndDeparsed(stmt);
19931993
}
19941994

1995+
public void testRlike() throws JSQLParserException {
1996+
String stmt = "SELECT * FROM mytable WHERE first_name RLIKE '^Ste(v|ph)en$'";
1997+
Statement st = CCJSqlParserUtil.parse(stmt);
1998+
assertStatementCanBeDeparsedAs(st, "SELECT * FROM mytable WHERE first_name REGEXP '^Ste(v|ph)en$'");
1999+
}
2000+
19952001
public void testBooleanFunction1() throws JSQLParserException {
19962002
String stmt = "SELECT * FROM mytable WHERE test_func(col1)";
19972003
assertSqlCanBeParsedAndDeparsed(stmt);

0 commit comments

Comments
 (0)