Merge "Move cookie-blocking methods to BlockManager"
[lhc/web/wiklou.git] / includes / libs / rdbms / database / DatabaseMysqlBase.php
index 25d78da..6d28717 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
         *
@@ -244,7 +277,7 @@ abstract class DatabaseMysqlBase extends Database {
        abstract protected function mysqlSetCharset( $charset );
 
        /**
-        * @param ResultWrapper|resource $res
+        * @param IResultWrapper|resource $res
         * @throws DBUnexpectedError
         */
        public function freeResult( $res ) {
@@ -268,7 +301,7 @@ abstract class DatabaseMysqlBase extends Database {
        abstract protected function mysqlFreeResult( $res );
 
        /**
-        * @param ResultWrapper|resource $res
+        * @param IResultWrapper|resource $res
         * @return stdClass|bool
         * @throws DBUnexpectedError
         */
@@ -341,7 +374,7 @@ abstract class DatabaseMysqlBase extends Database {
 
        /**
         * @throws DBUnexpectedError
-        * @param ResultWrapper|resource $res
+        * @param IResultWrapper|resource $res
         * @return int
         */
        function numRows( $res ) {
@@ -369,7 +402,7 @@ abstract class DatabaseMysqlBase extends Database {
        abstract protected function mysqlNumRows( $res );
 
        /**
-        * @param ResultWrapper|resource $res
+        * @param IResultWrapper|resource $res
         * @return int
         */
        public function numFields( $res ) {
@@ -389,7 +422,7 @@ abstract class DatabaseMysqlBase extends Database {
        abstract protected function mysqlNumFields( $res );
 
        /**
-        * @param ResultWrapper|resource $res
+        * @param IResultWrapper|resource $res
         * @param int $n
         * @return string
         */
@@ -404,7 +437,7 @@ abstract class DatabaseMysqlBase extends Database {
        /**
         * Get the name of the specified field in a result
         *
-        * @param ResultWrapper|resource $res
+        * @param IResultWrapper|resource $res
         * @param int $n
         * @return string
         */
@@ -412,7 +445,7 @@ abstract class DatabaseMysqlBase extends Database {
 
        /**
         * mysql_field_type() wrapper
-        * @param ResultWrapper|resource $res
+        * @param IResultWrapper|resource $res
         * @param int $n
         * @return string
         */
@@ -427,14 +460,14 @@ abstract class DatabaseMysqlBase extends Database {
        /**
         * Get the type of the specified field in a result
         *
-        * @param ResultWrapper|resource $res
+        * @param IResultWrapper|resource $res
         * @param int $n
         * @return string
         */
        abstract protected function mysqlFieldType( $res, $n );
 
        /**
-        * @param ResultWrapper|resource $res
+        * @param IResultWrapper|resource $res
         * @param int $row
         * @return bool
         */
@@ -449,7 +482,7 @@ abstract class DatabaseMysqlBase extends Database {
        /**
         * Move internal result pointer
         *
-        * @param ResultWrapper|resource $res
+        * @param IResultWrapper|resource $res
         * @param int $row
         * @return bool
         */
@@ -1427,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 );
        }
 
        /**
@@ -1457,7 +1490,7 @@ abstract class DatabaseMysqlBase extends Database {
        /**
         * @param string $tableName
         * @param string $fName
-        * @return bool|ResultWrapper
+        * @return bool|IResultWrapper
         */
        public function dropTable( $tableName, $fName = __METHOD__ ) {
                if ( !$this->tableExists( $tableName, $fName ) ) {