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

xml文件审核,pg插件报错 #2356

Closed
hasa1K opened this issue Apr 16, 2024 · 1 comment
Closed

xml文件审核,pg插件报错 #2356

hasa1K opened this issue Apr 16, 2024 · 1 comment
Assignees
Labels
bug Something isn't working publish-pre1 verified the issue all pr is verified
Milestone

Comments

@hasa1K
Copy link
Contributor

hasa1K commented Apr 16, 2024

版本信息(Version)

v3 86cd961

问题描述(Describe)

使用pg数据源对xml进行文件审核,发生报错

截图或日志(Log)

页面表现:
image
sqled.log日志:
time="2024-04-15T18:25:51+08:00" level=error msg="fail to call plugin interface [Parse], error: rpc error: code = Unknown desc = syntax error at or near "`"" plugin=PostgreSQL plugin_version=2 session_id=GEeoeRpbQOqVB9L8K6t2 thread_id=GPO

排查过程

后端进行xml解析时,会将sql中的字段名和表名加上反引号
image
将解析之后的sql,放入pg中执行,同样出现该问题
image

如何复现(To Reproduce)

  1. 添加pg数据源
  2. 使用pg数据源,进行xml文件审核

实现方案

为什么xml解析之后,sql会带反引号?

xml解析流程为:
从xml中提取sql内容 -> 解析为ast语法树 -> 从语法树中还原为字符串
在第三步还原字符串的过程中,会使用反引号将列名,表名或者库民使用反引号包裹起来
具体代码:
image

报错原因

反引号在mysql中用于引用标识符,但是在PostgreSQL中,反引号(``)并没有特殊的作用,也不是用于引用标识符的合法符号。相反,PostgreSQL使用双引号("")来引用标识符,如表名、列名、数据库名等。

解决方案

当前的XML解析器在将AST语法树还原为SQL字符串时,固定使用反引号包裹标识符,缺乏灵活性。为了解决该问题,计划对XML解析器进行以下改进:

  1. 增加一个配置参数,允许调用者指定在将AST还原为SQL字符串时应使用的引用符号类型。该配置选项应支持多种引用符号,如双引号(PostgreSQL)和反引号(MySQL)。
  2. 在解析器实现中,依据传入的配置参数选择合适的引用符号。对于PostgreSQL,使用双引号包裹标识符;对于MySQL,则使用反引号。

变更影响面

新增调用参数之后,调用方可能会额外传递参数

@hasa1K
Copy link
Contributor Author

hasa1K commented Aug 27, 2024

版本

sqle-ee:55917e1f1c5485f612f189dca241885e6e599846

测试

选择pg数据源进行xml文件审核
image
没有出现报错,正常审核
image

@hasa1K hasa1K added the verified the issue all pr is verified label Aug 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working publish-pre1 verified the issue all pr is verified
Projects
None yet
Development

No branches or pull requests

2 participants