You are here

protected function Schema::createFieldSql in Drupal driver for SQL Server and SQL Azure 8.2

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

Create an SQL string for a field to be used in table creation or alteration.

Before passing a field out of a schema definition into this function it has to be processed by _db_process_field().

Parameters

$table: The name of the table.

$name: Name of the field.

$spec: The field specification, as per the schema data structure format.

3 calls to Schema::createFieldSql()
Schema::addField in drivers/lib/Drupal/Driver/Database/sqlsrv/Schema.php
Override DatabaseSchema::addField().
Schema::changeField in drivers/lib/Drupal/Driver/Database/sqlsrv/Schema.php
Override DatabaseSchema::changeField().
Schema::createTableSql in drivers/lib/Drupal/Driver/Database/sqlsrv/Schema.php
Generate SQL to create a new table from a Drupal schema definition.

File

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

Class

Schema

Namespace

Drupal\Driver\Database\sqlsrv

Code

protected function createFieldSql($table, $name, $spec, $skip_checks = false) {
  $sql = $this->connection
    ->quoteIdentifier($name) . ' ' . $spec['sqlsrv_type'];

  // When binary is true, case sensitivity is requested.
  if (isset($spec['sqlsrv_collation'])) {
    $sql .= ' COLLATE ' . $spec['sqlsrv_collation'];
  }
  if (isset($spec['not null']) && $spec['not null']) {
    $sql .= ' NOT NULL';
  }
  if (!$skip_checks) {
    if (isset($spec['default'])) {

      // Use a prefixed table.
      $table_prefixed = $this->connection
        ->prefixTables('{' . $table . '}');
      $default = $this->connection
        ->Scheme()
        ->DefaultValueExpression($spec['sqlsrv_type'], $spec['default']);
      $sql .= " CONSTRAINT {$table_prefixed}_{$name}_df DEFAULT  {$default}";
    }
    if (!empty($spec['identity'])) {
      $sql .= ' IDENTITY';
    }
    if (!empty($spec['unsigned'])) {
      $sql .= ' CHECK (' . $this->connection
        ->quoteIdentifier($name) . ' >= 0)';
    }
  }
  return $sql;
}