protected DbDumpCommand::getTableIndexes(Connection $connection, $table, &$definition)
Adds primary key, unique keys, and index information to the schema.
Parameters
\Drupal\Core\Database\Connection $connection: The database connection to use.
string $table: The table to find indexes for.
array &$definition: The schema definition to modify.
File
- core/lib/Drupal/Core/Command/DbDumpCommand.php, line 221
Class
- DbDumpCommand
- Provides a command to dump the current database to a script.
Namespace
Drupal\Core\Command
Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | protected function getTableIndexes(Connection $connection , $table , & $definition ) { // Note, this query doesn't support ordering, so that is worked around // below by keying the array on Seq_in_index. $query = $connection ->query( "SHOW INDEX FROM {" . $table . "}" ); while (( $row = $query ->fetchAssoc()) !== FALSE) { $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 ; } } } |
Please login to continue.