From 239a8729a669dc4e24b9be359b1cd3da17f1b535 Mon Sep 17 00:00:00 2001 From: xing Date: Fri, 16 Sep 2022 23:03:55 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- models/model.go | 49 ++++++++++++++++++------------------------------- 1 file changed, 18 insertions(+), 31 deletions(-) diff --git a/models/model.go b/models/model.go index c774cd2..77115c1 100644 --- a/models/model.go +++ b/models/model.go @@ -91,38 +91,25 @@ func (w SqlBuilder) ParseWhere(in ...[]interface{}) (string, []interface{}) { for i := 0; i < j; i++ { start := i * 5 end := start + 5 - if ss[start] == "or" { - st := s.String() - if strings.Contains(st, "and ") { - st = strings.TrimRight(st, "and ") - s.Reset() - s.WriteString(st) - s.WriteString(" or ") - } - if i == 0 { - s.WriteString("( ") - fl = true - } - - w.parseField(ss[start+1:end], &s) - if w.parseIn(ss[start+1:end], &s, &c, &args, in) { - s.WriteString(" and ") - continue - } - s.WriteString(ss[start+2]) - s.WriteString(" ? and ") - w.parseType(ss[start+1:end], &s, &args) - } else { - w.parseField(ss[start+1:end], &s) - if w.parseIn(ss[start+1:end], &s, &c, &args, in) { - s.WriteString(" and ") - continue - } - s.WriteString(ss[start+2]) - s.WriteString(" ? and ") - w.parseType(ss[start+1:start+4], &s, &args) - + st := s.String() + if strings.Contains(st, "and ") && ss[start] == "or" { + st = strings.TrimRight(st, "and ") + s.Reset() + s.WriteString(st) + s.WriteString(fmt.Sprintf(" %s ", ss[start])) } + if i == 0 { + s.WriteString("( ") + fl = true + } + w.parseField(ss[start+1:end], &s) + if w.parseIn(ss[start+1:end], &s, &c, &args, in) { + s.WriteString(" and ") + continue + } + s.WriteString(ss[start+2]) + s.WriteString(" ? and ") + w.parseType(ss[start+1:end], &s, &args) if i == j-1 && fl { st := s.String() st = strings.TrimRight(st, "and ")