Skip to content

Commit

Permalink
修正在WhereIn为空时尽量将对应字段查询转换Null查询或Not Null查询
Browse files Browse the repository at this point in the history
这样可避免在实际业务场景输入in空内容时程序不会出现500错误,并阻止因缺少限制字段而导致本不应该输出的数据被输出的问题

如果依赖ORM逻辑检测的用户,建议更新
  • Loading branch information
tobycroft committed Sep 11, 2023
1 parent 313c9ba commit d7db276
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions orm.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,30 +286,35 @@ func (dba *Orm) OrWhereNotRegexp(arg string, expstr string) IOrm {
func (dba *Orm) WhereIn(needle string, hystack []interface{}) IOrm {
if len(hystack) > 0 {
return dba.Where(needle, "IN", hystack)
} else {
return dba.WhereNull(needle)
}
return dba
}

// OrWhereIn ...
func (dba *Orm) OrWhereIn(needle string, hystack []interface{}) IOrm {
if len(hystack) > 0 {
dba.OrWhere(needle, "IN", hystack)
return dba.OrWhere(needle, "IN", hystack)
} else {
return dba.OrWhereNull(needle)
}
return dba
}

// WhereNotIn ...
func (dba *Orm) WhereNotIn(needle string, hystack []interface{}) IOrm {
if len(hystack) > 0 {
return dba.Where(needle, "NOT IN", hystack)
} else {
return dba.WhereNotNull(needle)
}
return dba
}

// OrWhereNotIn ...
func (dba *Orm) OrWhereNotIn(needle string, hystack []interface{}) IOrm {
if len(hystack) > 0 {
return dba.OrWhere(needle, "NOT IN", hystack)
dba.OrWhere(needle, "NOT IN", hystack)
} else {
dba.OrWhereNotNull(needle)
}
return dba
}
Expand Down

0 comments on commit d7db276

Please sign in to comment.