Skip to content
Merged
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 @@ -45,6 +45,7 @@
import net.sf.jsqlparser.expression.operators.relational.MinorThanEquals;
import net.sf.jsqlparser.expression.operators.relational.NotEqualsTo;
import net.sf.jsqlparser.expression.operators.relational.RegExpMatchOperator;
import net.sf.jsqlparser.expression.operators.relational.RegExpMySQLOperator;
import net.sf.jsqlparser.schema.Column;
import net.sf.jsqlparser.statement.select.SubSelect;

Expand Down Expand Up @@ -145,4 +146,6 @@ public interface ExpressionVisitor {
void visit(RegExpMatchOperator rexpr);

void visit(JsonExpression jsonExpr);

void visit(RegExpMySQLOperator regExpMySQLOperator);
}
Original file line number Diff line number Diff line change
Expand Up @@ -307,4 +307,9 @@ protected void visitBinaryExpression(BinaryExpression expr) {
public void visit(JsonExpression jsonExpr) {
visit(jsonExpr.getColumn());
}

@Override
public void visit(RegExpMySQLOperator expr) {
visitBinaryExpression(expr);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* #%L
* JSQLParser library
* %%
* Copyright (C) 2004 - 2013 JSQLParser
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
* #L%
*/
package net.sf.jsqlparser.expression.operators.relational;

import net.sf.jsqlparser.expression.BinaryExpression;
import net.sf.jsqlparser.expression.ExpressionVisitor;

public class RegExpMySQLOperator extends BinaryExpression {

private RegExpMatchOperatorType operatorType;

public RegExpMySQLOperator(RegExpMatchOperatorType operatorType) {
if (operatorType == null) {
throw new NullPointerException();
}
this.operatorType = operatorType;
}

public RegExpMatchOperatorType getOperatorType() {
return operatorType;
}

@Override
public void accept(ExpressionVisitor expressionVisitor) {
expressionVisitor.visit(this);
}

@Override
public String getStringExpression() {
switch (operatorType) {
case MATCH_CASESENSITIVE:
return "REGEXP BINARY";
case MATCH_CASEINSENSITIVE:
return "REGEXP";
default:
}
return null;
}
}
7 changes: 7 additions & 0 deletions src/main/java/net/sf/jsqlparser/util/TablesNamesFinder.java
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,14 @@ public void visit(RegExpMatchOperator rexpr) {
visitBinaryExpression(rexpr);
}

@Override
public void visit(RegExpMySQLOperator rexpr) {
visitBinaryExpression(rexpr);
}

@Override
public void visit(JsonExpression jsonExpr) {
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -501,8 +501,15 @@ public void visit(RegExpMatchOperator rexpr) {
visitBinaryExpression(rexpr, " " + rexpr.getStringExpression() + " ");
}

@Override
public void visit(RegExpMySQLOperator rexpr) {
visitBinaryExpression(rexpr, " " + rexpr.getStringExpression() + " ");
}

@Override
public void visit(JsonExpression jsonExpr) {
buffer.append(jsonExpr.toString());
}


}
4 changes: 4 additions & 0 deletions src/main/javacc/net/sf/jsqlparser/parser/JSqlParserCC.jj
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,8 @@ TOKEN: /* SQL Keywords. prefixed with K_ to avoid name clashes */
| <K_CURRENT: "CURRENT">
| <K_ROW: "ROW">
| <K_RETURNING: "RETURNING">
| <K_BINARY: "BINARY">
| <K_REGEXP: "REGEXP">
}

TOKEN : /* Numeric Constants */
Expand Down Expand Up @@ -1278,6 +1280,8 @@ Expression RegularCondition():
| "!=" { result = new NotEqualsTo("!="); }
| "@@" { result = new Matches(); }
| "~" { result = new RegExpMatchOperator(RegExpMatchOperatorType.MATCH_CASESENSITIVE); }
| LOOKAHEAD(2) <K_REGEXP> <K_BINARY> { result = new RegExpMySQLOperator(RegExpMatchOperatorType.MATCH_CASESENSITIVE); }
| <K_REGEXP> { result = new RegExpMySQLOperator(RegExpMatchOperatorType.MATCH_CASEINSENSITIVE); }
| "~*" { result = new RegExpMatchOperator(RegExpMatchOperatorType.MATCH_CASEINSENSITIVE); }
| "!~" { result = new RegExpMatchOperator(RegExpMatchOperatorType.NOT_MATCH_CASESENSITIVE); }
| "!~*" { result = new RegExpMatchOperator(RegExpMatchOperatorType.NOT_MATCH_CASEINSENSITIVE); }
Expand Down
10 changes: 10 additions & 0 deletions src/test/java/net/sf/jsqlparser/test/select/SelectTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1325,6 +1325,16 @@ public void testRegexpLike2() throws JSQLParserException {
String stmt = "SELECT CASE WHEN REGEXP_LIKE(first_name, '^Ste(v|ph)en$') THEN 1 ELSE 2 END FROM mytable";
assertSqlCanBeParsedAndDeparsed(stmt);
}

public void testRegexpMySQL() throws JSQLParserException {
String stmt = "SELECT * FROM mytable WHERE first_name REGEXP '^Ste(v|ph)en$'";
assertSqlCanBeParsedAndDeparsed(stmt);
}

public void testRegexpBinaryMySQL() throws JSQLParserException {
String stmt = "SELECT * FROM mytable WHERE first_name REGEXP BINARY '^Ste(v|ph)en$'";
assertSqlCanBeParsedAndDeparsed(stmt);
}

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