From e40193e9a65edd32d1cf58272c15a2d9ab0cb81b Mon Sep 17 00:00:00 2001 From: Nicolas Boisselier Date: Mon, 4 Jul 2016 17:30:57 +0100 Subject: [PATCH] Virtual --- etc/dbs/ui.php | 2 +- lib/php/db.php | 38 +++++++++++++++++++++++++++++++------- lib/php/db/table.php | 1 + 3 files changed, 33 insertions(+), 8 deletions(-) diff --git a/etc/dbs/ui.php b/etc/dbs/ui.php index d7a32161..1a07cbf0 100644 --- a/etc/dbs/ui.php +++ b/etc/dbs/ui.php @@ -41,7 +41,7 @@ $CONF['_ui'] = array( 'contact' => array( 'extras'=> array( - ' pic' => '\'\'', + 'pic' => '\'\'', ), ), diff --git a/lib/php/db.php b/lib/php/db.php index ce3753d1..1141d746 100644 --- a/lib/php/db.php +++ b/lib/php/db.php @@ -68,10 +68,28 @@ class Db extends nb { # Tables - Add missing infos if (!empty($tables)) { + foreach ($this->tables() as $name=>$t) { + #foreach (array_merge(array_keys($this->tables()),[]) as $name) { + #foreach (array_merge(array_keys($this->tables()),array_keys($tables)) as $name) { + if (empty($tables[$name])) continue; $this->table($name,$tables[$name]); + + } + + # Virtual - NB 04.07.16 + foreach ($tables as $name => $t) { + if (empty($t['sql'])) continue; + $sql = $t['sql']; + unset($t['sql']); + #debug($name); + $t = $this->table($name,$t); + $t->sql = $sql; + $t->type = 'sql'; + $this->tables[] = $t; } + } # Extras should disapear - NB 29.03.16 @@ -271,14 +289,12 @@ class Db extends nb { } function table($name,$opt=array()) { -# NB 29.03.16 if (empty($opt['db'])) $opt['db'] = $this; if ($this->tables() and array_key_exists($name,$this->tables)) { #if ($opt) bye($opt); if ($opt) $this->tables[$name]->__construct($name,$opt); return $this->tables[$name]; } return new Table($name,$opt); - bye("Unknow table `$name`"); } public function localFile() { @@ -324,13 +340,21 @@ class Db extends nb { return $DB_TYPES[$type][$key]; } +# NB 04.07.16 public function all_tables() { +# NB 04.07.16 $tables= $this->tables(); +# NB 04.07.16 return $tables; +# NB 04.07.16 } + public function tables() { - if (isset($this->tables)) return $this->tables; - $this->tables = array(); - foreach ($this->conn->query($this->type('tables',true,$this->type),PDO::FETCH_ASSOC) as $row) { - $name = current($row); - $this->tables[$name] = $this->table($name,$row); + if (!isset($this->tables)) { + $this->tables = array(); + + foreach ($this->conn->query($this->type('tables',true,$this->type),PDO::FETCH_ASSOC) as $row) { + $name = current($row); + $this->tables[$name] = $this->table($name,$row); + } + } return $this->tables; diff --git a/lib/php/db/table.php b/lib/php/db/table.php index 72aab783..31e2fbc0 100644 --- a/lib/php/db/table.php +++ b/lib/php/db/table.php @@ -244,6 +244,7 @@ Class Table extends nb { */ public function fields($name=null) { + if (!empty($this->sql)) return []; # Virtual - NB 04.07.16 if (!isset($this->fields)) { $this->fields = array(); -- 2.47.3