Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions bind.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,9 +211,9 @@ func In(query string, args ...any) (string, []any, error) {

argMeta := meta[arg]
arg++
isSlice := argMeta.v.IsValid()

// not an in-list
if !inIn {
if !inIn || !isSlice {
newArgs = append(newArgs, argMeta.i)
buf.WriteString(token.Text)
continue
Expand Down
15 changes: 15 additions & 0 deletions bind_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ package sqlx
import (
"math/rand"
"testing"
"time"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func oldBindType(driverName string) int {
Expand Down Expand Up @@ -77,3 +81,14 @@ func BenchmarkBindSpeed(b *testing.B) {

})
}

func TestInNotSlice(t *testing.T) {
now := time.Now()
args := []any{[]string{"a", "b"}, now}
query := ` SELECT * FROM person WHERE first_name IN (?) AND id IN ( SELECT id FROM something WHERE created_at = ? )`
insql, newArgs, err := In(query, args...)
require.NoError(t, err)
assert.Contains(t, insql, "IN (?, ?)")
assert.Contains(t, insql, "WHERE created_at = ? )")
assert.Equal(t, []any{"a", "b", now}, newArgs)
}
Loading