]> git.nbdom.net Git - nb.git/commitdiff
fix bug db.tables
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Mon, 5 Dec 2016 10:25:03 +0000 (10:25 +0000)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Mon, 5 Dec 2016 10:25:03 +0000 (10:25 +0000)
lib/php/db.php
lib/php/db/table.php
www/dbq/html/default.css
www/dbq/html/index.php

index 4c9c744323108ca59585e3975d227de80f413a57..9f6f7aafa68165ac73d6baa3a4d193fb501b7ce6 100644 (file)
@@ -383,8 +383,9 @@ class Db extends nb {
     if (!$name and !empty($this->default_table)) $name = $this->default_table;
     if (!$name) bye('table name is empty');
 
+    if (empty($params) or empty($params['db'])) $params['db'] = $this;
     if (empty($this->tables[$name])) {
-      $this->tables[$name] = new Table($name,['db'=>$this]+$params);
+      $this->tables[$name] = new Table($name,$params);
     } elseif ($params) {
       $this->tables[$name]->__construct($name,$params);
     }
@@ -403,7 +404,6 @@ class Db extends nb {
 
     $return = [];
     foreach (explode("\n",file_get_contents($config[0])) as $line) {
-#bye($line);
       if (!preg_match('/'.($config[1]).'/',$line,$m)) continue;
       foreach ($m as $k=>$v) if (preg_match('/^\d+$/',$k)) unset($m[$k]);
       $return = array_replace_recursive($return,$m);
index fdcca9a45fd0b30b60704ce8d3618222724f2380..5294cded837524bea2d0470836a60dcbaa3f4806 100644 (file)
@@ -124,6 +124,7 @@ Class Table extends nb {
    */
   public function db($set=null) {
     static $db = null;
+    #if ($set !== null) debug($set->name);
     if ($set !== null) $db = $set;
     return $db;
   }
@@ -856,6 +857,7 @@ Class Table extends nb {
       : false
     ;
 
+#debug($this->db()->name);
     if ($opt['is_html'] and !$this->p('action') and !$this->p('inc')) {
       echo $this->html_menu();
     }
@@ -944,10 +946,8 @@ Class Table extends nb {
 
     } # < rows
 
-    if (!$count) {
-      $st->closeCursor();
-      return;
-    }
+    $st->closeCursor();
+    if (!$count) return;
 
     $this->count = $opt['count'] = $count;
     $this->limit = $opt['limit'] = $limit;
@@ -1011,8 +1011,6 @@ Class Table extends nb {
       echo '</div>'.NB_EOL;
     }
 
-    $st->closeCursor();
-
     return $count;
   }
 
@@ -1758,11 +1756,6 @@ Class Table extends nb {
     return $r;
   }
 
-  public function __wakeup() {
-    global $Db;
-    $this->db($Db);
-  }
-
   public function __sleep() {
     return [
       'name',
index 4066e1a1593fbf5d5dd7886863cee78dff43f359..129f7fdb5359ab0b025f767418089e3b9593a315 100644 (file)
@@ -102,6 +102,7 @@ table.rows tr:last-child td { border-bottom: none; }
   background-color: #3C3C3B;
   border-color: #3C3C3B;
   border-radius: 4px;
+  padding: 0 0.2em;
 }
 
 a:hover,
index c4c4e2e49fd495b3b0f16e1f37c7e17448d2d8bd..aa108f0da7486e614c9b3b0782d4a5bace77342c 100644 (file)
@@ -2,7 +2,6 @@
 # Make it work in php_cli
 if (empty($_SERVER['DOCUMENT_ROOT'])) $_SERVER['DOCUMENT_ROOT'] = dirname(__FILE__);
 #var_export([$_SERVER['REQUEST_URI']]);
-if (empty($_SERVER['SERVER_PROTOCOL'])) $_SERVER['SERVER_PROTOCOL'] = 'HTTP/1.0';
 
 function run() {
   $params = parse_uri([
@@ -17,7 +16,9 @@ function run() {
   #
   # Page
   require_once($_SERVER['DOCUMENT_ROOT'].'/../../../lib/php/page.php');
-  $Page = new Page();
+  $Page = new Page([
+    'css' => '/default.css',
+  ]);
   $Page->content_type($Page->ext2mime($params['format']) ? $Page->ext2mime($params['format']) : 'text/plain');
   #$Page->content_type('text/plain');
   #if ($Page->is('text') and !$Page->is('html')) $Page->content_type('text/plain');
@@ -190,6 +191,7 @@ $Page->call([
 
 function not_implemented() {
   #return http_response_code(501);
+  if (empty($_SERVER['SERVER_PROTOCOL'])) $_SERVER['SERVER_PROTOCOL'] = 'HTTP/1.0';
   $msg = '501 Not Implemented';
   header($_SERVER['SERVER_PROTOCOL'].' '.$msg);
   echo "$msg\n";