forked from mirror/gorm
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:
|
case reflect.Slice, reflect.Array:
|
||||||
if rv.Len() == 0 {
|
if rv.Len() == 0 {
|
||||||
builder.AddVar(builder, nil)
|
builder.AddVar(builder, nil)
|
||||||
}
|
} else {
|
||||||
for i := 0; i < rv.Len(); i++ {
|
for i := 0; i < rv.Len(); i++ {
|
||||||
if i > 0 {
|
if i > 0 {
|
||||||
builder.WriteByte(',')
|
builder.WriteByte(',')
|
||||||
|
}
|
||||||
|
builder.AddVar(builder, rv.Index(i).Interface())
|
||||||
}
|
}
|
||||||
builder.AddVar(builder, rv.Index(i).Interface())
|
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
builder.AddVar(builder, expr.Vars[idx])
|
builder.AddVar(builder, expr.Vars[idx])
|
||||||
|
|
|
@ -6,6 +6,10 @@ require (
|
||||||
github.com/google/uuid v1.1.1
|
github.com/google/uuid v1.1.1
|
||||||
github.com/jinzhu/now v1.1.1
|
github.com/jinzhu/now v1.1.1
|
||||||
github.com/lib/pq v1.6.0
|
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
|
gorm.io/gorm v1.9.19
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -204,7 +204,7 @@ func TestFind(t *testing.T) {
|
||||||
})
|
})
|
||||||
|
|
||||||
var models []User
|
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))
|
t.Errorf("errors happened when query find with in clause: %v, length: %v", err, len(models))
|
||||||
} else {
|
} else {
|
||||||
for idx, user := range users {
|
for idx, user := range users {
|
||||||
|
@ -215,7 +215,7 @@ func TestFind(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
var none []User
|
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))
|
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