]> git.nbdom.net Git - nb.git/commitdiff
table.status
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Wed, 7 Sep 2016 14:56:41 +0000 (16:56 +0200)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Wed, 7 Sep 2016 14:56:41 +0000 (16:56 +0200)
lib/php/db.php
lib/php/db/table.php

index 93c8eb66c45a8915382045beebf0d4524ec836d1..cb2de02a5220eb113e622c5518585dd4712eafc4 100644 (file)
@@ -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']); });
index 5e87274b3a4c0ca5084cf810a29bdf41d75f66ac..aeae87c00b650403e8f81509bf1f613f484812de 100644 (file)
@@ -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;
   }