From f4301c866727dca98d04695c5310c214a8d199ef Mon Sep 17 00:00:00 2001 From: thinkphp Date: Fri, 27 Apr 2018 15:38:45 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E8=BF=9B=E9=A9=B1=E5=8A=A8=E7=9A=84pa?= =?UTF-8?q?rseKey=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/db/builder/Mysql.php | 7 +++++-- library/think/db/builder/Pgsql.php | 8 +++++++- library/think/db/builder/Sqlite.php | 8 +++++++- library/think/db/builder/Sqlsrv.php | 6 ++++-- 4 files changed, 23 insertions(+), 6 deletions(-) diff --git a/library/think/db/builder/Mysql.php b/library/think/db/builder/Mysql.php index 94f82b83..8eee746f 100644 --- a/library/think/db/builder/Mysql.php +++ b/library/think/db/builder/Mysql.php @@ -82,15 +82,18 @@ class Mysql extends Builder /** * 字段和表名处理 * @access protected - * @param string $key + * @param mixed $key * @param array $options * @return string */ protected function parseKey($key, $options = [], $strict = false) { - if (is_int($key)) { + if (is_numeric($key)) { return $key; + } elseif ($key instanceof Expression) { + return $key->getValue(); } + $key = trim($key); if (strpos($key, '$.') && false === strpos($key, '(')) { // JSON字段支持 diff --git a/library/think/db/builder/Pgsql.php b/library/think/db/builder/Pgsql.php index 5885e721..acc22896 100644 --- a/library/think/db/builder/Pgsql.php +++ b/library/think/db/builder/Pgsql.php @@ -44,12 +44,18 @@ class Pgsql extends Builder /** * 字段和表名处理 * @access protected - * @param string $key + * @param mixed $key * @param array $options * @return string */ protected function parseKey($key, $options = [], $strict = false) { + if (is_numeric($key)) { + return $key; + } elseif ($key instanceof Expression) { + return $key->getValue(); + } + $key = trim($key); if (strpos($key, '$.') && false === strpos($key, '(')) { // JSON字段支持 diff --git a/library/think/db/builder/Sqlite.php b/library/think/db/builder/Sqlite.php index fbd3bbaf..c727f04b 100644 --- a/library/think/db/builder/Sqlite.php +++ b/library/think/db/builder/Sqlite.php @@ -52,12 +52,18 @@ class Sqlite extends Builder /** * 字段和表名处理 * @access protected - * @param string $key + * @param mixed $key * @param array $options * @return string */ protected function parseKey($key, $options = [], $strict = false) { + if (is_numeric($key)) { + return $key; + } elseif ($key instanceof Expression) { + return $key->getValue(); + } + $key = trim($key); if (strpos($key, '.')) { list($table, $key) = explode('.', $key, 2); diff --git a/library/think/db/builder/Sqlsrv.php b/library/think/db/builder/Sqlsrv.php index e904827a..f79ae030 100644 --- a/library/think/db/builder/Sqlsrv.php +++ b/library/think/db/builder/Sqlsrv.php @@ -73,14 +73,16 @@ class Sqlsrv extends Builder /** * 字段和表名处理 * @access protected - * @param string $key + * @param mixed $key * @param array $options * @return string */ protected function parseKey($key, $options = [], $strict = false) { - if (is_int($key)) { + if (is_numeric($key)) { return $key; + } elseif ($key instanceof Expression) { + return $key->getValue(); } $key = trim($key); if (strpos($key, '.') && !preg_match('/[,\'\"\(\)\[\s]/', $key)) {