fix:AND GROUP 报错
This commit is contained in:
parent
36ba5041b8
commit
a2eb8010d3
@ -221,14 +221,7 @@ func SqlQuery(tx *gorm.DB, sql string, list interface{}, q *PaginationQuery, par
|
||||
|
||||
// 安全地添加 WHERE 子句
|
||||
if hasWhere(sql) { // 原SQL已有WHERE子句
|
||||
// 确保 where 子句以 AND 或 OR 开头,然后安全添加
|
||||
if strings.HasPrefix(where, " AND ") || strings.HasPrefix(where, " OR ") {
|
||||
builder.WriteString(where)
|
||||
} else {
|
||||
// 如果 where 不是以 AND/OR 开头,添加 AND 前缀
|
||||
builder.WriteString(" AND ")
|
||||
builder.WriteString(strings.TrimSpace(where))
|
||||
}
|
||||
builder.WriteString(where) // 去掉where 前头的and or ..
|
||||
} else { // 原SQL没有WHERE子句
|
||||
if strings.HasPrefix(where, " AND ") {
|
||||
where = strings.Replace(where, " AND ", " WHERE ", 1)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user