From: Aaron Schulz Date: Tue, 13 Feb 2018 06:58:57 +0000 (-0800) Subject: rdbms: remove "m" prefix from Database fields X-Git-Tag: 1.31.0-rc.0~589^2 X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=commitdiff_plain;h=ec550d4823c261c4a2f4fb153defb6283cfd7b48 rdbms: remove "m" prefix from Database fields Done using the PhpStorm refactor->rename tool. Also move "defaultBigSelects" declaration to DatabaseMysqlBase as no other classes uses that. Change-Id: I424a2d9815de3a5d4cca2522f3db23a5efe6b592 --- diff --git a/includes/db/DatabaseOracle.php b/includes/db/DatabaseOracle.php index eb28b30138..156e315833 100644 --- a/includes/db/DatabaseOracle.php +++ b/includes/db/DatabaseOracle.php @@ -61,7 +61,7 @@ class DatabaseOracle extends Database { } function __destruct() { - if ( $this->mOpened ) { + if ( $this->opened ) { Wikimedia\suppressWarnings(); $this->close(); Wikimedia\restoreWarnings(); @@ -100,21 +100,21 @@ class DatabaseOracle extends Database { } $this->close(); - $this->mUser = $user; - $this->mPassword = $password; + $this->user = $user; + $this->password = $password; // changed internal variables functions // mServer now holds the TNS endpoint // mDBname is schema name if different from username if ( !$server ) { // backward compatibillity (server used to be null and TNS was supplied in dbname) - $this->mServer = $dbName; - $this->mDBname = $user; + $this->server = $dbName; + $this->dbName = $user; } else { - $this->mServer = $server; + $this->server = $server; if ( !$dbName ) { - $this->mDBname = $user; + $this->dbName = $user; } else { - $this->mDBname = $dbName; + $this->dbName = $dbName; } } @@ -126,53 +126,53 @@ class DatabaseOracle extends Database { $this->setFlag( DBO_PERSISTENT ); } - $session_mode = $this->mFlags & DBO_SYSDBA ? OCI_SYSDBA : OCI_DEFAULT; + $session_mode = $this->flags & DBO_SYSDBA ? OCI_SYSDBA : OCI_DEFAULT; Wikimedia\suppressWarnings(); - if ( $this->mFlags & DBO_PERSISTENT ) { - $this->mConn = oci_pconnect( - $this->mUser, - $this->mPassword, - $this->mServer, + if ( $this->flags & DBO_PERSISTENT ) { + $this->conn = oci_pconnect( + $this->user, + $this->password, + $this->server, $this->defaultCharset, $session_mode ); - } elseif ( $this->mFlags & DBO_DEFAULT ) { - $this->mConn = oci_new_connect( - $this->mUser, - $this->mPassword, - $this->mServer, + } elseif ( $this->flags & DBO_DEFAULT ) { + $this->conn = oci_new_connect( + $this->user, + $this->password, + $this->server, $this->defaultCharset, $session_mode ); } else { - $this->mConn = oci_connect( - $this->mUser, - $this->mPassword, - $this->mServer, + $this->conn = oci_connect( + $this->user, + $this->password, + $this->server, $this->defaultCharset, $session_mode ); } Wikimedia\restoreWarnings(); - if ( $this->mUser != $this->mDBname ) { + if ( $this->user != $this->dbName ) { // change current schema in session - $this->selectDB( $this->mDBname ); + $this->selectDB( $this->dbName ); } - if ( !$this->mConn ) { + if ( !$this->conn ) { throw new DBConnectionError( $this, $this->lastError() ); } - $this->mOpened = true; + $this->opened = true; # removed putenv calls because they interfere with the system globaly $this->doQuery( 'ALTER SESSION SET NLS_TIMESTAMP_FORMAT=\'DD-MM-YYYY HH24:MI:SS.FF6\'' ); $this->doQuery( 'ALTER SESSION SET NLS_TIMESTAMP_TZ_FORMAT=\'DD-MM-YYYY HH24:MI:SS.FF6\'' ); $this->doQuery( 'ALTER SESSION SET NLS_NUMERIC_CHARACTERS=\'.,\'' ); - return $this->mConn; + return $this->conn; } /** @@ -181,11 +181,11 @@ class DatabaseOracle extends Database { * @return bool */ protected function closeConnection() { - return oci_close( $this->mConn ); + return oci_close( $this->conn ); } function execFlags() { - return $this->mTrxLevel ? OCI_NO_AUTO_COMMIT : OCI_COMMIT_ON_SUCCESS; + return $this->trxLevel ? OCI_NO_AUTO_COMMIT : OCI_COMMIT_ON_SUCCESS; } protected function doQuery( $sql ) { @@ -217,9 +217,9 @@ class DatabaseOracle extends Database { Wikimedia\suppressWarnings(); - $this->mLastResult = $stmt = oci_parse( $this->mConn, $sql ); + $this->mLastResult = $stmt = oci_parse( $this->conn, $sql ); if ( $stmt === false ) { - $e = oci_error( $this->mConn ); + $e = oci_error( $this->conn ); $this->reportQueryError( $e['message'], $e['code'], $sql, __METHOD__ ); return false; @@ -335,20 +335,20 @@ class DatabaseOracle extends Database { } function lastError() { - if ( $this->mConn === false ) { + if ( $this->conn === false ) { $e = oci_error(); } else { - $e = oci_error( $this->mConn ); + $e = oci_error( $this->conn ); } return $e['message']; } function lastErrno() { - if ( $this->mConn === false ) { + if ( $this->conn === false ) { $e = oci_error(); } else { - $e = oci_error( $this->mConn ); + $e = oci_error( $this->conn ); } return $e['code']; @@ -470,9 +470,9 @@ class DatabaseOracle extends Database { } $sql .= ')'; - $this->mLastResult = $stmt = oci_parse( $this->mConn, $sql ); + $this->mLastResult = $stmt = oci_parse( $this->conn, $sql ); if ( $stmt === false ) { - $e = oci_error( $this->mConn ); + $e = oci_error( $this->conn ); $this->reportQueryError( $e['message'], $e['code'], $sql, __METHOD__ ); return false; @@ -502,7 +502,7 @@ class DatabaseOracle extends Database { } } else { /** @var OCI_Lob[] $lob */ - $lob[$col] = oci_new_descriptor( $this->mConn, OCI_D_LOB ); + $lob[$col] = oci_new_descriptor( $this->conn, OCI_D_LOB ); if ( $lob[$col] === false ) { $e = oci_error( $stmt ); throw new DBUnexpectedError( $this, "Cannot create LOB descriptor: " . $e['message'] ); @@ -545,8 +545,8 @@ class DatabaseOracle extends Database { } } - if ( !$this->mTrxLevel ) { - oci_commit( $this->mConn ); + if ( !$this->trxLevel ) { + oci_commit( $this->conn ); } return oci_free_statement( $stmt ); @@ -658,13 +658,13 @@ class DatabaseOracle extends Database { FROM all_sequences asq, all_tab_columns atc WHERE decode( atc.table_name, - '{$this->mTablePrefix}MWUSER', - '{$this->mTablePrefix}USER', + '{$this->tablePrefix}MWUSER', + '{$this->tablePrefix}USER', atc.table_name ) || '_' || - atc.column_name || '_SEQ' = '{$this->mTablePrefix}' || asq.sequence_name - AND asq.sequence_owner = upper('{$this->mDBname}') - AND atc.owner = upper('{$this->mDBname}')" ); + atc.column_name || '_SEQ' = '{$this->tablePrefix}' || asq.sequence_name + AND asq.sequence_owner = upper('{$this->dbName}') + AND atc.owner = upper('{$this->dbName}')" ); while ( ( $row = $result->fetchRow() ) !== false ) { $this->sequenceData[$row[1]] = [ @@ -730,9 +730,9 @@ class DatabaseOracle extends Database { $newName = strtoupper( $newName ); $oldName = strtoupper( $oldName ); - $tabName = substr( $newName, strlen( $this->mTablePrefix ) ); + $tabName = substr( $newName, strlen( $this->tablePrefix ) ); $oldPrefix = substr( $oldName, 0, strlen( $oldName ) - strlen( $tabName ) ); - $newPrefix = strtoupper( $this->mTablePrefix ); + $newPrefix = strtoupper( $this->tablePrefix ); return $this->doQuery( "BEGIN DUPLICATE_TABLE( '$tabName', " . "'$oldPrefix', '$newPrefix', $temporary ); END;" ); @@ -744,7 +744,7 @@ class DatabaseOracle extends Database { $listWhere = ' AND table_name LIKE \'' . strtoupper( $prefix ) . '%\''; } - $owner = strtoupper( $this->mDBname ); + $owner = strtoupper( $this->dbName ); $result = $this->doQuery( "SELECT table_name FROM all_tables " . "WHERE owner='$owner' AND table_name NOT LIKE '%!_IDX\$_' ESCAPE '!' $listWhere" ); @@ -805,7 +805,7 @@ class DatabaseOracle extends Database { ); $row = $rset->fetchRow(); if ( !$row ) { - return oci_server_version( $this->mConn ); + return oci_server_version( $this->conn ); } return $row['version']; @@ -822,7 +822,7 @@ class DatabaseOracle extends Database { $table = $this->tableName( $table ); $table = strtoupper( $this->removeIdentifierQuotes( $table ) ); $index = strtoupper( $index ); - $owner = strtoupper( $this->mDBname ); + $owner = strtoupper( $this->dbName ); $sql = "SELECT 1 FROM all_indexes WHERE owner='$owner' AND index_name='{$table}_{$index}'"; $res = $this->doQuery( $sql ); if ( $res ) { @@ -844,7 +844,7 @@ class DatabaseOracle extends Database { function tableExists( $table, $fname = __METHOD__ ) { $table = $this->tableName( $table ); $table = $this->addQuotes( strtoupper( $this->removeIdentifierQuotes( $table ) ) ); - $owner = $this->addQuotes( strtoupper( $this->mDBname ) ); + $owner = $this->addQuotes( strtoupper( $this->dbName ) ); $sql = "SELECT 1 FROM all_tables WHERE owner=$owner AND table_name=$table"; $res = $this->doQuery( $sql ); if ( $res && $res->numRows() > 0 ) { @@ -890,7 +890,7 @@ class DatabaseOracle extends Database { } $fieldInfoStmt = oci_parse( - $this->mConn, + $this->conn, 'SELECT * FROM wiki_field_info_full WHERE table_name ' . $tableWhere . ' and column_name = \'' . $field . '\'' ); @@ -935,25 +935,25 @@ class DatabaseOracle extends Database { } protected function doBegin( $fname = __METHOD__ ) { - $this->mTrxLevel = 1; + $this->trxLevel = 1; $this->doQuery( 'SET CONSTRAINTS ALL DEFERRED' ); } protected function doCommit( $fname = __METHOD__ ) { - if ( $this->mTrxLevel ) { - $ret = oci_commit( $this->mConn ); + if ( $this->trxLevel ) { + $ret = oci_commit( $this->conn ); if ( !$ret ) { throw new DBUnexpectedError( $this, $this->lastError() ); } - $this->mTrxLevel = 0; + $this->trxLevel = 0; $this->doQuery( 'SET CONSTRAINTS ALL IMMEDIATE' ); } } protected function doRollback( $fname = __METHOD__ ) { - if ( $this->mTrxLevel ) { - oci_rollback( $this->mConn ); - $this->mTrxLevel = 0; + if ( $this->trxLevel ) { + oci_rollback( $this->conn ); + $this->trxLevel = 0; $this->doQuery( 'SET CONSTRAINTS ALL IMMEDIATE' ); } } @@ -1041,12 +1041,12 @@ class DatabaseOracle extends Database { } function selectDB( $db ) { - $this->mDBname = $db; - if ( $db == null || $db == $this->mUser ) { + $this->dbName = $db; + if ( $db == null || $db == $this->user ) { return true; } $sql = 'ALTER SESSION SET CURRENT_SCHEMA=' . strtoupper( $db ); - $stmt = oci_parse( $this->mConn, $sql ); + $stmt = oci_parse( $this->conn, $sql ); Wikimedia\suppressWarnings(); $success = oci_execute( $stmt ); Wikimedia\restoreWarnings(); @@ -1245,9 +1245,9 @@ class DatabaseOracle extends Database { $sql .= ' WHERE ' . $this->makeList( $conds, LIST_AND ); } - $this->mLastResult = $stmt = oci_parse( $this->mConn, $sql ); + $this->mLastResult = $stmt = oci_parse( $this->conn, $sql ); if ( $stmt === false ) { - $e = oci_error( $this->mConn ); + $e = oci_error( $this->conn ); $this->reportQueryError( $e['message'], $e['code'], $sql, __METHOD__ ); return false; @@ -1276,7 +1276,7 @@ class DatabaseOracle extends Database { } } else { /** @var OCI_Lob[] $lob */ - $lob[$col] = oci_new_descriptor( $this->mConn, OCI_D_LOB ); + $lob[$col] = oci_new_descriptor( $this->conn, OCI_D_LOB ); if ( $lob[$col] === false ) { $e = oci_error( $stmt ); throw new DBUnexpectedError( $this, "Cannot create LOB descriptor: " . $e['message'] ); @@ -1319,8 +1319,8 @@ class DatabaseOracle extends Database { } } - if ( !$this->mTrxLevel ) { - oci_commit( $this->mConn ); + if ( !$this->trxLevel ) { + oci_commit( $this->conn ); } return oci_free_statement( $stmt ); @@ -1340,11 +1340,11 @@ class DatabaseOracle extends Database { } function getDBname() { - return $this->mDBname; + return $this->dbName; } function getServer() { - return $this->mServer; + return $this->server; } public function buildGroupConcatField( diff --git a/includes/libs/rdbms/database/Database.php b/includes/libs/rdbms/database/Database.php index d1814e18b5..f4f9d31e7a 100644 --- a/includes/libs/rdbms/database/Database.php +++ b/includes/libs/rdbms/database/Database.php @@ -59,19 +59,19 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware const SMALL_WRITE_ROWS = 100; /** @var string SQL query */ - protected $mLastQuery = ''; + protected $lastQuery = ''; /** @var float|bool UNIX timestamp of last write query */ - protected $mLastWriteTime = false; + protected $lastWriteTime = false; /** @var string|bool */ - protected $mPHPError = false; + protected $phpError = false; /** @var string */ - protected $mServer; + protected $server; /** @var string */ - protected $mUser; + protected $user; /** @var string */ - protected $mPassword; + protected $password; /** @var string */ - protected $mDBname; + protected $dbName; /** @var array[] $aliases Map of (table => (dbname, schema, prefix) map) */ protected $tableAliases = []; /** @var bool Whether this PHP instance is for a CLI script */ @@ -89,35 +89,33 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware protected $errorLogger; /** @var resource|null Database connection */ - protected $mConn = null; + protected $conn = null; /** @var bool */ - protected $mOpened = false; + protected $opened = false; /** @var array[] List of (callable, method name) */ - protected $mTrxIdleCallbacks = []; + protected $trxIdleCallbacks = []; /** @var array[] List of (callable, method name) */ - protected $mTrxPreCommitCallbacks = []; + protected $trxPreCommitCallbacks = []; /** @var array[] List of (callable, method name) */ - protected $mTrxEndCallbacks = []; + protected $trxEndCallbacks = []; /** @var callable[] Map of (name => callable) */ - protected $mTrxRecurringCallbacks = []; + protected $trxRecurringCallbacks = []; /** @var bool Whether to suppress triggering of transaction end callbacks */ - protected $mTrxEndCallbacksSuppressed = false; + protected $trxEndCallbacksSuppressed = false; /** @var string */ - protected $mTablePrefix = ''; + protected $tablePrefix = ''; /** @var string */ - protected $mSchema = ''; + protected $schema = ''; /** @var int */ - protected $mFlags; + protected $flags; /** @var array */ - protected $mLBInfo = []; - /** @var bool|null */ - protected $mDefaultBigSelects = null; + protected $lbInfo = []; /** @var array|bool */ - protected $mSchemaVars = false; + protected $schemaVars = false; /** @var array */ - protected $mSessionVars = []; + protected $sessionVars = []; /** @var array|null */ protected $preparedArgs; /** @var string|bool|null Stashed value of html_errors INI setting */ @@ -135,94 +133,94 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware * * @var int */ - protected $mTrxLevel = 0; + protected $trxLevel = 0; /** * Either a short hexidecimal string if a transaction is active or "" * * @var string - * @see Database::mTrxLevel + * @see Database::trxLevel */ - protected $mTrxShortId = ''; + protected $trxShortId = ''; /** * The UNIX time that the transaction started. Callers can assume that if * snapshot isolation is used, then the data is *at least* up to date to that * point (possibly more up-to-date since the first SELECT defines the snapshot). * * @var float|null - * @see Database::mTrxLevel + * @see Database::trxLevel */ - private $mTrxTimestamp = null; + private $trxTimestamp = null; /** @var float Lag estimate at the time of BEGIN */ - private $mTrxReplicaLag = null; + private $trxReplicaLag = null; /** * Remembers the function name given for starting the most recent transaction via begin(). * Used to provide additional context for error reporting. * * @var string - * @see Database::mTrxLevel + * @see Database::trxLevel */ - private $mTrxFname = null; + private $trxFname = null; /** * Record if possible write queries were done in the last transaction started * * @var bool - * @see Database::mTrxLevel + * @see Database::trxLevel */ - private $mTrxDoneWrites = false; + private $trxDoneWrites = false; /** * Record if the current transaction was started implicitly due to DBO_TRX being set. * * @var bool - * @see Database::mTrxLevel + * @see Database::trxLevel */ - private $mTrxAutomatic = false; + private $trxAutomatic = false; /** * Array of levels of atomicity within transactions * * @var array */ - private $mTrxAtomicLevels = []; + private $trxAtomicLevels = []; /** * Record if the current transaction was started implicitly by Database::startAtomic * * @var bool */ - private $mTrxAutomaticAtomic = false; + private $trxAutomaticAtomic = false; /** * Track the write query callers of the current transaction * * @var string[] */ - private $mTrxWriteCallers = []; + private $trxWriteCallers = []; /** * @var float Seconds spent in write queries for the current transaction */ - private $mTrxWriteDuration = 0.0; + private $trxWriteDuration = 0.0; /** * @var int Number of write queries for the current transaction */ - private $mTrxWriteQueryCount = 0; + private $trxWriteQueryCount = 0; /** * @var int Number of rows affected by write queries for the current transaction */ - private $mTrxWriteAffectedRows = 0; + private $trxWriteAffectedRows = 0; /** - * @var float Like mTrxWriteQueryCount but excludes lock-bound, easy to replicate, queries + * @var float Like trxWriteQueryCount but excludes lock-bound, easy to replicate, queries */ - private $mTrxWriteAdjDuration = 0.0; + private $trxWriteAdjDuration = 0.0; /** - * @var int Number of write queries counted in mTrxWriteAdjDuration + * @var int Number of write queries counted in trxWriteAdjDuration */ - private $mTrxWriteAdjQueryCount = 0; + private $trxWriteAdjQueryCount = 0; /** * @var float RTT time estimate */ - private $mRTTEstimate = 0.0; + private $rttEstimate = 0.0; /** @var array Map of (name => 1) for locks obtained via lock() */ - private $mNamedLocksHeld = []; + private $namedLocksHeld = []; /** @var array Map of (table name => 1) for TEMPORARY tables */ - protected $mSessionTempTables = []; + protected $sessionTempTables = []; /** @var IDatabase|null Lazy handle to the master DB this server replicates from */ private $lazyMasterHandle; @@ -230,7 +228,7 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware /** @var float UNIX timestamp */ protected $lastPing = 0.0; - /** @var int[] Prior mFlags values */ + /** @var int[] Prior flags member variable values */ private $priorFlags = []; /** @var object|string Class name or object With profileIn/profileOut methods */ @@ -252,23 +250,23 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware $password = $params['password']; $dbName = $params['dbname']; - $this->mSchema = $params['schema']; - $this->mTablePrefix = $params['tablePrefix']; + $this->schema = $params['schema']; + $this->tablePrefix = $params['tablePrefix']; $this->cliMode = $params['cliMode']; // Agent name is added to SQL queries in a comment, so make sure it can't break out $this->agent = str_replace( '/', '-', $params['agent'] ); - $this->mFlags = $params['flags']; - if ( $this->mFlags & self::DBO_DEFAULT ) { + $this->flags = $params['flags']; + if ( $this->flags & self::DBO_DEFAULT ) { if ( $this->cliMode ) { - $this->mFlags &= ~self::DBO_TRX; + $this->flags &= ~self::DBO_TRX; } else { - $this->mFlags |= self::DBO_TRX; + $this->flags |= self::DBO_TRX; } } - $this->mSessionVars = $params['variables']; + $this->sessionVars = $params['variables']; $this->srvCache = isset( $params['srvCache'] ) ? $params['srvCache'] @@ -290,9 +288,9 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware } // Set the domain object after open() sets the relevant fields - if ( $this->mDBname != '' ) { + if ( $this->dbName != '' ) { // Domains with server scope but a table prefix are not used by IDatabase classes - $this->currentDomain = new DatabaseDomain( $this->mDBname, null, $this->mTablePrefix ); + $this->currentDomain = new DatabaseDomain( $this->dbName, null, $this->tablePrefix ); } } @@ -464,9 +462,9 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware if ( $ignoreErrors !== null ) { // setFlag()/clearFlag() do not allow DBO_IGNORE changes for sanity if ( $ignoreErrors ) { - $this->mFlags |= self::DBO_IGNORE; + $this->flags |= self::DBO_IGNORE; } else { - $this->mFlags &= ~self::DBO_IGNORE; + $this->flags &= ~self::DBO_IGNORE; } } @@ -474,19 +472,19 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware } public function trxLevel() { - return $this->mTrxLevel; + return $this->trxLevel; } public function trxTimestamp() { - return $this->mTrxLevel ? $this->mTrxTimestamp : null; + return $this->trxLevel ? $this->trxTimestamp : null; } public function tablePrefix( $prefix = null ) { - $old = $this->mTablePrefix; + $old = $this->tablePrefix; if ( $prefix !== null ) { - $this->mTablePrefix = $prefix; - $this->currentDomain = ( $this->mDBname != '' ) - ? new DatabaseDomain( $this->mDBname, null, $this->mTablePrefix ) + $this->tablePrefix = $prefix; + $this->currentDomain = ( $this->dbName != '' ) + ? new DatabaseDomain( $this->dbName, null, $this->tablePrefix ) : DatabaseDomain::newUnspecified(); } @@ -494,9 +492,9 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware } public function dbSchema( $schema = null ) { - $old = $this->mSchema; + $old = $this->schema; if ( $schema !== null ) { - $this->mSchema = $schema; + $this->schema = $schema; } return $old; @@ -504,10 +502,10 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware public function getLBInfo( $name = null ) { if ( is_null( $name ) ) { - return $this->mLBInfo; + return $this->lbInfo; } else { - if ( array_key_exists( $name, $this->mLBInfo ) ) { - return $this->mLBInfo[$name]; + if ( array_key_exists( $name, $this->lbInfo ) ) { + return $this->lbInfo[$name]; } else { return null; } @@ -516,9 +514,9 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware public function setLBInfo( $name, $value = null ) { if ( is_null( $value ) ) { - $this->mLBInfo = $name; + $this->lbInfo = $name; } else { - $this->mLBInfo[$name] = $value; + $this->lbInfo[$name] = $value; } } @@ -544,55 +542,55 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware } public function lastQuery() { - return $this->mLastQuery; + return $this->lastQuery; } public function doneWrites() { - return (bool)$this->mLastWriteTime; + return (bool)$this->lastWriteTime; } public function lastDoneWrites() { - return $this->mLastWriteTime ?: false; + return $this->lastWriteTime ?: false; } public function writesPending() { - return $this->mTrxLevel && $this->mTrxDoneWrites; + return $this->trxLevel && $this->trxDoneWrites; } public function writesOrCallbacksPending() { - return $this->mTrxLevel && ( - $this->mTrxDoneWrites || $this->mTrxIdleCallbacks || $this->mTrxPreCommitCallbacks + return $this->trxLevel && ( + $this->trxDoneWrites || $this->trxIdleCallbacks || $this->trxPreCommitCallbacks ); } public function pendingWriteQueryDuration( $type = self::ESTIMATE_TOTAL ) { - if ( !$this->mTrxLevel ) { + if ( !$this->trxLevel ) { return false; - } elseif ( !$this->mTrxDoneWrites ) { + } elseif ( !$this->trxDoneWrites ) { return 0.0; } switch ( $type ) { case self::ESTIMATE_DB_APPLY: $this->ping( $rtt ); - $rttAdjTotal = $this->mTrxWriteAdjQueryCount * $rtt; - $applyTime = max( $this->mTrxWriteAdjDuration - $rttAdjTotal, 0 ); + $rttAdjTotal = $this->trxWriteAdjQueryCount * $rtt; + $applyTime = max( $this->trxWriteAdjDuration - $rttAdjTotal, 0 ); // For omitted queries, make them count as something at least - $omitted = $this->mTrxWriteQueryCount - $this->mTrxWriteAdjQueryCount; + $omitted = $this->trxWriteQueryCount - $this->trxWriteAdjQueryCount; $applyTime += self::TINY_WRITE_SEC * $omitted; return $applyTime; default: // everything - return $this->mTrxWriteDuration; + return $this->trxWriteDuration; } } public function pendingWriteCallers() { - return $this->mTrxLevel ? $this->mTrxWriteCallers : []; + return $this->trxLevel ? $this->trxWriteCallers : []; } public function pendingWriteRowsAffected() { - return $this->mTrxWriteAffectedRows; + return $this->trxWriteAffectedRows; } /** @@ -602,15 +600,15 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware * @return array */ protected function pendingWriteAndCallbackCallers() { - if ( !$this->mTrxLevel ) { + if ( !$this->trxLevel ) { return []; } - $fnames = $this->mTrxWriteCallers; + $fnames = $this->trxWriteCallers; foreach ( [ - $this->mTrxIdleCallbacks, - $this->mTrxPreCommitCallbacks, - $this->mTrxEndCallbacks + $this->trxIdleCallbacks, + $this->trxPreCommitCallbacks, + $this->trxEndCallbacks ] as $callbacks ) { foreach ( $callbacks as $callback ) { $fnames[] = $callback[1]; @@ -621,7 +619,7 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware } public function isOpen() { - return $this->mOpened; + return $this->opened; } public function setFlag( $flag, $remember = self::REMEMBER_NOTHING ) { @@ -630,9 +628,9 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware } if ( $remember === self::REMEMBER_PRIOR ) { - array_push( $this->priorFlags, $this->mFlags ); + array_push( $this->priorFlags, $this->flags ); } - $this->mFlags |= $flag; + $this->flags |= $flag; } public function clearFlag( $flag, $remember = self::REMEMBER_NOTHING ) { @@ -641,9 +639,9 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware } if ( $remember === self::REMEMBER_PRIOR ) { - array_push( $this->priorFlags, $this->mFlags ); + array_push( $this->priorFlags, $this->flags ); } - $this->mFlags &= ~$flag; + $this->flags &= ~$flag; } public function restoreFlags( $state = self::RESTORE_PRIOR ) { @@ -652,15 +650,15 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware } if ( $state === self::RESTORE_INITIAL ) { - $this->mFlags = reset( $this->priorFlags ); + $this->flags = reset( $this->priorFlags ); $this->priorFlags = []; } else { - $this->mFlags = array_pop( $this->priorFlags ); + $this->flags = array_pop( $this->priorFlags ); } } public function getFlag( $flag ) { - return !!( $this->mFlags & $flag ); + return !!( $this->flags & $flag ); } /** @@ -701,7 +699,7 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware * Set a custom error handler for logging errors during database connection */ protected function installErrorHandler() { - $this->mPHPError = false; + $this->phpError = false; $this->htmlErrors = ini_set( 'html_errors', '0' ); set_error_handler( [ $this, 'connectionErrorLogger' ] ); } @@ -724,8 +722,8 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware * @return string|bool Last PHP error for this DB (typically connection errors) */ protected function getLastPHPError() { - if ( $this->mPHPError ) { - $error = preg_replace( '!\[\]!', '', $this->mPHPError ); + if ( $this->phpError ) { + $error = preg_replace( '!\[\]!', '', $this->phpError ); $error = preg_replace( '!^.*?:\s?(.*)$!', '$1', $error ); return $error; @@ -742,7 +740,7 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware * @param string $errstr */ public function connectionErrorLogger( $errno, $errstr ) { - $this->mPHPError = $errstr; + $this->phpError = $errstr; } /** @@ -754,32 +752,32 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware protected function getLogContext( array $extras = [] ) { return array_merge( [ - 'db_server' => $this->mServer, - 'db_name' => $this->mDBname, - 'db_user' => $this->mUser, + 'db_server' => $this->server, + 'db_name' => $this->dbName, + 'db_user' => $this->user, ], $extras ); } public function close() { - if ( $this->mConn ) { + if ( $this->conn ) { if ( $this->trxLevel() ) { $this->commit( __METHOD__, self::FLUSHING_INTERNAL ); } $closed = $this->closeConnection(); - $this->mConn = false; + $this->conn = false; } elseif ( - $this->mTrxIdleCallbacks || - $this->mTrxPreCommitCallbacks || - $this->mTrxEndCallbacks + $this->trxIdleCallbacks || + $this->trxPreCommitCallbacks || + $this->trxEndCallbacks ) { // sanity throw new RuntimeException( "Transaction callbacks still pending." ); } else { $closed = true; } - $this->mOpened = false; + $this->opened = false; return $closed; } @@ -868,7 +866,7 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware $sql, $matches ) ) { - $this->mSessionTempTables[$matches[1]] = 1; + $this->sessionTempTables[$matches[1]] = 1; return true; } elseif ( preg_match( @@ -876,8 +874,8 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware $sql, $matches ) ) { - $isTemp = isset( $this->mSessionTempTables[$matches[1]] ); - unset( $this->mSessionTempTables[$matches[1]] ); + $isTemp = isset( $this->sessionTempTables[$matches[1]] ); + unset( $this->sessionTempTables[$matches[1]] ); return $isTemp; } elseif ( preg_match( @@ -885,13 +883,13 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware $sql, $matches ) ) { - return isset( $this->mSessionTempTables[$matches[1]] ); + return isset( $this->sessionTempTables[$matches[1]] ); } elseif ( preg_match( '/^(?:INSERT\s+(?:\w+\s+)?INTO|UPDATE|DELETE\s+FROM)\s+[`"\']?(\w+)[`"\']?/i', $sql, $matches ) ) { - return isset( $this->mSessionTempTables[$matches[1]] ); + return isset( $this->sessionTempTables[$matches[1]] ); } return false; @@ -899,7 +897,7 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware public function query( $sql, $fname = __METHOD__, $tempIgnore = false ) { $priorWritesPending = $this->writesOrCallbacksPending(); - $this->mLastQuery = $sql; + $this->lastQuery = $sql; $isWrite = $this->isWriteQuery( $sql ); if ( $isWrite ) { @@ -922,7 +920,7 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware throw new DBReadOnlyError( $this, "Database is read-only: $reason" ); } # Set a flag indicating that writes have been done - $this->mLastWriteTime = microtime( true ); + $this->lastWriteTime = microtime( true ); } # Add trace comment to the begin of the sql string, right after the operator. @@ -930,22 +928,22 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware $commentedSql = preg_replace( '/\s|$/', " /* $fname {$this->agent} */ ", $sql, 1 ); # Start implicit transactions that wrap the request if DBO_TRX is enabled - if ( !$this->mTrxLevel && $this->getFlag( self::DBO_TRX ) + if ( !$this->trxLevel && $this->getFlag( self::DBO_TRX ) && $this->isTransactableQuery( $sql ) ) { $this->begin( __METHOD__ . " ($fname)", self::TRANSACTION_INTERNAL ); - $this->mTrxAutomatic = true; + $this->trxAutomatic = true; } # Keep track of whether the transaction has write queries pending - if ( $this->mTrxLevel && !$this->mTrxDoneWrites && $isWrite ) { - $this->mTrxDoneWrites = true; + if ( $this->trxLevel && !$this->trxDoneWrites && $isWrite ) { + $this->trxDoneWrites = true; $this->trxProfiler->transactionWritingIn( - $this->mServer, $this->mDBname, $this->mTrxShortId ); + $this->server, $this->dbName, $this->trxShortId ); } if ( $this->getFlag( self::DBO_DEBUG ) ) { - $this->queryLogger->debug( "{$this->mDBname} {$commentedSql}" ); + $this->queryLogger->debug( "{$this->dbName} {$commentedSql}" ); } # Avoid fatals if close() was called @@ -1024,7 +1022,7 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware } # Include query transaction state - $queryProf .= $this->mTrxShortId ? " [TRX#{$this->mTrxShortId}]" : ""; + $queryProf .= $this->trxShortId ? " [TRX#{$this->trxShortId}]" : ""; $startTime = microtime( true ); if ( $this->profiler ) { @@ -1042,14 +1040,14 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware if ( $ret !== false ) { $this->lastPing = $startTime; - if ( $isWrite && $this->mTrxLevel ) { + if ( $isWrite && $this->trxLevel ) { $this->updateTrxWriteQueryTime( $sql, $queryRuntime, $this->affectedRows() ); - $this->mTrxWriteCallers[] = $fname; + $this->trxWriteCallers[] = $fname; } } if ( $sql === self::PING_QUERY ) { - $this->mRTTEstimate = $queryRuntime; + $this->rttEstimate = $queryRuntime; } $this->trxProfiler->recordQueryCompletion( @@ -1089,12 +1087,12 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware } } - $this->mTrxWriteDuration += $runtime; - $this->mTrxWriteQueryCount += 1; - $this->mTrxWriteAffectedRows += $affected; + $this->trxWriteDuration += $runtime; + $this->trxWriteQueryCount += 1; + $this->trxWriteAffectedRows += $affected; if ( $indicativeOfReplicaRuntime ) { - $this->mTrxWriteAdjDuration += $runtime; - $this->mTrxWriteAdjQueryCount += 1; + $this->trxWriteAdjDuration += $runtime; + $this->trxWriteAdjQueryCount += 1; } } @@ -1113,7 +1111,7 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware # Dropped connections also mean that named locks are automatically released. # Only allow error suppression in autocommit mode or when the lost transaction # didn't matter anyway (aside from DBO_TRX snapshot loss). - if ( $this->mNamedLocksHeld ) { + if ( $this->namedLocksHeld ) { return false; // possible critical section violation } elseif ( $sql === 'COMMIT' ) { return !$priorWritesPending; // nothing written anyway? (T127428) @@ -1134,13 +1132,13 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware * @return null|Exception */ private function handleSessionLoss() { - $this->mTrxLevel = 0; - $this->mTrxIdleCallbacks = []; // T67263 - $this->mTrxPreCommitCallbacks = []; // T67263 - $this->mSessionTempTables = []; - $this->mNamedLocksHeld = []; + $this->trxLevel = 0; + $this->trxIdleCallbacks = []; // T67263 + $this->trxPreCommitCallbacks = []; // T67263 + $this->sessionTempTables = []; + $this->namedLocksHeld = []; try { - // Handle callbacks in mTrxEndCallbacks + // Handle callbacks in trxEndCallbacks $this->runOnTransactionIdleCallbacks( self::TRIGGER_ROLLBACK ); $this->runTransactionListenerCallbacks( self::TRIGGER_ROLLBACK ); return null; @@ -1545,7 +1543,7 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware public function tableExists( $table, $fname = __METHOD__ ) { $tableRaw = $this->tableName( $table, 'raw' ); - if ( isset( $this->mSessionTempTables[$tableRaw] ) ) { + if ( isset( $this->sessionTempTables[$tableRaw] ) ) { return true; // already known to exist } @@ -1811,17 +1809,17 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware # Stub. Shouldn't cause serious problems if it's not overridden, but # if your database engine supports a concept similar to MySQL's # databases you may as well. - $this->mDBname = $db; + $this->dbName = $db; return true; } public function getDBname() { - return $this->mDBname; + return $this->dbName; } public function getServer() { - return $this->mServer; + return $this->server; } public function tableName( $name, $format = 'quoted' ) { @@ -1890,14 +1888,14 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware $database = $this->tableAliases[$table]['dbname']; $schema = is_string( $this->tableAliases[$table]['schema'] ) ? $this->tableAliases[$table]['schema'] - : $this->mSchema; + : $this->schema; $prefix = is_string( $this->tableAliases[$table]['prefix'] ) ? $this->tableAliases[$table]['prefix'] - : $this->mTablePrefix; + : $this->tablePrefix; } else { $database = ''; - $schema = $this->mSchema; # Default schema - $prefix = $this->mTablePrefix; # Default prefix + $schema = $this->schema; # Default schema + $prefix = $this->tablePrefix; # Default prefix } } @@ -2349,7 +2347,7 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware } $affectedRowCount = 0; - $useTrx = !$this->mTrxLevel; + $useTrx = !$this->trxLevel; if ( $useTrx ) { $this->begin( $fname, self::TRANSACTION_INTERNAL ); } @@ -2756,25 +2754,25 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware } final public function onTransactionResolution( callable $callback, $fname = __METHOD__ ) { - if ( !$this->mTrxLevel ) { + if ( !$this->trxLevel ) { throw new DBUnexpectedError( $this, "No transaction is active." ); } - $this->mTrxEndCallbacks[] = [ $callback, $fname ]; + $this->trxEndCallbacks[] = [ $callback, $fname ]; } final public function onTransactionIdle( callable $callback, $fname = __METHOD__ ) { - $this->mTrxIdleCallbacks[] = [ $callback, $fname ]; - if ( !$this->mTrxLevel ) { + $this->trxIdleCallbacks[] = [ $callback, $fname ]; + if ( !$this->trxLevel ) { $this->runOnTransactionIdleCallbacks( self::TRIGGER_IDLE ); } } final public function onTransactionPreCommitOrIdle( callable $callback, $fname = __METHOD__ ) { - if ( $this->mTrxLevel || $this->getFlag( self::DBO_TRX ) ) { + if ( $this->trxLevel || $this->getFlag( self::DBO_TRX ) ) { // As long as DBO_TRX is set, writes will accumulate until the load balancer issues // an implicit commit of all peer databases. This is true even if a transaction has // not yet been triggered by writes; make sure $callback runs *after* any such writes. - $this->mTrxPreCommitCallbacks[] = [ $callback, $fname ]; + $this->trxPreCommitCallbacks[] = [ $callback, $fname ]; } else { // No transaction is active nor will start implicitly, so make one for this callback $this->startAtomic( __METHOD__ ); @@ -2790,9 +2788,9 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware final public function setTransactionListener( $name, callable $callback = null ) { if ( $callback ) { - $this->mTrxRecurringCallbacks[$name] = $callback; + $this->trxRecurringCallbacks[$name] = $callback; } else { - unset( $this->mTrxRecurringCallbacks[$name] ); + unset( $this->trxRecurringCallbacks[$name] ); } } @@ -2805,7 +2803,7 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware * @since 1.28 */ final public function setTrxEndCallbackSuppression( $suppress ) { - $this->mTrxEndCallbacksSuppressed = $suppress; + $this->trxEndCallbacksSuppressed = $suppress; } /** @@ -2818,7 +2816,7 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware * @throws Exception */ public function runOnTransactionIdleCallbacks( $trigger ) { - if ( $this->mTrxEndCallbacksSuppressed ) { + if ( $this->trxEndCallbacksSuppressed ) { return; } @@ -2827,11 +2825,11 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware $e = null; // first exception do { // callbacks may add callbacks :) $callbacks = array_merge( - $this->mTrxIdleCallbacks, - $this->mTrxEndCallbacks // include "transaction resolution" callbacks + $this->trxIdleCallbacks, + $this->trxEndCallbacks // include "transaction resolution" callbacks ); - $this->mTrxIdleCallbacks = []; // consumed (and recursion guard) - $this->mTrxEndCallbacks = []; // consumed (recursion guard) + $this->trxIdleCallbacks = []; // consumed (and recursion guard) + $this->trxEndCallbacks = []; // consumed (recursion guard) foreach ( $callbacks as $callback ) { try { list( $phpCallback ) = $callback; @@ -2852,7 +2850,7 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware } } } - } while ( count( $this->mTrxIdleCallbacks ) ); + } while ( count( $this->trxIdleCallbacks ) ); if ( $e instanceof Exception ) { throw $e; // re-throw any first exception @@ -2870,8 +2868,8 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware public function runOnTransactionPreCommitCallbacks() { $e = null; // first exception do { // callbacks may add callbacks :) - $callbacks = $this->mTrxPreCommitCallbacks; - $this->mTrxPreCommitCallbacks = []; // consumed (and recursion guard) + $callbacks = $this->trxPreCommitCallbacks; + $this->trxPreCommitCallbacks = []; // consumed (and recursion guard) foreach ( $callbacks as $callback ) { try { list( $phpCallback ) = $callback; @@ -2881,7 +2879,7 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware $e = $e ?: $ex; } } - } while ( count( $this->mTrxPreCommitCallbacks ) ); + } while ( count( $this->trxPreCommitCallbacks ) ); if ( $e instanceof Exception ) { throw $e; // re-throw any first exception @@ -2898,14 +2896,14 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware * @since 1.20 */ public function runTransactionListenerCallbacks( $trigger ) { - if ( $this->mTrxEndCallbacksSuppressed ) { + if ( $this->trxEndCallbacksSuppressed ) { return; } /** @var Exception $e */ $e = null; // first exception - foreach ( $this->mTrxRecurringCallbacks as $phpCallback ) { + foreach ( $this->trxRecurringCallbacks as $phpCallback ) { try { $phpCallback( $trigger, $this ); } catch ( Exception $ex ) { @@ -2920,29 +2918,29 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware } final public function startAtomic( $fname = __METHOD__ ) { - if ( !$this->mTrxLevel ) { + if ( !$this->trxLevel ) { $this->begin( $fname, self::TRANSACTION_INTERNAL ); // If DBO_TRX is set, a series of startAtomic/endAtomic pairs will result // in all changes being in one transaction to keep requests transactional. if ( !$this->getFlag( self::DBO_TRX ) ) { - $this->mTrxAutomaticAtomic = true; + $this->trxAutomaticAtomic = true; } } - $this->mTrxAtomicLevels[] = $fname; + $this->trxAtomicLevels[] = $fname; } final public function endAtomic( $fname = __METHOD__ ) { - if ( !$this->mTrxLevel ) { + if ( !$this->trxLevel ) { throw new DBUnexpectedError( $this, "No atomic transaction is open (got $fname)." ); } - if ( !$this->mTrxAtomicLevels || - array_pop( $this->mTrxAtomicLevels ) !== $fname + if ( !$this->trxAtomicLevels || + array_pop( $this->trxAtomicLevels ) !== $fname ) { throw new DBUnexpectedError( $this, "Invalid atomic section ended (got $fname)." ); } - if ( !$this->mTrxAtomicLevels && $this->mTrxAutomaticAtomic ) { + if ( !$this->trxAtomicLevels && $this->trxAutomaticAtomic ) { $this->commit( $fname, self::FLUSHING_INTERNAL ); } } @@ -2962,17 +2960,17 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware final public function begin( $fname = __METHOD__, $mode = self::TRANSACTION_EXPLICIT ) { // Protect against mismatched atomic section, transaction nesting, and snapshot loss - if ( $this->mTrxLevel ) { - if ( $this->mTrxAtomicLevels ) { - $levels = implode( ', ', $this->mTrxAtomicLevels ); + if ( $this->trxLevel ) { + if ( $this->trxAtomicLevels ) { + $levels = implode( ', ', $this->trxAtomicLevels ); $msg = "$fname: Got explicit BEGIN while atomic section(s) $levels are open."; throw new DBUnexpectedError( $this, $msg ); - } elseif ( !$this->mTrxAutomatic ) { - $msg = "$fname: Explicit transaction already active (from {$this->mTrxFname})."; + } elseif ( !$this->trxAutomatic ) { + $msg = "$fname: Explicit transaction already active (from {$this->trxFname})."; throw new DBUnexpectedError( $this, $msg ); } else { // @TODO: make this an exception at some point - $msg = "$fname: Implicit transaction already active (from {$this->mTrxFname})."; + $msg = "$fname: Implicit transaction already active (from {$this->trxFname})."; $this->queryLogger->error( $msg ); return; // join the main transaction set } @@ -2987,27 +2985,27 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware $this->assertOpen(); $this->doBegin( $fname ); - $this->mTrxTimestamp = microtime( true ); - $this->mTrxFname = $fname; - $this->mTrxDoneWrites = false; - $this->mTrxAutomaticAtomic = false; - $this->mTrxAtomicLevels = []; - $this->mTrxShortId = sprintf( '%06x', mt_rand( 0, 0xffffff ) ); - $this->mTrxWriteDuration = 0.0; - $this->mTrxWriteQueryCount = 0; - $this->mTrxWriteAffectedRows = 0; - $this->mTrxWriteAdjDuration = 0.0; - $this->mTrxWriteAdjQueryCount = 0; - $this->mTrxWriteCallers = []; + $this->trxTimestamp = microtime( true ); + $this->trxFname = $fname; + $this->trxDoneWrites = false; + $this->trxAutomaticAtomic = false; + $this->trxAtomicLevels = []; + $this->trxShortId = sprintf( '%06x', mt_rand( 0, 0xffffff ) ); + $this->trxWriteDuration = 0.0; + $this->trxWriteQueryCount = 0; + $this->trxWriteAffectedRows = 0; + $this->trxWriteAdjDuration = 0.0; + $this->trxWriteAdjQueryCount = 0; + $this->trxWriteCallers = []; // First SELECT after BEGIN will establish the snapshot in REPEATABLE-READ. // Get an estimate of the replica DB lag before then, treating estimate staleness // as lag itself just to be safe $status = $this->getApproximateLagStatus(); - $this->mTrxReplicaLag = $status['lag'] + ( microtime( true ) - $status['since'] ); + $this->trxReplicaLag = $status['lag'] + ( microtime( true ) - $status['since'] ); // T147697: make explicitTrxActive() return true until begin() finishes. This way, no // caller will think its OK to muck around with the transaction just because startAtomic() - // has not yet completed (e.g. setting mTrxAtomicLevels). - $this->mTrxAutomatic = ( $mode === self::TRANSACTION_INTERNAL ); + // has not yet completed (e.g. setting trxAtomicLevels). + $this->trxAutomatic = ( $mode === self::TRANSACTION_INTERNAL ); } /** @@ -3018,13 +3016,13 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware */ protected function doBegin( $fname ) { $this->query( 'BEGIN', $fname ); - $this->mTrxLevel = 1; + $this->trxLevel = 1; } final public function commit( $fname = __METHOD__, $flush = '' ) { - if ( $this->mTrxLevel && $this->mTrxAtomicLevels ) { + if ( $this->trxLevel && $this->trxAtomicLevels ) { // There are still atomic sections open. This cannot be ignored - $levels = implode( ', ', $this->mTrxAtomicLevels ); + $levels = implode( ', ', $this->trxAtomicLevels ); throw new DBUnexpectedError( $this, "$fname: Got COMMIT while atomic sections $levels are still open." @@ -3032,20 +3030,20 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware } if ( $flush === self::FLUSHING_INTERNAL || $flush === self::FLUSHING_ALL_PEERS ) { - if ( !$this->mTrxLevel ) { + if ( !$this->trxLevel ) { return; // nothing to do - } elseif ( !$this->mTrxAutomatic ) { + } elseif ( !$this->trxAutomatic ) { throw new DBUnexpectedError( $this, "$fname: Flushing an explicit transaction, getting out of sync." ); } } else { - if ( !$this->mTrxLevel ) { + if ( !$this->trxLevel ) { $this->queryLogger->error( "$fname: No transaction to commit, something got out of sync." ); return; // nothing to do - } elseif ( $this->mTrxAutomatic ) { + } elseif ( $this->trxAutomatic ) { // @TODO: make this an exception at some point $msg = "$fname: Explicit commit of implicit transaction."; $this->queryLogger->error( $msg ); @@ -3059,14 +3057,14 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware $this->runOnTransactionPreCommitCallbacks(); $writeTime = $this->pendingWriteQueryDuration( self::ESTIMATE_DB_APPLY ); $this->doCommit( $fname ); - if ( $this->mTrxDoneWrites ) { - $this->mLastWriteTime = microtime( true ); + if ( $this->trxDoneWrites ) { + $this->lastWriteTime = microtime( true ); $this->trxProfiler->transactionWritingOut( - $this->mServer, - $this->mDBname, - $this->mTrxShortId, + $this->server, + $this->dbName, + $this->trxShortId, $writeTime, - $this->mTrxWriteAffectedRows + $this->trxWriteAffectedRows ); } @@ -3081,19 +3079,19 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware * @param string $fname */ protected function doCommit( $fname ) { - if ( $this->mTrxLevel ) { + if ( $this->trxLevel ) { $this->query( 'COMMIT', $fname ); - $this->mTrxLevel = 0; + $this->trxLevel = 0; } } final public function rollback( $fname = __METHOD__, $flush = '' ) { if ( $flush === self::FLUSHING_INTERNAL || $flush === self::FLUSHING_ALL_PEERS ) { - if ( !$this->mTrxLevel ) { + if ( !$this->trxLevel ) { return; // nothing to do } } else { - if ( !$this->mTrxLevel ) { + if ( !$this->trxLevel ) { $this->queryLogger->error( "$fname: No transaction to rollback, something got out of sync." ); return; // nothing to do @@ -3109,17 +3107,17 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware $this->assertOpen(); $this->doRollback( $fname ); - $this->mTrxAtomicLevels = []; - if ( $this->mTrxDoneWrites ) { + $this->trxAtomicLevels = []; + if ( $this->trxDoneWrites ) { $this->trxProfiler->transactionWritingOut( - $this->mServer, - $this->mDBname, - $this->mTrxShortId + $this->server, + $this->dbName, + $this->trxShortId ); } - $this->mTrxIdleCallbacks = []; // clear - $this->mTrxPreCommitCallbacks = []; // clear + $this->trxIdleCallbacks = []; // clear + $this->trxPreCommitCallbacks = []; // clear try { $this->runOnTransactionIdleCallbacks( self::TRIGGER_ROLLBACK ); } catch ( Exception $e ) { @@ -3139,11 +3137,11 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware * @param string $fname */ protected function doRollback( $fname ) { - if ( $this->mTrxLevel ) { + if ( $this->trxLevel ) { # Disconnects cause rollback anyway, so ignore those errors $ignoreErrors = true; $this->query( 'ROLLBACK', $fname, $ignoreErrors ); - $this->mTrxLevel = 0; + $this->trxLevel = 0; } } @@ -3161,7 +3159,7 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware } public function explicitTrxActive() { - return $this->mTrxLevel && ( $this->mTrxAtomicLevels || !$this->mTrxAutomatic ); + return $this->trxLevel && ( $this->trxAtomicLevels || !$this->trxAutomatic ); } public function duplicateTableStructure( @@ -3232,8 +3230,8 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware public function ping( &$rtt = null ) { // Avoid hitting the server if it was hit recently if ( $this->isOpen() && ( microtime( true ) - $this->lastPing ) < self::PING_TTL ) { - if ( !func_num_args() || $this->mRTTEstimate > 0 ) { - $rtt = $this->mRTTEstimate; + if ( !func_num_args() || $this->rttEstimate > 0 ) { + $rtt = $this->rttEstimate; return true; // don't care about $rtt } } @@ -3244,7 +3242,7 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware $this->restoreFlags( self::RESTORE_PRIOR ); if ( $ok ) { - $rtt = $this->mRTTEstimate; + $rtt = $this->rttEstimate; } return $ok; @@ -3257,10 +3255,10 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware */ protected function reconnect() { $this->closeConnection(); - $this->mOpened = false; - $this->mConn = false; + $this->opened = false; + $this->conn = false; try { - $this->open( $this->mServer, $this->mUser, $this->mPassword, $this->mDBname ); + $this->open( $this->server, $this->user, $this->password, $this->dbName ); $this->lastPing = microtime( true ); $ok = true; } catch ( DBConnectionError $e ) { @@ -3286,8 +3284,8 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware * @since 1.27 */ protected function getTransactionLagStatus() { - return $this->mTrxLevel - ? [ 'lag' => $this->mTrxReplicaLag, 'since' => $this->trxTimestamp() ] + return $this->trxLevel + ? [ 'lag' => $this->trxReplicaLag, 'since' => $this->trxTimestamp() ] : null; } @@ -3395,7 +3393,7 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware } public function setSchemaVars( $vars ) { - $this->mSchemaVars = $vars; + $this->schemaVars = $vars; } public function sourceStream( @@ -3547,8 +3545,8 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware * @return array */ protected function getSchemaVars() { - if ( $this->mSchemaVars ) { - return $this->mSchemaVars; + if ( $this->schemaVars ) { + return $this->schemaVars; } else { return $this->getDefaultSchemaVars(); } @@ -3571,13 +3569,13 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware } public function lock( $lockName, $method, $timeout = 5 ) { - $this->mNamedLocksHeld[$lockName] = 1; + $this->namedLocksHeld[$lockName] = 1; return true; } public function unlock( $lockName, $method ) { - unset( $this->mNamedLocksHeld[$lockName] ); + unset( $this->namedLocksHeld[$lockName] ); return true; } @@ -3733,9 +3731,9 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware } /** - * Get the underlying binding handle, mConn + * Get the underlying binding connection handle * - * Makes sure that mConn is set (disconnects and ping() failure can unset it). + * Makes sure the connection resource is set (disconnects and ping() failure can unset it). * This catches broken callers than catch and ignore disconnection exceptions. * Unlike checking isOpen(), this is safe to call inside of open(). * @@ -3744,14 +3742,14 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware * @since 1.26 */ protected function getBindingHandle() { - if ( !$this->mConn ) { + if ( !$this->conn ) { throw new DBUnexpectedError( $this, 'DB connection was already closed or the connection dropped.' ); } - return $this->mConn; + return $this->conn; } /** @@ -3759,7 +3757,7 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware * @return string */ public function __toString() { - return (string)$this->mConn; + return (string)$this->conn; } /** @@ -3774,11 +3772,11 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware if ( $this->isOpen() ) { // Open a new connection resource without messing with the old one - $this->mOpened = false; - $this->mConn = false; - $this->mTrxEndCallbacks = []; // don't copy + $this->opened = false; + $this->conn = false; + $this->trxEndCallbacks = []; // don't copy $this->handleSessionLoss(); // no trx or locks anymore - $this->open( $this->mServer, $this->mUser, $this->mPassword, $this->mDBname ); + $this->open( $this->server, $this->user, $this->password, $this->dbName ); $this->lastPing = microtime( true ); } } @@ -3797,8 +3795,8 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware * Run a few simple sanity checks and close dangling connections */ public function __destruct() { - if ( $this->mTrxLevel && $this->mTrxDoneWrites ) { - trigger_error( "Uncommitted DB writes (transaction from {$this->mTrxFname})." ); + if ( $this->trxLevel && $this->trxDoneWrites ) { + trigger_error( "Uncommitted DB writes (transaction from {$this->trxFname})." ); } $danglingWriters = $this->pendingWriteAndCallbackCallers(); @@ -3807,14 +3805,14 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware trigger_error( "DB transaction writes or callbacks still pending ($fnames)." ); } - if ( $this->mConn ) { + if ( $this->conn ) { // Avoid connection leaks for sanity. Normally, resources close at script completion. // The connection might already be closed in zend/hhvm by now, so suppress warnings. Wikimedia\suppressWarnings(); $this->closeConnection(); Wikimedia\restoreWarnings(); - $this->mConn = false; - $this->mOpened = false; + $this->conn = false; + $this->opened = false; } } } diff --git a/includes/libs/rdbms/database/DatabaseMssql.php b/includes/libs/rdbms/database/DatabaseMssql.php index 9a0e8c9cf5..c7e12894e0 100644 --- a/includes/libs/rdbms/database/DatabaseMssql.php +++ b/includes/libs/rdbms/database/DatabaseMssql.php @@ -93,10 +93,10 @@ class DatabaseMssql extends Database { } $this->close(); - $this->mServer = $server; - $this->mUser = $user; - $this->mPassword = $password; - $this->mDBname = $dbName; + $this->server = $server; + $this->user = $user; + $this->password = $password; + $this->dbName = $dbName; $connectionInfo = []; @@ -112,16 +112,16 @@ class DatabaseMssql extends Database { } Wikimedia\suppressWarnings(); - $this->mConn = sqlsrv_connect( $server, $connectionInfo ); + $this->conn = sqlsrv_connect( $server, $connectionInfo ); Wikimedia\restoreWarnings(); - if ( $this->mConn === false ) { + if ( $this->conn === false ) { throw new DBConnectionError( $this, $this->lastError() ); } - $this->mOpened = true; + $this->opened = true; - return $this->mConn; + return $this->conn; } /** @@ -130,7 +130,7 @@ class DatabaseMssql extends Database { * @return bool */ protected function closeConnection() { - return sqlsrv_close( $this->mConn ); + return sqlsrv_close( $this->conn ); } /** @@ -186,10 +186,10 @@ class DatabaseMssql extends Database { if ( $this->mPrepareStatements ) { // we do prepare + execute so we can get its field metadata for later usage if desired - $stmt = sqlsrv_prepare( $this->mConn, $sql, [], $scrollArr ); + $stmt = sqlsrv_prepare( $this->conn, $sql, [], $scrollArr ); $success = sqlsrv_execute( $stmt ); } else { - $stmt = sqlsrv_query( $this->mConn, $sql, [], $scrollArr ); + $stmt = sqlsrv_query( $this->conn, $sql, [], $scrollArr ); $success = (bool)$stmt; } @@ -953,7 +953,7 @@ class DatabaseMssql extends Database { * @return string Version information from the database */ public function getServerVersion() { - $server_info = sqlsrv_server_info( $this->mConn ); + $server_info = sqlsrv_server_info( $this->conn ); $version = 'Error'; if ( isset( $server_info['SQLServerVersion'] ) ) { $version = $server_info['SQLServerVersion']; @@ -977,7 +977,7 @@ class DatabaseMssql extends Database { } if ( $schema === false ) { - $schema = $this->mSchema; + $schema = $this->schema; } $res = $this->query( "SELECT 1 FROM INFORMATION_SCHEMA.TABLES @@ -1042,8 +1042,8 @@ class DatabaseMssql extends Database { * @param string $fname */ protected function doBegin( $fname = __METHOD__ ) { - sqlsrv_begin_transaction( $this->mConn ); - $this->mTrxLevel = 1; + sqlsrv_begin_transaction( $this->conn ); + $this->trxLevel = 1; } /** @@ -1051,8 +1051,8 @@ class DatabaseMssql extends Database { * @param string $fname */ protected function doCommit( $fname = __METHOD__ ) { - sqlsrv_commit( $this->mConn ); - $this->mTrxLevel = 0; + sqlsrv_commit( $this->conn ); + $this->trxLevel = 0; } /** @@ -1061,8 +1061,8 @@ class DatabaseMssql extends Database { * @param string $fname */ protected function doRollback( $fname = __METHOD__ ) { - sqlsrv_rollback( $this->mConn ); - $this->mTrxLevel = 0; + sqlsrv_rollback( $this->conn ); + $this->trxLevel = 0; } /** @@ -1131,7 +1131,7 @@ class DatabaseMssql extends Database { */ public function selectDB( $db ) { try { - $this->mDBname = $db; + $this->dbName = $db; $this->query( "USE $db" ); return true; } catch ( Exception $e ) { @@ -1255,8 +1255,8 @@ class DatabaseMssql extends Database { private function populateColumnCaches() { $res = $this->select( 'INFORMATION_SCHEMA.COLUMNS', '*', [ - 'TABLE_CATALOG' => $this->mDBname, - 'TABLE_SCHEMA' => $this->mSchema, + 'TABLE_CATALOG' => $this->dbName, + 'TABLE_SCHEMA' => $this->schema, 'DATA_TYPE' => [ 'varbinary', 'binary', 'image', 'bit' ] ] ); diff --git a/includes/libs/rdbms/database/DatabaseMysqlBase.php b/includes/libs/rdbms/database/DatabaseMysqlBase.php index 390f9a9c3d..7e6ddc3b8f 100644 --- a/includes/libs/rdbms/database/DatabaseMysqlBase.php +++ b/includes/libs/rdbms/database/DatabaseMysqlBase.php @@ -60,6 +60,8 @@ abstract class DatabaseMysqlBase extends Database { protected $sqlMode; /** @var bool Use experimental UTF-8 transmission encoding */ protected $utf8Mode; + /** @var bool|null */ + protected $defaultBigSelects = null; /** @var string|null */ private $serverVersion = null; @@ -126,14 +128,14 @@ abstract class DatabaseMysqlBase extends Database { # Close/unset connection handle $this->close(); - $this->mServer = $server; - $this->mUser = $user; - $this->mPassword = $password; - $this->mDBname = $dbName; + $this->server = $server; + $this->user = $user; + $this->password = $password; + $this->dbName = $dbName; $this->installErrorHandler(); try { - $this->mConn = $this->mysqlConnect( $this->mServer ); + $this->conn = $this->mysqlConnect( $this->server ); } catch ( Exception $ex ) { $this->restoreErrorHandler(); throw $ex; @@ -141,7 +143,7 @@ abstract class DatabaseMysqlBase extends Database { $error = $this->restoreErrorHandler(); # Always log connection errors - if ( !$this->mConn ) { + if ( !$this->conn ) { if ( !$error ) { $error = $this->lastError(); } @@ -171,7 +173,7 @@ abstract class DatabaseMysqlBase extends Database { ] ) ); $this->queryLogger->debug( - "Error selecting database $dbName on server {$this->mServer}" ); + "Error selecting database $dbName on server {$this->server}" ); $this->reportConnectionError( "Error selecting database $dbName" ); } @@ -190,7 +192,7 @@ abstract class DatabaseMysqlBase extends Database { } // Set any custom settings defined by site config // (e.g. https://dev.mysql.com/doc/refman/4.1/en/innodb-parameters.html) - foreach ( $this->mSessionVars as $var => $val ) { + foreach ( $this->sessionVars as $var => $val ) { // Escape strings but not numbers to avoid MySQL complaining if ( !is_int( $val ) && !is_float( $val ) ) { $val = $this->addQuotes( $val ); @@ -213,7 +215,7 @@ abstract class DatabaseMysqlBase extends Database { } } - $this->mOpened = true; + $this->opened = true; return true; } @@ -465,10 +467,10 @@ abstract class DatabaseMysqlBase extends Database { * @return string */ public function lastError() { - if ( $this->mConn ) { + if ( $this->conn ) { # Even if it's non-zero, it can still be invalid Wikimedia\suppressWarnings(); - $error = $this->mysqlError( $this->mConn ); + $error = $this->mysqlError( $this->conn ); if ( !$error ) { $error = $this->mysqlError(); } @@ -477,7 +479,7 @@ abstract class DatabaseMysqlBase extends Database { $error = $this->mysqlError(); } if ( $error ) { - $error .= ' (' . $this->mServer . ')'; + $error .= ' (' . $this->server . ')'; } return $error; @@ -594,7 +596,7 @@ abstract class DatabaseMysqlBase extends Database { list( $database, , $prefix, $table ) = $this->qualifiedTableComponents( $table ); $tableName = "{$prefix}{$table}"; - if ( isset( $this->mSessionTempTables[$tableName] ) ) { + if ( isset( $this->sessionTempTables[$tableName] ) ) { return true; // already known to exist and won't show in SHOW TABLES anyway } @@ -1170,14 +1172,14 @@ abstract class DatabaseMysqlBase extends Database { */ public function setBigSelects( $value = true ) { if ( $value === 'default' ) { - if ( $this->mDefaultBigSelects === null ) { + if ( $this->defaultBigSelects === null ) { # Function hasn't been called before so it must already be set to the default return; } else { - $value = $this->mDefaultBigSelects; + $value = $this->defaultBigSelects; } - } elseif ( $this->mDefaultBigSelects === null ) { - $this->mDefaultBigSelects = + } elseif ( $this->defaultBigSelects === null ) { + $this->defaultBigSelects = (bool)$this->selectField( false, '@@sql_big_selects', '', __METHOD__ ); } $encValue = $value ? '1' : '0'; @@ -1376,7 +1378,7 @@ abstract class DatabaseMysqlBase extends Database { */ public function listViews( $prefix = null, $fname = __METHOD__ ) { // The name of the column containing the name of the VIEW - $propertyName = 'Tables_in_' . $this->mDBname; + $propertyName = 'Tables_in_' . $this->dbName; // Query for the VIEWS $res = $this->query( 'SHOW FULL TABLES WHERE TABLE_TYPE = "VIEW"' ); diff --git a/includes/libs/rdbms/database/DatabaseMysqli.php b/includes/libs/rdbms/database/DatabaseMysqli.php index 09ea66cac8..9152d1e9f9 100644 --- a/includes/libs/rdbms/database/DatabaseMysqli.php +++ b/includes/libs/rdbms/database/DatabaseMysqli.php @@ -86,7 +86,7 @@ class DatabaseMysqli extends DatabaseMysqlBase { $mysqli = mysqli_init(); $connFlags = 0; - if ( $this->mFlags & self::DBO_SSL ) { + if ( $this->flags & self::DBO_SSL ) { $connFlags |= MYSQLI_CLIENT_SSL; $mysqli->ssl_set( $this->sslKeyPath, @@ -96,10 +96,10 @@ class DatabaseMysqli extends DatabaseMysqlBase { $this->sslCiphers ); } - if ( $this->mFlags & self::DBO_COMPRESS ) { + if ( $this->flags & self::DBO_COMPRESS ) { $connFlags |= MYSQLI_CLIENT_COMPRESS; } - if ( $this->mFlags & self::DBO_PERSISTENT ) { + if ( $this->flags & self::DBO_PERSISTENT ) { $realServer = 'p:' . $realServer; } @@ -112,8 +112,8 @@ class DatabaseMysqli extends DatabaseMysqlBase { } $mysqli->options( MYSQLI_OPT_CONNECT_TIMEOUT, 3 ); - if ( $mysqli->real_connect( $realServer, $this->mUser, - $this->mPassword, $this->mDBname, $port, $socket, $connFlags ) + if ( $mysqli->real_connect( $realServer, $this->user, + $this->password, $this->dbName, $port, $socket, $connFlags ) ) { return $mysqli; } @@ -162,8 +162,8 @@ class DatabaseMysqli extends DatabaseMysqlBase { * @return int */ function lastErrno() { - if ( $this->mConn ) { - return $this->mConn->errno; + if ( $this->conn ) { + return $this->conn->errno; } else { return mysqli_connect_errno(); } @@ -185,7 +185,7 @@ class DatabaseMysqli extends DatabaseMysqlBase { function selectDB( $db ) { $conn = $this->getBindingHandle(); - $this->mDBname = $db; + $this->dbName = $db; return $conn->select_db( $db ); } @@ -326,11 +326,11 @@ class DatabaseMysqli extends DatabaseMysqlBase { * @return string */ public function __toString() { - if ( $this->mConn instanceof mysqli ) { - return (string)$this->mConn->thread_id; + if ( $this->conn instanceof mysqli ) { + return (string)$this->conn->thread_id; } else { // mConn might be false or something. - return (string)$this->mConn; + return (string)$this->conn; } } } diff --git a/includes/libs/rdbms/database/DatabasePostgres.php b/includes/libs/rdbms/database/DatabasePostgres.php index 8fbb7de7ce..7c07a07826 100644 --- a/includes/libs/rdbms/database/DatabasePostgres.php +++ b/includes/libs/rdbms/database/DatabasePostgres.php @@ -97,10 +97,10 @@ class DatabasePostgres extends Database { ); } - $this->mServer = $server; - $this->mUser = $user; - $this->mPassword = $password; - $this->mDBname = $dbName; + $this->server = $server; + $this->user = $user; + $this->password = $password; + $this->dbName = $dbName; $connectVars = [ // pg_connect() user $user as the default database. Since a database is *required*, @@ -116,7 +116,7 @@ class DatabasePostgres extends Database { if ( (int)$this->port > 0 ) { $connectVars['port'] = (int)$this->port; } - if ( $this->mFlags & self::DBO_SSL ) { + if ( $this->flags & self::DBO_SSL ) { $connectVars['sslmode'] = 1; } @@ -126,7 +126,7 @@ class DatabasePostgres extends Database { try { // Use new connections to let LoadBalancer/LBFactory handle reuse - $this->mConn = pg_connect( $this->connectString, PGSQL_CONNECT_FORCE_NEW ); + $this->conn = pg_connect( $this->connectString, PGSQL_CONNECT_FORCE_NEW ); } catch ( Exception $ex ) { $this->restoreErrorHandler(); throw $ex; @@ -134,7 +134,7 @@ class DatabasePostgres extends Database { $phpError = $this->restoreErrorHandler(); - if ( !$this->mConn ) { + if ( !$this->conn ) { $this->queryLogger->debug( "DB connection error\n" . "Server: $server, Database: $dbName, User: $user, Password: " . @@ -144,7 +144,7 @@ class DatabasePostgres extends Database { throw new DBConnectionError( $this, str_replace( "\n", ' ', $phpError ) ); } - $this->mOpened = true; + $this->opened = true; # If called from the command-line (e.g. importDump), only show errors if ( $this->cliMode ) { @@ -159,11 +159,11 @@ class DatabasePostgres extends Database { $this->query( "SET bytea_output = 'escape'", __METHOD__ ); // PHP bug 53127 } - $this->determineCoreSchema( $this->mSchema ); + $this->determineCoreSchema( $this->schema ); // The schema to be used is now in the search path; no need for explicit qualification - $this->mSchema = ''; + $this->schema = ''; - return $this->mConn; + return $this->conn; } public function databasesAreIndependent() { @@ -178,8 +178,8 @@ class DatabasePostgres extends Database { * @throws DBUnexpectedError */ public function selectDB( $db ) { - if ( $this->mDBname !== $db ) { - return (bool)$this->open( $this->mServer, $this->mUser, $this->mPassword, $db ); + if ( $this->dbName !== $db ) { + return (bool)$this->open( $this->server, $this->user, $this->password, $db ); } else { return true; } @@ -199,7 +199,7 @@ class DatabasePostgres extends Database { } protected function closeConnection() { - return $this->mConn ? pg_close( $this->mConn ) : true; + return $this->conn ? pg_close( $this->conn ) : true; } public function doQuery( $sql ) { @@ -253,7 +253,7 @@ class DatabasePostgres extends Database { } } /* Transaction stays in the ERROR state until rolled back */ - if ( $this->mTrxLevel ) { + if ( $this->trxLevel ) { // Throw away the transaction state, then raise the error as normal. // Note that if this connection is managed by LBFactory, it's already expected // that the other transactions LBFactory manages will be rolled back. @@ -365,7 +365,7 @@ class DatabasePostgres extends Database { } public function lastError() { - if ( $this->mConn ) { + if ( $this->conn ) { if ( $this->mLastResult ) { return pg_result_error( $this->mLastResult ); } else { @@ -1255,11 +1255,11 @@ SQL; } public function getDBname() { - return $this->mDBname; + return $this->dbName; } public function getServer() { - return $this->mServer; + return $this->server; } public function buildConcat( $stringList ) { diff --git a/includes/libs/rdbms/database/DatabaseSqlite.php b/includes/libs/rdbms/database/DatabaseSqlite.php index 01772cf809..458d308f77 100644 --- a/includes/libs/rdbms/database/DatabaseSqlite.php +++ b/includes/libs/rdbms/database/DatabaseSqlite.php @@ -51,7 +51,7 @@ class DatabaseSqlite extends Database { protected $mLastResult; /** @var PDO */ - protected $mConn; + protected $conn; /** @var FSLockManager (hopefully on the same server as the DB) */ protected $lockMgr; @@ -79,8 +79,8 @@ class DatabaseSqlite extends Database { throw new InvalidArgumentException( "Need 'dbDirectory' or 'dbFilePath' parameter." ); } else { $this->dbDir = $p['dbDirectory']; - $this->mDBname = $p['dbname']; - $lockDomain = $this->mDBname; + $this->dbName = $p['dbname']; + $lockDomain = $this->dbName; // Stock wiki mode using standard file names per DB. parent::__construct( $p ); // Super doesn't open when $user is false, but we can work with $dbName @@ -153,12 +153,12 @@ class DatabaseSqlite extends Database { $this->close(); $fileName = self::generateFileName( $this->dbDir, $dbName ); if ( !is_readable( $fileName ) ) { - $this->mConn = false; + $this->conn = false; throw new DBConnectionError( $this, "SQLite database not accessible" ); } $this->openFile( $fileName ); - return (bool)$this->mConn; + return (bool)$this->conn; } /** @@ -173,29 +173,29 @@ class DatabaseSqlite extends Database { $this->dbPath = $fileName; try { - if ( $this->mFlags & self::DBO_PERSISTENT ) { - $this->mConn = new PDO( "sqlite:$fileName", '', '', + if ( $this->flags & self::DBO_PERSISTENT ) { + $this->conn = new PDO( "sqlite:$fileName", '', '', [ PDO::ATTR_PERSISTENT => true ] ); } else { - $this->mConn = new PDO( "sqlite:$fileName", '', '' ); + $this->conn = new PDO( "sqlite:$fileName", '', '' ); } } catch ( PDOException $e ) { $err = $e->getMessage(); } - if ( !$this->mConn ) { + if ( !$this->conn ) { $this->queryLogger->debug( "DB connection error: $err\n" ); throw new DBConnectionError( $this, $err ); } - $this->mOpened = !!$this->mConn; - if ( $this->mOpened ) { + $this->opened = !!$this->conn; + if ( $this->opened ) { # Set error codes only, don't raise exceptions - $this->mConn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_SILENT ); + $this->conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_SILENT ); # Enforce LIKE to be case sensitive, just like MySQL $this->query( 'PRAGMA case_sensitive_like = 1' ); - return $this->mConn; + return $this->conn; } return false; @@ -218,7 +218,7 @@ class DatabaseSqlite extends Database { * @return bool */ protected function closeConnection() { - $this->mConn = null; + $this->conn = null; return true; } @@ -311,7 +311,7 @@ class DatabaseSqlite extends Database { * @return bool|ResultWrapper */ protected function doQuery( $sql ) { - $res = $this->mConn->query( $sql ); + $res = $this->conn->query( $sql ); if ( $res === false ) { return false; } @@ -447,7 +447,7 @@ class DatabaseSqlite extends Database { */ function insertId() { // PDO::lastInsertId yields a string :( - return intval( $this->mConn->lastInsertId() ); + return intval( $this->conn->lastInsertId() ); } /** @@ -472,10 +472,10 @@ class DatabaseSqlite extends Database { * @return string */ function lastError() { - if ( !is_object( $this->mConn ) ) { + if ( !is_object( $this->conn ) ) { return "Cannot return last error, no db connection"; } - $e = $this->mConn->errorInfo(); + $e = $this->conn->errorInfo(); return isset( $e[2] ) ? $e[2] : ''; } @@ -484,10 +484,10 @@ class DatabaseSqlite extends Database { * @return string */ function lastErrno() { - if ( !is_object( $this->mConn ) ) { + if ( !is_object( $this->conn ) ) { return "Cannot return last error, no db connection"; } else { - $info = $this->mConn->errorInfo(); + $info = $this->conn->errorInfo(); return $info[1]; } @@ -720,7 +720,7 @@ class DatabaseSqlite extends Database { * @return string Version information from the database */ function getServerVersion() { - $ver = $this->mConn->getAttribute( PDO::ATTR_SERVER_VERSION ); + $ver = $this->conn->getAttribute( PDO::ATTR_SERVER_VERSION ); return $ver; } @@ -752,7 +752,7 @@ class DatabaseSqlite extends Database { } else { $this->query( 'BEGIN', $fname ); } - $this->mTrxLevel = 1; + $this->trxLevel = 1; } /** @@ -810,7 +810,7 @@ class DatabaseSqlite extends Database { ); return "x'" . bin2hex( (string)$s ) . "'"; } else { - return $this->mConn->quote( (string)$s ); + return $this->conn->quote( (string)$s ); } } @@ -1054,7 +1054,7 @@ class DatabaseSqlite extends Database { * @return string */ public function __toString() { - return 'SQLite ' . (string)$this->mConn->getAttribute( PDO::ATTR_SERVER_VERSION ); + return 'SQLite ' . (string)$this->conn->getAttribute( PDO::ATTR_SERVER_VERSION ); } } diff --git a/tests/phpunit/includes/db/DatabaseSqliteTest.php b/tests/phpunit/includes/db/DatabaseSqliteTest.php index 369aa83c7b..2de35a7c88 100644 --- a/tests/phpunit/includes/db/DatabaseSqliteTest.php +++ b/tests/phpunit/includes/db/DatabaseSqliteTest.php @@ -6,8 +6,6 @@ use Wikimedia\Rdbms\DatabaseSqlite; use Wikimedia\Rdbms\ResultWrapper; class DatabaseSqliteMock extends DatabaseSqlite { - private $lastQuery; - public static function newInstance( array $p = [] ) { $p['dbFilePath'] = ':memory:'; $p['schema'] = false; @@ -16,8 +14,6 @@ class DatabaseSqliteMock extends DatabaseSqlite { } function query( $sql, $fname = '', $tempIgnore = false ) { - $this->lastQuery = $sql; - return true; } diff --git a/tests/phpunit/includes/db/DatabaseTestHelper.php b/tests/phpunit/includes/db/DatabaseTestHelper.php index fa9898d1cd..606c12d58e 100644 --- a/tests/phpunit/includes/db/DatabaseTestHelper.php +++ b/tests/phpunit/includes/db/DatabaseTestHelper.php @@ -108,7 +108,7 @@ class DatabaseTestHelper extends Database { public function tableExists( $table, $fname = __METHOD__ ) { $tableRaw = $this->tableName( $table, 'raw' ); - if ( isset( $this->mSessionTempTables[$tableRaw] ) ) { + if ( isset( $this->sessionTempTables[$tableRaw] ) ) { return true; // already known to exist }