mirror of
				https://github.com/yiisoft/yii2.git
				synced 2025-11-04 22:57:40 +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.
 | 
					 * ColumnSchemaBuilder is the schema builder for MSSQL databases.
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * @author Chris Harris <chris@buckshotsoftware.com>
 | 
					 * @author Valerii Gorbachev <darkdef@gmail.com>
 | 
				
			||||||
 * @since 2.0.8
 | 
					 * @since 2.0.42
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
class ColumnSchemaBuilder extends AbstractColumnSchemaBuilder
 | 
					class ColumnSchemaBuilder extends AbstractColumnSchemaBuilder
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
@ -64,7 +64,7 @@ class ColumnSchemaBuilder extends AbstractColumnSchemaBuilder
 | 
				
			|||||||
     */
 | 
					     */
 | 
				
			||||||
    public function getCheckValue()
 | 
					    public function getCheckValue()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        return $this->check !== null ? "{$this->check}" : null;
 | 
					        return $this->check !== null ? (string) $this->check : null;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
 | 
				
			|||||||
@ -176,13 +176,14 @@ class QueryBuilder extends \yii\db\QueryBuilder
 | 
				
			|||||||
    {
 | 
					    {
 | 
				
			||||||
        $sqlAfter = [$this->dropConstraintsForColumn($table, $column, 'D')];
 | 
					        $sqlAfter = [$this->dropConstraintsForColumn($table, $column, 'D')];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if ($type instanceof \yii\db\mssql\ColumnSchemaBuilder) {
 | 
					 | 
				
			||||||
            $type->setAlterColumnFormat();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        $columnName = $this->db->quoteColumnName($column);
 | 
					        $columnName = $this->db->quoteColumnName($column);
 | 
				
			||||||
        $tableName = $this->db->quoteTableName($table);
 | 
					        $tableName = $this->db->quoteTableName($table);
 | 
				
			||||||
        $constraintBase = preg_replace('/[^a-z0-9_]/i', '', $table . '_' . $column);
 | 
					        $constraintBase = preg_replace('/[^a-z0-9_]/i', '', $table . '_' . $column);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if ($type instanceof \yii\db\mssql\ColumnSchemaBuilder) {
 | 
				
			||||||
 | 
					            $type->setAlterColumnFormat();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            $defaultValue = $type->getDefaultValue();
 | 
					            $defaultValue = $type->getDefaultValue();
 | 
				
			||||||
            if ($defaultValue !== null) {
 | 
					            if ($defaultValue !== null) {
 | 
				
			||||||
                $sqlAfter[] = $this->addDefaultValue(
 | 
					                $sqlAfter[] = $this->addDefaultValue(
 | 
				
			||||||
@ -195,7 +196,9 @@ class QueryBuilder extends \yii\db\QueryBuilder
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
            $checkValue = $type->getCheckValue();
 | 
					            $checkValue = $type->getCheckValue();
 | 
				
			||||||
            if ($checkValue !== null) {
 | 
					            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()) {
 | 
					            if ($type->isUnique()) {
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user