From 810a88a48e3cc80660a4d84c924cf28140faa288 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Thu, 28 Apr 2016 14:19:55 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E8=BF=9Bwhere=E6=96=B9=E6=B3=95?= =?UTF-8?q?=E7=9A=84=E5=8E=9F=E7=94=9Fsql=E6=9D=A1=E4=BB=B6=20=E5=B9=B6?= =?UTF-8?q?=E4=B8=94=E6=94=AF=E6=8C=81=E5=8F=82=E6=95=B0=E7=BB=91=E5=AE=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/db/Builder.php | 2 +- library/think/db/Query.php | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) 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;