You are here

protected function Schema::ensureIdentifiersLength in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/lib/Drupal/Core/Database/Driver/pgsql/Schema.php \Drupal\Core\Database\Driver\pgsql\Schema::ensureIdentifiersLength()

Make sure to limit identifiers according to PostgreSQL compiled in length.

PostgreSQL allows in standard configuration no longer identifiers than 63 chars for table/relation names, indexes, primary keys, and constraints. So we map all identifiers that are too long to drupal_base64hash_tag, where tag is one of:

  • idx for indexes
  • key for constraints
  • pkey for primary keys

Parameters

$identifiers: The arguments to build the identifier string

Return value

The index/constraint/pkey identifier

10 calls to Schema::ensureIdentifiersLength()
Schema::addPrimaryKey in core/lib/Drupal/Core/Database/Driver/pgsql/Schema.php
Add a primary key.
Schema::addUniqueKey in core/lib/Drupal/Core/Database/Driver/pgsql/Schema.php
Add a unique key.
Schema::constraintExists in core/lib/Drupal/Core/Database/Driver/pgsql/Schema.php
Helper function: check if a constraint (PK, FK, UK) exists.
Schema::createTableSql in core/lib/Drupal/Core/Database/Driver/pgsql/Schema.php
Generate SQL to create a new table from a Drupal schema definition.
Schema::dropIndex in core/lib/Drupal/Core/Database/Driver/pgsql/Schema.php
Drop an index.

... See full list

File

core/lib/Drupal/Core/Database/Driver/pgsql/Schema.php, line 62
Contains \Drupal\Core\Database\Driver\pgsql\Schema.

Class

Schema
PostgreSQL implementation of \Drupal\Core\Database\Schema.

Namespace

Drupal\Core\Database\Driver\pgsql

Code

protected function ensureIdentifiersLength($identifier) {
  $args = func_get_args();
  $info = $this
    ->getPrefixInfo($identifier);
  $args[0] = $info['table'];
  $identifierName = implode('__', $args);

  // Retrieve the max identifier length which is usually 63 characters
  // but can be altered before PostgreSQL is compiled so we need to check.
  $this->maxIdentifierLength = $this->connection
    ->query("SHOW max_identifier_length")
    ->fetchField();
  if (strlen($identifierName) > $this->maxIdentifierLength) {
    $saveIdentifier = '"drupal_' . $this
      ->hashBase64($identifierName) . '_' . $args[2] . '"';
  }
  else {
    $saveIdentifier = $identifierName;
  }
  return $saveIdentifier;
}