From 29bd46caf57173fa526d1f2df68960aedc78e174 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Wed, 24 Aug 2016 16:12:05 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E8=BF=9B=E6=A8=A1=E5=9E=8B=E7=9A=84?= =?UTF-8?q?=E5=AD=97=E6=AE=B5=E4=BF=A1=E6=81=AF=E5=AE=9A=E4=B9=89=E7=AC=AC?= =?UTF-8?q?=E4=BA=8C=E6=AC=A1=E6=9F=A5=E8=AF=A2=E4=B8=8D=E7=94=9F=E6=95=88?= =?UTF-8?q?=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 | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/library/think/db/Query.php b/library/think/db/Query.php index d4bdac85..3b33b4ae 100644 --- a/library/think/db/Query.php +++ b/library/think/db/Query.php @@ -41,6 +41,12 @@ class Query protected $table = ''; // 当前数据表名称(不含前缀) protected $name = ''; + // 当前数据表主键 + protected $pk; + // 当前表字段类型信息 + protected $fieldType; + // 当前允许的字段列表 + protected $allowField; // 当前数据表前缀 protected $prefix = ''; // 查询参数 @@ -727,11 +733,11 @@ class Query } if (true === $field) { // 获取全部字段 - $fields = isset($this->options['allow_field']) ? $this->options['allow_field'] : $this->getTableInfo($tableName ?: (isset($this->options['table']) ? $this->options['table'] : ''), 'fields'); + $fields = isset($this->allowField) ? $this->allowField : $this->getTableInfo($tableName ?: (isset($this->options['table']) ? $this->options['table'] : ''), 'fields'); $field = $fields ?: ['*']; } elseif ($except) { // 字段排除 - $fields = isset($this->options['allow_field']) ? $this->options['allow_field'] : $this->getTableInfo($tableName ?: (isset($this->options['table']) ? $this->options['table'] : ''), 'fields'); + $fields = isset($this->allowField) ? $this->allowField : $this->getTableInfo($tableName ?: (isset($this->options['table']) ? $this->options['table'] : ''), 'fields'); $field = $fields ? array_diff($fields, $field) : $field; } if ($tableName) { @@ -1255,7 +1261,7 @@ class Query } elseif (is_string($field)) { $field = explode(',', $field); } - $this->options['allow_field'] = $field; + $this->allowField = $field; return $this; } @@ -1267,7 +1273,7 @@ class Query */ public function setFieldType($fieldType = []) { - $this->options['field_type'] = $fieldType; + $this->fieldType = $fieldType; return $this; } @@ -1279,7 +1285,7 @@ class Query */ public function pk($pk) { - $this->options['pk'] = $pk; + $this->pk = $pk; return $this; } @@ -1387,10 +1393,8 @@ class Query */ public function getPk($options = '') { - if (!empty($options['pk'])) { - $pk = $options['pk']; - } elseif (isset($this->options['pk'])) { - $pk = $this->options['pk']; + if (!empty($this->pk)) { + $pk = $this->pk; } else { $pk = $this->getTableInfo(is_array($options) ? $options['table'] : $options, 'pk'); } @@ -1400,13 +1404,13 @@ class Query // 获取当前数据表字段信息 public function getTableFields($options) { - return !empty($options['allow_field']) ? $options['allow_field'] : $this->getTableInfo($options['table'], 'fields'); + return !empty($this->allowField) ? $this->allowField : $this->getTableInfo($options['table'], 'fields'); } // 获取当前数据表字段类型 public function getFieldsType($options) { - return !empty($options['field_type']) ? $options['field_type'] : $this->getTableInfo($options['table'], 'type'); + return !empty($this->fieldType) ? $this->fieldType : $this->getTableInfo($options['table'], 'type'); } // 获取当前数据表绑定信息