renameColumn() public static method

Throws Exception if the table does not exist, the column name is invalid or the column already exists.
public static renameColumn ( string $strTableName, string $strColumnName, string $strNewColumnName, string $strNewType, boolean $blnAllowSystemCol = false ) : void
$strTableName string The name of the table the column is in.
$strColumnName string The current name of the column to be renamed.
$strNewColumnName string The new name for the column.
$strNewType string The new SQL type notation of the column.
$blnAllowSystemCol boolean If this is set to true, no system column name checking will be applied.
return void
示例#1
0
 /**
  * Renames the underlying database structure for this field.
  *
  * @param string $strNewColumnName The new column name.
  *
  * @return void
  */
 public function renameColumn($strNewColumnName)
 {
     TableManipulation::checkColumnName($strNewColumnName);
     if ($this->getColName() && $this->getMetaModel()->getServiceContainer()->getDatabase()->fieldExists($this->getColName(), $this->getMetaModel()->getTableName(), true)) {
         TableManipulation::renameColumn($this->getMetaModel()->getTableName(), $this->getColName(), $strNewColumnName, $this->getSQLDataType());
     } else {
         $strBackupColName = $this->getColName();
         $this->set('colname', $strNewColumnName);
         $this->createColumn();
         $this->set('colname', $strBackupColName);
     }
 }