]> git.nbdom.net Git - nb.git/commitdiff
fix bug on sql type table when call table.status
authorNicolas Boisselier <nicolas.boisselier@semantico.com>
Fri, 28 Oct 2016 09:26:00 +0000 (10:26 +0100)
committerNicolas Boisselier <nicolas.boisselier@semantico.com>
Fri, 28 Oct 2016 09:26:00 +0000 (10:26 +0100)
etc/dbq/nb.php
lib/php/db.php
lib/php/db/table.php

index f751a60b44261027750a41e7da2f6c644bb8edcd..53724cc32429c61613e8707a9b8510dd330e3023 100644 (file)
@@ -24,7 +24,7 @@ $DBQ['nb'] = [
     ],
 
     'test' => [
-      'sql' => "SELECT 'Test sql table'",
+      'sql' => "SELECT 'Test sql table' as Test",
     ],
 
     'rent' => [
index c418595e22f5374a33d4de9cb537c34ea03072f4..8d74357fdd32e20db6eb501e6ff65995777ccc9b 100644 (file)
@@ -452,7 +452,7 @@ class Db extends nb {
         foreach ($this->conn->query($sql,PDO::FETCH_ASSOC) as $row) {
           #debug($row);
           $name = current($row);
-          $this->table($name,$row+['status'=>$row]); # add to this->tables too !
+          $t = $this->table($name,$row+['status'=>$row]); # add to this->tables too !
         }
       }
 
@@ -541,23 +541,32 @@ class Db extends nb {
           ]);
 
         } elseif ($action == 'db.tables') {
+
+          # Options
           # Filters
           $type = $this->p('type','');
           $name = $this->p('name','');
           $engine = $this->p('engine','');
 
           #var_dump ($this->tables());
+#foreach($this->tables as $t) debug($t->name.'='.$t->type);
+#bye($this->tables);
           foreach ($this->tables() as $t) {
-            #debug($t->name);
+            #debug($t->name.'='.$t->type);
+
             if (!empty($name) and !$this->str_match($t->name,$name)) continue;
             if (!empty($type) and !$this->str_match($t->type,$type)) continue;
             if (!empty($count) and !$this->str_match($t->count,$count)) continue;
             if (!empty($engine) and !$this->str_match($t->engine,$engine)) continue;
 
-            $rows[] = $t->status();
+            $row = $t->status();
+            if ($this->p('count')) $row['count'] = $t->status('count');
+            #if ($this->p('fields')) $row['fields'] = $t->status('fields');
+            if ($this->p('fields')) $row['fields'] = join(',',array_keys($t->fields()));
+
+            $rows[] = $row;
           }
 
-          #bye($rows);
           $rows = self::array_fill_assoc($rows);
           usort($rows,function($a,$b) { return strcmp($a['name'],$b['name']); });
           $return = $this->out($rows);
index 36a0b6dafb4b37ef97102539668e3ed7a2d3357e..8b899489fa17eb77a7ffe36dcde2a0af5d1a62e4 100644 (file)
@@ -1714,7 +1714,8 @@ Class Table extends nb {
         'name',
         'type',
       ] as $k) {
-        if (!empty($this->$k) and empty($this->status[$k])) $this->status[$k] = $this->$k;
+# NB 28.10.16         if (!empty($this->$k) and empty($this->status[$k])) $this->status[$k] = $this->$k;
+        if (!empty($this->$k)) $this->status[$k] = $this->$k;
       }
 
       # Add from status array
@@ -1726,21 +1727,30 @@ Class Table extends nb {
       }
     }
 
+    #$key = 'count';
+    # Params
     foreach ([
       'count',
       'fields',
       'sql',
     ] as $k) {
-      if (!self::p($k) or !empty($this->status[$k])) continue;
+      if (!empty($this->status[$k])) continue;
+
+      if (empty($key)) {
+        if (!self::p($k)) continue;
+      } else {
+        if ($k!=$key) continue;
+      }
 
       # No count for view
-      if ($k == 'count' and $this->type != 'table') continue;
+      #if ($k == 'count' and $this->type != 'table') 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] );
+#debug($this->name.'='.$this->type);
     return $this->status;
   }