function Schema::createKeysSql

Same name and namespace in other branches
  1. 8.9.x core/lib/Drupal/Core/Database/Driver/mysql/Schema.php \Drupal\Core\Database\Driver\mysql\Schema::createKeysSql()
  2. 10 core/modules/mysql/src/Driver/Database/mysql/Schema.php \Drupal\mysql\Driver\Database\mysql\Schema::createKeysSql()
  3. 11.x core/modules/mysql/src/Driver/Database/mysql/Schema.php \Drupal\mysql\Driver\Database\mysql\Schema::createKeysSql()
3 calls to Schema::createKeysSql()
Schema::addField in core/modules/mysql/src/Driver/Database/mysql/Schema.php
Add a new field to a table.
Schema::changeField in core/modules/mysql/src/Driver/Database/mysql/Schema.php
Change a field definition.
Schema::createTableSql in core/modules/mysql/src/Driver/Database/mysql/Schema.php
Generate SQL to create a new table from a Drupal schema definition.

File

core/modules/mysql/src/Driver/Database/mysql/Schema.php, line 279

Class

Schema
MySQL implementation of <a href="/api/drupal/core%21lib%21Drupal%21Core%21Database%21Schema.php/class/Schema/9" title="Provides a base implementation for Database Schema." class="local">\Drupal\Core\Database\Schema</a>.

Namespace

Drupal\mysql\Driver\Database\mysql

Code

protected function createKeysSql($spec) {
    $keys = [];
    if (!empty($spec['primary key'])) {
        $keys[] = 'PRIMARY KEY (' . $this->createKeySql($spec['primary key']) . ')';
    }
    if (!empty($spec['unique keys'])) {
        foreach ($spec['unique keys'] as $key => $fields) {
            $keys[] = 'UNIQUE KEY `' . $key . '` (' . $this->createKeySql($fields) . ')';
        }
    }
    if (!empty($spec['indexes'])) {
        $indexes = $this->getNormalizedIndexes($spec);
        foreach ($indexes as $index => $fields) {
            $keys[] = 'INDEX `' . $index . '` (' . $this->createKeySql($fields) . ')';
        }
    }
    return $keys;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.