Skip to content

Commit 49301af

Browse files
committed
fix count
1 parent 1989c59 commit 49301af

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

ormlite.go

+7-4
Original file line numberDiff line numberDiff line change
@@ -1001,22 +1001,25 @@ func Count(db *sql.DB, m Model, opts *Options) (count int64, err error) {
10011001
divider = opts.Divider
10021002
for f, v := range opts.Where {
10031003
if v != nil {
1004-
switch reflect.TypeOf(v).Kind() {
1004+
value := reflect.ValueOf(v)
1005+
switch value.Kind() {
10051006
case reflect.Slice:
10061007
if strings.Contains(f, ",") {
10071008
rowValueCount := len(strings.Split(f, ","))
1008-
for i := 0; i < len(v.([]interface{}))/rowValueCount; i++ {
1009+
for i := 0; i < value.Len()/rowValueCount; i++ {
10091010
query.WriteString("(" + f + ") = (" + strings.Trim(strings.Repeat("?,", rowValueCount), ",") + ")" + divider)
10101011
}
10111012
opts.Divider = OR
10121013
} else {
1013-
count := len(v.([]interface{}))
1014+
count := value.Len()
10141015
if opts.Limit != 0 && opts.Limit < count {
10151016
count = opts.Limit
10161017
}
10171018
query.WriteString(f + " in (" + strings.Trim(strings.Repeat("?,", count), ",") + ")" + divider)
10181019
}
1019-
args = append(args, v.([]interface{})...)
1020+
for i := 0; i < value.Len(); i++ {
1021+
args = append(args, value.Index(i).Interface())
1022+
}
10201023
case reflect.String:
10211024
query.WriteString(f + " like ?" + divider)
10221025
args = append(args, fmt.Sprintf("%%%s%%", v))

0 commit comments

Comments
 (0)