mirror of
https://github.com/yiisoft/yii2.git
synced 2025-11-02 04:37:42 +08:00
Fixes after review
This commit is contained in:
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -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()) {
|
||||
|
||||
Reference in New Issue
Block a user