From: umherirrender Date: Wed, 18 Feb 2015 18:34:30 +0000 (+0100) Subject: Fixed detection of unsigned mysql column in updater X-Git-Tag: 1.31.0-rc.0~12174^2 X-Git-Url: http://git.cyclocoop.org/fichier?a=commitdiff_plain;h=b21bf82bb1782106cfbeb1d7d8a9eedd07191f5b;p=lhc%2Fweb%2Fwiklou.git Fixed detection of unsigned mysql column in updater MediaWiki running with an old mysql or php without mysqli cannot use the newly added flags property of Database::fieldInfo. For backward compatibility add the missing properties using the flags property to the result of Database::fieldInfo. Added missing unsigned, numeric, blob and zerofill properties to the MysqlField using flags in mysqli. The missing fields in mysqli are taken from http://php.net/manual/en/function.mysql-fetch-field.php Follow-Up: I641dc1fad0a5bb14815f55e0357243a562fd672b Change-Id: I1da904df72f8af7725fc7ff94121ef85b18a36f8 --- diff --git a/includes/db/DatabaseMysqlBase.php b/includes/db/DatabaseMysqlBase.php index c1f2969d73..aac95a8cca 100644 --- a/includes/db/DatabaseMysqlBase.php +++ b/includes/db/DatabaseMysqlBase.php @@ -1188,7 +1188,8 @@ abstract class DatabaseMysqlBase extends DatabaseBase { */ class MySQLField implements Field { private $name, $tablename, $default, $max_length, $nullable, - $is_pk, $is_unique, $is_multiple, $is_key, $type, $binary; + $is_pk, $is_unique, $is_multiple, $is_key, $type, $binary, + $is_numeric, $is_blob, $is_unsigned, $is_zerofill; function __construct( $info ) { $this->name = $info->name; @@ -1201,8 +1202,11 @@ class MySQLField implements Field { $this->is_multiple = $info->multiple_key; $this->is_key = ( $this->is_pk || $this->is_unique || $this->is_multiple ); $this->type = $info->type; - $this->flags = $info->flags; $this->binary = isset( $info->binary ) ? $info->binary : false; + $this->is_numeric = isset( $info->numeric ) ? $info->numeric : false; + $this->is_blob = isset( $info->blob ) ? $info->blob : false; + $this->is_unsigned = isset( $info->unsigned ) ? $info->unsigned : false; + $this->is_zerofill = isset( $info->zerofill ) ? $info->zerofill : false; } /** @@ -1252,15 +1256,39 @@ class MySQLField implements Field { } /** - * @return int + * @return bool */ - function flags() { - return $this->flags; - } - function isBinary() { return $this->binary; } + + /** + * @return bool + */ + function isNumeric() { + return $this->is_numeric; + } + + /** + * @return bool + */ + function isBlob() { + return $this->is_blob; + } + + /** + * @return bool + */ + function isUnsigned() { + return $this->is_unsigned; + } + + /** + * @return bool + */ + function isZerofill() { + return $this->is_zerofill; + } } class MySQLMasterPos implements DBMasterPos { diff --git a/includes/db/DatabaseMysqli.php b/includes/db/DatabaseMysqli.php index e9c4b39f56..ad12e196ed 100644 --- a/includes/db/DatabaseMysqli.php +++ b/includes/db/DatabaseMysqli.php @@ -224,11 +224,18 @@ class DatabaseMysqli extends DatabaseMysqlBase { */ protected function mysqlFetchField( $res, $n ) { $field = $res->fetch_field_direct( $n ); + + // Add missing properties to result (using flags property) + // which will be part of function mysql-fetch-field for backward compatibility $field->not_null = $field->flags & MYSQLI_NOT_NULL_FLAG; $field->primary_key = $field->flags & MYSQLI_PRI_KEY_FLAG; $field->unique_key = $field->flags & MYSQLI_UNIQUE_KEY_FLAG; $field->multiple_key = $field->flags & MYSQLI_MULTIPLE_KEY_FLAG; $field->binary = $field->flags & MYSQLI_BINARY_FLAG; + $field->numeric = $field->flags & MYSQLI_NUM_FLAG; + $field->blob = $field->flags & MYSQLI_BLOB_FLAG; + $field->unsigned = $field->flags & MYSQLI_UNSIGNED_FLAG; + $field->zerofill = $field->flags & MYSQLI_ZEROFILL_FLAG; return $field; } diff --git a/includes/installer/MysqlUpdater.php b/includes/installer/MysqlUpdater.php index eada44a918..ae1a1d4021 100644 --- a/includes/installer/MysqlUpdater.php +++ b/includes/installer/MysqlUpdater.php @@ -1073,7 +1073,7 @@ class MysqlUpdater extends DatabaseUpdater { if ( $info === false ) { return true; } - if ( ( $info->flags() & 32 /*MYSQLI_UNSIGNED_FLAG*/ ) ) { + if ( $info->isUnsigned() ) { $this->output( "...user_id is already unsigned int.\n" ); return true;