|
|
@ -399,6 +399,16 @@ class Schema extends \yii\db\Schema |
|
|
|
{ |
|
|
|
{ |
|
|
|
$indexes = $this->db->createCommand('PRAGMA INDEX_LIST (' . $this->quoteValue($tableName) . ')')->queryAll(); |
|
|
|
$indexes = $this->db->createCommand('PRAGMA INDEX_LIST (' . $this->quoteValue($tableName) . ')')->queryAll(); |
|
|
|
$indexes = $this->normalizePdoRowKeyCase($indexes, true); |
|
|
|
$indexes = $this->normalizePdoRowKeyCase($indexes, true); |
|
|
|
|
|
|
|
$tableColumns = null; |
|
|
|
|
|
|
|
if (!empty($indexes) && !isset($indexes[0]['origin'])) { |
|
|
|
|
|
|
|
/* |
|
|
|
|
|
|
|
* SQLite may not have an "origin" column in INDEX_LIST |
|
|
|
|
|
|
|
* See https://www.sqlite.org/src/info/2743846cdba572f6 |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
$tableColumns = $this->db->createCommand('PRAGMA TABLE_INFO (' . $this->quoteValue($tableName) . ')')->queryAll(); |
|
|
|
|
|
|
|
$tableColumns = $this->normalizePdoRowKeyCase($tableColumns, true); |
|
|
|
|
|
|
|
$tableColumns = ArrayHelper::index($tableColumns, 'cid'); |
|
|
|
|
|
|
|
} |
|
|
|
$result = [ |
|
|
|
$result = [ |
|
|
|
'primaryKey' => null, |
|
|
|
'primaryKey' => null, |
|
|
|
'indexes' => [], |
|
|
|
'indexes' => [], |
|
|
@ -408,6 +418,15 @@ class Schema extends \yii\db\Schema |
|
|
|
$columns = $this->db->createCommand('PRAGMA INDEX_INFO (' . $this->quoteValue($index['name']) . ')')->queryAll(); |
|
|
|
$columns = $this->db->createCommand('PRAGMA INDEX_INFO (' . $this->quoteValue($index['name']) . ')')->queryAll(); |
|
|
|
$columns = $this->normalizePdoRowKeyCase($columns, true); |
|
|
|
$columns = $this->normalizePdoRowKeyCase($columns, true); |
|
|
|
ArrayHelper::multisort($columns, 'seqno', SORT_ASC, SORT_NUMERIC); |
|
|
|
ArrayHelper::multisort($columns, 'seqno', SORT_ASC, SORT_NUMERIC); |
|
|
|
|
|
|
|
if ($tableColumns !== null) { |
|
|
|
|
|
|
|
// SQLite may not have an "origin" column in INDEX_LIST |
|
|
|
|
|
|
|
$index['origin'] = 'c'; |
|
|
|
|
|
|
|
if (!empty($columns) && $tableColumns[$columns[0]['cid']]['pk'] > 0) { |
|
|
|
|
|
|
|
$index['origin'] = 'pk'; |
|
|
|
|
|
|
|
} elseif ($index['unique'] && $this->isSystemIdentifier($index['name'])) { |
|
|
|
|
|
|
|
$index['origin'] = 'u'; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
$result['indexes'][] = new IndexConstraint([ |
|
|
|
$result['indexes'][] = new IndexConstraint([ |
|
|
|
'isPrimary' => $index['origin'] === 'pk', |
|
|
|
'isPrimary' => $index['origin'] === 'pk', |
|
|
|
'isUnique' => (bool) $index['unique'], |
|
|
|
'isUnique' => (bool) $index['unique'], |
|
|
@ -430,4 +449,15 @@ class Schema extends \yii\db\Schema |
|
|
|
} |
|
|
|
} |
|
|
|
return $result[$returnType]; |
|
|
|
return $result[$returnType]; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Return whether the specified identifier is a SQLite system identifier. |
|
|
|
|
|
|
|
* @param string $identifier |
|
|
|
|
|
|
|
* @return bool |
|
|
|
|
|
|
|
* @see https://www.sqlite.org/src/artifact/74108007d286232f |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
private function isSystemIdentifier($identifier) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
return strpos($identifier, 'sqlite_') === 0; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|