fixed: UpdateChain.toSQL()

This commit is contained in:
开源海哥 2023-07-30 09:37:38 +08:00
parent 60df82a231
commit 621f151aa5
2 changed files with 13 additions and 9 deletions

View File

@ -628,11 +628,13 @@ public class TableInfo {
if (value != null) { if (value != null) {
ColumnInfo columnInfo = columnInfoMapping.get(column); ColumnInfo columnInfo = columnInfoMapping.get(column);
if (columnInfo != null) {
TypeHandler typeHandler = columnInfo.buildTypeHandler(); TypeHandler typeHandler = columnInfo.buildTypeHandler();
if (typeHandler != null) { if (typeHandler != null) {
value = new TypeHandlerObject(typeHandler, value, columnInfo.getJdbcType()); value = new TypeHandlerObject(typeHandler, value, columnInfo.getJdbcType());
} }
} }
}
// ModifyAttrsRecord 忽略 ignoreNulls 的设置 // ModifyAttrsRecord 忽略 ignoreNulls 的设置
// 当使用 ModifyAttrsRecord 可以理解为要对字段进行 null 值进行更新否则没必要使用 ModifyAttrsRecord // 当使用 ModifyAttrsRecord 可以理解为要对字段进行 null 值进行更新否则没必要使用 ModifyAttrsRecord

View File

@ -25,10 +25,7 @@ import com.mybatisflex.core.query.QueryColumn;
import com.mybatisflex.core.query.QueryWrapperAdapter; import com.mybatisflex.core.query.QueryWrapperAdapter;
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.util.ClassUtil; import com.mybatisflex.core.util.*;
import com.mybatisflex.core.util.LambdaGetter;
import com.mybatisflex.core.util.SqlUtil;
import com.mybatisflex.core.util.UpdateEntity;
import java.lang.reflect.ParameterizedType; import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type; import java.lang.reflect.Type;
@ -124,6 +121,7 @@ public class UpdateChain<T> extends QueryWrapperAdapter<UpdateChain<T>> {
return SqlUtil.toBool(baseMapper.deleteByQuery(this)); return SqlUtil.toBool(baseMapper.deleteByQuery(this));
} }
public boolean update() { public boolean update() {
return SqlUtil.toBool(baseMapper.updateByQuery(entity, this)); return SqlUtil.toBool(baseMapper.updateByQuery(entity, this));
} }
@ -133,8 +131,12 @@ public class UpdateChain<T> extends QueryWrapperAdapter<UpdateChain<T>> {
public String toSQL() { public String toSQL() {
TableInfo tableInfo = TableInfoFactory.ofMapperClass(baseMapper.getClass()); TableInfo tableInfo = TableInfoFactory.ofMapperClass(baseMapper.getClass());
CPI.setFromIfNecessary(this, tableInfo.getSchema(), tableInfo.getTableName()); CPI.setFromIfNecessary(this, tableInfo.getSchema(), tableInfo.getTableName());
String sql = DialectFactory.getDialect().forUpdateEntityByQuery(tableInfo,entity,true,this); String sql = DialectFactory.getDialect().forUpdateEntityByQuery(tableInfo, entity, true, this);
return SqlUtil.replaceSqlParams(sql, CPI.getValueArray(this));
Object[] values = tableInfo.buildUpdateSqlArgs(entity, true, true);
values = ArrayUtil.concat(values, CPI.getValueArray(this));
return SqlUtil.replaceSqlParams(sql, values);
} }
} }