$this->type = $type_to;
}
+ # Specific function
+ $row_opt = [
+ 'parser' => false,
+ ];
+ if ($fct = $this->conf_type('table.sql.create')) {
+ $row_opt['fct'] = $fct;
+ }
+
# SQL_PRE
$i = 0; foreach ($this->sql_pre() as $s) {
if (($i++) == 0) echo "\n-- SQL_PRE\n";
}
#bye($this->db()->type);
- $fct = $this->conf_type('table.sql.create',false);
- if (!$fct) $fct = false;
foreach ($tables as $t) {
+ #if ($fct) $t->row_parse_post = $fct;
+ #$t->row_parse_pre = null;
+
# DROP / CREATE
$create = rtrim($t->create(false),';');
$create = str_replace(';CREATE',";\nCREATE",$create);
# INSERT
if ($insert and $t->type == 'table') {
if ($type_from) $this->type = $type_from;
- $t->rows();
+ $t->rows($row_opt);
if ($type_to) $this->type = $type_to;
}
public $extra;
public $extras;
- public function __sleep() { return array(
+ public function __sleep() { return [
'name',
'type',
'null',
'default',
'autoincrement',
'extra',
- ); }
+ ]; }
- public function __construct($attr=array()) {
- if (is_scalar($attr)) $attr = array('name'=>$attr);
+ public function __construct($attr=[]) {
+ if (is_scalar($attr)) $attr = ['name'=>$attr];
foreach ($attr as $k => $v) { $this->$k = $v; }
if ($this->default == "''") $this->default = '';
}
}
public function db() {
+ if (!empty($this->table) and !empty($this->table->db)) return $this->table->db();
global $Db;
return ( isset($Db) ? $Db : null );
}
if (isset($conf['fct'])) $conf['fct']($row) ;
$field = array(
+ 'table' => $this,
'name' => $row['name'],
'type' => strtolower($row['type']),
'key' => (preg_match('/^(f.*|no|0)?\s*$/i',$row['key']) ? 0 : 1),
out::head($out_conf,$this->fields(),[$row]);
} else {
- echo $this->{"rows_begin_$format"}($this->fields());
+ echo $this->{"rows_begin_$format"}($this->fields(),$opt);
}
}
if ($out_conf) {
out::row($out_conf,$row);
} else {
- echo $this->{"rows_rec_$format"}($row);
+ echo $this->{"rows_rec_$format"}($row,$opt);
}
} # < rows
return "\n-- ".$this->name."\n";
}
- public function rows_rec_sql(&$row) {
+ public function rows_rec_sql(&$row,&$opt) {
$keys = $values = array();
foreach ($row as $k=>$v) {
$sql = "INSERT INTO ".$this->sql_name()." VALUES (".join(',',array_values($values)).");";
#$sql = "INSERT INTO ".$this->sql_name()." (".join(',',$keys).") VALUES (".join(',',array_values($values)).");";
#if ($fct and $this->name=='place') debug($sql);
+ $fct = !empty($opt['fct']) ? $opt['fct'] : null;
+ if ($fct) $sql = $fct($sql,$this);
+
return $sql.NB_EOL;
}
'extra_where' => 'denorm',
'quote_name' => '`',
-'quote' => function(&$v) { return "'".str_replace("'","''",$v)."'"; },
+'quote' => function($v) {
+ $v = "'".str_replace("'","''",$v)."'";
+ return $v;
+},
'databases' => [
'PRAGMA database_list',function(&$r) {
#debug($GLOBALS['Db']->databases());
'table.sql.create' => function($sql,$t) {
#$sql .= $t->db()->row("SELECT sql FROM sqlite_master WHERE type='index' AND tbl_name=".$t->sql_name());
$sql = str_replace("\\'","''",$sql);
+ $sql = str_replace('\\r',"\r",$sql);
+ $sql = str_replace('\\n',"\n",$sql);
#$sql = preg_replace("/\\'/","''",$sql);
#$sql = 'espace';
#$sql = "zaza $sql";