]> git.nbdom.net Git - nb.git/commitdiff
dbs
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Wed, 23 Dec 2015 23:09:43 +0000 (00:09 +0100)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Wed, 23 Dec 2015 23:09:43 +0000 (00:09 +0100)
lib/php/db.php
lib/php/db/table.php

index 5d61913d39d8d4a2309453969700f9f035655a00..508a68dce6bdc43737dd80da3c70f8706fb5561c 100644 (file)
@@ -40,6 +40,7 @@ class db extends nb {
   public $tables = array();
 
   # Web
+  public $dbs; // others databases keys
   public $table;
   public $help_criterias = array(
     ' * or % for wildcar',
@@ -68,7 +69,8 @@ class db extends nb {
     }
 
     #if (empty($this->name)) $this->name = preg_replace('/^(?:(?:sqlite:.*(.*?)(\.\w+)?)|(?:.*?dbname=([^;]+).*?))$/','\1',$this->pdo);
-    if (empty($this->name) and preg_match('/(?:sqlite:|dbname=)([^;\.]+)/',$this->pdo,$m)) {
+# NB 22.12.15     if (empty($this->name) and preg_match('/(?:sqlite:|dbname=)([^;\.]+)/',$this->pdo,$m)) {
+    if (empty($this->name) and preg_match('/(?:sqlite:(?:.*\/)?|dbname=)([^;\.]+)/',$this->pdo,$m)) {
       $this->name = $m[1];
     }
     if (empty($this->title)) $this->title = prettyText($this->name);
@@ -319,11 +321,22 @@ EOF;
       '10','20','50','100','500','1000'
     ),array(
       'html'       => 'class="limit" name="limit" id="limit"',
-      'selected'   => $this->p('table'),
+      'selected'   => $this->p('limit'),
       'prettyText' => true,
     ));
     $r .= '</span>';
 
+    // Dbs
+    if (!empty($this->dbs) and count($this->dbs)>1) {
+      $r .= '<span class="label">';
+      $r .= '<label for="db">Db</label>'.html_select_array($this->dbs,array(
+        'html'       => 'class="dbs" onchange="document.location=\''.preg_replace('/\?.*$/','',$_SERVER['REQUEST_URI']).'?db=\'+this.value"',
+        'selected'   => $this->name,
+        'prettyText' => true,
+      ));
+      $r .= '</span>';
+    }
+
     // Buttons
     $r .= DB_HTML_FORM_BUTTONS;
 
index 5dad705d909e8063913b0c818c48aa06e3804b68..1f85e01b73906db7e59b9c69770145fbc1f5931c 100644 (file)
@@ -298,7 +298,7 @@ FROM pg_catalog.pg_attribute a WHERE a.attrelid = (SELECT c.oid FROM pg_catalog.
       .'</div>'.PHP_EOL
       .'<input type="hidden" name="table" value="'.$this->name.'"/>'
       .'<input type="hidden" name="action" value="update"/>'
-      .'<input type="hidden" name="db" value="'.$this->db->name.'"/>'
+      .'<input type="hidden" name="db" value="'.$this->p('db').'"/>'
       .'<input type="hidden" name="debug" value="'.$this->p('debug').'"/>'
       .'<input type="hidden" name="referer" value="'.urlencode(@$_SERVER['HTTP_REFERER']).'"/>'
     .'</form>'.PHP_EOL;
@@ -445,10 +445,9 @@ FROM pg_catalog.pg_attribute a WHERE a.attrelid = (SELECT c.oid FROM pg_catalog.
       'html' => 'name="format"',
       'selected' => $this->p('format'),
     ));
-    $criteria[] = '<input type="submit" class="button" value="GO"/>';
 
+    $criteria[] = '<input type="submit" class="button" value="GO"/>';
     echo join(''.PHP_EOL,$criteria);
-
     echo '</form>'.PHP_EOL;
 
   }
@@ -994,7 +993,7 @@ FROM pg_catalog.pg_attribute a WHERE a.attrelid = (SELECT c.oid FROM pg_catalog.
       if ($this->p('referer')) {
         header('Location: '.urldecode($this->p('referer')));
       } else {
-        header('Location: ?table=' . $this->name . ($this->p('db') ? '&db='.$this->db->name : ''));
+        header('Location: ?table=' . $this->name . ($this->p('db') ? '&db='.$this->p('db') : ''));
       }
       #header('Location: '.str_replace('&amp;','&',$this->url_list()));
       return true;
@@ -1005,7 +1004,7 @@ FROM pg_catalog.pg_attribute a WHERE a.attrelid = (SELECT c.oid FROM pg_catalog.
       if ($this->p('referer')) {
         header('Location: '.urldecode($this->p('referer')));
       } else {
-        header('Location: ?table=' . $this->name . ($this->p('db') ? '&db='.$this->db->name : ''));
+        header('Location: ?table=' . $this->name . ($this->p('db') ? '&db='.$this->p('db') : ''));
       }
       #header('Location: '.str_replace('&amp;','&',$this->url_list()));
       return true;