From 3b000dc2a8743e71fd0b29a194ec80312d8654b3 Mon Sep 17 00:00:00 2001 From: Reedy Date: Thu, 30 Mar 2017 12:29:35 +0100 Subject: [PATCH] Make the indexName functions more obviously laid out Move Sqlites's indexName to Database to have no remapping by default. This is because MSSQL and Postgresql both don't need remapping, it's just MySQL that's the problem. So move the one from Database into MysqlBase to only do the remappings there. Also fix up the comments to make them less vague, not mentioning tables when the function has no table parameter passed, so hence, no context as to which table said index is wanted to be used Bug: T154872 Change-Id: I46c575771e6cb36176bcf6cd1a865b703db0275d --- includes/libs/rdbms/database/Database.php | 15 ++----------- .../libs/rdbms/database/DatabaseMysqlBase.php | 21 +++++++++++++++++++ .../libs/rdbms/database/DatabaseSqlite.php | 10 --------- 3 files changed, 23 insertions(+), 23 deletions(-) diff --git a/includes/libs/rdbms/database/Database.php b/includes/libs/rdbms/database/Database.php index fbfd899e6d..49ddd14ee8 100644 --- a/includes/libs/rdbms/database/Database.php +++ b/includes/libs/rdbms/database/Database.php @@ -1951,24 +1951,13 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware } /** - * Get the name of an index in a given table. + * Allows for index remapping in queries where this is not consistent across DBMS * * @param string $index * @return string */ protected function indexName( $index ) { - // Backwards-compatibility hack - $renamed = [ - 'ar_usertext_timestamp' => 'usertext_timestamp', - 'un_user_id' => 'user_id', - 'un_user_ip' => 'user_ip', - ]; - - if ( isset( $renamed[$index] ) ) { - return $renamed[$index]; - } else { - return $index; - } + return $index; } public function addQuotes( $s ) { diff --git a/includes/libs/rdbms/database/DatabaseMysqlBase.php b/includes/libs/rdbms/database/DatabaseMysqlBase.php index e90002797c..4b3a644932 100644 --- a/includes/libs/rdbms/database/DatabaseMysqlBase.php +++ b/includes/libs/rdbms/database/DatabaseMysqlBase.php @@ -1335,4 +1335,25 @@ abstract class DatabaseMysqlBase extends Database { public function isView( $name, $prefix = null ) { return in_array( $name, $this->listViews( $prefix ) ); } + + /** + * Allows for index remapping in queries where this is not consistent across DBMS + * + * @param string $index + * @return string + */ + protected function indexName( $index ) { + // Backwards-compatibility hack + $renamed = [ + 'ar_usertext_timestamp' => 'usertext_timestamp', + 'un_user_id' => 'user_id', + 'un_user_ip' => 'user_ip', + ]; + + if ( isset( $renamed[$index] ) ) { + return $renamed[$index]; + } else { + return $index; + } + } } diff --git a/includes/libs/rdbms/database/DatabaseSqlite.php b/includes/libs/rdbms/database/DatabaseSqlite.php index 2a5deb63f9..090ce8eeae 100644 --- a/includes/libs/rdbms/database/DatabaseSqlite.php +++ b/includes/libs/rdbms/database/DatabaseSqlite.php @@ -430,16 +430,6 @@ class DatabaseSqlite extends Database { return str_replace( '"', '', parent::tableName( $name, $format ) ); } - /** - * Index names have DB scope - * - * @param string $index - * @return string - */ - protected function indexName( $index ) { - return $index; - } - /** * This must be called after nextSequenceVal * -- 2.20.1