From 5afd03c9480342d69ce98e622590753bcfa53ce9 Mon Sep 17 00:00:00 2001 From: cybzzz Date: Sun, 16 Mar 2025 20:27:58 +0800 Subject: [PATCH 1/2] =?UTF-8?q?fix:=20exists=20=E6=9D=A1=E4=BB=B6=E4=B8=AD?= =?UTF-8?q?=E7=9A=84=E8=A1=A8=E5=88=AB=E5=90=8D=E5=92=8C=E7=88=B6=E6=9F=A5?= =?UTF-8?q?=E8=AF=A2=E4=BF=9D=E6=8C=81=E4=B8=80=E8=87=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/mybatisflex/core/dialect/IDialect.java | 5 +++++ .../mybatisflex/core/dialect/impl/CommonsDialectImpl.java | 6 ++++++ .../com/mybatisflex/core/query/OperatorSelectCondition.java | 2 +- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/dialect/IDialect.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/dialect/IDialect.java index 573c8376..0e87f0ca 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/dialect/IDialect.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/dialect/IDialect.java @@ -15,6 +15,7 @@ */ package com.mybatisflex.core.dialect; +import com.mybatisflex.core.query.QueryTable; import com.mybatisflex.core.query.QueryWrapper; import com.mybatisflex.core.row.Row; import com.mybatisflex.core.table.TableInfo; @@ -64,6 +65,10 @@ public interface IDialect { String buildSelectSql(QueryWrapper queryWrapper); + default String buildSelectSql(QueryWrapper queryWrapper, List contextTables) { + return buildSelectSql(queryWrapper); + } + String buildNoSelectSql(QueryWrapper queryWrapper); String buildDeleteSql(QueryWrapper queryWrapper); diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/dialect/impl/CommonsDialectImpl.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/dialect/impl/CommonsDialectImpl.java index 9d2dc399..16eb206f 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/dialect/impl/CommonsDialectImpl.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/dialect/impl/CommonsDialectImpl.java @@ -395,10 +395,16 @@ public class CommonsDialectImpl implements IDialect { ////////////build query sql/////// @Override public String buildSelectSql(QueryWrapper queryWrapper) { + return buildSelectSql(queryWrapper, Collections.emptyList()); + } + + @Override + public String buildSelectSql(QueryWrapper queryWrapper, List contextTables) { List queryTables = CPI.getQueryTables(queryWrapper); List joinTables = CPI.getJoinTables(queryWrapper); List allTables = CollectionUtil.merge(queryTables, joinTables); + allTables = CollectionUtil.merge(allTables, contextTables); List selectColumns = CPI.getSelectColumns(queryWrapper); diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/OperatorSelectCondition.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/OperatorSelectCondition.java index c43b6865..9bd28183 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/OperatorSelectCondition.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/OperatorSelectCondition.java @@ -48,7 +48,7 @@ public class OperatorSelectCondition extends QueryCondition { //检测是否生效 if (checkEffective()) { - String childSql = dialect.buildSelectSql(queryWrapper); + String childSql = dialect.buildSelectSql(queryWrapper, queryTables); if (StringUtil.hasText(childSql)) { QueryCondition prevEffectiveCondition = getPrevEffectiveCondition(); if (prevEffectiveCondition != null && this.connector != null) { From a35ca5cd62caff7330bae88ae6dc1b5c356262a8 Mon Sep 17 00:00:00 2001 From: cybzzz Date: Sun, 16 Mar 2025 22:43:22 +0800 Subject: [PATCH 2/2] =?UTF-8?q?fix:=20exists=20=E5=88=AB=E5=90=8D=E5=8D=95?= =?UTF-8?q?=E4=BE=A7=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../test/java/com/mybatisflex/coretest/AccountSqlTester.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mybatis-flex-core/src/test/java/com/mybatisflex/coretest/AccountSqlTester.java b/mybatis-flex-core/src/test/java/com/mybatisflex/coretest/AccountSqlTester.java index 796c24a6..c0447e38 100644 --- a/mybatis-flex-core/src/test/java/com/mybatisflex/coretest/AccountSqlTester.java +++ b/mybatis-flex-core/src/test/java/com/mybatisflex/coretest/AccountSqlTester.java @@ -400,7 +400,7 @@ public class AccountSqlTester { Assert.assertEquals("SELECT * FROM `tb_account` " + "WHERE `id` >= 100 " + - "AND EXISTS (SELECT 1 AS `temp_one` FROM `tb_article` AS `a` WHERE `id` >= 100)" + "AND EXISTS (SELECT 1 AS `temp_one` FROM `tb_article` AS `a` WHERE `a`.`id` >= 100)" , query.toSQL()); System.out.println(query.toSQL());