function DatabaseSchema_mysql::changeField

Overrides DatabaseSchema::changeField

1 call to DatabaseSchema_mysql::changeField()
DatabaseSchema_mysql::addField in includes/database/mysql/schema.inc
Add a new field to a table.

File

includes/database/mysql/schema.inc, line 465

Class

DatabaseSchema_mysql

Code

public function changeField($table, $field, $field_new, $spec, $keys_new = array()) {
    if (!$this->fieldExists($table, $field)) {
        throw new DatabaseSchemaObjectDoesNotExistException(t("Cannot change the definition of field @table.@name: field doesn't exist.", array(
            '@table' => $table,
            '@name' => $field,
        )));
    }
    if ($field != $field_new && $this->fieldExists($table, $field_new)) {
        throw new DatabaseSchemaObjectExistsException(t("Cannot rename field @table.@name to @name_new: target field already exists.", array(
            '@table' => $table,
            '@name' => $field,
            '@name_new' => $field_new,
        )));
    }
    $sql = 'ALTER TABLE {' . $table . '} CHANGE `' . $field . '` ' . $this->createFieldSql($field_new, $this->processField($spec));
    if ($keys_sql = $this->createKeysSql($keys_new)) {
        $sql .= ', ADD ' . implode(', ADD ', $keys_sql);
    }
    $this->connection
        ->query($sql);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.