Skip to content

Commit

Permalink
Merge 6c172cd into 42baf69
Browse files Browse the repository at this point in the history
  • Loading branch information
spencerkimball committed Mar 4, 2016
2 parents 42baf69 + 6c172cd commit 1a5ed3b
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion named.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ func (s *SQLBinder) named(c *decoded, arg interface{}, opts ...NamedOption) (str
sql.WriteString(p.data)
case typePlaceholder:
val, _ := value(p.data, arg, e.args...)
if rval := reflect.ValueOf(val); rval.Kind() == reflect.Slice {
if rval := reflect.ValueOf(val); shouldExpandSlice(rval) {
for si := 0; si < rval.Len(); si++ {
if si != 0 {
sql.WriteString(", ")
Expand All @@ -305,6 +305,17 @@ func (s *SQLBinder) named(c *decoded, arg interface{}, opts ...NamedOption) (str
return sql.String(), args, nil
}

func shouldExpandSlice(rval reflect.Value) bool {
if rval.Kind() != reflect.Slice {
return false
}
// Do not expand byte slices, which correspond to BLOB or BYTES SQL types.
if rval.Type().Elem().Kind() == reflect.Uint8 {
return false
}
return true
}

func (s *SQLBinder) writePlaceholder(buf *bytes.Buffer, i int) {
switch s.style {
case PostgreSQL:
Expand Down

0 comments on commit 1a5ed3b

Please sign in to comment.