예제 #1
0
 protected function getSQLField(Type $type, $without_auto_increment = false)
 {
     $result = "`" . $type->getName() . "` " . $type->getType() . "";
     if ($type->getLength()) {
         $result .= "(" . $type->getLength() . ")";
     }
     if ($type->getAttribute()) {
         $result .= " {$type->getAttribute()}";
     }
     if ($type->getCollate()) {
         $charset = explode("_", $type->getCollate(), 2);
         $result .= " CHARACTER SET " . $charset[0] . " COLLATE " . $type->getCollate();
     }
     if ($type->isNull()) {
         $result .= " NULL";
     } else {
         $result .= " NOT NULL";
     }
     if ($type->getDefault() !== null) {
         if (is_string($type->getDefault()) && strlen($type->getDefault()) > 0 && $type->getDefault()[0] == "#") {
             $result .= " DEFAULT " . substr($type->getDefault(), -strlen($type->getDefault()) + 1);
         } else {
             $result .= " DEFAULT '{$type->getDefault()}'";
         }
     }
     if ($type->isAutoIncrement() && !$without_auto_increment) {
         $result .= " auto_increment";
     }
     return $result;
 }
예제 #2
0
 public function enum($name, array $enum = [], $default = null, $index = "", $collation = "utf8_general_ci")
 {
     return $this->addColumn(Type::enum($name, $enum, $default, $index, $collation));
 }