make Count compatible with Select with Count func, close #3962

This commit is contained in:
Jinzhu 2021-01-18 19:43:04 +08:00
parent 4a15540504
commit 3d87575e7e
1 changed files with 1 additions and 1 deletions

View File

@ -378,7 +378,7 @@ func (db *DB) Count(count *int64) (tx *DB) {
if len(tx.Statement.Selects) == 0 { if len(tx.Statement.Selects) == 0 {
tx.Statement.AddClause(clause.Select{Expression: clause.Expr{SQL: "count(1)"}}) tx.Statement.AddClause(clause.Select{Expression: clause.Expr{SQL: "count(1)"}})
} else if !strings.Contains(strings.ToLower(tx.Statement.Selects[0]), "count(") { } else if !strings.HasPrefix(strings.TrimSpace(strings.ToLower(tx.Statement.Selects[0])), "count(") {
expr := clause.Expr{SQL: "count(1)"} expr := clause.Expr{SQL: "count(1)"}
if len(tx.Statement.Selects) == 1 { if len(tx.Statement.Selects) == 1 {