diff --git a/framework/CHANGELOG.md b/framework/CHANGELOG.md index fffdfe0673..1e3de45842 100644 --- a/framework/CHANGELOG.md +++ b/framework/CHANGELOG.md @@ -16,6 +16,7 @@ Yii Framework 2 Change Log - Bug #20482: Fix deprecation of `ReflectionMethod::setAccessible()` in PHP `8.5` (terabytesoftw) - Enh #20480: Add PHPStan/Psalm annotations for `ServiceLocator::get` (max-s-lab) - Bug #20447: Fix behavior for `yii\web\Controller::bindActionParams` around `mixed` type (chriscpty) +- Bug #20479: Fix issue with MSSQL related to char and nchar (craiglondon) - Bug #20492: Fix deprecation of `finfo_close()` in PHP `8.5` by conditionally closing the resource (terabytesoftw) - Bug #20495: Fix behavior when resetting sequence in `QueryBuilder` for `MSSQL` (achretien) - Bug #20489: Replace deprecated `strftime` with `date` in `YiiRequirementChecker` (max-s-lab) diff --git a/framework/db/QueryBuilder.php b/framework/db/QueryBuilder.php index 9d243abe12..45b67b1bb3 100644 --- a/framework/db/QueryBuilder.php +++ b/framework/db/QueryBuilder.php @@ -1034,13 +1034,13 @@ class QueryBuilder extends \yii\base\BaseObject * Creates a SQL statement for resetting the sequence value of a table's primary key. * The sequence will be reset such that the primary key of the next new row inserted * will have the specified value or the maximum existing value +1. - * @param string $table the name of the table whose primary key sequence will be reset + * @param string $tableName the name of the table whose primary key sequence will be reset * @param array|string|null $value the value for the primary key of the next new row inserted. If this is not set, * the next new row's primary key will have the maximum existing value +1. * @return string the SQL statement for resetting sequence * @throws NotSupportedException if this is not supported by the underlying DBMS */ - public function resetSequence($table, $value = null) + public function resetSequence($tableName, $value = null) { throw new NotSupportedException($this->db->getDriverName() . ' does not support resetting sequence.'); } diff --git a/framework/db/mssql/QueryBuilder.php b/framework/db/mssql/QueryBuilder.php index d08ca44503..e14d3653c4 100644 --- a/framework/db/mssql/QueryBuilder.php +++ b/framework/db/mssql/QueryBuilder.php @@ -504,9 +504,12 @@ class QueryBuilder extends \yii\db\QueryBuilder } $dbType = $column->dbType; - if (in_array($dbType, ['char', 'varchar', 'nchar', 'nvarchar', 'binary', 'varbinary'])) { + if (in_array($dbType, ['varchar', 'nvarchar', 'binary', 'varbinary'])) { $dbType .= '(MAX)'; + } elseif (in_array($dbType, ['char', 'nchar'])) { + $dbType .= "($column->size)"; } + if ($column->dbType === Schema::TYPE_TIMESTAMP) { $dbType = $column->allowNull ? 'varbinary(8)' : 'binary(8)'; }