protected function Schema::createDescriptionSql in Drupal driver for SQL Server and SQL Azure 8
Return the SQL statement to create or update a description.
File
- drivers/
lib/ Drupal/ Driver/ Database/ sqlsrv/ Schema.php, line 1723 - Definition of Drupal\Driver\Database\sqlsrv\Schema
Class
Namespace
Drupal\Driver\Database\sqlsrvCode
protected function createDescriptionSql($value, $table = NULL, $column = NULL) {
// Inside the same transaction, you won't be able to read uncommited extended properties
// leading to SQL Exception if calling sp_addextendedproperty twice on same object.
static $columns;
if (!isset($columns)) {
$columns = array();
}
$schema = $this->defaultSchema;
$table_info = $this
->getPrefixInfo($table);
$table = $table_info['table'];
$name = 'MS_Description';
// Determine if a value exists for this database object.
$key = $this->defaultSchema . '.' . $table . '.' . $column;
if (isset($columns[$key])) {
$result = $columns[$key];
}
else {
$result = $this
->getComment($table, $column);
}
$columns[$key] = $value;
// Only continue if the new value is different from the existing value.
$sql = '';
if ($result !== $value) {
if ($value == '') {
$sp = "sp_dropextendedproperty";
$sql = "EXEC " . $sp . " @name=N'" . $name;
}
else {
if ($result != '') {
$sp = "sp_updateextendedproperty";
}
else {
$sp = "sp_addextendedproperty";
}
$sql = "EXEC " . $sp . " @name=N'" . $name . "', @value=" . $value . "";
}
if (isset($schema)) {
$sql .= ",@level0type = N'Schema', @level0name = '" . $schema . "'";
if (isset($table)) {
$sql .= ",@level1type = N'Table', @level1name = '" . $table . "'";
if ($column !== NULL) {
$sql .= ",@level2type = N'Column', @level2name = '" . $column . "'";
}
}
}
}
return $sql;
}