From: Kevin Israel Date: Sun, 31 Aug 2014 10:43:50 +0000 (-0400) Subject: DatabaseMysqlBase: Use VERSION() rather than server_info X-Git-Tag: 1.31.0-rc.0~13912^2 X-Git-Url: https://git.cyclocoop.org//%22?a=commitdiff_plain;h=b824271351da407c4d3520afae27b925909e600a;p=lhc%2Fweb%2Fwiklou.git DatabaseMysqlBase: Use VERSION() rather than server_info 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 --- diff --git a/includes/db/DatabaseMysql.php b/includes/db/DatabaseMysql.php index dc4a67dff3..823d9b67a6 100644 --- a/includes/db/DatabaseMysql.php +++ b/includes/db/DatabaseMysql.php @@ -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 ); } diff --git a/includes/db/DatabaseMysqlBase.php b/includes/db/DatabaseMysqlBase.php index ba0f39ffde..2008f4d73c 100644 --- a/includes/db/DatabaseMysqlBase.php +++ b/includes/db/DatabaseMysqlBase.php @@ -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 */ diff --git a/includes/db/DatabaseMysqli.php b/includes/db/DatabaseMysqli.php index a03c9aaf62..e9c4b39f56 100644 --- a/includes/db/DatabaseMysqli.php +++ b/includes/db/DatabaseMysqli.php @@ -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