From 289a07a156ab47f8413cde35edb565dd312a9093 Mon Sep 17 00:00:00 2001 From: Nicolas Boisselier Date: Wed, 10 Jan 2018 00:27:10 +0000 Subject: [PATCH] lib/php/db/table.php --- lib/php/db/table.php | 17 +++++++++++------ www/dbq/dbq.php | 2 +- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/lib/php/db/table.php b/lib/php/db/table.php index 3be2e015..d9ce8199 100644 --- a/lib/php/db/table.php +++ b/lib/php/db/table.php @@ -216,7 +216,7 @@ Class Table extends nb { * return the sql to create the table build internaly * */ - public function create($from_engine=true) { + public function create($from_engine=true,$db_type='') { // String replace function $sql_replace_fct = $this->db()->conf_type('table.sql.create'); @@ -232,6 +232,15 @@ 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'].')'; + } + // 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) { @@ -266,11 +275,7 @@ Class Table extends nb { ; } - $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'].')'; - } + $this->db()->type = $type; return $sql_replace($sql.')'.($indexes ? ';'.join(';',$indexes) : '')); } diff --git a/www/dbq/dbq.php b/www/dbq/dbq.php index feae74d5..9fc0121d 100644 --- a/www/dbq/dbq.php +++ b/www/dbq/dbq.php @@ -1221,7 +1221,7 @@ EOF; $this->page_table_ls($this->params['args']); } elseif ($action == 'schema') { - $this->page(preg_replace('/\s*;\s*$/','',$this->table->create()).";\n"); + $this->page(preg_replace('/\s*;\s*$/','',$this->table->create(true,$this->params['args'])).";\n"); } elseif ($action == 'sql') { $this->page(['sql'=>$this->table->sql()]); -- 2.47.3