mirror of https://github.com/go-gorm/gorm.git
Fix Eq, Neq support slice of data
This commit is contained in:
parent
14e96080d8
commit
9abac96546
|
@ -241,7 +241,7 @@ func (eq Eq) Build(builder Builder) {
|
||||||
if i > 0 {
|
if i > 0 {
|
||||||
builder.WriteByte(',')
|
builder.WriteByte(',')
|
||||||
}
|
}
|
||||||
builder.AddVar(builder, rv.Index(i))
|
builder.AddVar(builder, rv.Index(i).Interface())
|
||||||
}
|
}
|
||||||
builder.WriteByte(')')
|
builder.WriteByte(')')
|
||||||
default:
|
default:
|
||||||
|
@ -272,7 +272,7 @@ func (neq Neq) Build(builder Builder) {
|
||||||
if i > 0 {
|
if i > 0 {
|
||||||
builder.WriteByte(',')
|
builder.WriteByte(',')
|
||||||
}
|
}
|
||||||
builder.AddVar(builder, rv.Index(i))
|
builder.AddVar(builder, rv.Index(i).Interface())
|
||||||
}
|
}
|
||||||
builder.WriteByte(')')
|
builder.WriteByte(')')
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -106,11 +106,13 @@ func TestExpression(t *testing.T) {
|
||||||
column := "column-name"
|
column := "column-name"
|
||||||
results := []struct {
|
results := []struct {
|
||||||
Expressions []clause.Expression
|
Expressions []clause.Expression
|
||||||
|
ExpectedVars []interface{}
|
||||||
Result string
|
Result string
|
||||||
}{{
|
}{{
|
||||||
Expressions: []clause.Expression{
|
Expressions: []clause.Expression{
|
||||||
clause.Eq{Column: column, Value: "column-value"},
|
clause.Eq{Column: column, Value: "column-value"},
|
||||||
},
|
},
|
||||||
|
ExpectedVars: []interface{}{"column-value"},
|
||||||
Result: "`column-name` = ?",
|
Result: "`column-name` = ?",
|
||||||
}, {
|
}, {
|
||||||
Expressions: []clause.Expression{
|
Expressions: []clause.Expression{
|
||||||
|
@ -126,6 +128,7 @@ func TestExpression(t *testing.T) {
|
||||||
Expressions: []clause.Expression{
|
Expressions: []clause.Expression{
|
||||||
clause.Neq{Column: column, Value: "column-value"},
|
clause.Neq{Column: column, Value: "column-value"},
|
||||||
},
|
},
|
||||||
|
ExpectedVars: []interface{}{"column-value"},
|
||||||
Result: "`column-name` <> ?",
|
Result: "`column-name` <> ?",
|
||||||
}, {
|
}, {
|
||||||
Expressions: []clause.Expression{
|
Expressions: []clause.Expression{
|
||||||
|
@ -140,11 +143,13 @@ func TestExpression(t *testing.T) {
|
||||||
Expressions: []clause.Expression{
|
Expressions: []clause.Expression{
|
||||||
clause.Eq{Column: column, Value: []string{"a", "b"}},
|
clause.Eq{Column: column, Value: []string{"a", "b"}},
|
||||||
},
|
},
|
||||||
|
ExpectedVars: []interface{}{"a", "b"},
|
||||||
Result: "`column-name` IN (?,?)",
|
Result: "`column-name` IN (?,?)",
|
||||||
}, {
|
}, {
|
||||||
Expressions: []clause.Expression{
|
Expressions: []clause.Expression{
|
||||||
clause.Neq{Column: column, Value: []string{"a", "b"}},
|
clause.Neq{Column: column, Value: []string{"a", "b"}},
|
||||||
},
|
},
|
||||||
|
ExpectedVars: []interface{}{"a", "b"},
|
||||||
Result: "`column-name` NOT IN (?,?)",
|
Result: "`column-name` NOT IN (?,?)",
|
||||||
}}
|
}}
|
||||||
|
|
||||||
|
@ -157,6 +162,10 @@ func TestExpression(t *testing.T) {
|
||||||
if stmt.SQL.String() != result.Result {
|
if stmt.SQL.String() != result.Result {
|
||||||
t.Errorf("generated SQL is not equal, expects %v, but got %v", result.Result, stmt.SQL.String())
|
t.Errorf("generated SQL is not equal, expects %v, but got %v", result.Result, stmt.SQL.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !reflect.DeepEqual(result.ExpectedVars, stmt.Vars) {
|
||||||
|
t.Errorf("generated vars is not equal, expects %v, but got %v", result.ExpectedVars, stmt.Vars)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue