MetaModels\Helper\TableManipulation::renameColumn PHP Метод

renameColumn() публичный статический Метод

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.
Результат void
    public static function renameColumn($strTableName, $strColumnName, $strNewColumnName, $strNewType, $blnAllowSystemCol = false)
    {
        if ($strColumnName != $strNewColumnName) {
            self::checkColumnExists($strTableName, $strColumnName, $blnAllowSystemCol);
            self::checkColumnDoesNotExist($strTableName, $strNewColumnName, $blnAllowSystemCol);
        }
        self::getDB()->execute(sprintf(self::STATEMENT_RENAME_COLUMN, $strTableName, $strColumnName, $strNewColumnName, $strNewType));
    }

Usage Example

Пример #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);
     }
 }