/** * @param $name * @param array $fields * @return string */ private function makeColumnsQuery(DatabaseColumn $field) { if (!$field instanceof DatabaseColumn) { $this->throwError("CreateTable Columns Error."); } $attr = array(); if ($field->getAttribute() == "unsigned") { $attr[] = "UNSIGNED"; } else { if ($field->getAttribute() == "zerofill") { $attr[] = "ZEROFILL"; } } if ($field->getNull()) { $attr[] = "NULL"; } else { $attr[] = "NOT NULL"; } if ($field->getAi()) { $attr[] = "AUTO_INCREMENT"; } if ($field->getDefaultSet()) { if ($field->getDefault() === NULL && $field->getNull()) { $attr[] = "DEFAULT NULL"; } else { if ($field->isDate() || $field->isString() || $field->isText()) { $attr[] = "DEFAULT '" . $field->getDefault() . "'"; } else { if ($field->isInt()) { $attr[] = "DEFAULT " . intval($field->getDefault()) . ""; } else { $attr[] = "DEFAULT " . $field->getDefault() . ""; } } } } else { if ($field->getNull()) { $attr[] = "DEFAULT NULL"; } } if ($field->getKey() == "unique") { $attr[] = "UNIQUE"; } if ($field->getComment()) { $attr[] = "COMMENT '" . $field->getComment() . "'"; } $sql = ""; $sql .= $field->getType(); if ($field->getLength()) { $sql .= "(" . $field->getLength() . ") "; } $sql .= " " . implode(" ", $attr); return $sql; }
protected function simplified_type($sql_type) { if (strtolower($sql_type) == 'tinyint(1)') { return 'boolean'; } if (preg_match('/enum/i', $sql_type)) { return string; } return parent::simplified_type($sql_type); }