Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. Schema.php

function Schema::introspectIndexSchema

Same name in this branch
  1. 11.1.x core/lib/Drupal/Core/Database/Schema.php \Drupal\Core\Database\Schema::introspectIndexSchema()
  2. 11.1.x core/modules/pgsql/src/Driver/Database/pgsql/Schema.php \Drupal\pgsql\Driver\Database\pgsql\Schema::introspectIndexSchema()
  3. 11.1.x core/modules/sqlite/src/Driver/Database/sqlite/Schema.php \Drupal\sqlite\Driver\Database\sqlite\Schema::introspectIndexSchema()

Overrides Schema::introspectIndexSchema

File

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

Class

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

Namespace

Drupal\mysql\Driver\Database\mysql

Code

protected function introspectIndexSchema($table) {
    if (!$this->tableExists($table)) {
        throw new SchemaObjectDoesNotExistException("The table {$table} doesn't exist.");
    }
    $index_schema = [
        'primary key' => [],
        'unique keys' => [],
        'indexes' => [],
    ];
    $result = $this->connection
        ->query('SHOW INDEX FROM {' . $table . '}')
        ->fetchAll();
    foreach ($result as $row) {
        if ($row->Key_name === 'PRIMARY') {
            $index_schema['primary key'][] = $row->Column_name;
        }
        elseif ($row->Non_unique == 0) {
            $index_schema['unique keys'][$row->Key_name][] = $row->Column_name;
        }
        else {
            $index_schema['indexes'][$row->Key_name][] = $row->Column_name;
        }
    }
    return $index_schema;
}
RSS feed
Powered by Drupal