fix count() …

COUNT()函数逻辑有错误,本应该是在执行任何SQL的时候,都可以返回正确的行数。而现在复杂的SQL集合无法正确获取行数。
This commit is contained in:
Code 2017-08-29 18:50:40 +08:00
parent c3bb6aaa82
commit 56fffcb25b
1 changed files with 6 additions and 1 deletions

View File

@ -950,7 +950,12 @@ func (scope *Scope) pluck(column string, value interface{}) *Scope {
func (scope *Scope) count(value interface{}) *Scope {
if query, ok := scope.Search.selects["query"]; !ok || !countingQueryRegexp.MatchString(fmt.Sprint(query)) {
scope.Search.Select("count(*)")
if len(scope.Search.group) != 0 {
scope.Search.Select("count(*) FROM ( SELECT count(*) ")
scope.Search.group += " ) AS count"
} else {
scope.Search.Select("count(*)")
}
}
scope.Search.ignoreOrderQuery = true
scope.Err(scope.row().Scan(value))