示例#1
0
 /**
  * changeColumn
  *
  * @param string $oldName
  * @param string|Column  $newName
  * @param string $type
  * @param bool   $signed
  * @param bool   $allowNull
  * @param string $default
  * @param string $comment
  * @param array  $options
  *
  * @return  static
  */
 public function changeColumn($oldName, $newName, $type = 'text', $signed = true, $allowNull = true, $default = '', $comment = '', $options = array())
 {
     if ($newName instanceof Column) {
         $column = $newName;
         $length = $column->getLength();
         $newName = $column->getName();
         $type = $column->getType() . $length;
         $signed = $column->getSigned();
         $allowNull = $column->getAllowNull();
         $default = $column->getDefault();
         $position = $column->getPosition();
         $comment = $column->getComment();
     } else {
         $position = isset($options['position']) ? $options['position'] : null;
     }
     $type = MysqlType::getType($type);
     $length = isset($length) ? $length : MysqlType::getLength($type);
     $length = $length ? '(' . $length . ')' : null;
     $query = MysqlQueryBuilder::changeColumn($this->table, $oldName, $newName, $type . $length, $signed, $allowNull, $default, $position, $comment);
     $this->db->setQuery($query)->execute();
     return $this;
 }
示例#2
0
 /**
  * addColumn
  *
  * @param string $name
  * @param string $type
  * @param bool   $signed
  * @param bool   $allowNull
  * @param string $default
  * @param string $comment
  * @param array  $options
  *
  * @return  static
  */
 public function addColumn($name, $type = 'text', $signed = true, $allowNull = true, $default = '', $comment = '', $options = array())
 {
     $column = $name;
     if (!$column instanceof Column) {
         $column = new Column($name, $type, $signed, $allowNull, $default, $comment, $options);
     }
     $type = MysqlType::getType($column->getType());
     $length = $column->getLength() ?: MysqlType::getLength($type);
     $column->type($type)->length($length);
     if ($column->isPrimary()) {
         $this->primary[] = $column->getName();
     }
     $this->columns[] = $column;
     return $this;
 }