renameColumn() public method

Builds and executes a SQL statement for renaming a column.
public renameColumn ( string $table, string $name, string $newName )
$table string the table whose column is to be renamed. The name will be properly quoted by the method.
$name string the old name of the column. The name will be properly quoted by the method.
$newName string the new name of the column. The name will be properly quoted by the method.
コード例 #1
0
ファイル: Migration.php プロジェクト: flexibuild/migrate
 /**
  * @inheritdoc
  * Note: table will be auto pefixied if [[$autoWrapTableNames]] is true.
  */
 public function renameColumn($table, $name, $newName)
 {
     $table = $this->autoWrappedTableName($table);
     return parent::renameColumn($table, $name, $newName);
 }
コード例 #2
-1
ファイル: CmField.php プロジェクト: jackieit/aimocms
 /**
  * @param bool $insert
  * @param array $changedAttributes
  * @return bool
  */
 public function afterSave($insert, $changedAttributes)
 {
     parent::afterSave($insert, $changedAttributes);
     if (!in_array($this->scenario, ['update', 'create'])) {
         return true;
     }
     $cm = $this->cm;
     $mg = new Migration();
     $table = Cm::$TAB_PREFIX[$cm->tab_index] . $cm->tab;
     $column = null;
     $type = $this->data_type;
     switch ($type) {
         case 'integer':
         case 'smallInteger':
         case 'boolean':
         case 'float':
         case 'double':
             $column = $mg->{$type}()->notNull()->defaultValue(0);
             break;
         case 'string':
             $column = $mg->{$type}($this->length)->notNull()->defaultValue('');
             break;
         case 'decimal':
             $column = $mg->{$type}($this->length)->notNull()->defaultValue(0);
             break;
         default:
             $column = $mg->{$type}()->defaultValue(null);
             break;
     }
     $column .= " COMMENT '" . $this->label . "'";
     if ($insert) {
         $mg->addColumn('{{%' . $table . '}}', $this->name, $column);
     } else {
         $oldName = $this->old_name;
         $newname = $this->name;
         if ($oldName !== $newname) {
             $mg->renameColumn('{{%' . $table . '}}', $oldName, $newname);
         }
         $mg->alterColumn('{{%' . $table . '}}', $newname, $column);
     }
     return true;
 }