From: Nicolas Boisselier Date: Wed, 10 Jan 2018 00:46:16 +0000 (+0000) Subject: www/dbq/dbq.php X-Git-Url: https://git.nbdom.net/?a=commitdiff_plain;h=36456c94c36b843d0afaf2d9fa2342281e1d79c2;p=nb.git www/dbq/dbq.php --- diff --git a/lib/php/db/table.php b/lib/php/db/table.php index d9ce8199..4bbf3042 100644 --- a/lib/php/db/table.php +++ b/lib/php/db/table.php @@ -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)) diff --git a/www/dbq/dbq.php b/www/dbq/dbq.php index 9fc0121d..b1d4d547 100644 --- a/www/dbq/dbq.php +++ b/www/dbq/dbq.php @@ -259,7 +259,9 @@ class DbQ extends nb { $rows = $obj; } elseif (empty($meth)) { + if ($this->is_html) echo '
'.NB_EOL; echo $obj; + if ($this->is_html) echo '
'.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()]);