From 137ccfc458a6650e1df937c79869dfcca87e359d Mon Sep 17 00:00:00 2001 From: thinkphp Date: Sat, 14 Apr 2018 10:12:25 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E8=BF=9BinsertAll=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/db/Builder.php | 14 +++++++------- library/think/db/Query.php | 4 ++-- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/library/think/db/Builder.php b/library/think/db/Builder.php index d951c232..fb8ef195 100644 --- a/library/think/db/Builder.php +++ b/library/think/db/Builder.php @@ -391,7 +391,7 @@ abstract class Builder } } elseif ('EXP' == $exp) { // 表达式查询 - $whereStr .= '( ' . $key . ' ' . $value . ' )'; + $whereStr .= '( ' . $key . ' ' . ($value instanceof Expression ? $value->getValue() : $value) . ' )'; } elseif (in_array($exp, ['NOT NULL', 'NULL'])) { // NULL 查询 $whereStr .= $key . ' IS ' . $exp; @@ -673,11 +673,7 @@ abstract class Builder return ''; } - if (is_array($index)) { - $index = join(",", $index); - } - - return sprintf(" FORCE INDEX ( %s ) ", $index); + return sprintf(" FORCE INDEX ( %s ) ", is_array($index) ? implode(',', $index) : $index); } /** @@ -795,10 +791,14 @@ abstract class Builder $values[] = 'SELECT ' . implode(',', $value); if (!isset($insertFields)) { - $insertFields = array_map([$this, 'parseKey'], array_keys($data)); + $insertFields = array_keys($data); } } + foreach ($insertFields as $field) { + $fields[] = $this->parseKey($query, $field, true); + } + return str_replace( ['%INSERT%', '%TABLE%', '%FIELD%', '%DATA%', '%COMMENT%'], [ diff --git a/library/think/db/Query.php b/library/think/db/Query.php index 35cad2ef..205f1f33 100644 --- a/library/think/db/Query.php +++ b/library/think/db/Query.php @@ -883,7 +883,7 @@ class Query */ public function exp($field, $value) { - $this->data($field, ['exp', $value]); + $this->data($field, $this->raw($value)); return $this; } @@ -1188,7 +1188,7 @@ class Query */ public function whereExp($field, $condition, $logic = 'AND') { - $this->parseWhereExp($logic, $field, 'exp', $condition, [], true); + $this->parseWhereExp($logic, $field, 'exp', $this->raw($condition), [], true); return $this; }