diff --git a/library/think/db/Builder.php b/library/think/db/Builder.php index d579e9b9..e07e51e7 100644 --- a/library/think/db/Builder.php +++ b/library/think/db/Builder.php @@ -311,7 +311,7 @@ abstract class Builder $whereStr .= $key . ' ' . $exp . ' ' . $this->parseValue($value); } elseif ('EXP' == $exp) { // 表达式查询 - $whereStr .= $key . ' ' . $value; + $whereStr .= '( ' . $key . ' ' . $value . ' )'; } elseif (in_array($exp, ['NOT NULL', 'NULL'])) { // NULL 查询 $whereStr .= $key . ' IS ' . $exp; diff --git a/library/think/db/Query.php b/library/think/db/Query.php index b54e84d4..26ab13cc 100644 --- a/library/think/db/Query.php +++ b/library/think/db/Query.php @@ -491,7 +491,13 @@ class Query if (is_string($field) && !empty($this->options['via'])) { $field = $this->options['via'] . '.' . $field; } - if (is_null($op) && is_null($condition)) { + if (is_string($field) && strpos($field, ' ')) { + $where[] = ['exp', $field]; + if (is_array($op)) { + // 参数绑定 + $this->bind($op); + } + } elseif (is_null($op) && is_null($condition)) { if (is_array($field)) { // 数组批量查询 $where = $field;