fix: fix '||' in Where condition but not wrap with brackets (#7002)
This commit is contained in:
parent
9d370bcb3e
commit
16ddae8dfa
@ -7,6 +7,8 @@ import (
|
|||||||
const (
|
const (
|
||||||
AndWithSpace = " AND "
|
AndWithSpace = " AND "
|
||||||
OrWithSpace = " OR "
|
OrWithSpace = " OR "
|
||||||
|
AndSymbolWithSpace = " && "
|
||||||
|
OrSymbolWithSpace = " || "
|
||||||
)
|
)
|
||||||
|
|
||||||
// Where where clause
|
// Where where clause
|
||||||
@ -58,22 +60,26 @@ func buildExprs(exprs []Expression, builder Builder, joinCond string) {
|
|||||||
if len(v.Exprs) == 1 {
|
if len(v.Exprs) == 1 {
|
||||||
if e, ok := v.Exprs[0].(Expr); ok {
|
if e, ok := v.Exprs[0].(Expr); ok {
|
||||||
sql := strings.ToUpper(e.SQL)
|
sql := strings.ToUpper(e.SQL)
|
||||||
wrapInParentheses = strings.Contains(sql, AndWithSpace) || strings.Contains(sql, OrWithSpace)
|
wrapInParentheses = strings.Contains(sql, AndWithSpace) || strings.Contains(sql, OrWithSpace) ||
|
||||||
|
strings.Contains(sql, AndSymbolWithSpace) || strings.Contains(sql, OrSymbolWithSpace)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case AndConditions:
|
case AndConditions:
|
||||||
if len(v.Exprs) == 1 {
|
if len(v.Exprs) == 1 {
|
||||||
if e, ok := v.Exprs[0].(Expr); ok {
|
if e, ok := v.Exprs[0].(Expr); ok {
|
||||||
sql := strings.ToUpper(e.SQL)
|
sql := strings.ToUpper(e.SQL)
|
||||||
wrapInParentheses = strings.Contains(sql, AndWithSpace) || strings.Contains(sql, OrWithSpace)
|
wrapInParentheses = strings.Contains(sql, AndWithSpace) || strings.Contains(sql, OrWithSpace) ||
|
||||||
|
strings.Contains(sql, AndSymbolWithSpace) || strings.Contains(sql, OrSymbolWithSpace)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case Expr:
|
case Expr:
|
||||||
sql := strings.ToUpper(v.SQL)
|
sql := strings.ToUpper(v.SQL)
|
||||||
wrapInParentheses = strings.Contains(sql, AndWithSpace) || strings.Contains(sql, OrWithSpace)
|
wrapInParentheses = strings.Contains(sql, AndWithSpace) || strings.Contains(sql, OrWithSpace) ||
|
||||||
|
strings.Contains(sql, AndSymbolWithSpace) || strings.Contains(sql, OrSymbolWithSpace)
|
||||||
case NamedExpr:
|
case NamedExpr:
|
||||||
sql := strings.ToUpper(v.SQL)
|
sql := strings.ToUpper(v.SQL)
|
||||||
wrapInParentheses = strings.Contains(sql, AndWithSpace) || strings.Contains(sql, OrWithSpace)
|
wrapInParentheses = strings.Contains(sql, AndWithSpace) || strings.Contains(sql, OrWithSpace) ||
|
||||||
|
strings.Contains(sql, AndSymbolWithSpace) || strings.Contains(sql, OrSymbolWithSpace)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user