Merge "mediawiki.Title: Remove redundant closure"
[lhc/web/wiklou.git] / includes / libs / rdbms / database / DatabaseMysqlBase.php
index 62110ef..36c947f 100644 (file)
@@ -106,7 +106,7 @@ abstract class DatabaseMysqlBase extends Database {
                                $this->$var = $params[$var];
                        }
                }
-               $this->sqlMode = $params['sqlMode'] ?? '';
+               $this->sqlMode = $params['sqlMode'] ?? null;
                $this->utf8Mode = !empty( $params['utf8Mode'] );
                $this->insertSelectIsSafe = isset( $params['insertSelectIsSafe'] )
                        ? (bool)$params['insertSelectIsSafe'] : null;
@@ -225,6 +225,39 @@ abstract class DatabaseMysqlBase extends Database {
                }
        }
 
+       protected function doSelectDomain( DatabaseDomain $domain ) {
+               if ( $domain->getSchema() !== null ) {
+                       throw new DBExpectedError( $this, __CLASS__ . ": domain schemas are not supported." );
+               }
+
+               $database = $domain->getDatabase();
+               // A null database means "don't care" so leave it as is and update the table prefix
+               if ( $database === null ) {
+                       $this->currentDomain = new DatabaseDomain(
+                               $this->currentDomain->getDatabase(),
+                               null,
+                               $domain->getTablePrefix()
+                       );
+
+                       return true;
+               }
+
+               if ( $database !== $this->getDBname() ) {
+                       $sql = 'USE ' . $this->addIdentifierQuotes( $database );
+                       $ret = $this->doQuery( $sql );
+                       if ( $ret === false ) {
+                               $error = $this->lastError();
+                               $errno = $this->lastErrno();
+                               $this->reportQueryError( $error, $errno, $sql, __METHOD__ );
+                       }
+               }
+
+               // Update that domain fields on success (no exception thrown)
+               $this->currentDomain = $domain;
+
+               return true;
+       }
+
        /**
         * Open a connection to a MySQL server
         *
@@ -486,15 +519,11 @@ abstract class DatabaseMysqlBase extends Database {
        abstract protected function mysqlError( $conn = null );
 
        protected function wasQueryTimeout( $error, $errno ) {
-               return $errno == 2062;
+               // https://dev.mysql.com/doc/refman/8.0/en/client-error-reference.html
+               // https://phabricator.wikimedia.org/T170638
+               return in_array( $errno, [ 2062, 3024 ] );
        }
 
-       /**
-        * @param string $table
-        * @param array $uniqueIndexes
-        * @param array $rows
-        * @param string $fname
-        */
        public function replace( $table, $uniqueIndexes, $rows, $fname = __METHOD__ ) {
                $this->nativeReplace( $table, $rows, $fname );
        }
@@ -1326,16 +1355,8 @@ abstract class DatabaseMysqlBase extends Database {
                $this->query( $sql, $fname );
        }
 
-       /**
-        * @param string $table
-        * @param array $rows
-        * @param array $uniqueIndexes
-        * @param array $set
-        * @param string $fname
-        * @return bool
-        */
-       public function upsert( $table, array $rows, array $uniqueIndexes,
-               array $set, $fname = __METHOD__
+       public function upsert(
+               $table, array $rows, $uniqueIndexes, array $set, $fname = __METHOD__
        ) {
                if ( $rows === [] ) {
                        return true; // nothing to do
@@ -1421,7 +1442,7 @@ abstract class DatabaseMysqlBase extends Database {
                }
 
                // See https://dev.mysql.com/doc/refman/5.5/en/error-messages-server.html
-               return in_array( $errno, [ 1022, 1216, 1217, 1137 ], true );
+               return in_array( $errno, [ 1022, 1062, 1216, 1217, 1137, 1146, 1051, 1054 ], true );
        }
 
        /**
@@ -1439,7 +1460,7 @@ abstract class DatabaseMysqlBase extends Database {
                $oldName = $this->addIdentifierQuotes( $oldName );
                $query = "CREATE $tmp TABLE $newName (LIKE $oldName)";
 
-               return $this->query( $query, $fname );
+               return $this->query( $query, $fname, $this::QUERY_PSEUDO_PERMANENT );
        }
 
        /**