Fix clause.IN with only one value of multiple rows

This commit is contained in:
Jinzhu 2020-11-17 19:11:16 +08:00
parent 9df9f7688b
commit 694e42d6a1
1 changed files with 15 additions and 5 deletions

View File

@ -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:
if _, ok := in.Values[0].([]interface{}); !ok {
builder.WriteString(" = ") builder.WriteString(" = ")
builder.AddVar(builder, in.Values...) 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:
if _, ok := in.Values[0].([]interface{}); !ok {
builder.WriteQuoted(in.Column) builder.WriteQuoted(in.Column)
builder.WriteString(" <> ") builder.WriteString(" <> ")
builder.AddVar(builder, in.Values...) 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 (")