fix: 修复嵌套空条件及表达式全被忽略时生成 NULL 导致 SQL 语义错误的问题
1. 嵌套子条件为空时也应返回对应逻辑类型的单位元(AND为true,OR为false), 而不是只在根条件生效,否则空子条件会在父级拼接出 NULL,污染整个 WHERE 子句 2. 表达式因 IsIgnoreEmptyParma 被全部过滤后 conditions 为空的情况, 同样需要按 AND/OR 返回单位元,避免拼出空的表达式列表
This commit is contained in:
+3
-3
@@ -108,10 +108,10 @@ func (this Condition) ToSql(m TokenValue) db.Expression {
|
||||
conditions = append(conditions, item.ToSql(m))
|
||||
}
|
||||
|
||||
if this.IsEmpty() {
|
||||
if this.parent == nil && this.Type() == OR {
|
||||
if this.IsEmpty() || len(conditions) == 0 {
|
||||
if this.Type() == OR {
|
||||
return db.V(false)
|
||||
} else if this.parent == nil && this.Type() == AND {
|
||||
} else if this.Type() == AND {
|
||||
return db.V(true)
|
||||
}
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user