Skip to content

Commit

Permalink
Merge pull request jmoiron#340 from npiganeau/patch-2
Browse files Browse the repository at this point in the history
[]byte should not be expanded by In
  • Loading branch information
jmoiron authored Feb 28, 2018
2 parents 5800ac0 + 364f96a commit 9adbc06
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
3 changes: 2 additions & 1 deletion bind.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ func In(query string, args ...interface{}) (string, []interface{}, error) {
v := reflect.ValueOf(arg)
t := reflectx.Deref(v.Type())

if t.Kind() == reflect.Slice {
// []byte is a driver.Value type so it should not be expanded
if t.Kind() == reflect.Slice && t != reflect.TypeOf([]byte{}) {
meta[i].length = v.Len()
meta[i].v = v

Expand Down
3 changes: 3 additions & 0 deletions sqlx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1497,6 +1497,9 @@ func TestIn(t *testing.T) {
{"SELECT * FROM foo WHERE x in (?)",
[]interface{}{[]int{1, 2, 3, 4, 5, 6, 7, 8}},
8},
{"SELECT * FROM foo WHERE x = ? AND y in (?)",
[]interface{}{[]byte("foo"), []int{0, 5, 3}},
4},
}
for _, test := range tests {
q, a, err := In(test.q, test.args...)
Expand Down

0 comments on commit 9adbc06

Please sign in to comment.