Fixes after review

This commit is contained in:
DarkDef
2021-04-27 12:15:31 +03:00
parent 12ccd2adde
commit 2d76f33dd4
2 changed files with 10 additions and 7 deletions

View File

@ -13,8 +13,8 @@ use yii\db\Expression;
/**
* ColumnSchemaBuilder is the schema builder for MSSQL databases.
*
* @author Chris Harris <chris@buckshotsoftware.com>
* @since 2.0.8
* @author Valerii Gorbachev <darkdef@gmail.com>
* @since 2.0.42
*/
class ColumnSchemaBuilder extends AbstractColumnSchemaBuilder
{
@ -64,7 +64,7 @@ class ColumnSchemaBuilder extends AbstractColumnSchemaBuilder
*/
public function getCheckValue()
{
return $this->check !== null ? "{$this->check}" : null;
return $this->check !== null ? (string) $this->check : null;
}
/**

View File

@ -176,12 +176,13 @@ class QueryBuilder extends \yii\db\QueryBuilder
{
$sqlAfter = [$this->dropConstraintsForColumn($table, $column, 'D')];
$columnName = $this->db->quoteColumnName($column);
$tableName = $this->db->quoteTableName($table);
$constraintBase = preg_replace('/[^a-z0-9_]/i', '', $table . '_' . $column);
if ($type instanceof \yii\db\mssql\ColumnSchemaBuilder) {
$type->setAlterColumnFormat();
$columnName = $this->db->quoteColumnName($column);
$tableName = $this->db->quoteTableName($table);
$constraintBase = preg_replace('/[^a-z0-9_]/i', '', $table . '_' . $column);
$defaultValue = $type->getDefaultValue();
if ($defaultValue !== null) {
@ -195,7 +196,9 @@ class QueryBuilder extends \yii\db\QueryBuilder
$checkValue = $type->getCheckValue();
if ($checkValue !== null) {
$sqlAfter[] = "ALTER TABLE {$tableName} ADD CONSTRAINT " . $this->db->quoteColumnName("CK_{$constraintBase}") . " CHECK ({$checkValue})";
$sqlAfter[] = "ALTER TABLE {$tableName} ADD CONSTRAINT " .
$this->db->quoteColumnName("CK_{$constraintBase}") .
" CHECK (" . ($defaultValue instanceof Expression ? $checkValue : new Expression($checkValue)) . ")";
}
if ($type->isUnique()) {