From 64f7e1d3ca99f6bbebb7a07dbc3a9b19463f3ba6 Mon Sep 17 00:00:00 2001 From: ThinkPHP Date: Tue, 30 Apr 2013 10:45:38 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E8=BF=9B=E6=95=B0=E6=8D=AE=E5=BA=93?= =?UTF-8?q?=E9=A9=B1=E5=8A=A8=E7=9A=84getFields=E6=96=B9=E6=B3=95=20?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E6=8C=87=E5=AE=9A=E5=88=AB=E5=90=8D=E7=9A=84?= =?UTF-8?q?=E6=83=85=E5=86=B5=20=E4=BF=AE=E6=AD=A3model=E7=B1=BB=E4=B8=80?= =?UTF-8?q?=E5=A4=84=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Library/Think/Db/Driver.php | 4 ++-- Library/Think/Db/Driver/Mysql.php | 1 + Library/Think/Db/Driver/Oracle.php | 1 + Library/Think/Db/Driver/Pgsql.php | 1 + Library/Think/Db/Driver/Sqlite.php | 1 + Library/Think/Db/Driver/Sqlsrv.php | 1 + Library/Think/Model.php | 2 +- 7 files changed, 8 insertions(+), 3 deletions(-) diff --git a/Library/Think/Db/Driver.php b/Library/Think/Db/Driver.php index 1c9e7dbb..facfe284 100644 --- a/Library/Think/Db/Driver.php +++ b/Library/Think/Db/Driver.php @@ -430,7 +430,7 @@ abstract class Driver { if(!is_numeric($table)) $array[] = $this->parseKey($table).' '.$this->parseKey($alias); else - $array[] = $this->parseKey($table); + $array[] = $this->parseKey($alias); } $tables = $array; }elseif(is_string($tables)){ @@ -563,7 +563,7 @@ abstract class Driver { } }else { //对字符串类型字段采用模糊匹配 - if($this->conf['db_like_fields'] && preg_match('/('.$this->conf['db_like_fields'].')/i',$key)) { + if($this->config['db_like_fields'] && preg_match('/('.$this->config['db_like_fields'].')/i',$key)) { $val = '%'.$val.'%'; $whereStr .= $key.' LIKE '.$this->parseValue($val); }else { diff --git a/Library/Think/Db/Driver/Mysql.php b/Library/Think/Db/Driver/Mysql.php index efa6dc4d..8f1b70bb 100644 --- a/Library/Think/Db/Driver/Mysql.php +++ b/Library/Think/Db/Driver/Mysql.php @@ -42,6 +42,7 @@ class Mysql extends Driver{ */ public function getFields($tableName) { $this->initConnect(true); + list($tableName) = explode(' ', $tableName); $sql = 'SHOW COLUMNS FROM `'.$tableName.'`'; $result = $this->query($sql); $info = []; diff --git a/Library/Think/Db/Driver/Oracle.php b/Library/Think/Db/Driver/Oracle.php index 3b1f5e49..ae77e14f 100644 --- a/Library/Think/Db/Driver/Oracle.php +++ b/Library/Think/Db/Driver/Oracle.php @@ -80,6 +80,7 @@ class Oracle extends Driver{ * @access public */ public function getFields($tableName) { + list($tableName) = explode(' ', $tableName); $result = $this->query("select a.column_name,data_type,decode(nullable,'Y',0,1) notnull,data_default,decode(a.column_name,b.column_name,1,0) pk " ."from user_tab_columns a,(select column_name from user_constraints c,user_cons_columns col " ."where c.constraint_name=col.constraint_name and c.constraint_type='P'and c.table_name='".strtoupper($tableName) diff --git a/Library/Think/Db/Driver/Pgsql.php b/Library/Think/Db/Driver/Pgsql.php index 8dd72cac..dc478103 100644 --- a/Library/Think/Db/Driver/Pgsql.php +++ b/Library/Think/Db/Driver/Pgsql.php @@ -37,6 +37,7 @@ class Pgsql extends Driver{ * @return array */ public function getFields($tableName) { + list($tableName) = explode(' ', $tableName); $result = $this->query('select fields_name as "field",fields_type as "type",fields_not_null as "null",fields_key_name as "key",fields_default as "default",fields_default as "extra" from table_msg('.$tableName.');'); $info = []; if($result){ diff --git a/Library/Think/Db/Driver/Sqlite.php b/Library/Think/Db/Driver/Sqlite.php index fcb77e13..02c0f14a 100644 --- a/Library/Think/Db/Driver/Sqlite.php +++ b/Library/Think/Db/Driver/Sqlite.php @@ -34,6 +34,7 @@ class Sqlite extends Driver { * @return array */ public function getFields($tableName) { + list($tableName) = explode(' ', $tableName); $result = $this->query('PRAGMA table_info( '.$tableName.' )'); $info = []; if($result){ diff --git a/Library/Think/Db/Driver/Sqlsrv.php b/Library/Think/Db/Driver/Sqlsrv.php index 80e73fa8..04e71ad3 100644 --- a/Library/Think/Db/Driver/Sqlsrv.php +++ b/Library/Think/Db/Driver/Sqlsrv.php @@ -46,6 +46,7 @@ class Sqlsrv extends Driver{ * @return array */ public function getFields($tableName) { + list($tableName) = explode(' ', $tableName); $result = $this->query("SELECT column_name, data_type, column_default, is_nullable FROM information_schema.tables AS t JOIN information_schema.columns AS c diff --git a/Library/Think/Model.php b/Library/Think/Model.php index a4254b33..625b4e56 100644 --- a/Library/Think/Model.php +++ b/Library/Think/Model.php @@ -396,7 +396,7 @@ class Model { $options['model'] = $this->name; if(isset($options['table'])) {// 动态指定表名 - $fields = $this->db->getFields($this->options['table']); + $fields = $this->db->getFields($options['table']); $fields = $fields?array_keys($fields):false; }else{ $options['table'] = $this->getTableName();