APIJSON [Bug] join时 on语句生成时表没有使用别名导致SQL报错

zed5wv10  于 4个月前  发布在  其他
关注(0)|答案(2)|浏览(77)

APIJSON Version/APIJSON 版本号

7.0.3

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

msyql 8

Environment/环境信息

- JDK/基础库: oracle jdk 21
- OS/系统: macOS Sonoma

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

Current Behavior/问题描述

请求参数
{
    "sumBizDict[]":{
        "join":"</BusinessGroup:level2/parent_id@,</BusinessGroup:level3/parent_id@",
        "BusinessGroup":{
            "@column":"id;name",
            "level":1
        },
        "BusinessGroup:level2":{
            "parent_id@":"/BusinessGroup/id",
            "level":2
        },
        "BusinessGroup:level3":{
            "parent_id@":"/BusinessGroup:level2/id",
            "level":3
        }

    }
}

响应信息:
{
    "sumBizDict[]": {
        "BusinessGroup": {
            "@column": "id;name",
            "level": 1
        },
        "BusinessGroup:level2": {
            "parent_id@": "/BusinessGroup/id",
            "level": 2
        },
        "BusinessGroup:level3": {
            "parent_id@": "/BusinessGroup:level2/id",
            "level": 3
        },
        "join": "</BusinessGroup:level2/parent_id@,</BusinessGroup:level3/parent_id@"
    },
    "ok": false,
    "code": 500,
    "msg": "Unknown column 'BusinessGroup:level2.id' in 'on clause'"
}

控制台异常及生成的SQL语句:
Consume Time:6 ms 2024-07-24 16:32:27
 Execute SQL:SELECT `BusinessGroup`.`id`,`BusinessGroup`.`name`, `level2`.*, `level3`.* FROM `quick-boot-app-space`.`1813027492868489217_business_group` AS `BusinessGroup` LEFT JOIN ( SELECT * FROM `quick-boot-app-space`.`1813027492868489217_business_group` WHERE ( (`level` = 2) ) ) AS `level2` ON `level2`.`parent_id` = `BusinessGroup`.`id` LEFT JOIN ( SELECT * FROM `quick-boot-app-space`.`1813027492868489217_business_group` WHERE ( (`level` = 3) ) ) AS `level3` ON `level3`.`parent_id` = `BusinessGroup:level2`.`id` WHERE ( (`BusinessGroup`.`level` = 1) ) LIMIT 10

2024-07-24 04:32:27.688: AbstractParser.DEBUG: <<<<<<<<<<<<<<<<<<<<<<<<<<<<<< 

 已执行 1/200 条 SQL 

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
apijson.orm.exception.CommonException: Unknown column 'BusinessGroup:level2.id' in 'on clause'

调试堆栈与问题代码:

Expected Behavior/期望结果

经调试,发现AbstractSQLConfig.concatJoinOn方法中有SQL语句拼接问题,
具体为AbstractSQLConfig 类的4819行和4831行 类似
sql += (first ? ON : AND) + quote + jt + quote + "." + quote + on.getKey() + quote + (isNot ? " != " : " = ")
							+ quote + on.getTargetTable() + quote + "." + quote + on.getTargetKey() + quote;

改为

sql += (first ? ON : AND) + quote + jt + quote + "." + quote + on.getKey() + quote + (isNot ? " != " : " = ")
							+ quote + on.getTargetAlias() + quote + "." + quote + on.getTargetKey() + quote;

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

No response

eimct9ow

eimct9ow2#

赞,可以为 APIJSON 提交 PR 贡献,谢谢,开源要大家一起参与贡献才会更美好~

提 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

相关问题