From c201873bfaa6ad2c2f113db6243f0aebf2afb47e Mon Sep 17 00:00:00 2001 From: Nicolas Boisselier Date: Wed, 27 Jul 2016 15:17:27 +0100 Subject: [PATCH] virtual fix --- lib/php/db.php | 12 +++++------- lib/php/db/index.php | 1 + lib/php/db/table.php | 24 ++++++++---------------- 3 files changed, 14 insertions(+), 23 deletions(-) diff --git a/lib/php/db.php b/lib/php/db.php index 254c819c..b968fe7d 100644 --- a/lib/php/db.php +++ b/lib/php/db.php @@ -385,8 +385,6 @@ class Db extends nb { } public function action($action,$table=null) { - #if ($this->p('format') == 'table') $this->pset('format',''); -# NB 20.04.16 $actions = explode(',',$this->p('action')); $actions = explode(',',$action); $this->pdef('format',($this->php_cli() ? 'csv' : '')); $rows = array(); @@ -414,15 +412,15 @@ class Db extends nb { } elseif ($action == 'db.tables' or $action == 'tables') { # Filters - $name = self::p('name',''); - $type = self::p('type',''); - #$count = self::p('count',''); - $engine = self::p('engine',''); + $type = $this->p('type','table'); + $name = $this->p('name',''); + #if ($count = $this->p('count','')) $this->pset('count',1); + $engine = $this->p('engine',''); foreach ($this->tables() as $t) { 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($count) and !$this->str_match($t->count,$count)) continue; if (!empty($engine) and !$this->str_match($t->engine,$engine)) continue; $rows[] = $t->infos(); } diff --git a/lib/php/db/index.php b/lib/php/db/index.php index c330117e..ec9b0716 100755 --- a/lib/php/db/index.php +++ b/lib/php/db/index.php @@ -13,6 +13,7 @@ Db::paliases(array( 'd' => 'db', 't' => 'table', 'f' => 'format', + 'out' => 'format', 'l' => 'limit', 'a' => 'action', 'h' => 'header', diff --git a/lib/php/db/table.php b/lib/php/db/table.php index edcc861f..5800d29d 100644 --- a/lib/php/db/table.php +++ b/lib/php/db/table.php @@ -15,6 +15,7 @@ if (!defined('DB_HTML_DELETE')) define('DB_HTML_DELETE','Delete'); # Create a temporary table when table is a SELECT if (!defined('DB_TABLE_QUERY_NAME')) define('DB_TABLE_QUERY_NAME','_query_'); +$DB_TABLE_QUERY_ID = 0; Class Table extends nb { @@ -57,7 +58,7 @@ Class Table extends nb { // Type $sql = ''; if (isset($opt['sql'])) { - $sql = $opt['sql']; unset($opt['sql']); + $this->sql = $opt['sql']; unset($opt['sql']); $this->type = 'sql'; unset($opt['type']); } @@ -80,33 +81,25 @@ Class Table extends nb { } - // Order BY -# NB 10.04.16 if (isset($opt['orderby'])) { -# NB 10.04.16 $this->pdef('orderby',$opt['orderby']); -# NB 10.04.16 unset($opt['orderby']); -# NB 10.04.16 } - // Add others -#if (empty($opt)) bye($opt); foreach ($opt as $k => $v) { $this->$k = $v; } // Name, could be a select if (DB_TABLE_QUERY_NAME and stripos($this->name,'SELECT ')===0) { - $this->db()->conn->query("CREATE TEMPORARY TABLE ".DB_TABLE_QUERY_NAME." AS $this->name"); - $this->name = DB_TABLE_QUERY_NAME; + $GLOBALS['DB_TABLE_QUERY_ID']++; $name = DB_TABLE_QUERY_NAME . $GLOBALS['DB_TABLE_QUERY_ID']; + $this->db()->conn->query("CREATE TEMPORARY TABLE $name AS $this->name"); + $this->name = $name; // Virtual Table } elseif (DB_TABLE_QUERY_NAME and !empty($this->sql)) { - $this->db()->conn->query("CREATE TEMPORARY TABLE ".DB_TABLE_QUERY_NAME." AS $this->sql"); - $this->name = DB_TABLE_QUERY_NAME; + $name = $this->name; + $this->db()->conn->query("CREATE TEMPORARY TABLE $name AS $this->sql"); } elseif (preg_match('/\b(\.import|LOAD DATA|COPY|INSERT|REPLACE|DELETE|TRUNCATE|CREATE|DROP|ALERT)\b/',$this->name)) { bye("Query not Allowed !"); } - if ($sql) $this->sql = $sql; # from $opt['sql'] -# NB 29.03.16 return $this->fields(); } /* @@ -116,7 +109,6 @@ Class Table extends nb { * */ public function db($set=null) { -#return $GLOBALS['Db']; static $db = null; if ($set !== null) $db = $set; return $db; @@ -1334,7 +1326,7 @@ Class Table extends nb { public function out($v,$head=array()) { return $this->db()->out($v,$head); } public function infos() { - return + return array( "name" => $this->name, "type" => $this->type, -- 2.47.3