Skip to content

Commit 10b04f4

Browse files
committed
Merge master into introducing-template-modern
2 parents 8d4f25c + a25fb7c commit 10b04f4

File tree

4 files changed

+27
-9
lines changed

4 files changed

+27
-9
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: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ TOKEN: /* SQL Keywords. prefixed with K_ to avoid name clashes */
246246
| <K_RECURSIVE:"RECURSIVE">
247247
| <K_REFERENCES:"REFERENCES">
248248
| <K_REGEXP: "REGEXP">
249+
| <K_RLIKE: "RLIKE">
249250
| <K_REPLACE:"REPLACE">
250251
| <K_RESTRICT: "RESTRICT">
251252
| <K_RETURNING: "RETURNING">
@@ -2000,6 +2001,7 @@ Expression RegularCondition() #RegularCondition:
20002001
| "@@" { result = new Matches(); }
20012002
| "~" { result = new RegExpMatchOperator(RegExpMatchOperatorType.MATCH_CASESENSITIVE); }
20022003
| <K_REGEXP> [ <K_BINARY> { binary=true; } ] { result = new RegExpMySQLOperator(binary?RegExpMatchOperatorType.MATCH_CASESENSITIVE:RegExpMatchOperatorType.MATCH_CASEINSENSITIVE); }
2004+
| <K_RLIKE> [ <K_BINARY> { binary=true; } ] { result = new RegExpMySQLOperator(binary?RegExpMatchOperatorType.MATCH_CASESENSITIVE:RegExpMatchOperatorType.MATCH_CASEINSENSITIVE).useRLike(); }
20032005
| "~*" { result = new RegExpMatchOperator(RegExpMatchOperatorType.MATCH_CASEINSENSITIVE); }
20042006
| "!~" { result = new RegExpMatchOperator(RegExpMatchOperatorType.NOT_MATCH_CASESENSITIVE); }
20052007
| "!~*" { result = new RegExpMatchOperator(RegExpMatchOperatorType.NOT_MATCH_CASEINSENSITIVE); }
@@ -3464,7 +3466,7 @@ AlterExpression AlterExpression():
34643466
alterExp.setOperation(AlterOperation.DROP);
34653467
}
34663468
(
3467-
( <K_COLUMN>
3469+
( (LOOKAHEAD(2) <K_COLUMN>)?
34683470
(tk=<S_IDENTIFIER> | tk=<S_QUOTED_IDENTIFIER>)
34693471
{
34703472
alterExp.setColumnName(tk.image);

src/test/java/net/sf/jsqlparser/test/alter/AlterTest.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,4 +244,12 @@ public void testAlterTableAddColumnKeywordTypes() throws JSQLParserException {
244244
public void testDropColumnRestrictIssue510() throws JSQLParserException {
245245
assertSqlCanBeParsedAndDeparsed("ALTER TABLE TABLE1 DROP COLUMN NewColumn CASCADE");
246246
}
247+
248+
public void testDropColumnRestrictIssue551() throws JSQLParserException {
249+
Statement stmt = CCJSqlParserUtil.parse("ALTER TABLE table1 DROP NewColumn");
250+
251+
// COLUMN keyword appears in deparsed statement, drop becomes all caps
252+
assertStatementCanBeDeparsedAs(stmt, "ALTER TABLE table1 DROP COLUMN NewColumn");
253+
254+
}
247255
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1991,6 +1991,10 @@ 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+
1995+
public void testRlike() throws JSQLParserException {
1996+
assertSqlCanBeParsedAndDeparsed("SELECT * FROM mytable WHERE first_name RLIKE '^Ste(v|ph)en$'");
1997+
}
19941998

19951999
public void testBooleanFunction1() throws JSQLParserException {
19962000
String stmt = "SELECT * FROM mytable WHERE test_func(col1)";

0 commit comments

Comments
 (0)