JSqlParser
JSqlParser copied to clipboard
[BUG] JSQLParser Version : 5.1 解析sqlserver数据库 stuff函数,当查询语句添加order by ,解析会报错
SQL Example:
public static void main(String[] args) { String sql = "SELECT STUFF((SELECT ',' + name FROM class order by id FOR XML PATH('')),1,1,'') AS names from " + "users"; try { Statement statement = CCJSqlParserUtil.parse(sql); } catch (JSQLParserException e) { throw new RuntimeException(e); } } CCJSqlParserUtil解析sql错误,错误信息如下
as expecting one of:
<EOF>
<ST_SEMICOLON>
at com.aciplaw.patas.operation.service.impl.CaseInfoServiceImpl.main(CaseInfoServiceImpl.java:1154)
Caused by: net.sf.jsqlparser.JSQLParserException: net.sf.jsqlparser.parser.ParseException: Encountered unexpected token: "(" "(" at line 1, column 13.
Was expecting one of:
<EOF>
<ST_SEMICOLON>
at net.sf.jsqlparser.parser.CCJSqlParserUtil.parseStatement(CCJSqlParserUtil.java:352)
at net.sf.jsqlparser.parser.CCJSqlParserUtil.parse(CCJSqlParserUtil.java:125)
at net.sf.jsqlparser.parser.CCJSqlParserUtil.parse(CCJSqlParserUtil.java:91)
at net.sf.jsqlparser.parser.CCJSqlParserUtil.parse(CCJSqlParserUtil.java:64)
at com.aciplaw.patas.operation.service.impl.CaseInfoServiceImpl.main(CaseInfoServiceImpl.java:1152)
Caused by: java.util.concurrent.ExecutionException: net.sf.jsqlparser.parser.ParseException: Encountered unexpected token: "(" "(" at line 1, column 13.
Was expecting one of:
<EOF>
<ST_SEMICOLON>
at java.base/java.util.concurrent.FutureTask.report(FutureTask.java:122)
at java.base/java.util.concurrent.FutureTask.get(FutureTask.java:205)
at net.sf.jsqlparser.parser.CCJSqlParserUtil.parseStatement(CCJSqlParserUtil.java:345)
... 4 more
Caused by: net.sf.jsqlparser.parser.ParseException: Encountered unexpected token: "(" "(" at line 1, column 13.
Was expecting one of:
<EOF>
<ST_SEMICOLON>
at net.sf.jsqlparser.parser.CCJSqlParser.generateParseException(CCJSqlParser.java:48520)
at net.sf.jsqlparser.parser.CCJSqlParser.jj_consume_token(CCJSqlParser.java:48341)
at net.sf.jsqlparser.parser.CCJSqlParser.Statement(CCJSqlParser.java:345)
at net.sf.jsqlparser.parser.CCJSqlParserUtil$1.call(CCJSqlParserUtil.java:341)
at net.sf.jsqlparser.parser.CCJSqlParserUtil$1.call(CCJSqlParserUtil.java:338)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:317)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642)
at java.base/java.lang.Thread.run(Thread.java:1583)
如果去掉order by ,解析就会正确,程序如何 public static void main(String[] args) { String sql = "SELECT STUFF((SELECT ',' + name FROM class FOR XML PATH('')),1,1,'') AS names from " + "users"; try { Statement statement = CCJSqlParserUtil.parse(sql); } catch (JSQLParserException e) { throw new RuntimeException(e); } }
估计是 CCJSqlParser 类解析时出错,应该时一个bug,期望下个版本可以解决