Skip to content

Commit

Permalink
fix a bug about COUNT Quote
Browse files Browse the repository at this point in the history
  • Loading branch information
xgfone committed Apr 6, 2024
1 parent 05ff370 commit 65bad94
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions dml_select.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,25 +129,22 @@ type SelectBuilder struct {

// Count returns a COUNT(field).
func Count(field string) string {
if strings.ContainsAny(field, " `") {
return strings.Join([]string{"COUNT(", ")"}, field)
}
return strings.Join([]string{"COUNT(`", "`)"}, field)
return strings.Join([]string{"COUNT(", ")"}, field)
}

// CountDistinct returns a COUNT(DISTINCT field).
func CountDistinct(field string) string {
return strings.Join([]string{"COUNT(DISTINCT `", "`)"}, field)
return strings.Join([]string{"COUNT(DISTINCT ", ")"}, field)
}

// SelectCount appends the selected COUNT(field) column in SELECT.
func (b *SelectBuilder) SelectCount(field string) *SelectBuilder {
return b.Select(Count(field))
return b.Select(Count(b.db.GetDialect().Quote(field)))
}

// SelectCountDistinct appends the selected COUNT(DISTINCT field) column in SELECT.
func (b *SelectBuilder) SelectCountDistinct(field string) *SelectBuilder {
return b.Select(CountDistinct(field))
return b.Select(CountDistinct(b.db.GetDialect().Quote(field)))
}

// Distinct marks SELECT as DISTINCT.
Expand Down

0 comments on commit 65bad94

Please sign in to comment.