From 52ac75a29a78da07d85e0829cf4dec3cf7e875f0 Mon Sep 17 00:00:00 2001 From: Jinzhu Date: Sun, 3 Jan 2016 20:23:37 +0800 Subject: [PATCH] Use []byte as condtions --- scope_private.go | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/scope_private.go b/scope_private.go index 1d3b57b8..4c5385d1 100644 --- a/scope_private.go +++ b/scope_private.go @@ -48,12 +48,16 @@ func (scope *Scope) buildWhereCondition(clause map[string]interface{}) (str stri for _, arg := range args { switch reflect.ValueOf(arg).Kind() { case reflect.Slice: // For where("id in (?)", []int64{1,2}) - values := reflect.ValueOf(arg) - var tempMarks []string - for i := 0; i < values.Len(); i++ { - tempMarks = append(tempMarks, scope.AddToVars(values.Index(i).Interface())) + if bytes, ok := arg.([]byte); ok { + scope.AddToVars(bytes) + } else { + values := reflect.ValueOf(arg) + var tempMarks []string + for i := 0; i < values.Len(); i++ { + tempMarks = append(tempMarks, scope.AddToVars(values.Index(i).Interface())) + } + str = strings.Replace(str, "?", strings.Join(tempMarks, ","), 1) } - str = strings.Replace(str, "?", strings.Join(tempMarks, ","), 1) default: if valuer, ok := interface{}(arg).(driver.Valuer); ok { arg, _ = valuer.Value()