You are here

protected function Schema::processField 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::processField()
  2. 3.0.x drivers/lib/Drupal/Driver/Database/sqlsrv/Schema.php \Drupal\Driver\Database\sqlsrv\Schema::processField()

Set database-engine specific properties for a field.

Parameters

$field: A field description array, as specified in the schema documentation.

3 calls to Schema::processField()
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 547
Definition of Drupal\Driver\Database\sqlsrv\Schema

Class

Schema

Namespace

Drupal\Driver\Database\sqlsrv

Code

protected function processField($field) {

  // Default size to normal.
  $field['size'] = $field['size'] ?? 'normal';

  // Set the correct database-engine specific datatype.
  if (!isset($field['sqlsrv_type'])) {
    $map = $this
      ->getFieldTypeMap();
    $field['sqlsrv_type'] = $map[$field['type'] . ':' . $field['size']];
    $field['sqlsrv_type_simple'] = DatabaseUtils::GetMSSQLType($field['sqlsrv_type']);
  }

  // Serial is identity.
  $field['identity'] = $field['type'] == 'serial';

  // If this is a text field.
  $field['sqlsrv_is_text'] = $field['sqlsrv_is_text'] ?? DatabaseUtils::IsTextType($field['sqlsrv_type']);
  if ($field['sqlsrv_is_text']) {
    $field['sqlsrv_collation'] = $field['sqlsrv_collation'] ?? $this
      ->getMssqlCollation($field);
  }

  // Adjust the length of the field if specified
  if (isset($field['length']) && $field['length'] > 0) {
    $field['sqlsrv_type'] = $field['sqlsrv_type_simple'] . '(' . $field['length'] . ')';
  }

  // Adjust numeric fields.
  if (in_array($field['sqlsrv_type_simple'], [
    'numeric',
    'decimal',
  ]) && isset($field['precision']) && isset($field['scale'])) {

    // Maximum precision for SQL Server 2008 or greater is 38.
    // For previous versions it's 28.
    if ($field['precision'] > 38) {
      $field['precision'] = 38;
    }
    $field['sqlsrv_type'] = $field['sqlsrv_type_simple'] . '(' . $field['precision'] . ', ' . $field['scale'] . ')';
  }
  return $field;
}