Merge "Call parent::__construct() in MysqlBase AFTER transferring specific parameters"
[lhc/web/wiklou.git] / includes / libs / rdbms / database / DatabaseMysqlBase.php
index 1efc6c8..9662a5b 100644 (file)
@@ -29,7 +29,7 @@
  * @since 1.22
  * @see Database
  */
-abstract class DatabaseMysqlBase extends DatabaseBase {
+abstract class DatabaseMysqlBase extends Database {
        /** @var MysqlMasterPos */
        protected $lastKnownReplicaPos;
        /** @var string Method to detect replica DB lag */
@@ -72,8 +72,6 @@ abstract class DatabaseMysqlBase extends DatabaseBase {
         * @param array $params
         */
        function __construct( array $params ) {
-               parent::__construct( $params );
-
                $this->lagDetectionMethod = isset( $params['lagDetectionMethod'] )
                        ? $params['lagDetectionMethod']
                        : 'Seconds_Behind_Master';
@@ -89,6 +87,8 @@ abstract class DatabaseMysqlBase extends DatabaseBase {
                }
                $this->sqlMode = isset( $params['sqlMode'] ) ? $params['sqlMode'] : '';
                $this->utf8Mode = !empty( $params['utf8Mode'] );
+
+               parent::__construct( $params );
        }
 
        /**
@@ -129,14 +129,14 @@ abstract class DatabaseMysqlBase extends DatabaseBase {
                        if ( !$error ) {
                                $error = $this->lastError();
                        }
-                       $this->queryLogger->error(
+                       $this->connLogger->error(
                                "Error connecting to {db_server}: {error}",
                                $this->getLogContext( [
                                        'method' => __METHOD__,
                                        'error' => $error,
                                ] )
                        );
-                       $this->queryLogger->debug( "DB connection error\n" .
+                       $this->connLogger->debug( "DB connection error\n" .
                                "Server: $server, User: $user, Password: " .
                                substr( $password, 0, 3 ) . "..., error: " . $error . "\n" );
 
@@ -608,6 +608,16 @@ abstract class DatabaseMysqlBase extends DatabaseBase {
         */
        abstract protected function mysqlRealEscapeString( $s );
 
+       public function addQuotes( $s ) {
+               if ( is_bool( $s ) ) {
+                       // Parent would transform to int, which does not play nice with MySQL type juggling.
+                       // When searching for an int in a string column, the strings are cast to int, which
+                       // means false would match any string not starting with a number.
+                       $s = (string)(int)$s;
+               }
+               return parent::addQuotes( $s );
+       }
+
        /**
         * MySQL uses `backticks` for identifier quoting instead of the sql standard "double quotes".
         *
@@ -811,7 +821,7 @@ abstract class DatabaseMysqlBase extends DatabaseBase {
                        // with an old master hostname. Such calls make MASTER_POS_WAIT() return null. Try
                        // to detect this and treat the replica DB as having reached the position; a proper master
                        // switchover already requires that the new master be caught up before the switch.
-                       $replicationPos = $this->getSlavePos();
+                       $replicationPos = $this->getReplicaPos();
                        if ( $replicationPos && !$replicationPos->channelsMatch( $pos ) ) {
                                $this->lastKnownReplicaPos = $replicationPos;
                                $status = 0;
@@ -829,7 +839,7 @@ abstract class DatabaseMysqlBase extends DatabaseBase {
         *
         * @return MySQLMasterPos|bool
         */
-       function getSlavePos() {
+       function getReplicaPos() {
                $res = $this->query( 'SHOW SLAVE STATUS', __METHOD__ );
                $row = $this->fetchObject( $res );