You are here

public function Schema::dropField in Drupal driver for SQL Server and SQL Azure 3.0.x

Same name and namespace in other branches
  1. 8.2 drivers/lib/Drupal/Driver/Database/sqlsrv/Schema.php \Drupal\Driver\Database\sqlsrv\Schema::dropField()
  2. 8 drivers/lib/Drupal/Driver/Database/sqlsrv/Schema.php \Drupal\Driver\Database\sqlsrv\Schema::dropField()

Should this be in a Transaction?

Overrides Schema::dropField

3 calls to Schema::dropField()
Schema::changeField in drivers/lib/Drupal/Driver/Database/sqlsrv/Schema.php
Change a field definition.
Schema::cleanUpPrimaryKey in drivers/lib/Drupal/Driver/Database/sqlsrv/Schema.php
Drop the primary key constraint.
Schema::cleanUpTechnicalPrimaryColumn in drivers/lib/Drupal/Driver/Database/sqlsrv/Schema.php
Tries to clean up the technical primary column.

File

drivers/lib/Drupal/Driver/Database/sqlsrv/Schema.php, line 335

Class

Schema

Namespace

Drupal\Driver\Database\sqlsrv

Code

public function dropField($table, $field) {
  if (!$this
    ->fieldExists($table, $field)) {
    return FALSE;
  }
  $primary_key_fields = $this
    ->findPrimaryKeyColumns($table);
  if (in_array($field, $primary_key_fields)) {

    // Let's drop the PK.
    $this
      ->cleanUpPrimaryKey($table);
    $this
      ->createTechnicalPrimaryColumn($table);
  }

  // Drop the related objects.
  $this
    ->dropFieldRelatedObjects($table, $field);

  // Drop field comments.
  if ($this
    ->getComment($table, $field) !== FALSE) {
    $this->connection
      ->queryDirect($this
      ->deleteCommentSql($table, $field));
  }
  $this->connection
    ->query('ALTER TABLE {' . $table . '} DROP COLUMN ' . $field);
  $this
    ->resetColumnInformation($table);
  return TRUE;
}