From 583af3aed6cc787ad099d141d1169d684b3ed391 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Fri, 6 May 2016 18:31:43 +0800 Subject: [PATCH] =?UTF-8?q?Query=E7=B1=BBvalue=E5=92=8Ccolumn=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E5=AF=B9=E8=B0=83=E7=94=A8field=E9=93=BE=E5=BC=8F?= =?UTF-8?q?=E6=93=8D=E4=BD=9C=E6=96=B9=E6=B3=95=E7=9A=84=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/db/Query.php | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/library/think/db/Query.php b/library/think/db/Query.php index bcd46730..8e2a67cf 100644 --- a/library/think/db/Query.php +++ b/library/think/db/Query.php @@ -81,7 +81,7 @@ class Query protected function builder() { static $builder = []; - $driver = $this->driver; + $driver = $this->driver; if (!isset($builder[$driver])) { $class = '\\think\\db\\builder\\' . ucfirst($driver); $builder[$driver] = new $class($this->connection); @@ -107,6 +107,9 @@ class Query $result = Cache::get($key); } if (!$result) { + if (isset($this->options['field'])) { + unset($this->options['field']); + } $pdo = $this->field($field)->fetchPdo(true)->find(); $result = $pdo->fetchColumn(); if (isset($cache)) { @@ -137,6 +140,9 @@ class Query $result = Cache::get($guid); } if (!$result) { + if (isset($this->options['field'])) { + unset($this->options['field']); + } if ($key && '*' != $field) { $field = $key . ',' . $field; } @@ -365,7 +371,7 @@ class Query } if (count($join)) { // 有设置第二个元素则把第二元素作为表前缀 - $table = (string)current($join) . $table; + $table = (string) current($join) . $table; } elseif (false === strpos($table, '.')) { // 加上默认的表前缀 $table = $prefix . $table; @@ -497,7 +503,7 @@ class Query protected function parseWhereExp($operator, $field, $op, $condition, $param = []) { if ($field instanceof \Closure) { - call_user_func_array($field, [& $this]); + call_user_func_array($field, [ & $this]); return; } @@ -640,16 +646,15 @@ class Query $class = (!empty($config['namespace']) ? $config['namespace'] : '\\think\\paginator\\driver\\') . ucwords($config['type']); - $page = isset($config['page']) ? (int)$config['page'] : call_user_func([ + $page = isset($config['page']) ? (int) $config['page'] : call_user_func([ $class, - 'getCurrentPage' + 'getCurrentPage', ], $config['var_page']); $page = $page < 1 ? 1 : $page; $config['path'] = isset($config['path']) ? $config['path'] : call_user_func([$class, 'getCurrentPath']); - /** @var Paginator $paginator */ if (!$simple) { $options = $this->getOptions(); @@ -947,7 +952,7 @@ class Query if (!isset($_info[$guid])) { $info = $this->connection->getFields($tableName); $fields = array_keys($info); - $bind = $type = []; + $bind = $type = []; foreach ($info as $key => $val) { // 记录字段类型 $type[$key] = $val['type']; @@ -1054,7 +1059,7 @@ class Query $relation = $key; $with[$key] = $key; } elseif (is_string($relation) && strpos($relation, '.')) { - $with[$key] = $relation; + $with[$key] = $relation; list($relation, $subRelation) = explode('.', $relation, 2); } @@ -1074,7 +1079,7 @@ class Query $this->join($joinTable . ' ' . $joinName, $name . '.' . $info['localKey'] . '=' . $joinName . '.' . $info['foreignKey'])->field(true, false, $joinTable, $joinName, $joinName . '__'); if ($closure) { // 执行闭包查询 - call_user_func_array($closure, [& $this]); + call_user_func_array($closure, [ & $this]); } $i++; } elseif ($closure) { @@ -1275,7 +1280,7 @@ class Query if ($data instanceof Query) { return $data->select(); } elseif ($data instanceof \Closure) { - call_user_func_array($data, [& $this]); + call_user_func_array($data, [ & $this]); } // 分析查询表达式 $options = $this->parseExpress(); @@ -1358,7 +1363,7 @@ class Query if ($data instanceof Query) { return $data->find(); } elseif ($data instanceof \Closure) { - call_user_func_array($data, [& $this]); + call_user_func_array($data, [ & $this]); } // 分析查询表达式 $options = $this->parseExpress(); @@ -1549,10 +1554,10 @@ class Query if (isset($options['page'])) { // 根据页数计算limit list($page, $listRows) = $options['page']; - $page = $page > 0 ? $page : 1; - $listRows = $listRows > 0 ? $listRows : (is_numeric($options['limit']) ? $options['limit'] : 20); - $offset = $listRows * ($page - 1); - $options['limit'] = $offset . ',' . $listRows; + $page = $page > 0 ? $page : 1; + $listRows = $listRows > 0 ? $listRows : (is_numeric($options['limit']) ? $options['limit'] : 20); + $offset = $listRows * ($page - 1); + $options['limit'] = $offset . ',' . $listRows; } $this->options = [];