Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like Database often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Database, and based on these observations, apply Extract Interface, too.
| 1 | <?php  | 
            ||
| 33 | abstract class Database implements IDatabase, LoggerAwareInterface { | 
            ||
| 34 | /** Number of times to re-try an operation in case of deadlock */  | 
            ||
| 35 | const DEADLOCK_TRIES = 4;  | 
            ||
| 36 | /** Minimum time to wait before retry, in microseconds */  | 
            ||
| 37 | const DEADLOCK_DELAY_MIN = 500000;  | 
            ||
| 38 | /** Maximum time to wait before retry */  | 
            ||
| 39 | const DEADLOCK_DELAY_MAX = 1500000;  | 
            ||
| 40 | |||
| 41 | /** How long before it is worth doing a dummy query to test the connection */  | 
            ||
| 42 | const PING_TTL = 1.0;  | 
            ||
| 43 | const PING_QUERY = 'SELECT 1 AS ping';  | 
            ||
| 44 | |||
| 45 | const TINY_WRITE_SEC = .010;  | 
            ||
| 46 | const SLOW_WRITE_SEC = .500;  | 
            ||
| 47 | const SMALL_WRITE_ROWS = 100;  | 
            ||
| 48 | |||
| 49 | /** @var string SQL query */  | 
            ||
| 50 | protected $mLastQuery = '';  | 
            ||
| 51 | /** @var bool */  | 
            ||
| 52 | protected $mDoneWrites = false;  | 
            ||
| 53 | /** @var string|bool */  | 
            ||
| 54 | protected $mPHPError = false;  | 
            ||
| 55 | /** @var string */  | 
            ||
| 56 | protected $mServer;  | 
            ||
| 57 | /** @var string */  | 
            ||
| 58 | protected $mUser;  | 
            ||
| 59 | /** @var string */  | 
            ||
| 60 | protected $mPassword;  | 
            ||
| 61 | /** @var string */  | 
            ||
| 62 | protected $mDBname;  | 
            ||
| 63 | /** @var array[] $aliases Map of (table => (dbname, schema, prefix) map) */  | 
            ||
| 64 | protected $tableAliases = [];  | 
            ||
| 65 | /** @var bool Whether this PHP instance is for a CLI script */  | 
            ||
| 66 | protected $cliMode;  | 
            ||
| 67 | /** @var string Agent name for query profiling */  | 
            ||
| 68 | protected $agent;  | 
            ||
| 69 | |||
| 70 | /** @var BagOStuff APC cache */  | 
            ||
| 71 | protected $srvCache;  | 
            ||
| 72 | /** @var LoggerInterface */  | 
            ||
| 73 | protected $connLogger;  | 
            ||
| 74 | /** @var LoggerInterface */  | 
            ||
| 75 | protected $queryLogger;  | 
            ||
| 76 | /** @var callback Error logging callback */  | 
            ||
| 77 | protected $errorLogger;  | 
            ||
| 78 | |||
| 79 | /** @var resource Database connection */  | 
            ||
| 80 | protected $mConn = null;  | 
            ||
| 81 | /** @var bool */  | 
            ||
| 82 | protected $mOpened = false;  | 
            ||
| 83 | |||
| 84 | /** @var array[] List of (callable, method name) */  | 
            ||
| 85 | protected $mTrxIdleCallbacks = [];  | 
            ||
| 86 | /** @var array[] List of (callable, method name) */  | 
            ||
| 87 | protected $mTrxPreCommitCallbacks = [];  | 
            ||
| 88 | /** @var array[] List of (callable, method name) */  | 
            ||
| 89 | protected $mTrxEndCallbacks = [];  | 
            ||
| 90 | /** @var callable[] Map of (name => callable) */  | 
            ||
| 91 | protected $mTrxRecurringCallbacks = [];  | 
            ||
| 92 | /** @var bool Whether to suppress triggering of transaction end callbacks */  | 
            ||
| 93 | protected $mTrxEndCallbacksSuppressed = false;  | 
            ||
| 94 | |||
| 95 | /** @var string */  | 
            ||
| 96 | protected $mTablePrefix = '';  | 
            ||
| 97 | /** @var string */  | 
            ||
| 98 | protected $mSchema = '';  | 
            ||
| 99 | /** @var integer */  | 
            ||
| 100 | protected $mFlags;  | 
            ||
| 101 | /** @var array */  | 
            ||
| 102 | protected $mLBInfo = [];  | 
            ||
| 103 | /** @var bool|null */  | 
            ||
| 104 | protected $mDefaultBigSelects = null;  | 
            ||
| 105 | /** @var array|bool */  | 
            ||
| 106 | protected $mSchemaVars = false;  | 
            ||
| 107 | /** @var array */  | 
            ||
| 108 | protected $mSessionVars = [];  | 
            ||
| 109 | /** @var array|null */  | 
            ||
| 110 | protected $preparedArgs;  | 
            ||
| 111 | /** @var string|bool|null Stashed value of html_errors INI setting */  | 
            ||
| 112 | protected $htmlErrors;  | 
            ||
| 113 | /** @var string */  | 
            ||
| 114 | protected $delimiter = ';';  | 
            ||
| 115 | /** @var DatabaseDomain */  | 
            ||
| 116 | protected $currentDomain;  | 
            ||
| 117 | |||
| 118 | /**  | 
            ||
| 119 | * Either 1 if a transaction is active or 0 otherwise.  | 
            ||
| 120 | * The other Trx fields may not be meaningfull if this is 0.  | 
            ||
| 121 | *  | 
            ||
| 122 | * @var int  | 
            ||
| 123 | */  | 
            ||
| 124 | protected $mTrxLevel = 0;  | 
            ||
| 125 | /**  | 
            ||
| 126 | * Either a short hexidecimal string if a transaction is active or ""  | 
            ||
| 127 | *  | 
            ||
| 128 | * @var string  | 
            ||
| 129 | * @see DatabaseBase::mTrxLevel  | 
            ||
| 130 | */  | 
            ||
| 131 | protected $mTrxShortId = '';  | 
            ||
| 132 | /**  | 
            ||
| 133 | * The UNIX time that the transaction started. Callers can assume that if  | 
            ||
| 134 | * snapshot isolation is used, then the data is *at least* up to date to that  | 
            ||
| 135 | * point (possibly more up-to-date since the first SELECT defines the snapshot).  | 
            ||
| 136 | *  | 
            ||
| 137 | * @var float|null  | 
            ||
| 138 | * @see DatabaseBase::mTrxLevel  | 
            ||
| 139 | */  | 
            ||
| 140 | private $mTrxTimestamp = null;  | 
            ||
| 141 | /** @var float Lag estimate at the time of BEGIN */  | 
            ||
| 142 | private $mTrxReplicaLag = null;  | 
            ||
| 143 | /**  | 
            ||
| 144 | * Remembers the function name given for starting the most recent transaction via begin().  | 
            ||
| 145 | * Used to provide additional context for error reporting.  | 
            ||
| 146 | *  | 
            ||
| 147 | * @var string  | 
            ||
| 148 | * @see DatabaseBase::mTrxLevel  | 
            ||
| 149 | */  | 
            ||
| 150 | private $mTrxFname = null;  | 
            ||
| 151 | /**  | 
            ||
| 152 | * Record if possible write queries were done in the last transaction started  | 
            ||
| 153 | *  | 
            ||
| 154 | * @var bool  | 
            ||
| 155 | * @see DatabaseBase::mTrxLevel  | 
            ||
| 156 | */  | 
            ||
| 157 | private $mTrxDoneWrites = false;  | 
            ||
| 158 | /**  | 
            ||
| 159 | * Record if the current transaction was started implicitly due to DBO_TRX being set.  | 
            ||
| 160 | *  | 
            ||
| 161 | * @var bool  | 
            ||
| 162 | * @see DatabaseBase::mTrxLevel  | 
            ||
| 163 | */  | 
            ||
| 164 | private $mTrxAutomatic = false;  | 
            ||
| 165 | /**  | 
            ||
| 166 | * Array of levels of atomicity within transactions  | 
            ||
| 167 | *  | 
            ||
| 168 | * @var array  | 
            ||
| 169 | */  | 
            ||
| 170 | private $mTrxAtomicLevels = [];  | 
            ||
| 171 | /**  | 
            ||
| 172 | * Record if the current transaction was started implicitly by DatabaseBase::startAtomic  | 
            ||
| 173 | *  | 
            ||
| 174 | * @var bool  | 
            ||
| 175 | */  | 
            ||
| 176 | private $mTrxAutomaticAtomic = false;  | 
            ||
| 177 | /**  | 
            ||
| 178 | * Track the write query callers of the current transaction  | 
            ||
| 179 | *  | 
            ||
| 180 | * @var string[]  | 
            ||
| 181 | */  | 
            ||
| 182 | private $mTrxWriteCallers = [];  | 
            ||
| 183 | /**  | 
            ||
| 184 | * @var float Seconds spent in write queries for the current transaction  | 
            ||
| 185 | */  | 
            ||
| 186 | private $mTrxWriteDuration = 0.0;  | 
            ||
| 187 | /**  | 
            ||
| 188 | * @var integer Number of write queries for the current transaction  | 
            ||
| 189 | */  | 
            ||
| 190 | private $mTrxWriteQueryCount = 0;  | 
            ||
| 191 | /**  | 
            ||
| 192 | * @var float Like mTrxWriteQueryCount but excludes lock-bound, easy to replicate, queries  | 
            ||
| 193 | */  | 
            ||
| 194 | private $mTrxWriteAdjDuration = 0.0;  | 
            ||
| 195 | /**  | 
            ||
| 196 | * @var integer Number of write queries counted in mTrxWriteAdjDuration  | 
            ||
| 197 | */  | 
            ||
| 198 | private $mTrxWriteAdjQueryCount = 0;  | 
            ||
| 199 | /**  | 
            ||
| 200 | * @var float RTT time estimate  | 
            ||
| 201 | */  | 
            ||
| 202 | private $mRTTEstimate = 0.0;  | 
            ||
| 203 | |||
| 204 | /** @var array Map of (name => 1) for locks obtained via lock() */  | 
            ||
| 205 | private $mNamedLocksHeld = [];  | 
            ||
| 206 | |||
| 207 | /** @var IDatabase|null Lazy handle to the master DB this server replicates from */  | 
            ||
| 208 | private $lazyMasterHandle;  | 
            ||
| 209 | |||
| 210 | /**  | 
            ||
| 211 | * @since 1.21  | 
            ||
| 212 | * @var resource File handle for upgrade  | 
            ||
| 213 | */  | 
            ||
| 214 | protected $fileHandle = null;  | 
            ||
| 215 | |||
| 216 | /**  | 
            ||
| 217 | * @since 1.22  | 
            ||
| 218 | * @var string[] Process cache of VIEWs names in the database  | 
            ||
| 219 | */  | 
            ||
| 220 | protected $allViews = null;  | 
            ||
| 221 | |||
| 222 | /** @var float UNIX timestamp */  | 
            ||
| 223 | protected $lastPing = 0.0;  | 
            ||
| 224 | |||
| 225 | /** @var int[] Prior mFlags values */  | 
            ||
| 226 | private $priorFlags = [];  | 
            ||
| 227 | |||
| 228 | /** @var object|string Class name or object With profileIn/profileOut methods */  | 
            ||
| 229 | protected $profiler;  | 
            ||
| 230 | /** @var TransactionProfiler */  | 
            ||
| 231 | protected $trxProfiler;  | 
            ||
| 232 | |||
| 233 | /**  | 
            ||
| 234 | * Constructor and database handle and attempt to connect to the DB server  | 
            ||
| 235 | *  | 
            ||
| 236 | * IDatabase classes should not be constructed directly in external  | 
            ||
| 237 | * code. Database::factory() should be used instead.  | 
            ||
| 238 | *  | 
            ||
| 239 | * @param array $params Parameters passed from Database::factory()  | 
            ||
| 240 | */  | 
            ||
| 241 | 	function __construct( array $params ) { | 
            ||
| 295 | |||
| 296 | /**  | 
            ||
| 297 | * Construct a Database subclass instance given a database type and parameters  | 
            ||
| 298 | *  | 
            ||
| 299 | * This also connects to the database immediately upon object construction  | 
            ||
| 300 | *  | 
            ||
| 301 | * @param string $dbType A possible DB type (sqlite, mysql, postgres)  | 
            ||
| 302 | * @param array $p Parameter map with keys:  | 
            ||
| 303 | * - host : The hostname of the DB server  | 
            ||
| 304 | * - user : The name of the database user the client operates under  | 
            ||
| 305 | * - password : The password for the database user  | 
            ||
| 306 | * - dbname : The name of the database to use where queries do not specify one.  | 
            ||
| 307 | * The database must exist or an error might be thrown. Setting this to the empty string  | 
            ||
| 308 | * will avoid any such errors and make the handle have no implicit database scope. This is  | 
            ||
| 309 | * useful for queries like SHOW STATUS, CREATE DATABASE, or DROP DATABASE. Note that a  | 
            ||
| 310 | * "database" in Postgres is rougly equivalent to an entire MySQL server. This the domain  | 
            ||
| 311 | * in which user names and such are defined, e.g. users are database-specific in Postgres.  | 
            ||
| 312 | * - schema : The database schema to use (if supported). A "schema" in Postgres is roughly  | 
            ||
| 313 | * equivalent to a "database" in MySQL. Note that MySQL and SQLite do not use schemas.  | 
            ||
| 314 | * - tablePrefix : Optional table prefix that is implicitly added on to all table names  | 
            ||
| 315 | * recognized in queries. This can be used in place of schemas for handle site farms.  | 
            ||
| 316 | * - flags : Optional bitfield of DBO_* constants that define connection, protocol,  | 
            ||
| 317 | * buffering, and transaction behavior. It is STRONGLY adviced to leave the DBO_DEFAULT  | 
            ||
| 318 | * flag in place UNLESS this this database simply acts as a key/value store.  | 
            ||
| 319 | * - driver: Optional name of a specific DB client driver. For MySQL, there is the old  | 
            ||
| 320 | * 'mysql' driver and the newer 'mysqli' driver.  | 
            ||
| 321 | * - variables: Optional map of session variables to set after connecting. This can be  | 
            ||
| 322 | * used to adjust lock timeouts or encoding modes and the like.  | 
            ||
| 323 | * - connLogger: Optional PSR-3 logger interface instance.  | 
            ||
| 324 | * - queryLogger: Optional PSR-3 logger interface instance.  | 
            ||
| 325 | * - profiler: Optional class name or object with profileIn()/profileOut() methods.  | 
            ||
| 326 | * These will be called in query(), using a simplified version of the SQL that also  | 
            ||
| 327 | * includes the agent as a SQL comment.  | 
            ||
| 328 | * - trxProfiler: Optional TransactionProfiler instance.  | 
            ||
| 329 | * - errorLogger: Optional callback that takes an Exception and logs it.  | 
            ||
| 330 | * - cliMode: Whether to consider the execution context that of a CLI script.  | 
            ||
| 331 | * - agent: Optional name used to identify the end-user in query profiling/logging.  | 
            ||
| 332 | * - srvCache: Optional BagOStuff instance to an APC-style cache.  | 
            ||
| 333 | * @return Database|null If the database driver or extension cannot be found  | 
            ||
| 334 | * @throws InvalidArgumentException If the database driver or extension cannot be found  | 
            ||
| 335 | * @since 1.18  | 
            ||
| 336 | */  | 
            ||
| 337 | 	final public static function factory( $dbType, $p = [] ) { | 
            ||
| 406 | |||
| 407 | 	public function setLogger( LoggerInterface $logger ) { | 
            ||
| 410 | |||
| 411 | 	public function getServerInfo() { | 
            ||
| 414 | |||
| 415 | View Code Duplication | 	public function bufferResults( $buffer = null ) { | 
            |
| 423 | |||
| 424 | /**  | 
            ||
| 425 | * Turns on (false) or off (true) the automatic generation and sending  | 
            ||
| 426 | * of a "we're sorry, but there has been a database error" page on  | 
            ||
| 427 | * database errors. Default is on (false). When turned off, the  | 
            ||
| 428 | * code should use lastErrno() and lastError() to handle the  | 
            ||
| 429 | * situation as appropriate.  | 
            ||
| 430 | *  | 
            ||
| 431 | * Do not use this function outside of the Database classes.  | 
            ||
| 432 | *  | 
            ||
| 433 | * @param null|bool $ignoreErrors  | 
            ||
| 434 | * @return bool The previous value of the flag.  | 
            ||
| 435 | */  | 
            ||
| 436 | View Code Duplication | 	protected function ignoreErrors( $ignoreErrors = null ) { | 
            |
| 444 | |||
| 445 | 	public function trxLevel() { | 
            ||
| 448 | |||
| 449 | 	public function trxTimestamp() { | 
            ||
| 452 | |||
| 453 | 	public function tablePrefix( $prefix = null ) { | 
            ||
| 464 | |||
| 465 | 	public function dbSchema( $schema = null ) { | 
            ||
| 473 | |||
| 474 | /**  | 
            ||
| 475 | * Set the filehandle to copy write statements to.  | 
            ||
| 476 | *  | 
            ||
| 477 | * @param resource $fh File handle  | 
            ||
| 478 | */  | 
            ||
| 479 | 	public function setFileHandle( $fh ) { | 
            ||
| 482 | |||
| 483 | 	public function getLBInfo( $name = null ) { | 
            ||
| 494 | |||
| 495 | 	public function setLBInfo( $name, $value = null ) { | 
            ||
| 502 | |||
| 503 | 	public function setLazyMasterHandle( IDatabase $conn ) { | 
            ||
| 506 | |||
| 507 | /**  | 
            ||
| 508 | * @return IDatabase|null  | 
            ||
| 509 | * @see setLazyMasterHandle()  | 
            ||
| 510 | * @since 1.27  | 
            ||
| 511 | */  | 
            ||
| 512 | 	public function getLazyMasterHandle() { | 
            ||
| 515 | |||
| 516 | 	public function implicitGroupby() { | 
            ||
| 519 | |||
| 520 | 	public function implicitOrderby() { | 
            ||
| 523 | |||
| 524 | 	public function lastQuery() { | 
            ||
| 527 | |||
| 528 | 	public function doneWrites() { | 
            ||
| 531 | |||
| 532 | 	public function lastDoneWrites() { | 
            ||
| 535 | |||
| 536 | 	public function writesPending() { | 
            ||
| 539 | |||
| 540 | 	public function writesOrCallbacksPending() { | 
            ||
| 545 | |||
| 546 | 	public function pendingWriteQueryDuration( $type = self::ESTIMATE_TOTAL ) { | 
            ||
| 567 | |||
| 568 | 	public function pendingWriteCallers() { | 
            ||
| 571 | |||
| 572 | 	protected function pendingWriteAndCallbackCallers() { | 
            ||
| 590 | |||
| 591 | 	public function isOpen() { | 
            ||
| 594 | |||
| 595 | 	public function setFlag( $flag, $remember = self::REMEMBER_NOTHING ) { | 
            ||
| 601 | |||
| 602 | 	public function clearFlag( $flag, $remember = self::REMEMBER_NOTHING ) { | 
            ||
| 608 | |||
| 609 | 	public function restoreFlags( $state = self::RESTORE_PRIOR ) { | 
            ||
| 621 | |||
| 622 | 	public function getFlag( $flag ) { | 
            ||
| 625 | |||
| 626 | 	public function getProperty( $name ) { | 
            ||
| 629 | |||
| 630 | 	public function getDomainID() { | 
            ||
| 633 | |||
| 634 | 	final public function getWikiID() { | 
            ||
| 637 | |||
| 638 | /**  | 
            ||
| 639 | * Get information about an index into an object  | 
            ||
| 640 | * @param string $table Table name  | 
            ||
| 641 | * @param string $index Index name  | 
            ||
| 642 | * @param string $fname Calling function name  | 
            ||
| 643 | * @return mixed Database-specific index description class or false if the index does not exist  | 
            ||
| 644 | */  | 
            ||
| 645 | abstract function indexInfo( $table, $index, $fname = __METHOD__ );  | 
            ||
| 646 | |||
| 647 | /**  | 
            ||
| 648 | * Wrapper for addslashes()  | 
            ||
| 649 | *  | 
            ||
| 650 | * @param string $s String to be slashed.  | 
            ||
| 651 | * @return string Slashed string.  | 
            ||
| 652 | */  | 
            ||
| 653 | abstract function strencode( $s );  | 
            ||
| 654 | |||
| 655 | 	protected function installErrorHandler() { | 
            ||
| 660 | |||
| 661 | /**  | 
            ||
| 662 | * @return bool|string  | 
            ||
| 663 | */  | 
            ||
| 664 | 	protected function restoreErrorHandler() { | 
            ||
| 678 | |||
| 679 | /**  | 
            ||
| 680 | * @param int $errno  | 
            ||
| 681 | * @param string $errstr  | 
            ||
| 682 | */  | 
            ||
| 683 | 	public function connectionerrorLogger( $errno, $errstr ) { | 
            ||
| 686 | |||
| 687 | /**  | 
            ||
| 688 | * Create a log context to pass to PSR-3 logger functions.  | 
            ||
| 689 | *  | 
            ||
| 690 | * @param array $extras Additional data to add to context  | 
            ||
| 691 | * @return array  | 
            ||
| 692 | */  | 
            ||
| 693 | 	protected function getLogContext( array $extras = [] ) { | 
            ||
| 703 | |||
| 704 | 	public function close() { | 
            ||
| 721 | |||
| 722 | /**  | 
            ||
| 723 | * Make sure isOpen() returns true as a sanity check  | 
            ||
| 724 | *  | 
            ||
| 725 | * @throws DBUnexpectedError  | 
            ||
| 726 | */  | 
            ||
| 727 | 	protected function assertOpen() { | 
            ||
| 732 | |||
| 733 | /**  | 
            ||
| 734 | * Closes underlying database connection  | 
            ||
| 735 | * @since 1.20  | 
            ||
| 736 | * @return bool Whether connection was closed successfully  | 
            ||
| 737 | */  | 
            ||
| 738 | abstract protected function closeConnection();  | 
            ||
| 739 | |||
| 740 | 	function reportConnectionError( $error = 'Unknown error' ) { | 
            ||
| 749 | |||
| 750 | /**  | 
            ||
| 751 | * The DBMS-dependent part of query()  | 
            ||
| 752 | *  | 
            ||
| 753 | * @param string $sql SQL query.  | 
            ||
| 754 | * @return ResultWrapper|bool Result object to feed to fetchObject,  | 
            ||
| 755 | * fetchRow, ...; or false on failure  | 
            ||
| 756 | */  | 
            ||
| 757 | abstract protected function doQuery( $sql );  | 
            ||
| 758 | |||
| 759 | /**  | 
            ||
| 760 | * Determine whether a query writes to the DB.  | 
            ||
| 761 | * Should return true if unsure.  | 
            ||
| 762 | *  | 
            ||
| 763 | * @param string $sql  | 
            ||
| 764 | * @return bool  | 
            ||
| 765 | */  | 
            ||
| 766 | 	protected function isWriteQuery( $sql ) { | 
            ||
| 770 | |||
| 771 | /**  | 
            ||
| 772 | * @param $sql  | 
            ||
| 773 | * @return string|null  | 
            ||
| 774 | */  | 
            ||
| 775 | 	protected function getQueryVerb( $sql ) { | 
            ||
| 778 | |||
| 779 | /**  | 
            ||
| 780 | * Determine whether a SQL statement is sensitive to isolation level.  | 
            ||
| 781 | * A SQL statement is considered transactable if its result could vary  | 
            ||
| 782 | * depending on the transaction isolation level. Operational commands  | 
            ||
| 783 | * such as 'SET' and 'SHOW' are not considered to be transactable.  | 
            ||
| 784 | *  | 
            ||
| 785 | * @param string $sql  | 
            ||
| 786 | * @return bool  | 
            ||
| 787 | */  | 
            ||
| 788 | 	protected function isTransactableQuery( $sql ) { | 
            ||
| 792 | |||
| 793 | 	public function query( $sql, $fname = __METHOD__, $tempIgnore = false ) { | 
            ||
| 883 | |||
| 884 | 	private function doProfiledQuery( $sql, $commentedSql, $isWrite, $fname ) { | 
            ||
| 932 | |||
| 933 | /**  | 
            ||
| 934 | * Update the estimated run-time of a query, not counting large row lock times  | 
            ||
| 935 | *  | 
            ||
| 936 | * LoadBalancer can be set to rollback transactions that will create huge replication  | 
            ||
| 937 | * lag. It bases this estimate off of pendingWriteQueryDuration(). Certain simple  | 
            ||
| 938 | * queries, like inserting a row can take a long time due to row locking. This method  | 
            ||
| 939 | * uses some simple heuristics to discount those cases.  | 
            ||
| 940 | *  | 
            ||
| 941 | * @param string $sql A SQL write query  | 
            ||
| 942 | * @param float $runtime Total runtime, including RTT  | 
            ||
| 943 | */  | 
            ||
| 944 | 	private function updateTrxWriteQueryTime( $sql, $runtime ) { | 
            ||
| 964 | |||
| 965 | 	private function canRecoverFromDisconnect( $sql, $priorWritesPending ) { | 
            ||
| 984 | |||
| 985 | 	private function handleTransactionLoss() { | 
            ||
| 999 | |||
| 1000 | 	public function reportQueryError( $error, $errno, $sql, $fname, $tempIgnore = false ) { | 
            ||
| 1019 | |||
| 1020 | 	public function freeResult( $res ) { | 
            ||
| 1022 | |||
| 1023 | public function selectField(  | 
            ||
| 1049 | |||
| 1050 | public function selectFieldValues(  | 
            ||
| 1075 | |||
| 1076 | /**  | 
            ||
| 1077 | * Returns an optional USE INDEX clause to go after the table, and a  | 
            ||
| 1078 | * string to go at the end of the query.  | 
            ||
| 1079 | *  | 
            ||
| 1080 | * @param array $options Associative array of options to be turned into  | 
            ||
| 1081 | * an SQL query, valid keys are listed in the function.  | 
            ||
| 1082 | * @return array  | 
            ||
| 1083 | * @see DatabaseBase::select()  | 
            ||
| 1084 | */  | 
            ||
| 1085 | 	public function makeSelectOptions( $options ) { | 
            ||
| 1165 | |||
| 1166 | /**  | 
            ||
| 1167 | * Returns an optional GROUP BY with an optional HAVING  | 
            ||
| 1168 | *  | 
            ||
| 1169 | * @param array $options Associative array of options  | 
            ||
| 1170 | * @return string  | 
            ||
| 1171 | * @see DatabaseBase::select()  | 
            ||
| 1172 | * @since 1.21  | 
            ||
| 1173 | */  | 
            ||
| 1174 | 	public function makeGroupByWithHaving( $options ) { | 
            ||
| 1191 | |||
| 1192 | /**  | 
            ||
| 1193 | * Returns an optional ORDER BY  | 
            ||
| 1194 | *  | 
            ||
| 1195 | * @param array $options Associative array of options  | 
            ||
| 1196 | * @return string  | 
            ||
| 1197 | * @see DatabaseBase::select()  | 
            ||
| 1198 | * @since 1.21  | 
            ||
| 1199 | */  | 
            ||
| 1200 | 	public function makeOrderBy( $options ) { | 
            ||
| 1211 | |||
| 1212 | // See IDatabase::select for the docs for this function  | 
            ||
| 1213 | public function select( $table, $vars, $conds = '', $fname = __METHOD__,  | 
            ||
| 1219 | |||
| 1220 | public function selectSQLText( $table, $vars, $conds = '', $fname = __METHOD__,  | 
            ||
| 1273 | |||
| 1274 | public function selectRow( $table, $vars, $conds, $fname = __METHOD__,  | 
            ||
| 1293 | |||
| 1294 | public function estimateRowCount(  | 
            ||
| 1307 | |||
| 1308 | public function selectRowCount(  | 
            ||
| 1322 | |||
| 1323 | /**  | 
            ||
| 1324 | * Removes most variables from an SQL query and replaces them with X or N for numbers.  | 
            ||
| 1325 | * It's only slightly flawed. Don't use for anything important.  | 
            ||
| 1326 | *  | 
            ||
| 1327 | * @param string $sql A SQL Query  | 
            ||
| 1328 | *  | 
            ||
| 1329 | * @return string  | 
            ||
| 1330 | */  | 
            ||
| 1331 | 	protected static function generalizeSQL( $sql ) { | 
            ||
| 1352 | |||
| 1353 | 	public function fieldExists( $table, $field, $fname = __METHOD__ ) { | 
            ||
| 1358 | |||
| 1359 | 	public function indexExists( $table, $index, $fname = __METHOD__ ) { | 
            ||
| 1371 | |||
| 1372 | 	public function tableExists( $table, $fname = __METHOD__ ) { | 
            ||
| 1380 | |||
| 1381 | 	public function indexUnique( $table, $index ) { | 
            ||
| 1390 | |||
| 1391 | /**  | 
            ||
| 1392 | * Helper for DatabaseBase::insert().  | 
            ||
| 1393 | *  | 
            ||
| 1394 | * @param array $options  | 
            ||
| 1395 | * @return string  | 
            ||
| 1396 | */  | 
            ||
| 1397 | 	protected function makeInsertOptions( $options ) { | 
            ||
| 1400 | |||
| 1401 | 	public function insert( $table, $a, $fname = __METHOD__, $options = [] ) { | 
            ||
| 1452 | |||
| 1453 | /**  | 
            ||
| 1454 | * Make UPDATE options array for DatabaseBase::makeUpdateOptions  | 
            ||
| 1455 | *  | 
            ||
| 1456 | * @param array $options  | 
            ||
| 1457 | * @return array  | 
            ||
| 1458 | */  | 
            ||
| 1459 | 	protected function makeUpdateOptionsArray( $options ) { | 
            ||
| 1472 | |||
| 1473 | /**  | 
            ||
| 1474 | * Make UPDATE options for the DatabaseBase::update function  | 
            ||
| 1475 | *  | 
            ||
| 1476 | * @param array $options The options passed to DatabaseBase::update  | 
            ||
| 1477 | * @return string  | 
            ||
| 1478 | */  | 
            ||
| 1479 | 	protected function makeUpdateOptions( $options ) { | 
            ||
| 1484 | |||
| 1485 | 	function update( $table, $values, $conds, $fname = __METHOD__, $options = [] ) { | 
            ||
| 1496 | |||
| 1497 | 	public function makeList( $a, $mode = self::LIST_COMMA ) { | 
            ||
| 1576 | |||
| 1577 | 	public function makeWhereFrom2d( $data, $baseKey, $subKey ) { | 
            ||
| 1595 | |||
| 1596 | /**  | 
            ||
| 1597 | * Return aggregated value alias  | 
            ||
| 1598 | *  | 
            ||
| 1599 | * @param array $valuedata  | 
            ||
| 1600 | * @param string $valuename  | 
            ||
| 1601 | *  | 
            ||
| 1602 | * @return string  | 
            ||
| 1603 | */  | 
            ||
| 1604 | 	public function aggregateValue( $valuedata, $valuename = 'value' ) { | 
            ||
| 1607 | |||
| 1608 | 	public function bitNot( $field ) { | 
            ||
| 1611 | |||
| 1612 | 	public function bitAnd( $fieldLeft, $fieldRight ) { | 
            ||
| 1615 | |||
| 1616 | 	public function bitOr( $fieldLeft, $fieldRight ) { | 
            ||
| 1619 | |||
| 1620 | 	public function buildConcat( $stringList ) { | 
            ||
| 1623 | |||
| 1624 | View Code Duplication | public function buildGroupConcatField(  | 
            |
| 1631 | |||
| 1632 | /**  | 
            ||
| 1633 | * @param string $field Field or column to cast  | 
            ||
| 1634 | * @return string  | 
            ||
| 1635 | * @since 1.28  | 
            ||
| 1636 | */  | 
            ||
| 1637 | 	public function buildStringCast( $field ) { | 
            ||
| 1640 | |||
| 1641 | 	public function selectDB( $db ) { | 
            ||
| 1649 | |||
| 1650 | 	public function getDBname() { | 
            ||
| 1653 | |||
| 1654 | 	public function getServer() { | 
            ||
| 1655 | return $this->mServer;  | 
            ||
| 1656 | }  | 
            ||
| 1657 | |||
| 1658 | /**  | 
            ||
| 1659 | * Format a table name ready for use in constructing an SQL query  | 
            ||
| 1660 | *  | 
            ||
| 1661 | * This does two important things: it quotes the table names to clean them up,  | 
            ||
| 1662 | * and it adds a table prefix if only given a table name with no quotes.  | 
            ||
| 1663 | *  | 
            ||
| 1664 | * All functions of this object which require a table name call this function  | 
            ||
| 1665 | * themselves. Pass the canonical name to such functions. This is only needed  | 
            ||
| 1666 | * when calling query() directly.  | 
            ||
| 1667 | *  | 
            ||
| 1668 | * @note This function does not sanitize user input. It is not safe to use  | 
            ||
| 1669 | * this function to escape user input.  | 
            ||
| 1670 | * @param string $name Database table name  | 
            ||
| 1671 | * @param string $format One of:  | 
            ||
| 1672 | * quoted - Automatically pass the table name through addIdentifierQuotes()  | 
            ||
| 1673 | * so that it can be used in a query.  | 
            ||
| 1674 | * raw - Do not add identifier quotes to the table name  | 
            ||
| 1675 | * @return string Full database name  | 
            ||
| 1676 | */  | 
            ||
| 1677 | 	public function tableName( $name, $format = 'quoted' ) { | 
            ||
| 1756 | |||
| 1757 | /**  | 
            ||
| 1758 | * Fetch a number of table names into an array  | 
            ||
| 1759 | * This is handy when you need to construct SQL for joins  | 
            ||
| 1760 | *  | 
            ||
| 1761 | * Example:  | 
            ||
| 1762 | * extract( $dbr->tableNames( 'user', 'watchlist' ) );  | 
            ||
| 1763 | * $sql = "SELECT wl_namespace,wl_title FROM $watchlist,$user  | 
            ||
| 1764 | * WHERE wl_user=user_id AND wl_user=$nameWithQuotes";  | 
            ||
| 1765 | *  | 
            ||
| 1766 | * @return array  | 
            ||
| 1767 | */  | 
            ||
| 1768 | View Code Duplication | 	public function tableNames() { | 
            |
| 1778 | |||
| 1779 | /**  | 
            ||
| 1780 | * Fetch a number of table names into an zero-indexed numerical array  | 
            ||
| 1781 | * This is handy when you need to construct SQL for joins  | 
            ||
| 1782 | *  | 
            ||
| 1783 | * Example:  | 
            ||
| 1784 | * list( $user, $watchlist ) = $dbr->tableNamesN( 'user', 'watchlist' );  | 
            ||
| 1785 | * $sql = "SELECT wl_namespace,wl_title FROM $watchlist,$user  | 
            ||
| 1786 | * WHERE wl_user=user_id AND wl_user=$nameWithQuotes";  | 
            ||
| 1787 | *  | 
            ||
| 1788 | * @return array  | 
            ||
| 1789 | */  | 
            ||
| 1790 | View Code Duplication | 	public function tableNamesN() { | 
            |
| 1800 | |||
| 1801 | /**  | 
            ||
| 1802 | * Get an aliased table name  | 
            ||
| 1803 | * e.g. tableName AS newTableName  | 
            ||
| 1804 | *  | 
            ||
| 1805 | * @param string $name Table name, see tableName()  | 
            ||
| 1806 | * @param string|bool $alias Alias (optional)  | 
            ||
| 1807 | * @return string SQL name for aliased table. Will not alias a table to its own name  | 
            ||
| 1808 | */  | 
            ||
| 1809 | 	public function tableNameWithAlias( $name, $alias = false ) { | 
            ||
| 1816 | |||
| 1817 | /**  | 
            ||
| 1818 | * Gets an array of aliased table names  | 
            ||
| 1819 | *  | 
            ||
| 1820 | * @param array $tables [ [alias] => table ]  | 
            ||
| 1821 | * @return string[] See tableNameWithAlias()  | 
            ||
| 1822 | */  | 
            ||
| 1823 | 	public function tableNamesWithAlias( $tables ) { | 
            ||
| 1834 | |||
| 1835 | /**  | 
            ||
| 1836 | * Get an aliased field name  | 
            ||
| 1837 | * e.g. fieldName AS newFieldName  | 
            ||
| 1838 | *  | 
            ||
| 1839 | * @param string $name Field name  | 
            ||
| 1840 | * @param string|bool $alias Alias (optional)  | 
            ||
| 1841 | * @return string SQL name for aliased field. Will not alias a field to its own name  | 
            ||
| 1842 | */  | 
            ||
| 1843 | 	public function fieldNameWithAlias( $name, $alias = false ) { | 
            ||
| 1850 | |||
| 1851 | /**  | 
            ||
| 1852 | * Gets an array of aliased field names  | 
            ||
| 1853 | *  | 
            ||
| 1854 | * @param array $fields [ [alias] => field ]  | 
            ||
| 1855 | * @return string[] See fieldNameWithAlias()  | 
            ||
| 1856 | */  | 
            ||
| 1857 | 	public function fieldNamesWithAlias( $fields ) { | 
            ||
| 1868 | |||
| 1869 | /**  | 
            ||
| 1870 | * Get the aliased table name clause for a FROM clause  | 
            ||
| 1871 | * which might have a JOIN and/or USE INDEX or IGNORE INDEX clause  | 
            ||
| 1872 | *  | 
            ||
| 1873 | * @param array $tables ( [alias] => table )  | 
            ||
| 1874 | * @param array $use_index Same as for select()  | 
            ||
| 1875 | * @param array $ignore_index Same as for select()  | 
            ||
| 1876 | * @param array $join_conds Same as for select()  | 
            ||
| 1877 | * @return string  | 
            ||
| 1878 | */  | 
            ||
| 1879 | protected function tableNamesWithIndexClauseOrJOIN(  | 
            ||
| 1946 | |||
| 1947 | /**  | 
            ||
| 1948 | * Get the name of an index in a given table.  | 
            ||
| 1949 | *  | 
            ||
| 1950 | * @param string $index  | 
            ||
| 1951 | * @return string  | 
            ||
| 1952 | */  | 
            ||
| 1953 | 	protected function indexName( $index ) { | 
            ||
| 1967 | |||
| 1968 | 	public function addQuotes( $s ) { | 
            ||
| 1982 | |||
| 1983 | /**  | 
            ||
| 1984 | * Quotes an identifier using `backticks` or "double quotes" depending on the database type.  | 
            ||
| 1985 | * MySQL uses `backticks` while basically everything else uses double quotes.  | 
            ||
| 1986 | * Since MySQL is the odd one out here the double quotes are our generic  | 
            ||
| 1987 | * and we implement backticks in DatabaseMysql.  | 
            ||
| 1988 | *  | 
            ||
| 1989 | * @param string $s  | 
            ||
| 1990 | * @return string  | 
            ||
| 1991 | */  | 
            ||
| 1992 | 	public function addIdentifierQuotes( $s ) { | 
            ||
| 1995 | |||
| 1996 | /**  | 
            ||
| 1997 | * Returns if the given identifier looks quoted or not according to  | 
            ||
| 1998 | * the database convention for quoting identifiers .  | 
            ||
| 1999 | *  | 
            ||
| 2000 | * @note Do not use this to determine if untrusted input is safe.  | 
            ||
| 2001 | * A malicious user can trick this function.  | 
            ||
| 2002 | * @param string $name  | 
            ||
| 2003 | * @return bool  | 
            ||
| 2004 | */  | 
            ||
| 2005 | 	public function isQuotedIdentifier( $name ) { | 
            ||
| 2008 | |||
| 2009 | /**  | 
            ||
| 2010 | * @param string $s  | 
            ||
| 2011 | * @return string  | 
            ||
| 2012 | */  | 
            ||
| 2013 | 	protected function escapeLikeInternal( $s ) { | 
            ||
| 2016 | |||
| 2017 | 	public function buildLike() { | 
            ||
| 2036 | |||
| 2037 | 	public function anyChar() { | 
            ||
| 2040 | |||
| 2041 | 	public function anyString() { | 
            ||
| 2044 | |||
| 2045 | 	public function nextSequenceValue( $seqName ) { | 
            ||
| 2048 | |||
| 2049 | /**  | 
            ||
| 2050 | * USE INDEX clause. Unlikely to be useful for anything but MySQL. This  | 
            ||
| 2051 | * is only needed because a) MySQL must be as efficient as possible due to  | 
            ||
| 2052 | * its use on Wikipedia, and b) MySQL 4.0 is kind of dumb sometimes about  | 
            ||
| 2053 | * which index to pick. Anyway, other databases might have different  | 
            ||
| 2054 | * indexes on a given table. So don't bother overriding this unless you're  | 
            ||
| 2055 | * MySQL.  | 
            ||
| 2056 | * @param string $index  | 
            ||
| 2057 | * @return string  | 
            ||
| 2058 | */  | 
            ||
| 2059 | 	public function useIndexClause( $index ) { | 
            ||
| 2062 | |||
| 2063 | /**  | 
            ||
| 2064 | * IGNORE INDEX clause. Unlikely to be useful for anything but MySQL. This  | 
            ||
| 2065 | * is only needed because a) MySQL must be as efficient as possible due to  | 
            ||
| 2066 | * its use on Wikipedia, and b) MySQL 4.0 is kind of dumb sometimes about  | 
            ||
| 2067 | * which index to pick. Anyway, other databases might have different  | 
            ||
| 2068 | * indexes on a given table. So don't bother overriding this unless you're  | 
            ||
| 2069 | * MySQL.  | 
            ||
| 2070 | * @param string $index  | 
            ||
| 2071 | * @return string  | 
            ||
| 2072 | */  | 
            ||
| 2073 | 	public function ignoreIndexClause( $index ) { | 
            ||
| 2076 | |||
| 2077 | 	public function replace( $table, $uniqueIndexes, $rows, $fname = __METHOD__ ) { | 
            ||
| 2124 | |||
| 2125 | /**  | 
            ||
| 2126 | * REPLACE query wrapper for MySQL and SQLite, which have a native REPLACE  | 
            ||
| 2127 | * statement.  | 
            ||
| 2128 | *  | 
            ||
| 2129 | * @param string $table Table name  | 
            ||
| 2130 | * @param array|string $rows Row(s) to insert  | 
            ||
| 2131 | * @param string $fname Caller function name  | 
            ||
| 2132 | *  | 
            ||
| 2133 | * @return ResultWrapper  | 
            ||
| 2134 | */  | 
            ||
| 2135 | 	protected function nativeReplace( $table, $rows, $fname ) { | 
            ||
| 2158 | |||
| 2159 | public function upsert( $table, array $rows, array $uniqueIndexes, array $set,  | 
            ||
| 2212 | |||
| 2213 | View Code Duplication | public function deleteJoin( $delTable, $joinTable, $delVar, $joinVar, $conds,  | 
            |
| 2230 | |||
| 2231 | /**  | 
            ||
| 2232 | * Returns the size of a text field, or -1 for "unlimited"  | 
            ||
| 2233 | *  | 
            ||
| 2234 | * @param string $table  | 
            ||
| 2235 | * @param string $field  | 
            ||
| 2236 | * @return int  | 
            ||
| 2237 | */  | 
            ||
| 2238 | 	public function textFieldSize( $table, $field ) { | 
            ||
| 2254 | |||
| 2255 | 	public function delete( $table, $conds, $fname = __METHOD__ ) { | 
            ||
| 2272 | |||
| 2273 | public function insertSelect(  | 
            ||
| 2311 | |||
| 2312 | public function nativeInsertSelect( $destTable, $srcTable, $varMap, $conds,  | 
            ||
| 2352 | |||
| 2353 | /**  | 
            ||
| 2354 | * Construct a LIMIT query with optional offset. This is used for query  | 
            ||
| 2355 | * pages. The SQL should be adjusted so that only the first $limit rows  | 
            ||
| 2356 | * are returned. If $offset is provided as well, then the first $offset  | 
            ||
| 2357 | * rows should be discarded, and the next $limit rows should be returned.  | 
            ||
| 2358 | * If the result of the query is not ordered, then the rows to be returned  | 
            ||
| 2359 | * are theoretically arbitrary.  | 
            ||
| 2360 | *  | 
            ||
| 2361 | * $sql is expected to be a SELECT, if that makes a difference.  | 
            ||
| 2362 | *  | 
            ||
| 2363 | * The version provided by default works in MySQL and SQLite. It will very  | 
            ||
| 2364 | * likely need to be overridden for most other DBMSes.  | 
            ||
| 2365 | *  | 
            ||
| 2366 | * @param string $sql SQL query we will append the limit too  | 
            ||
| 2367 | * @param int $limit The SQL limit  | 
            ||
| 2368 | * @param int|bool $offset The SQL offset (default false)  | 
            ||
| 2369 | * @throws DBUnexpectedError  | 
            ||
| 2370 | * @return string  | 
            ||
| 2371 | */  | 
            ||
| 2372 | 	public function limitResult( $sql, $limit, $offset = false ) { | 
            ||
| 2381 | |||
| 2382 | 	public function unionSupportsOrderAndLimit() { | 
            ||
| 2385 | |||
| 2386 | 	public function unionQueries( $sqls, $all ) { | 
            ||
| 2391 | |||
| 2392 | 	public function conditional( $cond, $trueVal, $falseVal ) { | 
            ||
| 2399 | |||
| 2400 | 	public function strreplace( $orig, $old, $new ) { | 
            ||
| 2403 | |||
| 2404 | 	public function getServerUptime() { | 
            ||
| 2407 | |||
| 2408 | 	public function wasDeadlock() { | 
            ||
| 2411 | |||
| 2412 | 	public function wasLockTimeout() { | 
            ||
| 2415 | |||
| 2416 | 	public function wasErrorReissuable() { | 
            ||
| 2419 | |||
| 2420 | 	public function wasReadOnlyError() { | 
            ||
| 2423 | |||
| 2424 | /**  | 
            ||
| 2425 | * Determines if the given query error was a connection drop  | 
            ||
| 2426 | * STUB  | 
            ||
| 2427 | *  | 
            ||
| 2428 | * @param integer|string $errno  | 
            ||
| 2429 | * @return bool  | 
            ||
| 2430 | */  | 
            ||
| 2431 | 	public function wasConnectionError( $errno ) { | 
            ||
| 2434 | |||
| 2435 | /**  | 
            ||
| 2436 | * Perform a deadlock-prone transaction.  | 
            ||
| 2437 | *  | 
            ||
| 2438 | * This function invokes a callback function to perform a set of write  | 
            ||
| 2439 | * queries. If a deadlock occurs during the processing, the transaction  | 
            ||
| 2440 | * will be rolled back and the callback function will be called again.  | 
            ||
| 2441 | *  | 
            ||
| 2442 | * Avoid using this method outside of Job or Maintenance classes.  | 
            ||
| 2443 | *  | 
            ||
| 2444 | * Usage:  | 
            ||
| 2445 | * $dbw->deadlockLoop( callback, ... );  | 
            ||
| 2446 | *  | 
            ||
| 2447 | * Extra arguments are passed through to the specified callback function.  | 
            ||
| 2448 | * This method requires that no transactions are already active to avoid  | 
            ||
| 2449 | * causing premature commits or exceptions.  | 
            ||
| 2450 | *  | 
            ||
| 2451 | * Returns whatever the callback function returned on its successful,  | 
            ||
| 2452 | * iteration, or false on error, for example if the retry limit was  | 
            ||
| 2453 | * reached.  | 
            ||
| 2454 | *  | 
            ||
| 2455 | * @return mixed  | 
            ||
| 2456 | * @throws DBUnexpectedError  | 
            ||
| 2457 | * @throws Exception  | 
            ||
| 2458 | */  | 
            ||
| 2459 | 	public function deadlockLoop() { | 
            ||
| 2494 | |||
| 2495 | 	public function masterPosWait( DBMasterPos $pos, $timeout ) { | 
            ||
| 2499 | |||
| 2500 | 	public function getSlavePos() { | 
            ||
| 2504 | |||
| 2505 | 	public function getMasterPos() { | 
            ||
| 2509 | |||
| 2510 | 	public function serverIsReadOnly() { | 
            ||
| 2513 | |||
| 2514 | 	final public function onTransactionResolution( callable $callback, $fname = __METHOD__ ) { | 
            ||
| 2520 | |||
| 2521 | 	final public function onTransactionIdle( callable $callback, $fname = __METHOD__ ) { | 
            ||
| 2527 | |||
| 2528 | 	final public function onTransactionPreCommitOrIdle( callable $callback, $fname = __METHOD__ ) { | 
            ||
| 2543 | |||
| 2544 | 	final public function setTransactionListener( $name, callable $callback = null ) { | 
            ||
| 2551 | |||
| 2552 | /**  | 
            ||
| 2553 | * Whether to disable running of post-COMMIT/ROLLBACK callbacks  | 
            ||
| 2554 | *  | 
            ||
| 2555 | * This method should not be used outside of Database/LoadBalancer  | 
            ||
| 2556 | *  | 
            ||
| 2557 | * @param bool $suppress  | 
            ||
| 2558 | * @since 1.28  | 
            ||
| 2559 | */  | 
            ||
| 2560 | 	final public function setTrxEndCallbackSuppression( $suppress ) { | 
            ||
| 2563 | |||
| 2564 | /**  | 
            ||
| 2565 | * Actually run and consume any "on transaction idle/resolution" callbacks.  | 
            ||
| 2566 | *  | 
            ||
| 2567 | * This method should not be used outside of Database/LoadBalancer  | 
            ||
| 2568 | *  | 
            ||
| 2569 | * @param integer $trigger IDatabase::TRIGGER_* constant  | 
            ||
| 2570 | * @since 1.20  | 
            ||
| 2571 | * @throws Exception  | 
            ||
| 2572 | */  | 
            ||
| 2573 | 	public function runOnTransactionIdleCallbacks( $trigger ) { | 
            ||
| 2614 | |||
| 2615 | /**  | 
            ||
| 2616 | * Actually run and consume any "on transaction pre-commit" callbacks.  | 
            ||
| 2617 | *  | 
            ||
| 2618 | * This method should not be used outside of Database/LoadBalancer  | 
            ||
| 2619 | *  | 
            ||
| 2620 | * @since 1.22  | 
            ||
| 2621 | * @throws Exception  | 
            ||
| 2622 | */  | 
            ||
| 2623 | 	public function runOnTransactionPreCommitCallbacks() { | 
            ||
| 2643 | |||
| 2644 | /**  | 
            ||
| 2645 | * Actually run any "transaction listener" callbacks.  | 
            ||
| 2646 | *  | 
            ||
| 2647 | * This method should not be used outside of Database/LoadBalancer  | 
            ||
| 2648 | *  | 
            ||
| 2649 | * @param integer $trigger IDatabase::TRIGGER_* constant  | 
            ||
| 2650 | * @throws Exception  | 
            ||
| 2651 | * @since 1.20  | 
            ||
| 2652 | */  | 
            ||
| 2653 | 	public function runTransactionListenerCallbacks( $trigger ) { | 
            ||
| 2674 | |||
| 2675 | 	final public function startAtomic( $fname = __METHOD__ ) { | 
            ||
| 2687 | |||
| 2688 | 	final public function endAtomic( $fname = __METHOD__ ) { | 
            ||
| 2702 | |||
| 2703 | 	final public function doAtomicSection( $fname, callable $callback ) { | 
            ||
| 2715 | |||
| 2716 | 	final public function begin( $fname = __METHOD__, $mode = self::TRANSACTION_EXPLICIT ) { | 
            ||
| 2761 | |||
| 2762 | /**  | 
            ||
| 2763 | * Issues the BEGIN command to the database server.  | 
            ||
| 2764 | *  | 
            ||
| 2765 | * @see DatabaseBase::begin()  | 
            ||
| 2766 | * @param string $fname  | 
            ||
| 2767 | */  | 
            ||
| 2768 | 	protected function doBegin( $fname ) { | 
            ||
| 2772 | |||
| 2773 | 	final public function commit( $fname = __METHOD__, $flush = '' ) { | 
            ||
| 2819 | |||
| 2820 | /**  | 
            ||
| 2821 | * Issues the COMMIT command to the database server.  | 
            ||
| 2822 | *  | 
            ||
| 2823 | * @see DatabaseBase::commit()  | 
            ||
| 2824 | * @param string $fname  | 
            ||
| 2825 | */  | 
            ||
| 2826 | 	protected function doCommit( $fname ) { | 
            ||
| 2832 | |||
| 2833 | 	final public function rollback( $fname = __METHOD__, $flush = '' ) { | 
            ||
| 2866 | |||
| 2867 | /**  | 
            ||
| 2868 | * Issues the ROLLBACK command to the database server.  | 
            ||
| 2869 | *  | 
            ||
| 2870 | * @see DatabaseBase::rollback()  | 
            ||
| 2871 | * @param string $fname  | 
            ||
| 2872 | */  | 
            ||
| 2873 | 	protected function doRollback( $fname ) { | 
            ||
| 2881 | |||
| 2882 | 	public function flushSnapshot( $fname = __METHOD__ ) { | 
            ||
| 2894 | |||
| 2895 | 	public function explicitTrxActive() { | 
            ||
| 2898 | |||
| 2899 | /**  | 
            ||
| 2900 | * Creates a new table with structure copied from existing table  | 
            ||
| 2901 | * Note that unlike most database abstraction functions, this function does not  | 
            ||
| 2902 | * automatically append database prefix, because it works at a lower  | 
            ||
| 2903 | * abstraction level.  | 
            ||
| 2904 | * The table names passed to this function shall not be quoted (this  | 
            ||
| 2905 | * function calls addIdentifierQuotes when needed).  | 
            ||
| 2906 | *  | 
            ||
| 2907 | * @param string $oldName Name of table whose structure should be copied  | 
            ||
| 2908 | * @param string $newName Name of table to be created  | 
            ||
| 2909 | * @param bool $temporary Whether the new table should be temporary  | 
            ||
| 2910 | * @param string $fname Calling function name  | 
            ||
| 2911 | * @throws RuntimeException  | 
            ||
| 2912 | * @return bool True if operation was successful  | 
            ||
| 2913 | */  | 
            ||
| 2914 | public function duplicateTableStructure( $oldName, $newName, $temporary = false,  | 
            ||
| 2919 | |||
| 2920 | 	function listTables( $prefix = null, $fname = __METHOD__ ) { | 
            ||
| 2923 | |||
| 2924 | /**  | 
            ||
| 2925 | * Reset the views process cache set by listViews()  | 
            ||
| 2926 | * @since 1.22  | 
            ||
| 2927 | */  | 
            ||
| 2928 | 	final public function clearViewsCache() { | 
            ||
| 2931 | |||
| 2932 | /**  | 
            ||
| 2933 | * Lists all the VIEWs in the database  | 
            ||
| 2934 | *  | 
            ||
| 2935 | * For caching purposes the list of all views should be stored in  | 
            ||
| 2936 | * $this->allViews. The process cache can be cleared with clearViewsCache()  | 
            ||
| 2937 | *  | 
            ||
| 2938 | * @param string $prefix Only show VIEWs with this prefix, eg. unit_test_  | 
            ||
| 2939 | * @param string $fname Name of calling function  | 
            ||
| 2940 | * @throws RuntimeException  | 
            ||
| 2941 | * @return array  | 
            ||
| 2942 | * @since 1.22  | 
            ||
| 2943 | */  | 
            ||
| 2944 | 	public function listViews( $prefix = null, $fname = __METHOD__ ) { | 
            ||
| 2947 | |||
| 2948 | /**  | 
            ||
| 2949 | * Differentiates between a TABLE and a VIEW  | 
            ||
| 2950 | *  | 
            ||
| 2951 | * @param string $name Name of the database-structure to test.  | 
            ||
| 2952 | * @throws RuntimeException  | 
            ||
| 2953 | * @return bool  | 
            ||
| 2954 | * @since 1.22  | 
            ||
| 2955 | */  | 
            ||
| 2956 | 	public function isView( $name ) { | 
            ||
| 2959 | |||
| 2960 | 	public function timestamp( $ts = 0 ) { | 
            ||
| 2965 | |||
| 2966 | 	public function timestampOrNull( $ts = null ) { | 
            ||
| 2973 | |||
| 2974 | /**  | 
            ||
| 2975 | * Take the result from a query, and wrap it in a ResultWrapper if  | 
            ||
| 2976 | * necessary. Boolean values are passed through as is, to indicate success  | 
            ||
| 2977 | * of write queries or failure.  | 
            ||
| 2978 | *  | 
            ||
| 2979 | * Once upon a time, DatabaseBase::query() returned a bare MySQL result  | 
            ||
| 2980 | * resource, and it was necessary to call this function to convert it to  | 
            ||
| 2981 | * a wrapper. Nowadays, raw database objects are never exposed to external  | 
            ||
| 2982 | * callers, so this is unnecessary in external code.  | 
            ||
| 2983 | *  | 
            ||
| 2984 | * @param bool|ResultWrapper|resource|object $result  | 
            ||
| 2985 | * @return bool|ResultWrapper  | 
            ||
| 2986 | */  | 
            ||
| 2987 | 	protected function resultObject( $result ) { | 
            ||
| 2999 | |||
| 3000 | 	public function ping( &$rtt = null ) { | 
            ||
| 3020 | |||
| 3021 | /**  | 
            ||
| 3022 | * @return bool  | 
            ||
| 3023 | */  | 
            ||
| 3024 | 	protected function reconnect() { | 
            ||
| 3038 | |||
| 3039 | 	public function getSessionLagStatus() { | 
            ||
| 3042 | |||
| 3043 | /**  | 
            ||
| 3044 | * Get the replica DB lag when the current transaction started  | 
            ||
| 3045 | *  | 
            ||
| 3046 | * This is useful when transactions might use snapshot isolation  | 
            ||
| 3047 | * (e.g. REPEATABLE-READ in innodb), so the "real" lag of that data  | 
            ||
| 3048 | * is this lag plus transaction duration. If they don't, it is still  | 
            ||
| 3049 | * safe to be pessimistic. This returns null if there is no transaction.  | 
            ||
| 3050 | *  | 
            ||
| 3051 | 	 * @return array|null ('lag': seconds or false on error, 'since': UNIX timestamp of BEGIN) | 
            ||
| 3052 | * @since 1.27  | 
            ||
| 3053 | */  | 
            ||
| 3054 | 	public function getTransactionLagStatus() { | 
            ||
| 3059 | |||
| 3060 | /**  | 
            ||
| 3061 | * Get a replica DB lag estimate for this server  | 
            ||
| 3062 | *  | 
            ||
| 3063 | 	 * @return array ('lag': seconds or false on error, 'since': UNIX timestamp of estimate) | 
            ||
| 3064 | * @since 1.27  | 
            ||
| 3065 | */  | 
            ||
| 3066 | 	public function getApproximateLagStatus() { | 
            ||
| 3072 | |||
| 3073 | /**  | 
            ||
| 3074 | * Merge the result of getSessionLagStatus() for several DBs  | 
            ||
| 3075 | * using the most pessimistic values to estimate the lag of  | 
            ||
| 3076 | * any data derived from them in combination  | 
            ||
| 3077 | *  | 
            ||
| 3078 | * This is information is useful for caching modules  | 
            ||
| 3079 | *  | 
            ||
| 3080 | * @see WANObjectCache::set()  | 
            ||
| 3081 | * @see WANObjectCache::getWithSetCallback()  | 
            ||
| 3082 | *  | 
            ||
| 3083 | * @param IDatabase $db1  | 
            ||
| 3084 | * @param IDatabase ...  | 
            ||
| 3085 | * @return array Map of values:  | 
            ||
| 3086 | * - lag: highest lag of any of the DBs or false on error (e.g. replication stopped)  | 
            ||
| 3087 | * - since: oldest UNIX timestamp of any of the DB lag estimates  | 
            ||
| 3088 | * - pending: whether any of the DBs have uncommitted changes  | 
            ||
| 3089 | * @since 1.27  | 
            ||
| 3090 | */  | 
            ||
| 3091 | 	public static function getCacheSetOptions( IDatabase $db1 ) { | 
            ||
| 3107 | |||
| 3108 | 	public function getLag() { | 
            ||
| 3111 | |||
| 3112 | 	function maxListLen() { | 
            ||
| 3115 | |||
| 3116 | 	public function encodeBlob( $b ) { | 
            ||
| 3119 | |||
| 3120 | 	public function decodeBlob( $b ) { | 
            ||
| 3126 | |||
| 3127 | 	public function setSessionOptions( array $options ) { | 
            ||
| 3129 | |||
| 3130 | /**  | 
            ||
| 3131 | * Read and execute SQL commands from a file.  | 
            ||
| 3132 | *  | 
            ||
| 3133 | * Returns true on success, error string or exception on failure (depending  | 
            ||
| 3134 | * on object's error ignore settings).  | 
            ||
| 3135 | *  | 
            ||
| 3136 | * @param string $filename File name to open  | 
            ||
| 3137 | * @param bool|callable $lineCallback Optional function called before reading each line  | 
            ||
| 3138 | * @param bool|callable $resultCallback Optional function called for each MySQL result  | 
            ||
| 3139 | * @param bool|string $fname Calling function name or false if name should be  | 
            ||
| 3140 | * generated dynamically using $filename  | 
            ||
| 3141 | * @param bool|callable $inputCallback Optional function called for each  | 
            ||
| 3142 | * complete line sent  | 
            ||
| 3143 | * @return bool|string  | 
            ||
| 3144 | * @throws Exception  | 
            ||
| 3145 | */  | 
            ||
| 3146 | public function sourceFile(  | 
            ||
| 3172 | |||
| 3173 | 	public function setSchemaVars( $vars ) { | 
            ||
| 3176 | |||
| 3177 | /**  | 
            ||
| 3178 | * Read and execute commands from an open file handle.  | 
            ||
| 3179 | *  | 
            ||
| 3180 | * Returns true on success, error string or exception on failure (depending  | 
            ||
| 3181 | * on object's error ignore settings).  | 
            ||
| 3182 | *  | 
            ||
| 3183 | * @param resource $fp File handle  | 
            ||
| 3184 | * @param bool|callable $lineCallback Optional function called before reading each query  | 
            ||
| 3185 | * @param bool|callable $resultCallback Optional function called for each MySQL result  | 
            ||
| 3186 | * @param string $fname Calling function name  | 
            ||
| 3187 | * @param bool|callable $inputCallback Optional function called for each complete query sent  | 
            ||
| 3188 | * @return bool|string  | 
            ||
| 3189 | */  | 
            ||
| 3190 | public function sourceStream( $fp, $lineCallback = false, $resultCallback = false,  | 
            ||
| 3240 | |||
| 3241 | /**  | 
            ||
| 3242 | * Called by sourceStream() to check if we've reached a statement end  | 
            ||
| 3243 | *  | 
            ||
| 3244 | * @param string $sql SQL assembled so far  | 
            ||
| 3245 | * @param string $newLine New line about to be added to $sql  | 
            ||
| 3246 | * @return bool Whether $newLine contains end of the statement  | 
            ||
| 3247 | */  | 
            ||
| 3248 | 	public function streamStatementEnd( &$sql, &$newLine ) { | 
            ||
| 3259 | |||
| 3260 | /**  | 
            ||
| 3261 | * Database independent variable replacement. Replaces a set of variables  | 
            ||
| 3262 | * in an SQL statement with their contents as given by $this->getSchemaVars().  | 
            ||
| 3263 | *  | 
            ||
| 3264 | 	 * Supports '{$var}' `{$var}` and / *$var* / (without the spaces) style variables. | 
            ||
| 3265 | *  | 
            ||
| 3266 | 	 * - '{$var}' should be used for text and is passed through the database's | 
            ||
| 3267 | * addQuotes method.  | 
            ||
| 3268 | 	 * - `{$var}` should be used for identifiers (e.g. table and database names). | 
            ||
| 3269 | * It is passed through the database's addIdentifierQuotes method which  | 
            ||
| 3270 | * can be overridden if the database uses something other than backticks.  | 
            ||
| 3271 | * - / *_* / or / *$wgDBprefix* / passes the name that follows through the  | 
            ||
| 3272 | * database's tableName method.  | 
            ||
| 3273 | * - / *i* / passes the name that follows through the database's indexName method.  | 
            ||
| 3274 | * - In all other cases, / *$var* / is left unencoded. Except for table options,  | 
            ||
| 3275 | * its use should be avoided. In 1.24 and older, string encoding was applied.  | 
            ||
| 3276 | *  | 
            ||
| 3277 | * @param string $ins SQL statement to replace variables in  | 
            ||
| 3278 | * @return string The new SQL statement with variables replaced  | 
            ||
| 3279 | */  | 
            ||
| 3280 | 	protected function replaceVars( $ins ) { | 
            ||
| 3311 | |||
| 3312 | /**  | 
            ||
| 3313 | * Get schema variables. If none have been set via setSchemaVars(), then  | 
            ||
| 3314 | * use some defaults from the current object.  | 
            ||
| 3315 | *  | 
            ||
| 3316 | * @return array  | 
            ||
| 3317 | */  | 
            ||
| 3318 | 	protected function getSchemaVars() { | 
            ||
| 3325 | |||
| 3326 | /**  | 
            ||
| 3327 | * Get schema variables to use if none have been set via setSchemaVars().  | 
            ||
| 3328 | *  | 
            ||
| 3329 | * Override this in derived classes to provide variables for tables.sql  | 
            ||
| 3330 | * and SQL patch files.  | 
            ||
| 3331 | *  | 
            ||
| 3332 | * @return array  | 
            ||
| 3333 | */  | 
            ||
| 3334 | 	protected function getDefaultSchemaVars() { | 
            ||
| 3337 | |||
| 3338 | 	public function lockIsFree( $lockName, $method ) { | 
            ||
| 3341 | |||
| 3342 | 	public function lock( $lockName, $method, $timeout = 5 ) { | 
            ||
| 3347 | |||
| 3348 | 	public function unlock( $lockName, $method ) { | 
            ||
| 3353 | |||
| 3354 | 	public function getScopedLockAndFlush( $lockKey, $fname, $timeout ) { | 
            ||
| 3388 | |||
| 3389 | 	public function namedLocksEnqueue() { | 
            ||
| 3392 | |||
| 3393 | /**  | 
            ||
| 3394 | * Lock specific tables  | 
            ||
| 3395 | *  | 
            ||
| 3396 | * @param array $read Array of tables to lock for read access  | 
            ||
| 3397 | * @param array $write Array of tables to lock for write access  | 
            ||
| 3398 | * @param string $method Name of caller  | 
            ||
| 3399 | * @param bool $lowPriority Whether to indicate writes to be LOW PRIORITY  | 
            ||
| 3400 | * @return bool  | 
            ||
| 3401 | */  | 
            ||
| 3402 | 	public function lockTables( $read, $write, $method, $lowPriority = true ) { | 
            ||
| 3405 | |||
| 3406 | /**  | 
            ||
| 3407 | * Unlock specific tables  | 
            ||
| 3408 | *  | 
            ||
| 3409 | * @param string $method The caller  | 
            ||
| 3410 | * @return bool  | 
            ||
| 3411 | */  | 
            ||
| 3412 | 	public function unlockTables( $method ) { | 
            ||
| 3415 | |||
| 3416 | /**  | 
            ||
| 3417 | * Delete a table  | 
            ||
| 3418 | * @param string $tableName  | 
            ||
| 3419 | * @param string $fName  | 
            ||
| 3420 | * @return bool|ResultWrapper  | 
            ||
| 3421 | * @since 1.18  | 
            ||
| 3422 | */  | 
            ||
| 3423 | View Code Duplication | 	public function dropTable( $tableName, $fName = __METHOD__ ) { | 
            |
| 3431 | |||
| 3432 | 	public function getInfinity() { | 
            ||
| 3435 | |||
| 3436 | 	public function encodeExpiry( $expiry ) { | 
            ||
| 3441 | |||
| 3442 | 	public function decodeExpiry( $expiry, $format = TS_MW ) { | 
            ||
| 3455 | |||
| 3456 | 	public function setBigSelects( $value = true ) { | 
            ||
| 3459 | |||
| 3460 | 	public function isReadOnly() { | 
            ||
| 3463 | |||
| 3464 | /**  | 
            ||
| 3465 | * @return string|bool Reason this DB is read-only or false if it is not  | 
            ||
| 3466 | */  | 
            ||
| 3467 | 	protected function getReadOnlyReason() { | 
            ||
| 3472 | |||
| 3473 | 	public function setTableAliases( array $aliases ) { | 
            ||
| 3476 | |||
| 3477 | /**  | 
            ||
| 3478 | * @return bool Whether a DB user is required to access the DB  | 
            ||
| 3479 | * @since 1.28  | 
            ||
| 3480 | */  | 
            ||
| 3481 | 	protected function requiresDatabaseUser() { | 
            ||
| 3484 | |||
| 3485 | /**  | 
            ||
| 3486 | * @since 1.19  | 
            ||
| 3487 | * @return string  | 
            ||
| 3488 | */  | 
            ||
| 3489 | 	public function __toString() { | 
            ||
| 3492 | |||
| 3493 | /**  | 
            ||
| 3494 | * Called by serialize. Throw an exception when DB connection is serialized.  | 
            ||
| 3495 | * This causes problems on some database engines because the connection is  | 
            ||
| 3496 | * not restored on unserialize.  | 
            ||
| 3497 | */  | 
            ||
| 3498 | 	public function __sleep() { | 
            ||
| 3502 | |||
| 3503 | /**  | 
            ||
| 3504 | * Run a few simple sanity checks  | 
            ||
| 3505 | */  | 
            ||
| 3506 | 	public function __destruct() { | 
            ||
| 3517 | }  | 
            ||
| 3518 | 
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..