]> git.nbdom.net Git - nb.git/commitdiff
virtual fix
authorNicolas Boisselier <nicolas.boisselier@semantico.com>
Wed, 27 Jul 2016 14:17:27 +0000 (15:17 +0100)
committerNicolas Boisselier <nicolas.boisselier@semantico.com>
Wed, 27 Jul 2016 14:17:27 +0000 (15:17 +0100)
lib/php/db.php
lib/php/db/index.php
lib/php/db/table.php

index 254c819c7ebbc0fb8c21bb996d0bc42ba7a69b5d..b968fe7ddad5f07df83b21d8c45b5c0079e04485 100644 (file)
@@ -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();
           }
index c330117ea3bffbac499df8dbcab6626649cb15b7..ec9b0716f9a50e67ad3a37312970cd6b72024c19 100755 (executable)
@@ -13,6 +13,7 @@ Db::paliases(array(
   'd' => 'db',
   't' => 'table',
   'f' => 'format',
+  'out' => 'format',
   'l' => 'limit',
   'a' => 'action',
   'h' => 'header',
index edcc861f2a323343382d5b5310dc47bc48c0ae14..5800d29d874e49e8c2b98d24d7bcf73cb9629418 100644 (file)
@@ -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,