From a924186ce6f58f5ab140362a92ede82b898cb211 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Sat, 12 Nov 2016 10:38:19 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3count=20avg=E6=96=B9=E6=B3=95?= =?UTF-8?q?=E4=BD=BF=E7=94=A8fetchsql=E6=97=A0=E6=B3=95=E6=AD=A3=E7=A1=AE?= =?UTF-8?q?=E8=BF=94=E5=9B=9Esql=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/db/Query.php | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/library/think/db/Query.php b/library/think/db/Query.php index 3f4d5fd0..fdf9d623 100644 --- a/library/think/db/Query.php +++ b/library/think/db/Query.php @@ -378,7 +378,7 @@ class Query public function value($field, $default = null) { $result = false; - if (!empty($this->options['cache'])) { + if (empty($options['fetch_sql']) && !empty($this->options['cache'])) { // 判断查询缓存 $cache = $this->options['cache']; if (empty($this->options['table'])) { @@ -422,7 +422,7 @@ class Query public function column($field, $key = '') { $result = false; - if (!empty($this->options['cache'])) { + if (empty($options['fetch_sql']) && !empty($this->options['cache'])) { // 判断查询缓存 $cache = $this->options['cache']; if (empty($this->options['table'])) { @@ -489,7 +489,8 @@ class Query */ public function count($field = '*') { - return (int) $this->value('COUNT(' . $field . ') AS tp_count', 0); + $value = $this->value('COUNT(' . $field . ') AS tp_count', 0); + return is_numeric($value) ? (int) $value : $value; } /** @@ -500,7 +501,8 @@ class Query */ public function sum($field = '*') { - return $this->value('SUM(' . $field . ') AS tp_sum', 0) + 0; + $value = $this->value('SUM(' . $field . ') AS tp_sum', 0); + return is_numeric($value) ? $value + 0 : $value; } /** @@ -535,7 +537,8 @@ class Query */ public function avg($field = '*') { - return $this->value('AVG(' . $field . ') AS tp_avg', 0) + 0; + $value = $this->value('AVG(' . $field . ') AS tp_avg', 0); + return is_numeric($value) ? $value + 0 : $value; } /**