public function DataTable::addField in Data 7
Same name and namespace in other branches
- 6 includes/DataTable.inc \DataTable::addField()
Add a field.
@todo: Check wether field name is available, otherwise change.
Throws
File
- includes/
DataTable.inc, line 263 - Contains class definition for DataTable.
Class
- DataTable
- Manages data access and manipulation for a single data table. Use data_create_table() or data_get_table() to instantiate an object from this class.
Code
public function addField($field, $spec) {
try {
db_add_field($this->name, $field, $spec);
$schema = $this->table_schema;
$schema['fields'][$field] = $spec;
$this
->update(array(
'table_schema' => $schema,
));
// @todo: use clearCaches().
drupal_get_schema($this->name, TRUE);
// Invalidate views caches to use new field immediately.
if (function_exists('views_invalidate_cache')) {
views_invalidate_cache();
}
return $field;
} catch (DatabaseSchemaObjectExistsException $e) {
throw new DataException(t('Error adding field.'));
}
throw new DataException(t('Error adding field.'));
}