JSqlParser icon indicating copy to clipboard operation
JSqlParser copied to clipboard

special character "?" support issues

Open worthy-commits opened this issue 3 years ago • 9 comments

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:

  1. Example SQL: select * from tl_recurring_shipments where shipment_param->'equipment' ?& array['van']
  2. Parsing this SQL using JSqlParser with this statements use with mybatisplus baseMapper.pageQueryRecurringShipment(page, vo)
  3. Exception net.sf.jsqlparser.parser.ParseException: Encountered unexpected token: "?" "?"

System

  • Database you are using pgsql
  • Java Version 1.8
  • JSqlParser version 3.2

worthy-commits avatar Jan 28 '22 06:01 worthy-commits

upgrade to 4.3

offSwitch avatar Jan 28 '22 06:01 offSwitch

upgrade to 4.3

I tried to upgrade 4.3, but still have this problem.

worthy-commits avatar Jan 28 '22 06:01 worthy-commits

I guess whether there is no adaptation SQL contains special characters "?" . e.g. , ?& ?|

worthy-commits avatar Jan 28 '22 07:01 worthy-commits

I guess whether there is no adaptation SQL contains special characters "?" . e.g. , ?& ?|

https://github.com/JSQLParser/JSqlParser/issues/1434

worthy-commits avatar Jan 28 '22 07:01 worthy-commits

4.3并没有这个问题,我这边就在用4.3,你这个sql我测试是没有问题的,能够正常解析。?& 这个在4.3里面是JSONOperator的op image

offSwitch avatar Jan 28 '22 07:01 offSwitch

4.3并没有这个问题,我这边就在用4.3,你这个sql我测试是没有问题的,能够正常解析。?& 这个在4.3里面是JSONOperator的op image

解析查询是没问题的,但当你使用排序时,order by就会出现这个问题,我没有直接使用JSqlParser,而是使用的MybatisPlus,其中分页插件用到的JSqlParser。当分页查询使用到排序时,排序将无效(但不影响运行),分页效果正常。

worthy-commits avatar Jan 28 '22 07:01 worthy-commits

这个问题我不认为是jsqlparser的,你应该向mybatis-plus提这个issue。

offSwitch avatar Jan 28 '22 09:01 offSwitch

这个问题我不认为是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

worthy-commits avatar Jan 29 '22 01:01 worthy-commits

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.

wumpz avatar Feb 06 '22 22:02 wumpz

Closed, since no further question has been asked.

manticore-projects avatar Nov 12 '22 06:11 manticore-projects