1 schema.inc | protected DatabaseSchema_mysql::createKeysSql(array $spec) |
Generates a string suitable for creating MySQL table keys.
Parameters
array $spec: The table specification.
Return value
string[]: An array of partial SQL strings for the keys specified within the table.
File
- core/
includes/ database/ mysql/ schema.inc, line 273 - Database schema code for MySQL database servers.
Class
- DatabaseSchema_mysql
- Class to create and manipulate MySQL tables.
Code
protected function createKeysSql(array $spec) {
$keys = array();
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'])) {
foreach ($spec['indexes'] as $index => $fields) {
$keys[] = 'INDEX `' . $index . '` (' . $this->createKeySql($fields) . ')';
}
}
return $keys;
}