X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Flibs%2Frdbms%2Fdatabase%2FDatabaseMysqlBase.php;h=991e0c6660d68c4abb34fb0a733706744f37655f;hb=89539f2aa1b158fdcc703ad053e2580cb97a6385;hp=50ead83b2002611a5f639c927333f239d1f16550;hpb=d234652df3a53af7f963f6c04a700eaae3517340;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/libs/rdbms/database/DatabaseMysqlBase.php b/includes/libs/rdbms/database/DatabaseMysqlBase.php index 50ead83b20..991e0c6660 100644 --- a/includes/libs/rdbms/database/DatabaseMysqlBase.php +++ b/includes/libs/rdbms/database/DatabaseMysqlBase.php @@ -527,16 +527,28 @@ abstract class DatabaseMysqlBase extends Database { } public function tableExists( $table, $fname = __METHOD__ ) { - $table = $this->tableName( $table, 'raw' ); - if ( isset( $this->mSessionTempTables[$table] ) ) { + // Split database and table into proper variables as Database::tableName() returns + // shared tables prefixed with their database, which do not work in SHOW TABLES statements + list( $database, , $prefix, $table ) = $this->qualifiedTableComponents( $table ); + $tableName = "{$prefix}{$table}"; + + if ( isset( $this->mSessionTempTables[$tableName] ) ) { return true; // already known to exist and won't show in SHOW TABLES anyway } // We can't use buildLike() here, because it specifies an escape character // other than the backslash, which is the only one supported by SHOW TABLES - $encLike = $this->escapeLikeInternal( $table, '\\' ); + $encLike = $this->escapeLikeInternal( $tableName, '\\' ); + + // If the database has been specified (such as for shared tables), use "FROM" + if ( $database !== '' ) { + $encDatabase = $this->addIdentifierQuotes( $database ); + $query = "SHOW TABLES FROM $encDatabase LIKE '$encLike'"; + } else { + $query = "SHOW TABLES LIKE '$encLike'"; + } - return $this->query( "SHOW TABLES LIKE '$encLike'", $fname )->numRows() > 0; + return $this->query( $query, $fname )->numRows() > 0; } /** @@ -977,8 +989,8 @@ abstract class DatabaseMysqlBase extends Database { } /** - * @param string $sql - * @param string $newLine + * @param string &$sql + * @param string &$newLine * @return bool */ public function streamStatementEnd( &$sql, &$newLine ) {