From c3e86347f5cceca184861d27dc4b5871b643a952 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Fri, 19 Feb 2016 22:12:09 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3sqlsrv=E9=A9=B1=E5=8A=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Model.php | 34 ++++++++++++++++++++++++------ library/think/db/driver/Sqlsrv.php | 13 +++++++++++- 2 files changed, 40 insertions(+), 7 deletions(-) diff --git a/library/think/Model.php b/library/think/Model.php index 7459e315..30d7cfb2 100644 --- a/library/think/Model.php +++ b/library/think/Model.php @@ -987,7 +987,12 @@ class Model protected function _create_filter(&$data) {} - // 数据自动验证 + /** + * 数据自动验证 + * @access protected + * @param array $data 数据 + * @return void + */ protected function dataValidate(&$data) { if (!empty($this->options['validate'])) { @@ -1038,7 +1043,12 @@ class Model return; } - // 数据自动填充 + /** + * 数据自动填充 + * @access protected + * @param array $data 数据 + * @return void + */ protected function dataFill(&$data) { if (!empty($this->options['auto'])) { @@ -1061,7 +1071,13 @@ class Model } } - // 获取数据值 + /** + * 获取数据值 + * @access protected + * @param array $data 数据 + * @param string $key 数据标识 支持二维 + * @return mixed + */ protected function getDataValue($data, $key) { if (strpos($key, '.')) { @@ -1074,7 +1090,13 @@ class Model return $value; } - // 获取数据自动验证或者完成的规则定义 + /** + * 获取数据自动验证或者完成的规则定义 + * @access protected + * @param array $data 数据 + * @param string $type 数据类型 支持 validate auto + * @return array + */ protected function getDataRule($data, $type) { if (is_string($data)) { @@ -1117,7 +1139,7 @@ class Model /** * 数据自动填充 - * @access public + * @access protected * @param string $key 字段名 * @param mixed $val 填充规则 * @param array $data 数据 @@ -1176,7 +1198,7 @@ class Model /** * 验证字段规则 - * @access public + * @access protected * @param mixed $value 字段值 * @param mixed $val 验证规则 * @param array $data 数据 diff --git a/library/think/db/driver/Sqlsrv.php b/library/think/db/driver/Sqlsrv.php index 6a554771..481309cc 100644 --- a/library/think/db/driver/Sqlsrv.php +++ b/library/think/db/driver/Sqlsrv.php @@ -92,6 +92,17 @@ class Sqlsrv extends Driver return $info; } + /** + * order分析 + * @access protected + * @param mixed $order + * @return string + */ + protected function parseOrder($order) + { + return !empty($order) ? ' ORDER BY ' . $order[0] : ' ORDER BY rand()'; + } + /** * 随机排序 * @access protected @@ -111,7 +122,7 @@ class Sqlsrv extends Driver protected function parseKey($key) { $key = trim($key); - if (!preg_match('/[,\'\"\*\(\)\[.\s]/', $key)) { + if (!is_numeric($key) && !preg_match('/[,\'\"\*\(\)\[.\s]/', $key)) { $key = '[' . $key . ']'; } return $key;