Fix #17457: Fixed phpTypecast() for MSSQL

This commit is contained in:
octicon-git-branch(16/)
octicon-tag(16/)
Alexander Kartavenko
2019-07-23 23:08:31 +03:00
committed by Alexander Makarov
gitea-unlock(16/)
parent 9988efc04f
commit c2eae6cb0e
octicon-diff(16/tw-mr-1) 3 changed files with 8 additions and 4 deletions

1
framework/CHANGELOG.md
View File

@@ -4,6 +4,7 @@ Yii Framework 2 Change Log
2.0.24 under development
------------------------
- Bug #17457: Fixed `phpTypecast()` for MSSQL (alexkart)
- Bug #17219: Fixed quoting of table names with spaces in MSSQL (alexkart)
- Bug #10020: Fixed quoting of column names with dots in MSSQL (alexkart)
- Bug #17424: Subdomain support for `User::loginRequired` (alex-code)

9
framework/db/mssql/ColumnSchema.php
View File

@@ -15,13 +15,16 @@ namespace yii\db\mssql;
class ColumnSchema extends \yii\db\ColumnSchema
{
/**
* {@inheritdoc}
* Prepares default value and converts it according to [[phpType]]
* @param mixed $value default value
* @return mixed converted value
* @since 2.0.24
*/
public function phpTypecast($value)
public function defaultPhpTypecast($value)
{
if ($value !== null) {
// convert from MSSQL column_default format, e.g. ('1') -> 1, ('string') -> string
$value = trim($value, "'()");
$value = substr(substr($value, 2), 0, -2);
}
return parent::phpTypecast($value);

2
framework/db/mssql/Schema.php
View File

@@ -397,7 +397,7 @@ SQL;
$info['column_default'] = null;
}
if (!$column->isPrimaryKey && ($column->type !== 'timestamp' || $info['column_default'] !== 'CURRENT_TIMESTAMP')) {
$column->defaultValue = $column->phpTypecast($info['column_default']);
$column->defaultValue = $column->defaultPhpTypecast($info['column_default']);
}
return $column;