}
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();
} 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();
}
# 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 {
// 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']);
}
}
- // 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();
}
/*
*
*/
public function db($set=null) {
-#return $GLOBALS['Db'];
static $db = null;
if ($set !== null) $db = $set;
return $db;
public function out($v,$head=array()) { return $this->db()->out($v,$head); }
public function infos() {
- return
+ return
array(
"name" => $this->name,
"type" => $this->type,