/**
* Constructor
*
- * @param DatabaseBase $db A database subclass
+ * @param IDatabase $db A database subclass
* @param array $tablesToClone An array of tables to clone, unprefixed
* @param string $newTablePrefix Prefix to assign to the tables
* @param string $oldTablePrefix Prefix on current tables, if not $wgDBprefix
* @param bool $dropCurrentTables
*/
- public function __construct( DatabaseBase $db, array $tablesToClone,
+ public function __construct( IDatabase $db, array $tablesToClone,
$newTablePrefix, $oldTablePrefix = '', $dropCurrentTables = true
) {
$this->db = $db;
global $wgDBprefix;
wfGetLBFactory()->forEachLB( function( LoadBalancer $lb ) use ( $prefix ) {
$lb->setDomainPrefix( $prefix );
- $lb->forEachOpenConnection( function ( DatabaseBase $db ) use ( $prefix ) {
+ $lb->forEachOpenConnection( function ( IDatabase $db ) use ( $prefix ) {
$db->tablePrefix( $prefix );
} );
} );
* connection object, by specifying no parameters to __construct(). This
* feature is deprecated and should be removed.
*
- * DatabaseBase subclasses should not be constructed directly in external
+ * IDatabase classes should not be constructed directly in external
* code. DatabaseBase::factory() should be used instead.
*
* @param array $params Parameters passed from DatabaseBase::factory()
/**
* Given a DB type, construct the name of the appropriate child class of
- * DatabaseBase. This is designed to replace all of the manual stuff like:
+ * IDatabase. This is designed to replace all of the manual stuff like:
* $class = 'Database' . ucfirst( strtolower( $dbType ) );
* as well as validate against the canonical list of DB types we have
*
* @param string $dbType A possible DB type
* @param array $p An array of options to pass to the constructor.
* Valid options are: host, user, password, dbname, flags, tablePrefix, schema, driver
- * @throws MWException If the database driver or extension cannot be found
- * @return DatabaseBase|null DatabaseBase subclass or null
+ * @return IDatabase|null If the database driver or extension cannot be found
+ * @throws MWException
*/
final public static function factory( $dbType, $p = [] ) {
global $wgCommandLineMode;
];
$class = 'Database' . ucfirst( $driver );
- if ( class_exists( $class ) && is_subclass_of( $class, 'DatabaseBase' ) ) {
+ if ( class_exists( $class ) && is_subclass_of( $class, 'IDatabase' ) ) {
// Resolve some defaults for b/c
$p['host'] = isset( $p['host'] ) ? $p['host'] : false;
$p['user'] = isset( $p['user'] ) ? $p['user'] : false;
}
public function setLogger( LoggerInterface $logger ) {
- $this->quertLogger = $logger;
+ $this->queryLogger = $logger;
}
public function getServerInfo() {
}
}
- /**
- * Set a lazy-connecting DB handle to the master DB (for replication status purposes)
- *
- * @param IDatabase $conn
- * @since 1.27
- */
public function setLazyMasterHandle( IDatabase $conn ) {
$this->lazyMasterHandle = $conn;
}
# generalizeSQL() will probably cut down the query to reasonable
# logging size most of the time. The substr is really just a sanity check.
if ( $isMaster ) {
- $queryProf = 'query-m: ' . substr( DatabaseBase::generalizeSQL( $sql ), 0, 255 );
+ $queryProf = 'query-m: ' . substr( self::generalizeSQL( $sql ), 0, 255 );
} else {
- $queryProf = 'query: ' . substr( DatabaseBase::generalizeSQL( $sql ), 0, 255 );
+ $queryProf = 'query: ' . substr( self::generalizeSQL( $sql ), 0, 255 );
}
# Include query transaction state
*
* @return array
*/
- protected function prepare( $sql, $func = 'DatabaseBase::prepare' ) {
+ protected function prepare( $sql, $func = __METHOD__ ) {
/* MySQL doesn't support prepared statements (yet), so just
* pack up the query for reference. We'll manually replace
* the bits later.
public function makeList( $a, $mode = LIST_COMMA ) {
if ( !is_array( $a ) ) {
- throw new DBUnexpectedError( $this, 'DatabaseBase::makeList called with incorrect parameters' );
+ throw new DBUnexpectedError( $this, __METHOD__ . ' called with incorrect parameters' );
}
$first = true;
$fname = __METHOD__
) {
if ( !$conds ) {
- throw new DBUnexpectedError( $this,
- 'DatabaseBase::deleteJoin() called with empty $conds' );
+ throw new DBUnexpectedError( $this, __METHOD__ . ' called with empty $conds' );
}
$delTable = $this->tableName( $delTable );
public function textFieldSize( $table, $field ) {
$table = $this->tableName( $table );
$sql = "SHOW COLUMNS FROM $table LIKE \"$field\";";
- $res = $this->query( $sql, 'DatabaseBase::textFieldSize' );
+ $res = $this->query( $sql, __METHOD__ );
$row = $this->fetchObject( $res );
$m = [];
public function delete( $table, $conds, $fname = __METHOD__ ) {
if ( !$conds ) {
- throw new DBUnexpectedError( $this, 'DatabaseBase::delete() called with no conditions' );
+ throw new DBUnexpectedError( $this, __METHOD__ . ' called with no conditions' );
}
$table = $this->tableName( $table );
public function duplicateTableStructure( $oldName, $newName, $temporary = false,
$fname = __METHOD__
) {
- throw new RuntimeException(
- 'DatabaseBase::duplicateTableStructure is not implemented in descendant class' );
+ throw new RuntimeException( __METHOD__ . ' is not implemented in descendant class' );
}
function listTables( $prefix = null, $fname = __METHOD__ ) {
- throw new RuntimeException( 'DatabaseBase::listTables is not implemented in descendant class' );
+ throw new RuntimeException( __METHOD__ . ' is not implemented in descendant class' );
}
/**
* @since 1.22
*/
public function listViews( $prefix = null, $fname = __METHOD__ ) {
- throw new RuntimeException( 'DatabaseBase::listViews is not implemented in descendant class' );
+ throw new RuntimeException( __METHOD__ . ' is not implemented in descendant class' );
}
/**
* @since 1.22
*/
public function isView( $name ) {
- throw new RuntimeException( 'DatabaseBase::isView is not implemented in descendant class' );
+ throw new RuntimeException( __METHOD__ . ' is not implemented in descendant class' );
}
public function timestamp( $ts = 0 ) {
* @param string $password
* @param string $dbName
* @throws DBConnectionError
- * @return bool|DatabaseBase|null
+ * @return bool|resource|null
*/
public function open( $server, $user, $password, $dbName ) {
# Test for driver support, to avoid suppressed fatal error
*/
public function makeList( $a, $mode = LIST_COMMA, $binaryColumns = [] ) {
if ( !is_array( $a ) ) {
- throw new DBUnexpectedError( $this,
- 'DatabaseBase::makeList called with incorrect parameters' );
+ throw new DBUnexpectedError( $this, __METHOD__ . ' called with incorrect parameters' );
}
if ( $mode != LIST_NAMES ) {
*/
function deleteJoin( $delTable, $joinTable, $delVar, $joinVar, $conds, $fname = __METHOD__ ) {
if ( !$conds ) {
- throw new DBUnexpectedError( $this, 'DatabaseBase::deleteJoin() called with empty $conds' );
+ throw new DBUnexpectedError( $this, __METHOD__ . ' called with empty $conds' );
}
$delTable = $this->tableName( $delTable );
}
/**
- * @param DatabaseBase $db
+ * @param IDatabase $db
* @param resource $stmt A valid OCI statement identifier
* @param bool $unique
*/
* @param string $password
* @param string $dbName
* @throws DBConnectionError
- * @return DatabaseBase|null
+ * @return resource|null
*/
function open( $server, $user, $password, $dbName ) {
global $wgDBOracleDRCP;
$has_default, $default;
/**
- * @param DatabaseBase $db
+ * @param IDatabase $db
* @param string $table
* @param string $field
* @return null|PostgresField
protected $didbegin;
/**
- * @param DatabaseBase $dbw
+ * @param IDatabase $dbw
* @param int $id
*/
public function __construct( $dbw, $id ) {
* @param string $password
* @param string $dbName
* @throws DBConnectionError|Exception
- * @return DatabaseBase|null
+ * @return resource|bool|null
*/
function open( $server, $user, $password, $dbName ) {
# Test for Postgres support, to avoid suppressed fatal error
return $this->query( "ATTACH DATABASE $file AS $name", $fname );
}
- /**
- * @see DatabaseBase::isWriteQuery()
- *
- * @param string $sql
- * @return bool
- */
function isWriteQuery( $sql ) {
return parent::isWriteQuery( $sql ) && !preg_match( '/^(ATTACH|PRAGMA)\b/i', $sql );
}
/** @var resource */
public $result;
- /** @var DatabaseBase */
+ /** @var IDatabase */
protected $db;
/** @var int */
/**
* 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 ) {
/**
* @param array $conf An associative array with one member:
- * - connection: The DatabaseBase connection object
+ * - connection: The IDatabase connection object
*/
public function __construct( array $conf ) {
parent::__construct( $conf );
* Helper class for LBFactorySingle.
*/
class LoadBalancerSingle extends LoadBalancer {
- /** @var DatabaseBase */
+ /** @var IDatabase */
private $db;
/**
* @param string $server
* @param bool $dbNameOverride
*
- * @return DatabaseBase
+ * @return IDatabase
*/
protected function reallyOpenConnection( $server, $dbNameOverride = false ) {
return $this->db;
class LoadBalancer implements ILoadBalancer {
/** @var array[] Map of (server index => server config array) */
private $mServers;
- /** @var array[] Map of (local/foreignUsed/foreignFree => server index => DatabaseBase array) */
+ /** @var array[] Map of (local/foreignUsed/foreignFree => server index => IDatabase array) */
private $mConns;
/** @var array Map of (server index => weight) */
private $mLoads;
/** @var LoggerInterface */
protected $perfLogger;
- /** @var bool|DatabaseBase Database connection that caused a problem */
+ /** @var bool|IDatabase Database connection that caused a problem */
private $mErrorConnection;
/** @var integer The generic (not query grouped) replica DB index (of $mServers) */
private $mReadIndex;
/**
* Get a database connection handle reference
*
- * The handle's methods wrap simply wrap those of a DatabaseBase handle
+ * The handle's methods wrap simply wrap those of a IDatabase handle
*
* @see LoadBalancer::getConnection() for parameter information
*
/**
* Get a database connection handle reference without connecting yet
*
- * The handle's methods wrap simply wrap those of a DatabaseBase handle
+ * The handle's methods wrap simply wrap those of a IDatabase handle
*
* @see LoadBalancer::getConnection() for parameter information
*
*
* @param int $i Server index
* @param string $domain Domain ID to open
- * @return DatabaseBase
+ * @return IDatabase
*/
private function openForeignConnection( $i, $domain ) {
list( $dbName, $prefix ) = explode( '-', $domain, 2 ) + [ '', '' ];
*
* @param array $server
* @param bool $dbNameOverride
- * @return DatabaseBase
+ * @return IDatabase
* @throws DBAccessError
* @throws MWException
*/
// Set loggers
$server['connLogger'] = $this->connLogger;
$server['queryLogger'] = $this->queryLogger;
+ $server['trxProfiler'] = $this->trxProfiler;
// Create a live connection object
try {
$db->setLazyMasterHandle(
$this->getLazyConnectionRef( DB_MASTER, [], $db->getWikiID() )
);
- $db->setTransactionProfiler( $this->trxProfiler );
if ( $server['serverIndex'] === $this->getWriterIndex() ) {
if ( $this->trxRoundId !== false ) {
}
public function closeAll() {
- $this->forEachOpenConnection( function ( DatabaseBase $conn ) {
+ $this->forEachOpenConnection( function ( IDatabase $conn ) {
$conn->close();
} );
$restore = ( $this->trxRoundId !== false );
$this->trxRoundId = false;
$this->forEachOpenConnection(
- function ( DatabaseBase $conn ) use ( $fname, $restore, &$failures ) {
+ function ( IDatabase $conn ) use ( $fname, $restore, &$failures ) {
try {
$conn->commit( $fname, $conn::FLUSHING_ALL_PEERS );
} catch ( DBError $e ) {
*/
public function approveMasterChanges( array $options ) {
$limit = isset( $options['maxWriteDuration'] ) ? $options['maxWriteDuration'] : 0;
- $this->forEachOpenMasterConnection( function ( DatabaseBase $conn ) use ( $limit ) {
+ $this->forEachOpenMasterConnection( function ( IDatabase $conn ) use ( $limit ) {
// If atomic sections or explicit transactions are still open, some caller must have
// caught an exception but failed to properly rollback any changes. Detect that and
// throw and error (causing rollback).
$restore = ( $this->trxRoundId !== false );
$this->trxRoundId = false;
$this->forEachOpenMasterConnection(
- function ( DatabaseBase $conn ) use ( $fname, $restore, &$failures ) {
+ function ( IDatabase $conn ) use ( $fname, $restore, &$failures ) {
try {
if ( $conn->writesOrCallbacksPending() ) {
$conn->commit( $fname, $conn::FLUSHING_ALL_PEERS );
$restore = ( $this->trxRoundId !== false );
$this->trxRoundId = false;
$this->forEachOpenMasterConnection(
- function ( DatabaseBase $conn ) use ( $fname, $restore ) {
+ function ( IDatabase $conn ) use ( $fname, $restore ) {
if ( $conn->writesOrCallbacksPending() ) {
$conn->rollback( $fname, $conn::FLUSHING_ALL_PEERS );
}
* @since 1.28
*/
public function flushReplicaSnapshots( $fname = __METHOD__ ) {
- $this->forEachOpenReplicaConnection( function ( DatabaseBase $conn ) {
+ $this->forEachOpenReplicaConnection( function ( IDatabase $conn ) {
$conn->flushSnapshot( __METHOD__ );
} );
}
*/
public function hasMasterChanges() {
$pending = 0;
- $this->forEachOpenMasterConnection( function ( DatabaseBase $conn ) use ( &$pending ) {
+ $this->forEachOpenMasterConnection( function ( IDatabase $conn ) use ( &$pending ) {
$pending |= $conn->writesOrCallbacksPending();
} );
*/
public function lastMasterChangeTimestamp() {
$lastTime = false;
- $this->forEachOpenMasterConnection( function ( DatabaseBase $conn ) use ( &$lastTime ) {
+ $this->forEachOpenMasterConnection( function ( IDatabase $conn ) use ( &$lastTime ) {
$lastTime = max( $lastTime, $conn->lastDoneWrites() );
} );
*/
public function pendingMasterChangeCallers() {
$fnames = [];
- $this->forEachOpenMasterConnection( function ( DatabaseBase $conn ) use ( &$fnames ) {
+ $this->forEachOpenMasterConnection( function ( IDatabase $conn ) use ( &$fnames ) {
$fnames = array_merge( $fnames, $conn->pendingWriteCallers() );
} );
public function pingAll() {
$success = true;
- $this->forEachOpenConnection( function ( DatabaseBase $conn ) use ( &$success ) {
+ $this->forEachOpenConnection( function ( IDatabase $conn ) use ( &$success ) {
if ( !$conn->ping() ) {
$success = false;
}
$masterIndex = $this->getWriterIndex();
foreach ( $this->mConns as $connsByServer ) {
if ( isset( $connsByServer[$masterIndex] ) ) {
- /** @var DatabaseBase $conn */
+ /** @var IDatabase $conn */
foreach ( $connsByServer[$masterIndex] as $conn ) {
$mergedParams = array_merge( [ $conn ], $params );
call_user_func_array( $callback, $mergedParams );
}
/**
- * Set a callback via DatabaseBase::setTransactionListener() on
+ * Set a callback via IDatabase::setTransactionListener() on
* all current and future master connections of this load balancer
*
* @param string $name Callback name
unset( $this->trxRecurringCallbacks[$name] );
}
$this->forEachOpenMasterConnection(
- function ( DatabaseBase $conn ) use ( $name, $callback ) {
+ function ( IDatabase $conn ) use ( $name, $callback ) {
$conn->setTransactionListener( $name, $callback );
}
);
*/
public function setLBInfo( $name, $value = null );
+ /**
+ * Set a lazy-connecting DB handle to the master DB (for replication status purposes)
+ *
+ * @param IDatabase $conn
+ * @since 1.27
+ */
+ public function setLazyMasterHandle( IDatabase $conn );
+
/**
* Returns true if this database does an implicit sort when doing GROUP BY
*
return $this->__call( __FUNCTION__, func_get_args() );
}
+ public function setLazyMasterHandle( IDatabase $conn ) {
+ return $this->__call( __FUNCTION__, func_get_args() );
+ }
+
public function implicitGroupby() {
return $this->__call( __FUNCTION__, func_get_args() );
}