diff --git a/docs/guide/db-dao.md b/docs/guide/db-dao.md index b7355d1a9a..98351e8853 100644 --- a/docs/guide/db-dao.md +++ b/docs/guide/db-dao.md @@ -107,6 +107,18 @@ and [[yii\db\Connection::password|password]]. Please refer to [[yii\db\Connectio > ], > ``` +For MS SQL Server additional connection option is needed for proper binary data handling: + +```php +'db' => [ + 'class' => 'yii\db\Connection', + 'dsn' => 'sqlsrv:Server=localhost;Database=mydatabase', + 'attributes' => [ + \PDO::SQLSRV_ATTR_ENCODING => \PDO::SQLSRV_ENCODING_SYSTEM + ] +], +``` + ## Executing SQL Queries diff --git a/framework/CHANGELOG.md b/framework/CHANGELOG.md index 6db7a93c30..17d35cd0f5 100644 --- a/framework/CHANGELOG.md +++ b/framework/CHANGELOG.md @@ -18,6 +18,7 @@ Yii Framework 2 Change Log - Enh #17792: Added support for `aria` attributes to `yii\helpers\BaseHtml::renderTagAttributes()` (brandonkelly) - Bug #17793: Fix inconsistent handling of null `data` attribute values in `yii\helpers\BaseHtml::renderTagAttributes()` (brandonkelly) - Bug #17300: Fix class-level Event handling with wildcards (Toma91) +- Bug #17635: Fix varbinary data handling for MSSQL (toatall) 2.0.31 December 18, 2019 diff --git a/framework/db/mssql/QueryBuilder.php b/framework/db/mssql/QueryBuilder.php index 350a9c8729..12a5d97a0c 100644 --- a/framework/db/mssql/QueryBuilder.php +++ b/framework/db/mssql/QueryBuilder.php @@ -426,7 +426,8 @@ class QueryBuilder extends \yii\db\QueryBuilder // @see https://github.com/yiisoft/yii2/issues/12599 if (isset($columnSchemas[$name]) && $columnSchemas[$name]->type === Schema::TYPE_BINARY && $columnSchemas[$name]->dbType === 'varbinary' && (is_string($value) || $value === null)) { $phName = $this->bindParam($value, $params); - $columns[$name] = new Expression("CONVERT(VARBINARY, $phName)", $params); + // @see https://github.com/yiisoft/yii2/issues/12599 + $columns[$name] = new Expression("CONVERT(VARBINARY(MAX), $phName)", $params); } } }