Merge "Title: Title::getSubpage should not lose the interwiki prefix"
[lhc/web/wiklou.git] / includes / libs / rdbms / database / DatabaseMysqlBase.php
index b3af8ad..1e3fa84 100644 (file)
@@ -24,7 +24,7 @@ namespace Wikimedia\Rdbms;
 
 use DateTime;
 use DateTimeZone;
-use Wikimedia;
+use Wikimedia\AtEase\AtEase;
 use InvalidArgumentException;
 use Exception;
 use RuntimeException;
@@ -96,7 +96,7 @@ abstract class DatabaseMysqlBase extends Database {
         *   - sslCiphers : array list of allowable ciphers [default: null]
         * @param array $params
         */
-       function __construct( array $params ) {
+       public function __construct( array $params ) {
                $this->lagDetectionMethod = $params['lagDetectionMethod'] ?? 'Seconds_Behind_Master';
                $this->lagDetectionOptions = $params['lagDetectionOptions'] ?? [];
                $this->useGTIDs = !empty( $params['useGTIDs' ] );
@@ -125,7 +125,7 @@ abstract class DatabaseMysqlBase extends Database {
                $this->close();
 
                if ( $schema !== null ) {
-                       throw new DBExpectedError( $this, __CLASS__ . ": domain schemas are not supported." );
+                       throw new DBExpectedError( $this, __CLASS__ . ": cannot use schemas ('$schema')" );
                }
 
                $this->server = $server;
@@ -194,7 +194,10 @@ abstract class DatabaseMysqlBase extends Database {
 
        protected function doSelectDomain( DatabaseDomain $domain ) {
                if ( $domain->getSchema() !== null ) {
-                       throw new DBExpectedError( $this, __CLASS__ . ": domain schemas are not supported." );
+                       throw new DBExpectedError(
+                               $this,
+                               __CLASS__ . ": domain '{$domain->getId()}' has a schema component"
+                       );
                }
 
                $database = $domain->getDatabase();
@@ -241,12 +244,9 @@ abstract class DatabaseMysqlBase extends Database {
         * @throws DBUnexpectedError
         */
        public function freeResult( $res ) {
-               if ( $res instanceof ResultWrapper ) {
-                       $res = $res->result;
-               }
-               Wikimedia\suppressWarnings();
-               $ok = $this->mysqlFreeResult( $res );
-               Wikimedia\restoreWarnings();
+               AtEase::suppressWarnings();
+               $ok = $this->mysqlFreeResult( ResultWrapper::unwrap( $res ) );
+               AtEase::restoreWarnings();
                if ( !$ok ) {
                        throw new DBUnexpectedError( $this, "Unable to free MySQL result" );
                }
@@ -266,12 +266,9 @@ abstract class DatabaseMysqlBase extends Database {
         * @throws DBUnexpectedError
         */
        public function fetchObject( $res ) {
-               if ( $res instanceof ResultWrapper ) {
-                       $res = $res->result;
-               }
-               Wikimedia\suppressWarnings();
-               $row = $this->mysqlFetchObject( $res );
-               Wikimedia\restoreWarnings();
+               AtEase::suppressWarnings();
+               $row = $this->mysqlFetchObject( ResultWrapper::unwrap( $res ) );
+               AtEase::restoreWarnings();
 
                $errno = $this->lastErrno();
                // Unfortunately, mysql_fetch_object does not reset the last errno.
@@ -302,12 +299,9 @@ abstract class DatabaseMysqlBase extends Database {
         * @throws DBUnexpectedError
         */
        public function fetchRow( $res ) {
-               if ( $res instanceof ResultWrapper ) {
-                       $res = $res->result;
-               }
-               Wikimedia\suppressWarnings();
-               $row = $this->mysqlFetchArray( $res );
-               Wikimedia\restoreWarnings();
+               AtEase::suppressWarnings();
+               $row = $this->mysqlFetchArray( ResultWrapper::unwrap( $res ) );
+               AtEase::restoreWarnings();
 
                $errno = $this->lastErrno();
                // Unfortunately, mysql_fetch_array does not reset the last errno.
@@ -338,12 +332,13 @@ abstract class DatabaseMysqlBase extends Database {
         * @return int
         */
        function numRows( $res ) {
-               if ( $res instanceof ResultWrapper ) {
-                       $res = $res->result;
+               if ( is_bool( $res ) ) {
+                       $n = 0;
+               } else {
+                       AtEase::suppressWarnings();
+                       $n = $this->mysqlNumRows( ResultWrapper::unwrap( $res ) );
+                       AtEase::restoreWarnings();
                }
-               Wikimedia\suppressWarnings();
-               $n = !is_bool( $res ) ? $this->mysqlNumRows( $res ) : 0;
-               Wikimedia\restoreWarnings();
 
                // Unfortunately, mysql_num_rows does not reset the last errno.
                // We are not checking for any errors here, since
@@ -366,11 +361,7 @@ abstract class DatabaseMysqlBase extends Database {
         * @return int
         */
        public function numFields( $res ) {
-               if ( $res instanceof ResultWrapper ) {
-                       $res = $res->result;
-               }
-
-               return $this->mysqlNumFields( $res );
+               return $this->mysqlNumFields( ResultWrapper::unwrap( $res ) );
        }
 
        /**
@@ -387,11 +378,7 @@ abstract class DatabaseMysqlBase extends Database {
         * @return string
         */
        public function fieldName( $res, $n ) {
-               if ( $res instanceof ResultWrapper ) {
-                       $res = $res->result;
-               }
-
-               return $this->mysqlFieldName( $res, $n );
+               return $this->mysqlFieldName( ResultWrapper::unwrap( $res ), $n );
        }
 
        /**
@@ -410,11 +397,7 @@ abstract class DatabaseMysqlBase extends Database {
         * @return string
         */
        public function fieldType( $res, $n ) {
-               if ( $res instanceof ResultWrapper ) {
-                       $res = $res->result;
-               }
-
-               return $this->mysqlFieldType( $res, $n );
+               return $this->mysqlFieldType( ResultWrapper::unwrap( $res ), $n );
        }
 
        /**
@@ -432,11 +415,7 @@ abstract class DatabaseMysqlBase extends Database {
         * @return bool
         */
        public function dataSeek( $res, $row ) {
-               if ( $res instanceof ResultWrapper ) {
-                       $res = $res->result;
-               }
-
-               return $this->mysqlDataSeek( $res, $row );
+               return $this->mysqlDataSeek( ResultWrapper::unwrap( $res ), $row );
        }
 
        /**
@@ -454,12 +433,12 @@ abstract class DatabaseMysqlBase extends Database {
        public function lastError() {
                if ( $this->conn ) {
                        # Even if it's non-zero, it can still be invalid
-                       Wikimedia\suppressWarnings();
+                       AtEase::suppressWarnings();
                        $error = $this->mysqlError( $this->conn );
                        if ( !$error ) {
                                $error = $this->mysqlError();
                        }
-                       Wikimedia\restoreWarnings();
+                       AtEase::restoreWarnings();
                } else {
                        $error = $this->mysqlError();
                }
@@ -606,9 +585,9 @@ abstract class DatabaseMysqlBase extends Database {
                if ( !$res ) {
                        return false;
                }
-               $n = $this->mysqlNumFields( $res->result );
+               $n = $this->mysqlNumFields( ResultWrapper::unwrap( $res ) );
                for ( $i = 0; $i < $n; $i++ ) {
-                       $meta = $this->mysqlFetchField( $res->result, $i );
+                       $meta = $this->mysqlFetchField( ResultWrapper::unwrap( $res ), $i );
                        if ( $field == $meta->name ) {
                                return new MySQLField( $meta );
                        }