| 6 database.mysql-common.inc |
db_change_field(&$ret, $table, $field, $field_new, $spec, $keys_new = array()) |
| 6 database.pgsql.inc |
db_change_field(&$ret, $table, $field, $field_new, $spec, $new_keys = array()) |
| 7 database.inc |
db_change_field($table, $field, $field_new, $spec, $keys_new = array()) |
| 8 database.inc |
db_change_field($table, $field, $field_new, $spec, $keys_new = array()) |
Related topics
- Schema API
- A Drupal schema definition is an array structure representing one or
more tables and their related keys and indexes. A schema is defined by
hook_schema(), which usually lives in a modulename.install file.
File
- includes/database.mysql-common.inc, line 523
- Functions shared between mysql and mysqli database engines.
Code
function db_change_field(&$ret, $table, $field, $field_new, $spec, $keys_new = array()) {
$sql = 'ALTER TABLE {' . $table . '} CHANGE `' . $field . '` ' .
_db_create_field_sql($field_new, _db_process_field($spec));
if (count($keys_new)) {
$sql .= ', ADD ' . implode(', ADD ', _db_create_keys_sql($keys_new));
}
$ret[] = update_sql($sql);
}
Login or
register to post comments
Comments
Changing a primary key's name
This was not straightforward for me, so I thought I'd write up a method for changing the name of a serial field that forms a primary key:
<?phpdb_change_field(
$ret,
'table_name',
'old_field_name',
'new_field_name',
array(
'type' => 'serial',
'description' => $t('Column description.'),
)
);
?>
documentation is elsewhere
View the documentation for this function at http://api.drupal.org/api/drupal/includes--database.pgsql.inc/function/d... .