Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

升级到6.1.0后jsqlparser4.7又出问题了 #811

Open
1 task
LSL1618 opened this issue Apr 8, 2024 · 2 comments
Open
1 task

升级到6.1.0后jsqlparser4.7又出问题了 #811

LSL1618 opened this issue Apr 8, 2024 · 2 comments

Comments

@LSL1618
Copy link

LSL1618 commented Apr 8, 2024

  • 我已在 issues 搜索类似问题,并且不存在相同的问题.

异常模板

使用环境

  • PageHelper 版本: 6.1.0
  • 数据库类型和版本: sqlserver2012
  • JDBC_URL: xxx

SQL 解析错误

分页参数

PageHelper.startPage(1, 10);
xxMapper.select(model);

原 SQL

select sj.*,         (select stuff(         (select ',' + su_.real_name from t_system_user su_         inner join t_user_job uj_ on uj_.user_id = su_.id         where uj_.job_id = sj.id         order by su_.real_name for xml path('')),         1, 1, '')) as user_names         from t_system_job sj         where 1 = 1                                                                                                             order by                           sj.job_index asc, sj.id desc

期望的结果:

select count(0) from (  select sj.*,         (select stuff(         (select ',' + su_.real_name from t_system_user su_         inner join t_user_job uj_ on uj_.user_id = su_.id         where uj_.job_id = sj.id         order by su_.real_name for xml path('')),         1, 1, '')) as user_names         from t_system_job sj         where 1 = 1  ) tmp_count

完整异常信息

org.springframework.jdbc.UncategorizedSQLException: 
### Error querying database.  Cause: com.microsoft.sqlserver.jdbc.SQLServerException: 除非另外还指定了 TOP、OFFSET 或 FOR XML,否则,ORDER BY 子句在视图、内联函数、派生表、子查询和公用表表达式中无效。
### The error may exist in file [\mapper\SystemJobMapper.xml]
### The error may involve mapper.SystemJobMapper.queryJobsByCondition-Inline
### The error occurred while setting parameters
### SQL: select count(0) from (  select sj.*,         (select stuff(         (select ',' + su_.real_name from t_system_user su_         inner join t_user_job uj_ on uj_.user_id = su_.id         where uj_.job_id = sj.id         order by su_.real_name for xml path('')),         1, 1, '')) as user_names         from t_system_job sj         where 1 = 1                                                                                                             order by                           sj.job_index asc, sj.id desc  ) tmp_count
### Cause: com.microsoft.sqlserver.jdbc.SQLServerException: 除非另外还指定了 TOP、OFFSET 或 FOR XML,否则,ORDER BY 子句在视图、内联函数、派生表、子查询和公用表表达式中无效。
; uncategorized SQLException; SQL state [S0001]; error code [1033]; 除非另外还指定了 TOP、OFFSET 或 FOR XML,否则,ORDER BY 子句在视图、内联函数、派生表、子查询和公用表表达式中无效。; nested exception is com.microsoft.sqlserver.jdbc.SQLServerException: 除非另外还指定了 TOP、OFFSET 或 FOR XML,否则,ORDER BY 子句在视图、内联函数、派生表、子查询和公用表表达式中无效。

其他类型的错误

跟踪发现在引用jsqlparser4.7时,DefaultCountSqlParser.getSmartCountSql()方法中stmt = SqlParserUtil.parse(sql);语句执行报异常且结果为null,进而导致走这一句return this.getSimpleCountSql(sql, countColumn);,之后保留了order by子句导致SQLServer查询异常。jsqlparser4.7解析上述原SQL语句的异常信息如下:

net.sf.jsqlparser.parser.ParseException: Encountered unexpected token: at line 2, column 10.

最后切换回jsqlparser4.5才正常,jsqlparser的各种版本真的是太坑人了,吓得都不敢升级了。

功能建议

详细说明,尽可能提供(伪)代码示例。

@LSL1618
Copy link
Author

LSL1618 commented Apr 8, 2024

jsqlparser4.5、jsqlparser4.7的引用参考PageHelper6.1.0更新说明。经测试发现更新的jsqlparser4.8、jsqlparser4.9依然无解,真真是坑死人不偿命啊!

@abel533
Copy link
Collaborator

abel533 commented Apr 9, 2024

jsqlparser的兼容性太差了。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants