Skip to content

Commit

Permalink
Fix #20195: Do not set non abstract values into ColumnSchema->type
Browse files Browse the repository at this point in the history
…on MSSQL version less then 2017
  • Loading branch information
axeltomasson authored Jun 18, 2024
1 parent 0e50cee commit 8dacd2a
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 #16116: Codeception: oci does not support enabling/disabling integrity check (@terabytesoftw)
- 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';
}
}
}
}
}
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 8dacd2a

Please sign in to comment.