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

index 3be2e0158ffccb5492414eb725119de5bcb2298b..d9ce8199e3cf147003ad181f31b1e76924aa0b84 100644 (file)
@@ -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) : ''));
   }
 
index feae74d58695b2d0a81a4b9ca07ad60b2a528333..9fc0121d03a2b6462a83ebfe3031fe354c245610 100644 (file)
@@ -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()]);