mirror of
https://gitee.com/mybatis-flex/mybatis-flex.git
synced 2025-12-08 01:28:24 +08:00
fix: close #I8ASWS
This commit is contained in:
parent
a7a41c3fc6
commit
3df467ef88
@ -491,6 +491,23 @@ public class CommonsDialectImpl implements IDialect {
|
|||||||
if (StringUtil.isNotBlank(hint)) {
|
if (StringUtil.isNotBlank(hint)) {
|
||||||
sqlBuilder.append(BLANK).append(hint).deleteCharAt(sqlBuilder.length() - 1);
|
sqlBuilder.append(BLANK).append(hint).deleteCharAt(sqlBuilder.length() - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//delete with join
|
||||||
|
if (joinTables != null && !joinTables.isEmpty()) {
|
||||||
|
if (queryTables == null || queryTables.isEmpty()) {
|
||||||
|
throw new IllegalArgumentException("Delete with join sql must designate the from table.");
|
||||||
|
} else if (queryTables.size() != 1) {
|
||||||
|
throw new IllegalArgumentException("Delete with join sql must has 1 table only. but current has " + queryTables.size());
|
||||||
|
}
|
||||||
|
QueryTable queryTable = queryTables.get(0);
|
||||||
|
String table = getRealTable(queryTable.getName());
|
||||||
|
if (StringUtil.isNotBlank(queryTable.getSchema())) {
|
||||||
|
sqlBuilder.append(wrap(getRealSchema(queryTable.getSchema(), table))).append(REFERENCE);
|
||||||
|
}
|
||||||
|
sqlBuilder.append(BLANK).append(wrap(getRealTable(table)));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
sqlBuilder.append(FROM).append(StringUtil.join(DELIMITER, queryTables, queryTable -> queryTable.toSql(this)));
|
sqlBuilder.append(FROM).append(StringUtil.join(DELIMITER, queryTables, queryTable -> queryTable.toSql(this)));
|
||||||
|
|
||||||
buildJoinSql(sqlBuilder, queryWrapper, allTables);
|
buildJoinSql(sqlBuilder, queryWrapper, allTables);
|
||||||
|
|||||||
@ -125,7 +125,7 @@ public class QueryWrapper extends BaseQueryWrapper<QueryWrapper> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public <T> QueryWrapper select(LambdaGetter<T>... lambdaGetters) {
|
public <T> QueryWrapper select(LambdaGetter<T>... lambdaGetters) {
|
||||||
for (LambdaGetter<T> lambdaGetter : lambdaGetters) {
|
for (LambdaGetter<?> lambdaGetter : lambdaGetters) {
|
||||||
QueryColumn queryColumn = LambdaUtil.getQueryColumn(lambdaGetter);
|
QueryColumn queryColumn = LambdaUtil.getQueryColumn(lambdaGetter);
|
||||||
addSelectColumn(queryColumn);
|
addSelectColumn(queryColumn);
|
||||||
}
|
}
|
||||||
@ -660,7 +660,6 @@ public class QueryWrapper extends BaseQueryWrapper<QueryWrapper> {
|
|||||||
addGroupByColumns(LambdaUtil.getQueryColumn(column));
|
addGroupByColumns(LambdaUtil.getQueryColumn(column));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public <T> QueryWrapper groupBy(LambdaGetter<T>... columns) {
|
public <T> QueryWrapper groupBy(LambdaGetter<T>... columns) {
|
||||||
for (LambdaGetter<T> column : columns) {
|
for (LambdaGetter<T> column : columns) {
|
||||||
groupBy(LambdaUtil.getQueryColumn(column));
|
groupBy(LambdaUtil.getQueryColumn(column));
|
||||||
|
|||||||
@ -21,10 +21,7 @@ import com.mybatisflex.core.dialect.IDialect;
|
|||||||
import com.mybatisflex.core.dialect.KeywordWrap;
|
import com.mybatisflex.core.dialect.KeywordWrap;
|
||||||
import com.mybatisflex.core.dialect.LimitOffsetProcessor;
|
import com.mybatisflex.core.dialect.LimitOffsetProcessor;
|
||||||
import com.mybatisflex.core.dialect.impl.CommonsDialectImpl;
|
import com.mybatisflex.core.dialect.impl.CommonsDialectImpl;
|
||||||
import com.mybatisflex.core.query.DistinctQueryColumn;
|
import com.mybatisflex.core.query.*;
|
||||||
import com.mybatisflex.core.query.QueryWrapper;
|
|
||||||
import com.mybatisflex.core.query.RawQueryColumn;
|
|
||||||
import com.mybatisflex.core.query.SqlOperators;
|
|
||||||
import com.mybatisflex.core.table.TableInfo;
|
import com.mybatisflex.core.table.TableInfo;
|
||||||
import com.mybatisflex.core.table.TableInfoFactory;
|
import com.mybatisflex.core.table.TableInfoFactory;
|
||||||
import com.mybatisflex.core.table.TableManager;
|
import com.mybatisflex.core.table.TableManager;
|
||||||
@ -560,6 +557,24 @@ public class AccountSqlTester {
|
|||||||
System.out.println(sql);
|
System.out.println(sql);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* test https://gitee.com/mybatis-flex/mybatis-flex/issues/I8ASWS
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testDeleteWithJoin() {
|
||||||
|
QueryWrapper qw = QueryWrapper.create()
|
||||||
|
.from(ACCOUNT).leftJoin(ARTICLE).on(ACCOUNT.ID.eq(ARTICLE.ACCOUNT_ID))
|
||||||
|
.where(ACCOUNT.USER_NAME.eq("x"));
|
||||||
|
IDialect dialect = new CommonsDialectImpl();
|
||||||
|
String sql = dialect.forDeleteByQuery(qw);
|
||||||
|
Assert.assertEquals("DELETE `tb_account` FROM `tb_account` " +
|
||||||
|
"LEFT JOIN `tb_article` ON `tb_account`.`id` = `tb_article`.`account_id` " +
|
||||||
|
"WHERE `tb_account`.`user_name` = ?"
|
||||||
|
,sql);
|
||||||
|
System.out.println(sql);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testForUpdate() {
|
public void testForUpdate() {
|
||||||
IDialect dialect = new CommonsDialectImpl();
|
IDialect dialect = new CommonsDialectImpl();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user