From 850376dfe7bdbe40d5be8acc05ee1d6e44205a1a Mon Sep 17 00:00:00 2001 From: thinkphp Date: Tue, 21 Jun 2016 10:58:19 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E8=BF=9BQuery=E7=B1=BB=E7=9A=84find?= =?UTF-8?q?=E5=92=8Cselect=E6=96=B9=E6=B3=95=E7=9A=84=E9=BB=98=E8=AE=A4?= =?UTF-8?q?=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Model.php | 36 +++++++++++++++++------------------ library/think/db/Query.php | 12 ++++++------ library/think/model/Merge.php | 6 +++--- 3 files changed, 27 insertions(+), 27 deletions(-) diff --git a/library/think/Model.php b/library/think/Model.php index 196fa8f2..166445d9 100644 --- a/library/think/Model.php +++ b/library/think/Model.php @@ -248,7 +248,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess $value = $_SERVER['REQUEST_TIME']; break; } - } elseif (is_string($this->autoWriteTimestamp) && in_array(strtolower($this->autoWriteTimestamp),['datetime','date','timestamp'])) { + } elseif (is_string($this->autoWriteTimestamp) && in_array(strtolower($this->autoWriteTimestamp), ['datetime', 'date', 'timestamp'])) { $value = date($this->dateFormat, $_SERVER['REQUEST_TIME']); } else { $value = $_SERVER['REQUEST_TIME']; @@ -282,9 +282,9 @@ abstract class Model implements \JsonSerializable, \ArrayAccess */ protected function writeTransform($value, $type) { - if(is_array($type)){ - list($type,$param) = $type; - }elseif (strpos($type, ':')) { + if (is_array($type)) { + list($type, $param) = $type; + } elseif (strpos($type, ':')) { list($type, $param) = explode(':', $type, 2); } switch ($type) { @@ -318,12 +318,12 @@ abstract class Model implements \JsonSerializable, \ArrayAccess case 'array': $value = (array) $value; case 'json': - $option = !empty($param) ? (int)$param : JSON_UNESCAPED_UNICODE; + $option = !empty($param) ? (int) $param : JSON_UNESCAPED_UNICODE; $value = json_encode($value, $option); break; case 'serialize': $value = serialize($value); - break; + break; } return $value; } @@ -363,9 +363,9 @@ abstract class Model implements \JsonSerializable, \ArrayAccess */ protected function readTransform($value, $type) { - if(is_array($type)){ - list($type,$param) = $type; - }elseif (strpos($type, ':')) { + if (is_array($type)) { + list($type, $param) = $type; + } elseif (strpos($type, ':')) { list($type, $param) = explode(':', $type, 2); } switch ($type) { @@ -399,7 +399,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess break; case 'serialize': $value = unserialize($value); - break; + break; } return $value; } @@ -636,7 +636,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess public function saveAll($dataSet) { $result = 0; - $db = $this->db(); + $db = $this->db(); $db->startTrans(); try { foreach ($dataSet as $data) { @@ -881,7 +881,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess * @return static * @throws exception\DbException */ - public static function get($data = '', $with = [], $cache = false) + public static function get($data = null, $with = [], $cache = false) { $query = self::parseQuery($data, $with, $cache); return $query->find($data); @@ -896,7 +896,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess * @return static[]|false * @throws exception\DbException */ - public static function all($data = [], $with = [], $cache = false) + public static function all($data = null, $with = [], $cache = false) { $query = self::parseQuery($data, $with, $cache); return $query->select($data); @@ -915,13 +915,13 @@ abstract class Model implements \JsonSerializable, \ArrayAccess $result = self::with($with)->cache($cache); if (is_array($data) && key($data) !== 0) { $result = $result->where($data); - $data = []; + $data = null; } elseif ($data instanceof \Closure) { call_user_func_array($data, [ & $result]); - $data = []; + $data = null; } elseif ($data instanceof Query) { $result = $data->with($with)->cache($cache); - $data = []; + $data = null; } return $result; } @@ -938,10 +938,10 @@ abstract class Model implements \JsonSerializable, \ArrayAccess $query = $model->db(); if (is_array($data) && key($data) !== 0) { $query->where($data); - $data = []; + $data = null; } elseif ($data instanceof \Closure) { call_user_func_array($data, [ & $query]); - $data = []; + $data = null; } $resultSet = $query->select($data); $count = 0; diff --git a/library/think/db/Query.php b/library/think/db/Query.php index cc248e0d..df66fa07 100644 --- a/library/think/db/Query.php +++ b/library/think/db/Query.php @@ -1703,13 +1703,13 @@ class Query * @throws Exception * @throws PDOException */ - public function select($data = []) + public function select($data = null) { if ($data instanceof Query) { return $data->select(); } elseif ($data instanceof \Closure) { call_user_func_array($data, [ & $this]); - $data = []; + $data = null; } // 分析查询表达式 $options = $this->parseExpress(); @@ -1717,7 +1717,7 @@ class Query if (false === $data) { // 用于子查询 不查询只返回SQL $options['fetch_sql'] = true; - } elseif (!empty($data)) { + } elseif (!is_null($data)) { // 主键条件分析 $this->parsePkWhere($data, $options); } @@ -1790,18 +1790,18 @@ class Query * @throws Exception * @throws PDOException */ - public function find($data = []) + public function find($data = null) { if ($data instanceof Query) { return $data->find(); } elseif ($data instanceof \Closure) { call_user_func_array($data, [ & $this]); - $data = []; + $data = null; } // 分析查询表达式 $options = $this->parseExpress(); - if (!empty($data) || 0 === $data) { + if (!is_null($data)) { // AR模式分析主键条件 $this->parsePkWhere($data, $options); } diff --git a/library/think/model/Merge.php b/library/think/model/Merge.php index 2f3b3e5d..8ade20ce 100644 --- a/library/think/model/Merge.php +++ b/library/think/model/Merge.php @@ -44,7 +44,7 @@ class Merge extends Model * @param bool $cache 是否缓存 * @return \think\Model */ - public static function get($data = '', $with = [], $cache = false) + public static function get($data = null, $with = [], $cache = false) { $query = self::parseQuery($data, $with, $cache); $query = self::attachQuery($query); @@ -106,7 +106,7 @@ class Merge extends Model * @param string $with 关联预查询 * @return array|false|string */ - public static function all($data = [], $with = [], $cache = false) + public static function all($data = null, $with = [], $cache = false) { $query = self::parseQuery($data, $with, $cache); $query = self::attachQuery($query); @@ -193,7 +193,7 @@ class Merge extends Model unset($data[$pk]); } } - + // 处理模型数据 $data = $this->parseData($this->name, $this->data); // 写入主表数据