From 6294f8b88783df9f6a79d88db9b3f6a57a98c9d1 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Tue, 1 Mar 2016 14:24:26 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A8=A1=E5=9E=8B=E7=B1=BB=E5=A2=9E=E5=8A=A0at?= =?UTF-8?q?trCase=E5=B1=9E=E6=80=A7=20=E7=94=A8=E4=BA=8E=E8=AE=BE=E7=BD=AE?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E8=A1=A8=E7=9A=84=E5=AD=97=E6=AE=B5=E5=A4=A7?= =?UTF-8?q?=E5=B0=8F=E5=86=99=20=E5=80=BC=E5=92=8CPDO=E7=9A=84=E5=B1=9E?= =?UTF-8?q?=E6=80=A7PDO::ATTR=5FCASE=E4=B8=80=E8=87=B4=EF=BC=8C=E8=AF=A5?= =?UTF-8?q?=E8=AE=BE=E7=BD=AE=E9=9C=80=E8=A6=81=E5=92=8C=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=BA=93=E7=9A=84params=E5=8F=82=E6=95=B0=E4=B8=80=E8=B5=B7?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=E6=89=8D=E6=9C=89=E6=95=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Model.php | 27 +++++++++++++++++++++++---- library/think/db/driver/Mysql.php | 1 - library/think/db/driver/Oracle.php | 1 - library/think/db/driver/Sqlite.php | 1 - library/think/log/driver/Trace.php | 8 ++++---- 5 files changed, 27 insertions(+), 11 deletions(-) diff --git a/library/think/Model.php b/library/think/Model.php index e689b3f1..51dcede1 100644 --- a/library/think/Model.php +++ b/library/think/Model.php @@ -32,6 +32,8 @@ class Model protected $name = ''; // 数据库名称 protected $dbName = ''; + // 数据表字段大小写 + protected $attrCase = \PDO::CASE_LOWER; //数据库配置 protected $connection = []; // 数据表名(不包含表前缀) @@ -96,6 +98,10 @@ class Model $this->dbName = $config['db_name']; } + if (isset($config['attr_case'])) { + $this->attrCase = $config['attr_case']; + } + // 数据库初始化操作 // 获取数据库操作对象 // 当前模型有独立的数据库连接信息 @@ -1242,7 +1248,7 @@ class Model // 行为验证 $result = Hook::exec($rule, '', $data); break; - case 'filter': // 使用filter_var验证 + case 'filter': // 使用filter_var验证 $result = filter_var($value, is_int($rule) ? $rule : filter_id($rule), $options); break; case 'confirm': @@ -1253,8 +1259,8 @@ class Model $range = is_array($rule) ? $rule : explode(',', $rule); $result = 'in' == $type ? in_array($value, $range) : !in_array($value, $range); break; - case 'between': // 验证是否在某个范围 - case 'notbetween': // 验证是否不在某个范围 + case 'between':// 验证是否在某个范围 + case 'notbetween': // 验证是否不在某个范围 if (is_string($rule)) { $rule = explode(',', $rule); } @@ -1428,7 +1434,20 @@ class Model $guid = md5($tableName); $result = Cache::get($guid); if (!$result) { - $info = array_change_key_case($this->db->getFields($tableName)); + $info = $this->db->getFields($tableName); + // 字段大小写转换 + switch ($this->attrCase) { + case \PDO::CASE_LOWER: + $info = array_change_key_case($info); + break; + case \PDO::CASE_UPPER: + $info = array_change_key_case($info, CASE_UPPER); + break; + case \PDO::CASE_NATURAL: + default: + // 不做转换 + } + $fields = array_keys($info); foreach ($info as $key => $val) { // 记录字段类型 diff --git a/library/think/db/driver/Mysql.php b/library/think/db/driver/Mysql.php index c08c6f59..471e44f2 100644 --- a/library/think/db/driver/Mysql.php +++ b/library/think/db/driver/Mysql.php @@ -58,7 +58,6 @@ class Mysql extends Driver $info = []; if ($result) { foreach ($result as $key => $val) { - $val = array_change_key_case($val); $info[$val['field']] = [ 'name' => $val['field'], 'type' => $val['type'], diff --git a/library/think/db/driver/Oracle.php b/library/think/db/driver/Oracle.php index 015f23f2..932803c0 100644 --- a/library/think/db/driver/Oracle.php +++ b/library/think/db/driver/Oracle.php @@ -111,7 +111,6 @@ class Oracle extends Driver $info = []; if ($result) { foreach ($result as $key => $val) { - $val = array_change_key_case($val); $info[$val['column_name']] = [ 'name' => $val['column_name'], 'type' => $val['data_type'], diff --git a/library/think/db/driver/Sqlite.php b/library/think/db/driver/Sqlite.php index 62c5c3ff..89be71b1 100644 --- a/library/think/db/driver/Sqlite.php +++ b/library/think/db/driver/Sqlite.php @@ -43,7 +43,6 @@ class Sqlite extends Driver $info = []; if ($result) { foreach ($result as $key => $val) { - $val = array_change_key_case($val); $info[$val['name']] = [ 'name' => $val['name'], 'type' => $val['type'], diff --git a/library/think/log/driver/Trace.php b/library/think/log/driver/Trace.php index 27695d39..3b30b8e7 100644 --- a/library/think/log/driver/Trace.php +++ b/library/think/log/driver/Trace.php @@ -14,7 +14,7 @@ use think\Config; use think\Debug; /** - * 页面Trace调试 需要设置 'response_exit' => false 才能生效 + * 页面Trace调试 */ class Trace { @@ -70,13 +70,13 @@ class Trace foreach ($this->tabs as $name => $title) { $name = strtolower($name); switch ($name) { - case 'base': // 基本信息 + case 'base': // 基本信息 $trace[$title] = $base; break; - case 'file': // 文件信息 + case 'file': // 文件信息 $trace[$title] = $info; break; - default: // 调试信息 + default: // 调试信息 if (strpos($name, '|')) { // 多组信息 $names = explode('|', $name);