public function Schema::fieldSetDefault in Drupal driver for SQL Server and SQL Azure 3.0.x
Same name and namespace in other branches
- 8.2 drivers/lib/Drupal/Driver/Database/sqlsrv/Schema.php \Drupal\Driver\Database\sqlsrv\Schema::fieldSetDefault()
- 8 drivers/lib/Drupal/Driver/Database/sqlsrv/Schema.php \Drupal\Driver\Database\sqlsrv\Schema::fieldSetDefault()
File
- drivers/
lib/ Drupal/ Driver/ Database/ sqlsrv/ Schema.php, line 363
Class
Namespace
Drupal\Driver\Database\sqlsrvCode
public function fieldSetDefault($table, $field, $default) {
@trigger_error('fieldSetDefault() is deprecated in drupal:8.7.0 and will be removed before drupal:9.0.0. Instead, call ::changeField() passing a full field specification. See https://www.drupal.org/node/2999035', E_USER_DEPRECATED);
if (!$this
->fieldExists($table, $field)) {
throw new SchemaObjectDoesNotExistException(t("Cannot set default value of field %table.%field: field doesn't exist.", [
'%table' => $table,
'%field' => $field,
]));
}
$default = $this
->escapeDefaultValue($default);
// Try to remove any existing default first.
try {
$this
->fieldSetNoDefault($table, $field);
} catch (\Exception $e) {
}
// Create the new default.
$this->connection
->query('ALTER TABLE [{' . $table . '}] ADD CONSTRAINT {' . $table . '}_' . $field . '_df DEFAULT ' . $default . ' FOR [' . $field . ']');
$this
->resetColumnInformation($table);
}