function DbDumpTest::getTableIndexes
Same name in other branches
- 8.9.x core/tests/Drupal/KernelTests/Core/Command/DbDumpTest.php \Drupal\KernelTests\Core\Command\DbDumpTest::getTableIndexes()
- 10 core/modules/mysql/tests/src/Kernel/mysql/DbDumpTest.php \Drupal\Tests\mysql\Kernel\mysql\DbDumpTest::getTableIndexes()
- 11.x core/modules/mysql/tests/src/Kernel/mysql/DbDumpTest.php \Drupal\Tests\mysql\Kernel\mysql\DbDumpTest::getTableIndexes()
Returns indexes for a given table.
Parameters
string $table: The table to find indexes for.
Return value
array The 'primary key', 'unique keys', and 'indexes' portion of the Drupal table schema.
1 call to DbDumpTest::getTableIndexes()
- DbDumpTest::testScriptLoad in core/
tests/ Drupal/ KernelTests/ Core/ Command/ DbDumpTest.php - Tests loading the script back into the database.
File
-
core/
tests/ Drupal/ KernelTests/ Core/ Command/ DbDumpTest.php, line 249
Class
- DbDumpTest
- Tests for the database dump commands.
Namespace
Drupal\KernelTests\Core\CommandCode
protected function getTableIndexes($table) {
$query = Database::getConnection()->query("SHOW INDEX FROM {" . $table . "}");
$definition = [];
while ($row = $query->fetchAssoc()) {
$index_name = $row['Key_name'];
$column = $row['Column_name'];
// Key the arrays by the index sequence for proper ordering (start at 0).
$order = $row['Seq_in_index'] - 1;
// If specified, add length to the index.
if ($row['Sub_part']) {
$column = [
$column,
$row['Sub_part'],
];
}
if ($index_name === 'PRIMARY') {
$definition['primary key'][$order] = $column;
}
elseif ($row['Non_unique'] == 0) {
$definition['unique keys'][$index_name][$order] = $column;
}
else {
$definition['indexes'][$index_name][$order] = $column;
}
}
return $definition;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.