mirror of
https://github.com/yiisoft/yii2.git
synced 2025-11-02 13:02:24 +08:00
Fix #17635: Fix varbinary data handling for MSSQL
This commit is contained in:
@ -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 <span id="executing-sql-queries"></span>
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user