Fix #20479: Fix issue with MSSQL related to char and nchar

This commit is contained in:
Craig London
2025-08-26 15:05:11 -04:00
committed by GitHub
parent 1ce35f98b0
commit 005d9f21fb
3 changed files with 7 additions and 3 deletions

View File

@ -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)

View File

@ -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.');
}

View File

@ -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)';
}