DatabaseMysqlBase: Use VERSION() rather than server_info
authorKevin Israel <pleasestand@live.com>
Sun, 31 Aug 2014 10:43:50 +0000 (06:43 -0400)
committerKevin Israel <pleasestand@live.com>
Sat, 20 Sep 2014 10:16:09 +0000 (06:16 -0400)
I noticed enwiki's Special:Version page was reporting the version
of MariaDB 10 as "5.5.5-10.0.11-MariaDB-log" rather than just
"10.0.11-MariaDB-log". This change should fix that.

Change-Id: I6bf7e27e88014f70594b33d089636b09b6c97527

includes/db/DatabaseMysql.php
includes/db/DatabaseMysqlBase.php
includes/db/DatabaseMysqli.php

index dc4a67d..823d9b6 100644 (file)
@@ -142,13 +142,6 @@ class DatabaseMysql extends DatabaseMysqlBase {
                return mysql_select_db( $db, $this->mConn );
        }
 
-       /**
-        * @return string
-        */
-       function getServerVersion() {
-               return mysql_get_server_info( $this->mConn );
-       }
-
        protected function mysqlFreeResult( $res ) {
                return mysql_free_result( $res );
        }
index ba0f39f..2008f4d 100644 (file)
@@ -38,6 +38,9 @@ abstract class DatabaseMysqlBase extends DatabaseBase {
 
        protected $mFakeMaster = false;
 
+       /** @var string|null */
+       private $serverVersion = null;
+
        /**
         * @return string
         */
@@ -763,9 +766,9 @@ abstract class DatabaseMysqlBase extends DatabaseBase {
         * @return string
         */
        public function getSoftwareLink() {
-               // MariaDB includes its name in its version string (sent when the connection is opened),
-               // and this is how MariaDB's version of the mysql command-line client identifies MariaDB
-               // servers (see the mariadb_connection() function in libmysql/libmysql.c).
+               // MariaDB includes its name in its version string; this is how MariaDB's version of
+               // the mysql command-line client identifies MariaDB servers (see mariadb_connection()
+               // in libmysql/libmysql.c).
                $version = $this->getServerVersion();
                if ( strpos( $version, 'MariaDB' ) !== false || strpos( $version, '-maria-' ) !== false ) {
                        return '[{{int:version-db-mariadb-url}} MariaDB]';
@@ -777,6 +780,19 @@ abstract class DatabaseMysqlBase extends DatabaseBase {
                return '[{{int:version-db-mysql-url}} MySQL]';
        }
 
+       /**
+        * @return string
+        */
+       public function getServerVersion() {
+               // Not using mysql_get_server_info() or similar for consistency: in the handshake,
+               // MariaDB 10 adds the prefix "5.5.5-", and only some newer client libraries strip
+               // it off (see RPL_VERSION_HACK in include/mysql_com.h).
+               if ( $this->serverVersion === null ) {
+                       $this->serverVersion = $this->selectField( '', 'VERSION()', '', __METHOD__ );
+               }
+               return $this->serverVersion;
+       }
+
        /**
         * @param array $options
         */
index a03c9aa..e9c4b39 100644 (file)
@@ -165,13 +165,6 @@ class DatabaseMysqli extends DatabaseMysqlBase {
                return $this->mConn->select_db( $db );
        }
 
-       /**
-        * @return string
-        */
-       function getServerVersion() {
-               return $this->mConn->server_info;
-       }
-
        /**
         * @param mysqli $res
         * @return bool