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

[Bug] 达梦数据库做表左关联时提示有歧义的列名[RN] #690

Open
jettisonJava opened this issue Mar 14, 2024 · 2 comments
Open

Comments

@jettisonJava
Copy link
Contributor

jettisonJava commented Mar 14, 2024

APIJSON Version/APIJSON 版本号

6.3.0

Database Type & Version/数据库类型及版本号

达梦8

Environment/环境信息

- JDK/基础库:11.0.16
- OS/系统:windows 10

APIAuto Screenshots/APIAuto 请求与结果完整截屏

代码定位截图(https://img-blog.csdnimg.cn/direct/5f0dfce1c33946148c98beedc89ca038.png)
数据请求截图(https://img-blog.csdnimg.cn/direct/917e8e5e1f2a4e39815a5c384a6109b3.png)

Current Behavior/问题描述

通过翻查源码,发现在AbstractSQLConfig类中,3203行的getOraclePageSql方法中,发现每一个进来的表sql都会默认拼接ROWNUM AS RN 的行数字段,当存在多表关联时,多个表都存在相同的RN列名,导致报错。印象中翻过一个issue有说过APIJSON会将每个相连的表建立alias(不知道是否只有mysql有,而oracle等其他库没有),但实际上达梦(oralce)并没有。包括联表内的字段都没有别名。请求参数中也无法通过建立别名影响RN列的生成。
------------------------
后端生成的sql:
SELECT * FROM (SELECT "Table20240311".*, ROWNUM RN FROM (SELECT "Table20240311".*, "Dd".* FROM "GR_BAS_DYMFORM"."Table20240311" AS "Table20240311"  
   LEFT JOIN ( SELECT * FROM (SELECT "Dd".*, ROWNUM RN FROM (SELECT "id" AS "Dd.id","pid" FROM "GR_BAS_DYMFORM"."Dd") "Dd"  WHERE ROWNUM <= 0) WHERE RN > 0 ) AS "Dd" ON "Dd"."pid" = "Table20240311"."id"  
) "Table20240311"  WHERE ROWNUM <= 50) WHERE RN > 0

--------------
请求参数:
{
    "[]": {
        "join": "</Dd/pid@",
        "Table20240311": {
            "@datasource": "dm",
        },
        "Dd": {
            "pid@": "/Table20240311/id",
            "@datasource": "dm",
            "@column": "id:Dd.id,pid;"
        }, "query": 2,
  "count": 50,
  "page": 0,
    },"info@":"/[]/info","total@":"/[]/total",
}

返回报错结果:
"msg": "第3 行附近出现错误:\n有歧义的列名[RN]",

Expected Behavior/期望结果

能否实现每个联表、字段都自动生成别名,让表字段唯一,互不影响。或者提供对默认的ROWNUM(RN)行数字段别名的修改。

Any additional comments?/其它补充说明?

@TommyLemon
Copy link
Collaborator

TommyLemon commented Mar 14, 2024

给和关键词冲突的别名 RN 加上引号,String quote = getQuote(); quote + "RN" + quote
https://github.com/Tencent/APIJSON/blob/master/APIJSONORM/src/main/java/apijson/orm/AbstractSQLConfig.java#L4596-L4597
image

改好后给 APIJSON提交 PR 贡献,谢谢,开源要大家一起参与贡献才会更美好~
image

提 PR 贡献代码的步骤可参考:
https://github.com/Tencent/APIJSON/blob/master/CONTRIBUTING.md#%E4%B8%BA%E4%BB%80%E4%B9%88%E4%B8%80%E5%AE%9A%E8%A6%81%E8%B4%A1%E7%8C%AE%E4%BB%A3%E7%A0%81

@jettisonJava
Copy link
Contributor Author

升级APIJSONORM 6.4.0版本,测试发现关联表内部不会再出现行数字段,最外层SQL只会在外部产生一个ROWNUM,不再有多个ROWNUM导致字段冲突,问题已解决。
该问题可通过升级>6.3.0版本的APIJSONORM修复。另外在RN字段前后加上quote双引号,显然更符合数据库规范。

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