From 7fe3681f51773a88a62c0ae04030e3792d939ba8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20T=C3=B3masson?= Date: Tue, 11 Jun 2024 10:26:26 +0000 Subject: [PATCH] Fix #20195 Do not set parts of ColumnSchema->dbType values into ColumnSchema->type for mssql less then version 2017 --- framework/CHANGELOG.md | 1 + framework/db/mssql/Schema.php | 32 +++++++++----------------------- 2 files changed, 10 insertions(+), 23 deletions(-) diff --git a/framework/CHANGELOG.md b/framework/CHANGELOG.md index 08982f47655..f2ca059ed01 100644 --- a/framework/CHANGELOG.md +++ b/framework/CHANGELOG.md @@ -4,6 +4,7 @@ Yii Framework 2 Change Log 2.0.51 under development ------------------------ +- Bug #20195: Do not set non abstract values into ColumnSchema->type on mssql version less then 2017 (axeltomasson) - Bug #20191: Fix `ActiveRecord::getDirtyAttributes()` for JSON columns with multi-dimensional array values (brandonkelly) - Bug #20175: Fix bad result for pagination when used with GridView (@lav45) diff --git a/framework/db/mssql/Schema.php b/framework/db/mssql/Schema.php index 96c09905801..35908437f48 100644 --- a/framework/db/mssql/Schema.php +++ b/framework/db/mssql/Schema.php @@ -408,7 +408,15 @@ protected function loadColumnSchema($info) } if ($isVersion2017orLater === false) { - $column->type = $this->booleanTypeLegacy($column->size, $type); + if ($column->size === 1 && ($type === 'tinyint' || $type === 'bit')) { + $column->type = 'boolean'; + } elseif ($type === 'bit') { + if ($column->size > 32) { + $column->type = 'bigint'; + } elseif ($column->size === 32) { + $column->type = 'integer'; + } + } } } } @@ -816,26 +824,4 @@ public function createColumnSchemaBuilder($type, $length = null) return Yii::createObject(ColumnSchemaBuilder::className(), [$type, $length, $this->db]); } - /** - * Assigns a type boolean for the column type bit, for legacy versions of MSSQL. - * - * @param int $size column size. - * @param string $type column type. - * - * @return string column type. - */ - private function booleanTypeLegacy($size, $type) - { - if ($size === 1 && ($type === 'tinyint' || $type === 'bit')) { - return 'boolean'; - } elseif ($type === 'bit') { - if ($size > 32) { - return 'bigint'; - } elseif ($size === 32) { - return 'integer'; - } - } - - return $type; - } }