Skip to content

Commit

Permalink
Fix #20195 Do not set parts of ColumnSchema->dbType values into Colum…
Browse files Browse the repository at this point in the history
…nSchema->type for mssql less then version 2017
  • Loading branch information
axeltomasson committed Jun 11, 2024
1 parent ec46ede commit 7fe3681
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 23 deletions.
1 change: 1 addition & 0 deletions framework/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
32 changes: 9 additions & 23 deletions framework/db/mssql/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Check warning on line 417 in framework/db/mssql/Schema.php

View check run for this annotation

Codecov / codecov/patch

framework/db/mssql/Schema.php#L411-L417

Added lines #L411 - L417 were not covered by tests
}
}
}
}
}
Expand Down Expand Up @@ -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;
}
}

0 comments on commit 7fe3681

Please sign in to comment.