]> git.nbdom.net Git - nb.git/commitdiff
www/dbq/dbq.php
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Wed, 10 Jan 2018 00:46:16 +0000 (00:46 +0000)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Wed, 10 Jan 2018 00:46:16 +0000 (00:46 +0000)
lib/php/db/table.php
www/dbq/dbq.php

index d9ce8199e3cf147003ad181f31b1e76924aa0b84..4bbf3042adce23608bac5ba180d3e03819c56e3c 100644 (file)
@@ -232,15 +232,22 @@ Class Table extends nb {
       return $sql_replace('CREATE VIEW '.$this->sql_name().' AS '.preg_replace('/^CREATE\s+.*?\s+AS\s+.*?SELECT/i','SELECT',$this->sql()));
     }
 
-    $type = $this->db()->type;
-    if (!empty($db_type)) $this->db()->type = $db_type;
-
     $indexes = [];
     foreach ($this->indexes() as $i) {
       if (!empty($i['unique']) or !empty($i['key'])) continue;
       $indexes[] = 'CREATE INDEX '.$i['name'].' ON '.$this->sql_name().' ('.$i['field'].')';
     }
 
+    # Get all fields
+    $fields = [];
+    foreach ($this->fields() as $f) {
+      if (!empty($f->extras)) continue;
+      $fields[] = $f;
+    }
+
+    $type = $this->db()->type;
+    if (!empty($db_type)) $this->db()->type = $db_type;
+
     // Specific function for fields if return something use it instead of default
     $_create_fct = $this->db()->conf_type('field.create',false);
     $_create = function(&$field) use ($_create_fct) {
@@ -255,13 +262,6 @@ Class Table extends nb {
       ;
     };
 
-    # Get all fields
-    $fields = [];
-    foreach ($this->fields() as $f) {
-      if (!empty($f->extras)) continue;
-      $fields[] = $f;
-    }
-
     $sql = 'CREATE '.strtoupper($this->type()).' '.$this->sql_name()
       .' ('
       .join(",",array_map(function($f) use ($_create) {return $_create($f);},$fields))
index 9fc0121d03a2b6462a83ebfe3031fe354c245610..b1d4d5473977ae43d950e2747fbb79c3f705a413 100644 (file)
@@ -259,7 +259,9 @@ class DbQ extends nb {
                        $rows = $obj;
 
                } elseif (empty($meth)) {
+                       if ($this->is_html) echo '<div class="block">'.NB_EOL;
                        echo $obj;
+                       if ($this->is_html) echo '</div>'.NB_EOL;
 
                } elseif (is_array($meth)) {
                        $rows = $meth;
@@ -1207,6 +1209,7 @@ EOF;
                                [ 'replace', 'Replace record' ],
                                [ 'rm', 'Remove record' ],
                                [ 'add', 'Record record' ],
+                               [ 'schema', 'Sql schema [/DB_TYPE]' ],
                                [ 'status', 'Status page' ],
                        ],['command','description'],function(&$r){
                                $r['command'] = $this->page->tag('a',$r['command'],'href="'
@@ -1221,7 +1224,7 @@ EOF;
                        $this->page_table_ls($this->params['args']);
 
                } elseif ($action == 'schema') {
-                       $this->page(preg_replace('/\s*;\s*$/','',$this->table->create(true,$this->params['args'])).";\n");
+                       $this->page(preg_replace('/\s*;\s*$/','',$this->table->create(false,$this->params['args'])).";\n");
 
                } elseif ($action == 'sql') {
                        $this->page(['sql'=>$this->table->sql()]);