From 42e8644437d27129c055a258b0225996f1184876 Mon Sep 17 00:00:00 2001 From: Max Semenik Date: Tue, 23 Nov 2010 11:14:48 +0000 Subject: [PATCH] This indexInfo() belongs to MySQL --- includes/db/Database.php | 38 +++++++++-------------------------- includes/db/DatabaseMysql.php | 28 ++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 29 deletions(-) diff --git a/includes/db/Database.php b/includes/db/Database.php index cf6d9dfa37..3f50a9e033 100644 --- a/includes/db/Database.php +++ b/includes/db/Database.php @@ -148,6 +148,15 @@ interface DatabaseType { */ public function fieldInfo( $table, $field ); + /** + * Get information about an index into an object + * @param $table string: Table name + * @param $index string: Index name + * @param $fname string: Calling function name + * @return Mixed: Database-specific index description class or false if the index does not exist + */ + function indexInfo( $table, $index, $fname ); + /** * Get the number of rows affected by the last write query * @see http://www.php.net/mysql_affected_rows @@ -1175,35 +1184,6 @@ abstract class DatabaseBase implements DatabaseType { } } - - /** - * Get information about an index into an object - * Returns false if the index does not exist - */ - function indexInfo( $table, $index, $fname = 'DatabaseBase::indexInfo' ) { - # SHOW INDEX works in MySQL 3.23.58, but SHOW INDEXES does not. - # SHOW INDEX should work for 3.x and up: - # http://dev.mysql.com/doc/mysql/en/SHOW_INDEX.html - $table = $this->tableName( $table ); - $index = $this->indexName( $index ); - $sql = 'SHOW INDEX FROM ' . $table; - $res = $this->query( $sql, $fname ); - - if ( !$res ) { - return null; - } - - $result = array(); - - foreach ( $res as $row ) { - if ( $row->Key_name == $index ) { - $result[] = $row; - } - } - - return empty( $result ) ? false : $result; - } - /** * Query whether a given table exists */ diff --git a/includes/db/DatabaseMysql.php b/includes/db/DatabaseMysql.php index 39e8037a4b..8a6d3527fc 100644 --- a/includes/db/DatabaseMysql.php +++ b/includes/db/DatabaseMysql.php @@ -282,6 +282,34 @@ class DatabaseMysql extends DatabaseBase { return false; } + /** + * Get information about an index into an object + * Returns false if the index does not exist + */ + function indexInfo( $table, $index, $fname = 'DatabaseMysql::indexInfo' ) { + # SHOW INDEX works in MySQL 3.23.58, but SHOW INDEXES does not. + # SHOW INDEX should work for 3.x and up: + # http://dev.mysql.com/doc/mysql/en/SHOW_INDEX.html + $table = $this->tableName( $table ); + $index = $this->indexName( $index ); + $sql = 'SHOW INDEX FROM ' . $table; + $res = $this->query( $sql, $fname ); + + if ( !$res ) { + return null; + } + + $result = array(); + + foreach ( $res as $row ) { + if ( $row->Key_name == $index ) { + $result[] = $row; + } + } + + return empty( $result ) ? false : $result; + } + function selectDB( $db ) { $this->mDBname = $db; return mysql_select_db( $db, $this->mConn ); -- 2.20.1