JSqlParser
JSqlParser copied to clipboard
special character "?" support issues
Describe the bug In PGSQL, the special character "?" Is used. An error occurred during order parsing(use with mybatisplus), error message: net.sf.jsqlparser.parser.ParseException: Encountered unexpected token: "?" "?" To Reproduce Steps to reproduce the behavior:
- Example SQL:
select * from tl_recurring_shipments where shipment_param->'equipment' ?& array['van'] - Parsing this SQL using JSqlParser with this statements
use with mybatisplus
baseMapper.pageQueryRecurringShipment(page, vo) - Exception net.sf.jsqlparser.parser.ParseException: Encountered unexpected token: "?" "?"
System
- Database you are using pgsql
- Java Version 1.8
- JSqlParser version 3.2
upgrade to 4.3
upgrade to 4.3
I tried to upgrade 4.3, but still have this problem.
I guess whether there is no adaptation SQL contains special characters "?" . e.g. , ?& ?|
I guess whether there is no adaptation SQL contains special characters "?" . e.g. , ?& ?|
https://github.com/JSQLParser/JSqlParser/issues/1434
4.3并没有这个问题,我这边就在用4.3,你这个sql我测试是没有问题的,能够正常解析。?& 这个在4.3里面是JSONOperator的op

4.3并没有这个问题,我这边就在用4.3,你这个sql我测试是没有问题的,能够正常解析。?& 这个在4.3里面是JSONOperator的op
解析查询是没问题的,但当你使用排序时,order by就会出现这个问题,我没有直接使用JSqlParser,而是使用的MybatisPlus,其中分页插件用到的JSqlParser。当分页查询使用到排序时,排序将无效(但不影响运行),分页效果正常。
这个问题我不认为是jsqlparser的,你应该向mybatis-plus提这个issue。
这个问题我不认为是jsqlparser的,你应该向mybatis-plus提这个issue。
刚参考资料发现,我忽略了一个问题,我使用的并不是 ?&,由于JDBC使用PreparedStatement时,会将?当作占位符,所以我使用了 ?? 转义 ?,从而导致MybatisPlus执行 Select select = (Select) CCJSqlParserUtil.parse(originalSql); 时发生错误。
JSqlParser对?&能够正常识别,但对??& 无法识别,我没有找到其它方式去解决JDBC将?当占位符和JSqlParser不能解析??&的问题?
所以我这里的解决方式是放弃了使用JSqlParser进行排序Order的自动拼接,而是利用MybatisPlus的动态特性将order by xxxx 写在Sql.xml当中。(虽然这是逃避问题,但不失为一个解决方案)
不知道是否有其它更好的解决方式?
参考:https://jdbc.postgresql.org/documentation/head/statement.html
This operator was implemented in commit a550481 (2016) . I tested this using JSqlParser 4.4-SNAPSHOT and it worked. Same with 4.3. So I think you have a different problem.
Closed, since no further question has been asked.