Skip to content

Commit 154cf37

Browse files
committed
1 parent 80153df commit 154cf37

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed

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

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ TOKEN: /* SQL Keywords. prefixed with K_ to avoid name clashes */
174174
| <K_HAVING:"HAVING">
175175
| <K_HIGH_PRIORITY : "HIGH_PRIORITY">
176176
| <K_IF:"IF">
177+
| <K_IIF:"IIF">
177178
| <K_IGNORE : "IGNORE">
178179
| <K_ILIKE:"ILIKE">
179180
| <K_IN:"IN">
@@ -2691,6 +2692,8 @@ Expression PrimaryExpression() #PrimaryExpression:
26912692

26922693
| LOOKAHEAD(JsonExpression()) retval=JsonExpression()
26932694

2695+
| LOOKAHEAD(FunctionWithCondParams()) retval = FunctionWithCondParams()
2696+
26942697
| LOOKAHEAD(Function()) retval=Function()
26952698

26962699
| token=<S_DOUBLE> { retval = new DoubleValue(token.image); }
@@ -3081,6 +3084,28 @@ Execute Execute(): {
30813084
}
30823085
}
30833086

3087+
Function FunctionWithCondParams() #Function: {
3088+
Function retval = new Function();
3089+
String funcName = null;
3090+
ExpressionList expressionList = null;
3091+
Token token = null;
3092+
}
3093+
{
3094+
(token = <K_IF> | token = <K_IIF>) { funcName=token.image; }
3095+
3096+
"("
3097+
expressionList=ConditionExpressionList()
3098+
")"
3099+
3100+
{
3101+
retval.setParameters(expressionList);
3102+
retval.setName(funcName);
3103+
linkAST(retval,jjtThis);
3104+
return retval;
3105+
}
3106+
}
3107+
3108+
30843109
Function Function() #Function:
30853110
{
30863111
Function retval = new Function();
@@ -3109,7 +3134,7 @@ Function Function() #Function:
31093134
|
31103135
LOOKAHEAD(NamedExpressionListExprFirst()) namedExpressionList = NamedExpressionListExprFirst()
31113136
|
3112-
LOOKAHEAD(SimpleExpressionList()) expressionList=SimpleExpressionList()
3137+
LOOKAHEAD(3) expressionList=SimpleExpressionList()
31133138
//|
31143139
//LOOKAHEAD(ConditionExpressionList()) expressionList=ConditionExpressionList()
31153140
|

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3374,17 +3374,17 @@ public void testOptimizeForIssue348() throws JSQLParserException {
33743374

33753375
@Test
33763376
public void testFuncConditionParameter() throws JSQLParserException {
3377-
assertSqlCanBeParsedAndDeparsed("SELECT func(a < b)");
3377+
assertSqlCanBeParsedAndDeparsed("SELECT if(a < b)");
33783378
}
33793379

33803380
@Test
33813381
public void testFuncConditionParameter2() throws JSQLParserException {
3382-
assertSqlCanBeParsedAndDeparsed("SELECT func(a < b, c)");
3382+
assertSqlCanBeParsedAndDeparsed("SELECT if(a < b, c)");
33833383
}
33843384

33853385
@Test
33863386
public void testFuncConditionParameter3() throws JSQLParserException {
3387-
assertSqlCanBeParsedAndDeparsed("SELECT CAST((MAX(CAST(IIF(isnumeric(license_no) = 1, license_no, 0) AS INT )) + 2) as varchar) FROM lcps.t_license WHERE profession_id = 60 and license_type = 100 and YEAR(issue_date) % 2 = case when YEAR(issue_date) % 2 = 0 then 0 else 1 end and ISNUMERIC(license_no) = 1");
3387+
assertSqlCanBeParsedAndDeparsed("SELECT CAST((MAX(CAST(IIF(isnumeric(license_no) = 1, license_no, 0) AS INT)) + 2) AS varchar) FROM lcps.t_license WHERE profession_id = 60 and license_type = 100 and YEAR(issue_date) % 2 = case when YEAR(issue_date) % 2 = 0 then 0 else 1 end and ISNUMERIC(license_no) = 1", true);
33883388
}
33893389

33903390
@Test

0 commit comments

Comments
 (0)