From: Marius Hoch Date: Thu, 6 Aug 2015 00:55:18 +0000 (+0200) Subject: Duplicate table indexes in DatabaseSqlite::duplicateTableStructure X-Git-Tag: 1.31.0-rc.0~10499^2 X-Git-Url: https://git.cyclocoop.org/%242?a=commitdiff_plain;h=b5cc74ef10aefda7fddc573c6df6805a14caa867;p=lhc%2Fweb%2Fwiklou.git Duplicate table indexes in DatabaseSqlite::duplicateTableStructure This is consistent with what we do with MySQL and is generally convenient to have for certain integration tests. Change-Id: Iaea79bd11263bf75061f19a94da9645ef634422f --- diff --git a/includes/db/DatabaseSqlite.php b/includes/db/DatabaseSqlite.php index 2bad711680..9c93951a21 100644 --- a/includes/db/DatabaseSqlite.php +++ b/includes/db/DatabaseSqlite.php @@ -964,7 +964,36 @@ class DatabaseSqlite extends DatabaseBase { } } - return $this->query( $sql, $fname ); + $res = $this->query( $sql, $fname ); + + // Take over indexes + $indexList = $this->query( 'PRAGMA INDEX_LIST(' . $this->addQuotes( $oldName ) . ')' ); + foreach ( $indexList as $index ) { + if ( strpos( $index->name, 'sqlite_autoindex' ) === 0 ) { + continue; + } + + if ( $index->unique ) { + $sql = 'CREATE UNIQUE INDEX'; + } else { + $sql = 'CREATE INDEX'; + } + // Try to come up with a new index name, given indexes have database scope in SQLite + $indexName = $newName . '_' . $index->name; + $sql .= ' ' . $indexName . ' ON ' . $newName; + + $indexInfo = $this->query( 'PRAGMA INDEX_INFO(' . $this->addQuotes( $index->name ) . ')' ); + $fields = array(); + foreach ( $indexInfo as $indexInfoRow ) { + $fields[ $indexInfoRow->seqno ] = $indexInfoRow->name; + } + + $sql .= '(' . implode( ',', $fields ) . ')'; + + $this->query( $sql ); + } + + return $res; } /**