File tree Expand file tree Collapse file tree 4 files changed +27
-9
lines changed
java/net/sf/jsqlparser/expression/operators/relational
jjtree/net/sf/jsqlparser/parser
test/java/net/sf/jsqlparser/test Expand file tree Collapse file tree 4 files changed +27
-9
lines changed Original file line number Diff line number Diff line change 27
27
public class RegExpMySQLOperator extends BinaryExpression {
28
28
29
29
private RegExpMatchOperatorType operatorType ;
30
+ private boolean useRLike = false ;
30
31
31
32
public RegExpMySQLOperator (RegExpMatchOperatorType operatorType ) {
32
33
if (operatorType == null ) {
@@ -39,20 +40,23 @@ public RegExpMatchOperatorType getOperatorType() {
39
40
return operatorType ;
40
41
}
41
42
43
+ public boolean isUseRLike () {
44
+ return useRLike ;
45
+ }
46
+
47
+ public RegExpMySQLOperator useRLike () {
48
+ useRLike = true ;
49
+ return this ;
50
+ }
51
+
42
52
@ Override
43
53
public void accept (ExpressionVisitor expressionVisitor ) {
44
54
expressionVisitor .visit (this );
45
55
}
46
56
47
57
@ Override
48
58
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" : "" );
57
61
}
58
62
}
Original file line number Diff line number Diff line change @@ -246,6 +246,7 @@ TOKEN: /* SQL Keywords. prefixed with K_ to avoid name clashes */
246
246
| <K_RECURSIVE:"RECURSIVE">
247
247
| <K_REFERENCES:"REFERENCES">
248
248
| <K_REGEXP: "REGEXP">
249
+ | <K_RLIKE: "RLIKE">
249
250
| <K_REPLACE:"REPLACE">
250
251
| <K_RESTRICT: "RESTRICT">
251
252
| <K_RETURNING: "RETURNING">
@@ -2000,6 +2001,7 @@ Expression RegularCondition() #RegularCondition:
2000
2001
| "@@" { result = new Matches(); }
2001
2002
| "~" { result = new RegExpMatchOperator(RegExpMatchOperatorType.MATCH_CASESENSITIVE); }
2002
2003
| <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(); }
2003
2005
| "~*" { result = new RegExpMatchOperator(RegExpMatchOperatorType.MATCH_CASEINSENSITIVE); }
2004
2006
| "!~" { result = new RegExpMatchOperator(RegExpMatchOperatorType.NOT_MATCH_CASESENSITIVE); }
2005
2007
| "!~*" { result = new RegExpMatchOperator(RegExpMatchOperatorType.NOT_MATCH_CASEINSENSITIVE); }
@@ -3464,7 +3466,7 @@ AlterExpression AlterExpression():
3464
3466
alterExp.setOperation(AlterOperation.DROP);
3465
3467
}
3466
3468
(
3467
- ( <K_COLUMN>
3469
+ ( (LOOKAHEAD(2) <K_COLUMN>)?
3468
3470
(tk=<S_IDENTIFIER> | tk=<S_QUOTED_IDENTIFIER>)
3469
3471
{
3470
3472
alterExp.setColumnName(tk.image);
Original file line number Diff line number Diff line change @@ -244,4 +244,12 @@ public void testAlterTableAddColumnKeywordTypes() throws JSQLParserException {
244
244
public void testDropColumnRestrictIssue510 () throws JSQLParserException {
245
245
assertSqlCanBeParsedAndDeparsed ("ALTER TABLE TABLE1 DROP COLUMN NewColumn CASCADE" );
246
246
}
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
+ }
247
255
}
Original file line number Diff line number Diff line change @@ -1991,6 +1991,10 @@ public void testRegexpBinaryMySQL() throws JSQLParserException {
1991
1991
String stmt = "SELECT * FROM mytable WHERE first_name REGEXP BINARY '^Ste(v|ph)en$'" ;
1992
1992
assertSqlCanBeParsedAndDeparsed (stmt );
1993
1993
}
1994
+
1995
+ public void testRlike () throws JSQLParserException {
1996
+ assertSqlCanBeParsedAndDeparsed ("SELECT * FROM mytable WHERE first_name RLIKE '^Ste(v|ph)en$'" );
1997
+ }
1994
1998
1995
1999
public void testBooleanFunction1 () throws JSQLParserException {
1996
2000
String stmt = "SELECT * FROM mytable WHERE test_func(col1)" ;
You can’t perform that action at this time.
0 commit comments