From: Nicolas Boisselier Date: Sun, 10 Jan 2016 01:05:32 +0000 (+0000) Subject: change db.yaml and move function to nb X-Git-Url: https://git.nbdom.net/?a=commitdiff_plain;h=94133ebbf21b637d456aeb5d6abf3a0c88b88a47;p=nb.git change db.yaml and move function to nb --- diff --git a/lib/php/db.php b/lib/php/db.php index 6fc708ad..70199701 100644 --- a/lib/php/db.php +++ b/lib/php/db.php @@ -195,14 +195,15 @@ class db extends nb { } function table($name) { - return new Table($name,array('db'=>$this)); - # TODEL - NB 18.08.15 - if (!$this->table) $this->table = new Table($name,array('db'=>$this)); - return $this->table; + $opt = array('db' => $this); + if (isset($this->tables) and array_key_exists($name,$this->tables)) { + foreach ($this->tables[$name] as $k=>$v) { $opt[$k] = $v; } + } + return new Table($name,array_merge($opt)); } function tables() { - if ($this->tables) return $this->tables; + if (isset($this->_tables) and $this->_tables) return $this->_tables; if ($this->type == 'sqlite') { $sql = "SELECT name FROM sqlite_master WHERE type='table' AND name NOT LIKE 'sqlite_%' ORDER BY name"; @@ -220,10 +221,10 @@ class db extends nb { $rows = $this->conn->query($sql); foreach ($rows as $row) { - $this->tables[] = current($row); + $this->_tables[] = current($row); } - return $this->tables; + return $this->_tables; } diff --git a/lib/php/db/table.php b/lib/php/db/table.php index 462d62b1..138193dd 100644 --- a/lib/php/db/table.php +++ b/lib/php/db/table.php @@ -32,9 +32,13 @@ class table extends nb { 'limit', 'debug', ); + public $order_by = null; function __construct($name,$opt=array()) { + foreach ($opt as $k => $v) { $this->$k = $v; } + #unset($opt['db']); bye($opt); + // Connection if (isset($opt['db'])) { $this->db = $opt['db']; @@ -67,10 +71,11 @@ class table extends nb { } // Sort - if ( - isset($this->db->sort) - and isset($this->db->sort[$this->name]) - ) $this->db->pset('sort',$this->db->sort[$this->name]); +# NB 10.01.16 if ( +# NB 10.01.16 isset($this->db->sort) +# NB 10.01.16 and isset($this->db->sort[$this->name]) +# NB 10.01.16 ) $this->db->pset('sort',$this->db->sort[$this->name]); + if ($this->order_by) $this->pset('sort',$this->order_by); return $this->fields(); } @@ -593,7 +598,6 @@ FROM pg_catalog.pg_attribute a WHERE a.attrelid = (SELECT c.oid FROM pg_catalog. $sql .= " FROM ".$this->sql_name(); $this->sql = $sql = $sql . $where; - $this->debug($sql,1); if ($this->p('sort')) $sql .= ' ORDER BY '.$this->p('sort'); @@ -607,6 +611,7 @@ FROM pg_catalog.pg_attribute a WHERE a.attrelid = (SELECT c.oid FROM pg_catalog. // // Get results // + $this->debug($sql,1); $st = $this->db->conn->prepare($sql); $st->execute(); diff --git a/lib/php/functions.php b/lib/php/functions.php index 1103b579..97dc5cc8 100644 --- a/lib/php/functions.php +++ b/lib/php/functions.php @@ -1,4 +1,5 @@ microtime(true)); - } - - if ($function === null) { - $prev = $_benchmark['.']; - echo "Iteration: $limit\n"; - foreach ($_benchmark as $lib => $sec) { - if ($lib === '.') continue; - printf("%-30s %s\n",$lib,($sec-$prev)); - $prev = $sec; - } - return; - } - - for ($i=0; $i<$limit; $i++) { - $function(); - } - - $_benchmark[$function] = microtime(true); -} +function argv2request() { return nb::argv2request(); } function html_select_array($data,$opt=array()) { diff --git a/lib/php/nb.php b/lib/php/nb.php index e64b49ad..5a62f158 100644 --- a/lib/php/nb.php +++ b/lib/php/nb.php @@ -93,6 +93,75 @@ class nb { return null; } + /* + * Function: argv2request + * Set $_REQUEST from argv + */ + static function argv2request() { + + global $argv; + + $new_argv = array(); + + for ($i=1;$i microtime(true)); + } + + if ($function === null) { + $prev = $_benchmark['.']; + echo "Iteration: $limit\n"; + foreach ($_benchmark as $lib => $sec) { + if ($lib === '.') continue; + printf("%-30s %s\n",$lib,($sec-$prev)); + $prev = $sec; + } + return; + } + + for ($i=0; $i<$limit; $i++) { + $function(); + } + + $_benchmark[$function] = microtime(true); + } + } #die(nb::ext2mime('csv')); ?>