From ce4c69958541adf86c1ec9ba0631df48434c9c2d Mon Sep 17 00:00:00 2001 From: Nicolas Boisselier Date: Wed, 7 Sep 2016 16:56:41 +0200 Subject: [PATCH] table.status --- lib/php/db.php | 13 ++----------- lib/php/db/table.php | 35 +++++++++++++++++++++++++++++------ 2 files changed, 31 insertions(+), 17 deletions(-) diff --git a/lib/php/db.php b/lib/php/db.php index 93c8eb66..cb2de02a 100644 --- a/lib/php/db.php +++ b/lib/php/db.php @@ -387,7 +387,7 @@ class Db extends nb { foreach ($this->conn->query($sql,PDO::FETCH_ASSOC) as $row) { #debug($row); $name = current($row); - $t = $this->table($name,$row); + $t = $this->table($name,$row+['status'=>$row]); } } @@ -460,16 +460,7 @@ class Db extends nb { if (!empty($count) and !$this->str_match($t->count,$count)) continue; if (!empty($engine) and !$this->str_match($t->engine,$engine)) continue; - $rows[] = [] - +[ - 'name' => $t->name, - 'type' => $t->type, - ] - +$t->infos() - +( self::p('fields') ?['fields' => count($t->fields())] : [] ) - +( self::p('count') ?['count' => $t->count()] : [] ) - +( self::p('sql') ? ['sql' => $t->sql()] : [] ) - ; + $rows[] = $t->status(); } usort($rows,function($a,$b) { return strcmp($a['name'],$b['name']); }); diff --git a/lib/php/db/table.php b/lib/php/db/table.php index 5e87274b..aeae87c0 100644 --- a/lib/php/db/table.php +++ b/lib/php/db/table.php @@ -1353,17 +1353,22 @@ Class Table extends nb { public function out($v,$head=array()) { return $this->db()->out($v,$head); } public function infos() { + return ['TODEL']; + # TODEL - NB 07.09.16 $this->type(); return - array( + [ "name" => $this->name, "type" => $this->type, #"fields" => count($this->fields()), #"count" => $this->count(), #"sql_name" => $this->sql_name(), - ) - +( isset($this->engine) ? array("engine" => $this->engine) : array() ) - +( isset($this->created) ? array("created" => $this->created) : array() ) + ] + +( isset($this->engine) ? ["engine" => $this->engine] : [] ) + +( isset($this->created) ? ["created" => $this->created] : [] ) +# NB 07.09.16 +( self::p('fields') ?['fields' => count($this->fields())] : [] ) +# NB 07.09.16 +( self::p('count') ?['count' => $this->count()] : [] ) +# NB 07.09.16 +( self::p('sql') ? ['sql' => $this->sql()] : [] ) ; } @@ -1682,9 +1687,27 @@ Class Table extends nb { #$sql .= ' AND name='.$this->db()->quote($this->name); $sql = "SELECT * FROM ($sql) t WHERE name=".$this->db()->quote($this->name); - $this->status = $this->db()->conn->query($sql,PDO::FETCH_ASSOC); - if (!empty($this->status)) $this->status = $this->status->fetch(); + $sth = $this->db()->conn->query($sql,PDO::FETCH_ASSOC); + if (!empty($sth)) $this->status = $sth->fetch(); + + foreach ([ + 'engine', + 'created', + ] as $k) { + if (empty($this->$k) and !empty($this->status[$k])) $this->$k = $this->status[$k]; + } } + + foreach ([ + 'count', + 'fields', + 'sql', + ] as $k) { + if (!self::p($k) or !empty($this->status[$k])) continue; + $this->status[$k] = $this->$k(); + if (is_array($this->status[$k])) $this->status[$k] = count($this->status[$k]); + } + if (!empty($key)) return ( empty($this->status[$key]) ? '' : $this->status[$key] ); return $this->status; } -- 2.47.3