mirror of https://github.com/go-gorm/gorm.git
Fix tests & refactor for PR #3429
This commit is contained in:
parent
aceb3dad3b
commit
2242ac6c0e
|
@ -39,12 +39,13 @@ func (expr Expr) Build(builder Builder) {
|
|||
case reflect.Slice, reflect.Array:
|
||||
if rv.Len() == 0 {
|
||||
builder.AddVar(builder, nil)
|
||||
}
|
||||
for i := 0; i < rv.Len(); i++ {
|
||||
if i > 0 {
|
||||
builder.WriteByte(',')
|
||||
} else {
|
||||
for i := 0; i < rv.Len(); i++ {
|
||||
if i > 0 {
|
||||
builder.WriteByte(',')
|
||||
}
|
||||
builder.AddVar(builder, rv.Index(i).Interface())
|
||||
}
|
||||
builder.AddVar(builder, rv.Index(i).Interface())
|
||||
}
|
||||
default:
|
||||
builder.AddVar(builder, expr.Vars[idx])
|
||||
|
|
|
@ -6,6 +6,10 @@ require (
|
|||
github.com/google/uuid v1.1.1
|
||||
github.com/jinzhu/now v1.1.1
|
||||
github.com/lib/pq v1.6.0
|
||||
gorm.io/driver/mysql v1.0.1
|
||||
gorm.io/driver/postgres v1.0.0
|
||||
gorm.io/driver/sqlite v1.1.1
|
||||
gorm.io/driver/sqlserver v1.0.3
|
||||
gorm.io/gorm v1.9.19
|
||||
)
|
||||
|
||||
|
|
|
@ -204,7 +204,7 @@ func TestFind(t *testing.T) {
|
|||
})
|
||||
|
||||
var models []User
|
||||
if err := DB.Where("name in ?", []string{"find"}).Find(&models).Error; err != nil || len(models) != 3 {
|
||||
if err := DB.Where("name in (?)", []string{"find"}).Find(&models).Error; err != nil || len(models) != 3 {
|
||||
t.Errorf("errors happened when query find with in clause: %v, length: %v", err, len(models))
|
||||
} else {
|
||||
for idx, user := range users {
|
||||
|
@ -215,7 +215,7 @@ func TestFind(t *testing.T) {
|
|||
}
|
||||
|
||||
var none []User
|
||||
if err := DB.Where("name in ?", []string{}).Find(&none).Error; err != nil || len(none) != 0 {
|
||||
if err := DB.Where("name in (?)", []string{}).Find(&none).Error; err != nil || len(none) != 0 {
|
||||
t.Errorf("errors happened when query find with in clause and zero length parameter: %v, length: %v", err, len(none))
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue