function Schema::ensureIdentifiersLength
Same name in other branches
- 9 core/modules/pgsql/src/Driver/Database/pgsql/Schema.php \Drupal\pgsql\Driver\Database\pgsql\Schema::ensureIdentifiersLength()
- 8.9.x core/lib/Drupal/Core/Database/Driver/pgsql/Schema.php \Drupal\Core\Database\Driver\pgsql\Schema::ensureIdentifiersLength()
- 11.x core/modules/pgsql/src/Driver/Database/pgsql/Schema.php \Drupal\pgsql\Driver\Database\pgsql\Schema::ensureIdentifiersLength()
Make sure to limit identifiers according to PostgreSQL compiled in length.
PostgreSQL allows in standard configuration identifiers no longer 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
- seq for sequences
Parameters
string $table_identifier_part: The first argument used to build the identifier string. This usually refers to a table/relation name.
string $column_identifier_part: The second argument used to build the identifier string. This usually refers to one or more column names.
string $tag: The identifier tag. It can be one of 'idx', 'key', 'pkey' or 'seq'.
string $separator: (optional) The separator used to glue together the aforementioned identifier parts. Defaults to '__'.
Return value
string The index/constraint/pkey identifier.
10 calls to Schema::ensureIdentifiersLength()
- Schema::addPrimaryKey in core/
modules/ pgsql/ src/ Driver/ Database/ pgsql/ Schema.php - Add a primary key.
- Schema::addUniqueKey in core/
modules/ pgsql/ src/ Driver/ Database/ pgsql/ Schema.php - Add a unique key.
- Schema::constraintExists in core/
modules/ pgsql/ src/ Driver/ Database/ pgsql/ Schema.php - Helper function: check if a constraint (PK, FK, UK) exists.
- Schema::createTableSql in core/
modules/ pgsql/ src/ Driver/ Database/ pgsql/ Schema.php - Generate SQL to create a new table from a Drupal schema definition.
- Schema::dropIndex in core/
modules/ pgsql/ src/ Driver/ Database/ pgsql/ Schema.php - Drop an index.
File
-
core/
modules/ pgsql/ src/ Driver/ Database/ pgsql/ Schema.php, line 91
Class
- Schema
- PostgreSQL implementation of \Drupal\Core\Database\Schema.
Namespace
Drupal\pgsql\Driver\Database\pgsqlCode
protected function ensureIdentifiersLength($table_identifier_part, $column_identifier_part, $tag, $separator = '__') {
$info = $this->getPrefixInfo($table_identifier_part);
$table_identifier_part = $info['table'];
$identifierName = implode($separator, [
$table_identifier_part,
$column_identifier_part,
$tag,
]);
// Retrieve the max identifier length which is usually 63 characters
// but can be altered before PostgreSQL is compiled so we need to check.
if (empty($this->maxIdentifierLength)) {
$this->maxIdentifierLength = $this->connection
->query("SHOW max_identifier_length")
->fetchField();
}
if (strlen($identifierName) > $this->maxIdentifierLength) {
$saveIdentifier = '"drupal_' . $this->hashBase64($identifierName) . '_' . $tag . '"';
}
else {
$saveIdentifier = $identifierName;
}
return $saveIdentifier;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.