改进数据库驱动的getFields方法 支持指定别名的情况 修正model类一处错误

This commit is contained in:
ThinkPHP
2013-04-30 10:45:38 +08:00
parent 7cfdde0ab7
commit 64f7e1d3ca
7 changed files with 8 additions and 3 deletions

View File

@@ -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 = [];

View File

@@ -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)

View File

@@ -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){

View File

@@ -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){

View File

@@ -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