protected function column_value(\ebi\Dao $dao, $name, $value) { if ($value === null) { return null; } try { switch ($dao->prop_anon($name, 'type')) { case 'timestamp': if (!ctype_digit($value)) { $value = strtotime($value); } // UTCとして扱う return date('Y-m-d H:i:s', $value - $this->timezone_offset); case 'date': if (!ctype_digit($value)) { $value = strtotime($value); } return date('Y-m-d', $value); case 'boolean': return (int) $value; } } catch (\Exception $e) { } return $value; }
protected function create_table_prop_cond(\ebi\Dao $dao, $prop_name) { return $dao->prop_anon($prop_name, 'extra') !== true && $dao->prop_anon($prop_name, 'cond') === null; }
/** * create table */ public function create_table_sql(\ebi\Dao $dao) { $columndef = $primary = []; $sql = 'create table ' . $this->quotation($dao->table()) . '(' . PHP_EOL; foreach ($dao->columns(true) as $prop_name => $column) { $type = $dao->prop_anon($prop_name, 'type'); if ($this->create_table_prop_cond($dao, $prop_name)) { $column_str = ' ' . $this->to_column_type($dao, $type, $column->column()) . ($type != 'serial' ? ' null ' : ''); $columndef[] = $column_str; if ($dao->prop_anon($prop_name, 'primary') === true || $type != 'serial') { $primary[] = $this->quotation($column->column()); } } } $sql .= implode(',' . PHP_EOL, $columndef) . PHP_EOL; if (!empty($primary)) { $sql .= ' ,primary key ( ' . implode(',', $primary) . ' ) ' . PHP_EOL; } $sql .= ' );' . PHP_EOL; return $sql; }