mirror of https://github.com/go-gorm/gorm.git
Fix clause.IN with only one value of multiple rows
This commit is contained in:
parent
9df9f7688b
commit
694e42d6a1
|
@ -160,8 +160,13 @@ func (in IN) Build(builder Builder) {
|
||||||
case 0:
|
case 0:
|
||||||
builder.WriteString(" IN (NULL)")
|
builder.WriteString(" IN (NULL)")
|
||||||
case 1:
|
case 1:
|
||||||
builder.WriteString(" = ")
|
if _, ok := in.Values[0].([]interface{}); !ok {
|
||||||
builder.AddVar(builder, in.Values...)
|
builder.WriteString(" = ")
|
||||||
|
builder.AddVar(builder, in.Values[0])
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
fallthrough
|
||||||
default:
|
default:
|
||||||
builder.WriteString(" IN (")
|
builder.WriteString(" IN (")
|
||||||
builder.AddVar(builder, in.Values...)
|
builder.AddVar(builder, in.Values...)
|
||||||
|
@ -173,9 +178,14 @@ func (in IN) NegationBuild(builder Builder) {
|
||||||
switch len(in.Values) {
|
switch len(in.Values) {
|
||||||
case 0:
|
case 0:
|
||||||
case 1:
|
case 1:
|
||||||
builder.WriteQuoted(in.Column)
|
if _, ok := in.Values[0].([]interface{}); !ok {
|
||||||
builder.WriteString(" <> ")
|
builder.WriteQuoted(in.Column)
|
||||||
builder.AddVar(builder, in.Values...)
|
builder.WriteString(" <> ")
|
||||||
|
builder.AddVar(builder, in.Values[0])
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
fallthrough
|
||||||
default:
|
default:
|
||||||
builder.WriteQuoted(in.Column)
|
builder.WriteQuoted(in.Column)
|
||||||
builder.WriteString(" NOT IN (")
|
builder.WriteString(" NOT IN (")
|
||||||
|
|
Loading…
Reference in New Issue