Skip to content

Commit f0ffe4c

Browse files
committed
made some modifications to rlike fix
1 parent 8a950b3 commit f0ffe4c

File tree

3 files changed

+15
-13
lines changed

3 files changed

+15
-13
lines changed

src/main/java/net/sf/jsqlparser/expression/operators/relational/RegExpMySQLOperator.java

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
public class RegExpMySQLOperator extends BinaryExpression {
2828

2929
private RegExpMatchOperatorType operatorType;
30+
private boolean useRLike = false;
3031

3132
public RegExpMySQLOperator(RegExpMatchOperatorType operatorType) {
3233
if (operatorType == null) {
@@ -39,20 +40,23 @@ public RegExpMatchOperatorType getOperatorType() {
3940
return operatorType;
4041
}
4142

43+
public boolean isUseRLike() {
44+
return useRLike;
45+
}
46+
47+
public RegExpMySQLOperator useRLike() {
48+
useRLike = true;
49+
return this;
50+
}
51+
4252
@Override
4353
public void accept(ExpressionVisitor expressionVisitor) {
4454
expressionVisitor.visit(this);
4555
}
4656

4757
@Override
4858
public String getStringExpression() {
49-
switch (operatorType) {
50-
case MATCH_CASESENSITIVE:
51-
return "REGEXP BINARY";
52-
case MATCH_CASEINSENSITIVE:
53-
return "REGEXP";
54-
default:
55-
}
56-
return null;
59+
return (useRLike ? "RLIKE" : "REGEXP")
60+
+ (operatorType == RegExpMatchOperatorType.MATCH_CASESENSITIVE ? " BINARY" : "");
5761
}
5862
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1998,7 +1998,7 @@ Expression RegularCondition() #RegularCondition:
19981998
| "@@" { result = new Matches(); }
19991999
| "~" { result = new RegExpMatchOperator(RegExpMatchOperatorType.MATCH_CASESENSITIVE); }
20002000
| <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); }
2001+
| <K_RLIKE> [ <K_BINARY> { binary=true; } ] { result = new RegExpMySQLOperator(binary?RegExpMatchOperatorType.MATCH_CASESENSITIVE:RegExpMatchOperatorType.MATCH_CASEINSENSITIVE).useRLike(); }
20022002
| "~*" { result = new RegExpMatchOperator(RegExpMatchOperatorType.MATCH_CASEINSENSITIVE); }
20032003
| "!~" { result = new RegExpMatchOperator(RegExpMatchOperatorType.NOT_MATCH_CASESENSITIVE); }
20042004
| "!~*" { result = new RegExpMatchOperator(RegExpMatchOperatorType.NOT_MATCH_CASEINSENSITIVE); }

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1991,11 +1991,9 @@ public void testRegexpBinaryMySQL() throws JSQLParserException {
19911991
String stmt = "SELECT * FROM mytable WHERE first_name REGEXP BINARY '^Ste(v|ph)en$'";
19921992
assertSqlCanBeParsedAndDeparsed(stmt);
19931993
}
1994-
1994+
19951995
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$'");
1996+
assertSqlCanBeParsedAndDeparsed("SELECT * FROM mytable WHERE first_name RLIKE '^Ste(v|ph)en$'");
19991997
}
20001998

20011999
public void testBooleanFunction1() throws JSQLParserException {

0 commit comments

Comments
 (0)