Merge pull request #822 from jseriff/master

Remove regex guess on counting query
This commit is contained in:
Jinzhu 2016-03-04 21:58:27 +08:00
commit f8377d80bf
1 changed files with 2 additions and 5 deletions

View File

@ -226,8 +226,6 @@ func (scope *Scope) whereSql() (sql string) {
return
}
var hasCountRegexp = regexp.MustCompile(`(?i)count\(.+\)`)
func (scope *Scope) selectSql() string {
if len(scope.Search.selects) == 0 {
if scope.Search.joins != "" {
@ -235,9 +233,7 @@ func (scope *Scope) selectSql() string {
}
return "*"
}
sql := scope.buildSelectQuery(scope.Search.selects)
scope.Search.countingQuery = (len(scope.Search.group) == 0) && hasCountRegexp.MatchString(sql)
return sql
return scope.buildSelectQuery(scope.Search.selects)
}
func (scope *Scope) orderSql() string {
@ -422,6 +418,7 @@ func (scope *Scope) pluck(column string, value interface{}) *Scope {
func (scope *Scope) count(value interface{}) *Scope {
scope.Search.Select("count(*)")
scope.Search.countingQuery = true
scope.Err(scope.row().Scan(value))
return scope
}