Merge "Add support for PHP7 random_bytes in favor of mcrypt_create_iv"
[lhc/web/wiklou.git] / includes / libs / rdbms / database / Database.php
index 1c5c77e..90e60a3 100644 (file)
@@ -29,8 +29,10 @@ use Wikimedia\ScopedCallback;
 use Wikimedia\Rdbms\TransactionProfiler;
 use Wikimedia\Rdbms\LikeMatch;
 use Wikimedia\Rdbms\DatabaseDomain;
+use Wikimedia\Rdbms\ResultWrapper;
 use Wikimedia\Rdbms\DBMasterPos;
 use Wikimedia\Rdbms\Blob;
+use Wikimedia\Timestamp\ConvertibleTimestamp;
 
 /**
  * Relational database abstraction object
@@ -846,7 +848,7 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware
                }
 
                // Add trace comment to the begin of the sql string, right after the operator.
-               // Or, for one-word queries (like "BEGIN" or COMMIT") add it to the end (bug 42598)
+               // Or, for one-word queries (like "BEGIN" or COMMIT") add it to the end (T44598)
                $commentedSql = preg_replace( '/\s|$/', " /* $fname {$this->agent} */ ", $sql, 1 );
 
                # Start implicit transactions that wrap the request if DBO_TRX is enabled
@@ -1025,8 +1027,8 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware
 
        private function handleSessionLoss() {
                $this->mTrxLevel = 0;
-               $this->mTrxIdleCallbacks = []; // bug 65263
-               $this->mTrxPreCommitCallbacks = []; // bug 65263
+               $this->mTrxIdleCallbacks = []; // T67263
+               $this->mTrxPreCommitCallbacks = []; // T67263
                $this->mSessionTempTables = [];
                $this->mNamedLocksHeld = [];
                try {
@@ -1141,12 +1143,6 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware
 
                $preLimitTail .= $this->makeOrderBy( $options );
 
-               // if (isset($options['LIMIT'])) {
-               //      $tailOpts .= $this->limitResult('', $options['LIMIT'],
-               //              isset($options['OFFSET']) ? $options['OFFSET']
-               //              : false);
-               // }
-
                if ( isset( $noKeyOptions['FOR UPDATE'] ) ) {
                        $postLimitTail .= ' FOR UPDATE';
                }
@@ -1358,7 +1354,10 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware
        ) {
                $rows = 0;
                $sql = $this->selectSQLText( $tables, '1', $conds, $fname, $options, $join_conds );
-               $res = $this->query( "SELECT COUNT(*) AS rowcount FROM ($sql) tmp_count", $fname );
+               // The identifier quotes is primarily for MSSQL.
+               $rowCountCol = $this->addIdentifierQuotes( "rowcount" );
+               $tableName = $this->addIdentifierQuotes( "tmp_count" );
+               $res = $this->query( "SELECT COUNT(*) AS $rowCountCol FROM ($sql) $tableName", $fname );
 
                if ( $res ) {
                        $row = $this->fetchRow( $res );
@@ -3416,7 +3415,7 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware
         */
        public function __clone() {
                $this->connLogger->warning(
-                       "Cloning " . get_class( $this ) . " is not recomended; forking connection:\n" .
+                       "Cloning " . static::class . " is not recomended; forking connection:\n" .
                        ( new RuntimeException() )->getTraceAsString()
                );