You are here

public function Schema::CommentCreateOrUpdate in Drupal driver for SQL Server and SQL Azure 8.2

Create, update or remove a comment for a database object, transaction friendly.

Parameters

$value: The actual comment, use null or empty string to remove the comment

null $table: The table

null $column: The column

Return value

mixed

2 calls to Schema::CommentCreateOrUpdate()
Schema::addField in drivers/lib/Drupal/Driver/Database/sqlsrv/Schema.php
Override DatabaseSchema::addField().
Schema::createTable in drivers/lib/Drupal/Driver/Database/sqlsrv/Schema.php
{@Inheritdoc}

File

drivers/lib/Drupal/Driver/Database/sqlsrv/Schema.php, line 237
Definition of Drupal\Driver\Database\sqlsrv\Schema

Class

Schema

Namespace

Drupal\Driver\Database\sqlsrv

Code

public function CommentCreateOrUpdate($value, $table = null, $column = null) : void {
  $schema = $this
    ->GetDefaultSchema();
  $name = 'MS_Description';
  $columns = $this->columnComments;

  // Determine if a value exists for this database object.
  $key = $schema . '.' . $table . '.' . $column;
  if (isset($columns[$key]) && $this->connection
    ->GetConnection()
    ->inTransaction()) {
    $result = $columns[$key];
  }
  else {
    $result = $this
      ->CommentGet($table, $column);
  }
  $columnComments[$key] = $value;

  // Only continue if the new value is different from the existing value.
  $sql = '';
  if ($result !== $value) {
    if ($value == '' || is_null($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)) {
      $table_prefixed = $this->connection
        ->prefixTable($table);
      $sql .= ",@level0type = N'Schema', @level0name = '" . $schema . "'";
      if (isset($table_prefixed)) {
        $sql .= ",@level1type = N'Table', @level1name = '" . $table_prefixed . "'";
        if ($column !== null) {
          $sql .= ",@level2type = N'Column', @level2name = '" . $column . "'";
        }
      }
    }
  }
  $this->connection
    ->GetConnection()
    ->query_execute($sql);
}