From: Nicolas Boisselier Date: Fri, 28 Oct 2016 09:26:00 +0000 (+0100) Subject: fix bug on sql type table when call table.status X-Git-Url: https://git.nbdom.net/?a=commitdiff_plain;h=06a2af1559a09ce6663b5a191c8a02f2d1df88b8;p=nb.git fix bug on sql type table when call table.status --- diff --git a/etc/dbq/nb.php b/etc/dbq/nb.php index f751a60b..53724cc3 100644 --- a/etc/dbq/nb.php +++ b/etc/dbq/nb.php @@ -24,7 +24,7 @@ $DBQ['nb'] = [ ], 'test' => [ - 'sql' => "SELECT 'Test sql table'", + 'sql' => "SELECT 'Test sql table' as Test", ], 'rent' => [ diff --git a/lib/php/db.php b/lib/php/db.php index c418595e..8d74357f 100644 --- a/lib/php/db.php +++ b/lib/php/db.php @@ -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); diff --git a/lib/php/db/table.php b/lib/php/db/table.php index 36a0b6da..8b899489 100644 --- a/lib/php/db/table.php +++ b/lib/php/db/table.php @@ -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; }