Move all of the reasonable DatabaseBase methods to Database class
The Database class was previously just a short-hand for "Database::", and such calls should still work. The class now resides in /libs/rdbms. The subclasses now extend DatabaseBase to avoid breaking type hints that use that (hints use either IDatabase or DatabaseBase). Also, use CASCADE with DROP TABLE for MySQL as with other DBs. Keep SQLite excempt due to lack of support. Added getDomainID() methods to avoid mentioning the word "wiki". Change-Id: Ibd05d786cb26c21dcc9cb9601f6b2b52056af9ae
This commit is contained in:
parent
2f90b6f00a
commit
403a1ea178
12 changed files with 3544 additions and 3510 deletions
|
|
@ -316,7 +316,7 @@ $wgAutoloadLocalClasses = [
|
|||
'DBTransactionSizeError' => __DIR__ . '/includes/libs/rdbms/exception/DBError.php',
|
||||
'DBUnexpectedError' => __DIR__ . '/includes/libs/rdbms/exception/DBError.php',
|
||||
'DataUpdate' => __DIR__ . '/includes/deferred/DataUpdate.php',
|
||||
'Database' => __DIR__ . '/includes/db/Database.php',
|
||||
'Database' => __DIR__ . '/includes/libs/rdbms/database/Database.php',
|
||||
'DatabaseBase' => __DIR__ . '/includes/db/Database.php',
|
||||
'DatabaseInstaller' => __DIR__ . '/includes/installer/DatabaseInstaller.php',
|
||||
'DatabaseLag' => __DIR__ . '/maintenance/lag.php',
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -28,7 +28,7 @@
|
|||
/**
|
||||
* @ingroup Database
|
||||
*/
|
||||
class DatabaseMssql extends Database {
|
||||
class DatabaseMssql extends DatabaseBase {
|
||||
protected $mInsertId = null;
|
||||
protected $mLastResult = null;
|
||||
protected $mAffectedRows = null;
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@
|
|||
* @since 1.22
|
||||
* @see Database
|
||||
*/
|
||||
abstract class DatabaseMysqlBase extends Database {
|
||||
abstract class DatabaseMysqlBase extends DatabaseBase {
|
||||
/** @var MysqlMasterPos */
|
||||
protected $lastKnownReplicaPos;
|
||||
/** @var string Method to detect replica DB lag */
|
||||
|
|
|
|||
|
|
@ -131,7 +131,7 @@ class ORAResult {
|
|||
/**
|
||||
* @ingroup Database
|
||||
*/
|
||||
class DatabaseOracle extends Database {
|
||||
class DatabaseOracle extends DatabaseBase {
|
||||
/** @var resource */
|
||||
protected $mLastResult = null;
|
||||
|
||||
|
|
|
|||
|
|
@ -204,7 +204,7 @@ class SavepointPostgres {
|
|||
/**
|
||||
* @ingroup Database
|
||||
*/
|
||||
class DatabasePostgres extends Database {
|
||||
class DatabasePostgres extends DatabaseBase {
|
||||
/** @var resource */
|
||||
protected $mLastResult = null;
|
||||
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@
|
|||
/**
|
||||
* @ingroup Database
|
||||
*/
|
||||
class DatabaseSqlite extends Database {
|
||||
class DatabaseSqlite extends DatabaseBase {
|
||||
/** @var bool Whether full text is enabled */
|
||||
private static $fulltextEnabled = null;
|
||||
|
||||
|
|
@ -1041,6 +1041,23 @@ class DatabaseSqlite extends Database {
|
|||
return $endArray;
|
||||
}
|
||||
|
||||
/**
|
||||
* Override due to no CASCADE support
|
||||
*
|
||||
* @param string $tableName
|
||||
* @param string $fName
|
||||
* @return bool|ResultWrapper
|
||||
* @throws DBReadOnlyError
|
||||
*/
|
||||
public function dropTable( $tableName, $fName = __METHOD__ ) {
|
||||
if ( !$this->tableExists( $tableName, $fName ) ) {
|
||||
return false;
|
||||
}
|
||||
$sql = "DROP TABLE " . $this->tableName( $tableName );
|
||||
|
||||
return $this->query( $sql, $fName );
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -145,7 +145,7 @@ class DBConnRef implements IDatabase {
|
|||
return $this->__call( __FUNCTION__, func_get_args() );
|
||||
}
|
||||
|
||||
public function getWikiID() {
|
||||
public function getDomainID() {
|
||||
if ( $this->conn === null ) {
|
||||
// Avoid triggering a connection
|
||||
return $this->params[self::FLD_WIKI];
|
||||
|
|
@ -154,6 +154,10 @@ class DBConnRef implements IDatabase {
|
|||
return $this->__call( __FUNCTION__, func_get_args() );
|
||||
}
|
||||
|
||||
public function getWikiID() {
|
||||
return $this->getDomainID();
|
||||
}
|
||||
|
||||
public function getType() {
|
||||
return $this->__call( __FUNCTION__, func_get_args() );
|
||||
}
|
||||
|
|
|
|||
3493
includes/libs/rdbms/database/Database.php
Normal file
3493
includes/libs/rdbms/database/Database.php
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -302,6 +302,13 @@ interface IDatabase {
|
|||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getDomainID();
|
||||
|
||||
/**
|
||||
* Alias for getDomainID()
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getWikiID();
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ class ResultWrapper implements Iterator {
|
|||
/** @var resource */
|
||||
public $result;
|
||||
|
||||
/** @var DatabaseBase */
|
||||
/** @var IDatabase */
|
||||
protected $db;
|
||||
|
||||
/** @var int */
|
||||
|
|
@ -19,7 +19,7 @@ class ResultWrapper implements Iterator {
|
|||
/**
|
||||
* Create a new result object from a result resource and a Database object
|
||||
*
|
||||
* @param DatabaseBase $database
|
||||
* @param IDatabase $database
|
||||
* @param resource|ResultWrapper $result
|
||||
*/
|
||||
function __construct( $database, $result ) {
|
||||
|
|
|
|||
|
|
@ -736,7 +736,7 @@ class DatabaseSQLTest extends MediaWikiTestCase {
|
|||
public function testDropTable() {
|
||||
$this->database->setExistingTables( [ 'table' ] );
|
||||
$this->database->dropTable( 'table', __METHOD__ );
|
||||
$this->assertLastSql( 'DROP TABLE table' );
|
||||
$this->assertLastSql( 'DROP TABLE table CASCADE' );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in a new issue