* 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');
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) {
;
}
- $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) : ''));
}
$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()]);