Skip to content

Conversation

@Albelt
Copy link

@Albelt Albelt commented May 15, 2025

What did this pull request do?

在替换查询语句中的表名时,只处理了FROM、ORDER BY里面的,像SELECT、WHERE、JOIN里面都有可能出现表名,如果不处理就可能导致SQL报错

User Case Description

修改前生成的SQL:

SELECT * FROM airspace_grids_11 
WHERE "airspace_grids"."level" = 11 AND "airspace_grids"."code" = 'xxx' 
ORDER BY "airspace_grids_11"."id" LIMIT 1

可以看到WHERE里面的表名并没有进行替换,从而导致SQL报错

修改后生成的SQL:

SELECT * FROM airspace_grids_11 
WHERE "airspace_grids_11"."level" = 11 AND "airspace_grids_11"."code" = 'xxx' 
ORDER BY "airspace_grids_11"."id" LIMIT 1

@jinzhu
Copy link
Member

jinzhu commented Jun 6, 2025

Can you add some tests?

@mrhashemian
Copy link

  • It only touches SELECT statements; we’d need identical logic for UPDATE and DELETE.
  • It performs in-place mutation of the original AST, so it may have side effects.

@Albelt Albelt closed this Jul 4, 2025
@Albelt Albelt deleted the fix/table_name_substitute branch July 4, 2025 05:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants