From b5cc74ef10aefda7fddc573c6df6805a14caa867 Mon Sep 17 00:00:00 2001 From: Marius Hoch Date: Thu, 6 Aug 2015 02:55:18 +0200 Subject: [PATCH] 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 --- includes/db/DatabaseSqlite.php | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) 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; } /** -- 2.20.1