Skip to content

Commit

Permalink
Added regexp_like support
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonathan Burnhams committed Aug 1, 2013
1 parent 43fe8ca commit 33f4f66
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/main/javacc/net/sf/jsqlparser/parser/JSqlParserCC.jj
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ TOKEN: /* SQL Keywords. prefixed with K_ to avoid name clashes */
| <K_NULL:"NULL">
| <K_LIKE:"LIKE">
| <K_REGEXP:"REGEXP">
| <K_REGEXP_LIKE:"REGEXP_LIKE">
| <K_DROP:"DROP">
| <K_JOIN:"JOIN">
| <K_LEFT:"LEFT">
Expand Down Expand Up @@ -1283,11 +1284,27 @@ Expression Condition():
}
{
(LOOKAHEAD(SQLCondition()) result=SQLCondition()
| result=RegularCondition())
| result=FunctionCondition()
| result=RegularCondition()
)

{ return result; }
}

Expression FunctionCondition():
{
Function result;
ExpressionList parameters;
}
{
<K_REGEXP_LIKE> { result = new Function(); result.setName("REGEXP_LIKE"); }
"("
parameters=SimpleExpressionList() { result.setParameters(parameters); }
")"

{ return result; }
}

Expression RegularCondition():
{
Expression result = null;
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 @@ -1022,4 +1022,14 @@ public void testPivotXml3() throws JSQLParserException {
assertSqlCanBeParsedAndDeparsed(stmt);
}

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

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);
}

}

0 comments on commit 33f4f66

Please sign in to comment.