}
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";
$rows = $this->conn->query($sql);
foreach ($rows as $row) {
- $this->tables[] = current($row);
+ $this->_tables[] = current($row);
}
- return $this->tables;
+ return $this->_tables;
}
'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'];
}
// 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();
}
$sql .= " FROM ".$this->sql_name();
$this->sql = $sql = $sql . $where;
- $this->debug($sql,1);
if ($this->p('sort')) $sql .= ' ORDER BY '.$this->p('sort');
//
// Get results
//
+ $this->debug($sql,1);
$st = $this->db->conn->prepare($sql);
$st->execute();
<?php
+require_once(dirname(__FILE__).'/nb.php');
/*
Vim:
}
-function argv2request() {
-/******************************************************************************
-# NB 14.07.11 - Put argv options into _REQUEST. Return argv without options
-******************************************************************************/
-
- global $argv;
-
- $new_argv = array();
-
- for ($i=1;$i<count($argv);$i++) {
-
- if (preg_match('/^([\w_\-\.]+)=(.+)\s*$/',$argv[$i],$f)) {
- $k = $f[1];
- $v = $f[2];
-
- // Array
- if (preg_match('/^(.*)\[\]$/',$k,$p)) {
- #bye($p);
- if (($_REQUEST[$p[1]]==NULL) or !in_array($v,$_REQUEST[$p[1]])) $_REQUEST[$p[1]][] = $v;
-
- } else {
- $_REQUEST[$k] = $v;
-
- }
-
- } else {
-
- if (preg_match('/^-(h|-?help)$/',$argv[$i])) $_REQUEST['help'] = 1;
- else $new_argv[] = $argv[$i];
-
- }
-
- }
-
- return $new_argv;
-
-}
-
-function benchmark($function=null,$limit=1000000) {
- global $_benchmark;
-
- if ($_benchmark === null) {
- $_benchmark = array('.' => 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()) {
return null;
}
+ /*
+ * Function: argv2request
+ * Set $_REQUEST from argv
+ */
+ static function argv2request() {
+
+ global $argv;
+
+ $new_argv = array();
+
+ for ($i=1;$i<count($argv);$i++) {
+
+ if (preg_match('/^([\w_\-\.]+)=(.+)\s*$/',$argv[$i],$f)) {
+ $k = $f[1];
+ $v = $f[2];
+
+ // Array
+ if (preg_match('/^(.*)\[\]$/',$k,$p)) {
+ #bye($p);
+ if (($_REQUEST[$p[1]]==NULL) or !in_array($v,$_REQUEST[$p[1]])) $_REQUEST[$p[1]][] = $v;
+
+ } else {
+ $_REQUEST[$k] = $v;
+
+ }
+
+ } else {
+
+ if (preg_match('/^-(h|-?help)$/',$argv[$i])) $_REQUEST['help'] = 1;
+ else $new_argv[] = $argv[$i];
+
+ }
+
+ }
+
+ return $new_argv;
+
+ }
+
+ /*
+ * Function: benchmark
+ * Call a function several times
+ * Usage: benchmark("f1"); benchmark("f2"); benchmark();
+ */
+ static function benchmark($function=null,$limit=1000000) {
+ global $_benchmark;
+
+ if ($_benchmark === null) {
+ $_benchmark = array('.' => 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'));
?>