Using Release: 0.6.2.a
The parser is throwing an exception on CASE WHEN ELSE END clauses where the ELSE expression contains more than 1 token.
Examples that Parsed Ok
select case when a=0 then b/c else b end from tbl;
select case when a=0 then b/c else 0 end from tbl;
Examples that throw an Exception
select case when a=0 then b/c else b/a end from tbl;
select case when a=0 then b else a*b end from tbl;
select case when a>100 then b else a+b end from tbl;
net.sf.jsqlparser.JSQLParserException
at net.sf.jsqlparser.parser.CCJSqlParserManager.parse(CCJSqlParserManager.java:40)
Caused by: net.sf.jsqlparser.parser.ParseException: Encountered "case when a = 0 then b / c else b /" at line 2, column 8.
Was expecting one of:
"ALL" ...
"TOP" ...
"DISTINCT" ...
"(" ...
"*" ...
<S_IDENTIFIER> ...
....
at net.sf.jsqlparser.parser.CCJSqlParser.generateParseException(CCJSqlParser.java:5921)
at net.sf.jsqlparser.parser.CCJSqlParser.jj_consume_token(CCJSqlParser.java:5799)
at net.sf.jsqlparser.parser.CCJSqlParser.SimpleExpression(CCJSqlParser.java:2047)
at net.sf.jsqlparser.parser.CCJSqlParser.SelectItem(CCJSqlParser.java:978)
at net.sf.jsqlparser.parser.CCJSqlParser.SelectItemsList(CCJSqlParser.java:922)
at net.sf.jsqlparser.parser.CCJSqlParser.PlainSelect(CCJSqlParser.java:634)
at net.sf.jsqlparser.parser.CCJSqlParser.SelectBody(CCJSqlParser.java:567)
at net.sf.jsqlparser.parser.CCJSqlParser.Select(CCJSqlParser.java:554)
at net.sf.jsqlparser.parser.CCJSqlParser.Statement(CCJSqlParser.java:110)
at net.sf.jsqlparser.parser.CCJSqlParserManager.parse(CCJSqlParserManager.java:38)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I know there were points to change the PrimaryExpression to SimpleExpression in the ELSE section to fix the above error. However, I am still getting the error. Is there anything else needed on top of the latest release 0.7 and patch?
Thanks,
Srini
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2012-03-14
I checked out the latest code, modified JSqlParserCC.jj lines 1409 and 1413 to change elseExp=PrimaryExpression() to elseExp=SimpleExpression(), and it seems to be working fine.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Using Release: 0.6.2.a
The parser is throwing an exception on CASE WHEN ELSE END clauses where the ELSE expression contains more than 1 token.
Examples that Parsed Ok
select case when a=0 then b/c else b end from tbl;
select case when a=0 then b/c else 0 end from tbl;
Examples that throw an Exception
select case when a=0 then b/c else b/a end from tbl;
select case when a=0 then b else a*b end from tbl;
select case when a>100 then b else a+b end from tbl;
net.sf.jsqlparser.JSQLParserException
at net.sf.jsqlparser.parser.CCJSqlParserManager.parse(CCJSqlParserManager.java:40)
Caused by: net.sf.jsqlparser.parser.ParseException: Encountered "case when a = 0 then b / c else b /" at line 2, column 8.
Was expecting one of:
"ALL" ...
"TOP" ...
"DISTINCT" ...
"(" ...
"*" ...
<S_IDENTIFIER> ...
....
at net.sf.jsqlparser.parser.CCJSqlParser.generateParseException(CCJSqlParser.java:5921)
at net.sf.jsqlparser.parser.CCJSqlParser.jj_consume_token(CCJSqlParser.java:5799)
at net.sf.jsqlparser.parser.CCJSqlParser.SimpleExpression(CCJSqlParser.java:2047)
at net.sf.jsqlparser.parser.CCJSqlParser.SelectItem(CCJSqlParser.java:978)
at net.sf.jsqlparser.parser.CCJSqlParser.SelectItemsList(CCJSqlParser.java:922)
at net.sf.jsqlparser.parser.CCJSqlParser.PlainSelect(CCJSqlParser.java:634)
at net.sf.jsqlparser.parser.CCJSqlParser.SelectBody(CCJSqlParser.java:567)
at net.sf.jsqlparser.parser.CCJSqlParser.Select(CCJSqlParser.java:554)
at net.sf.jsqlparser.parser.CCJSqlParser.Statement(CCJSqlParser.java:110)
at net.sf.jsqlparser.parser.CCJSqlParserManager.parse(CCJSqlParserManager.java:38)
I know there were points to change the PrimaryExpression to SimpleExpression in the ELSE section to fix the above error. However, I am still getting the error. Is there anything else needed on top of the latest release 0.7 and patch?
Thanks,
Srini
I checked out the latest code, modified JSqlParserCC.jj lines 1409 and 1413 to change elseExp=PrimaryExpression() to elseExp=SimpleExpression(), and it seems to be working fine.