0 follower

Final Class Yiisoft\Db\Mssql\Column\ColumnDefinitionBuilder

InheritanceYiisoft\Db\Mssql\Column\ColumnDefinitionBuilder » Yiisoft\Db\QueryBuilder\AbstractColumnDefinitionBuilder

Constants

Hide inherited constants

Constant Value Description Defined By
AUTO_INCREMENT_KEYWORD 'IDENTITY' Yiisoft\Db\Mssql\Column\ColumnDefinitionBuilder
TYPES_WITH_SCALE [ 'decimal', 'numeric', ] Yiisoft\Db\Mssql\Column\ColumnDefinitionBuilder
TYPES_WITH_SIZE [ 'decimal', 'numeric', 'float', 'datetime2', 'datetimeoffset', 'time', 'char', 'varchar', 'nchar', 'nvarchar', 'binary', 'varbinary', ] Yiisoft\Db\Mssql\Column\ColumnDefinitionBuilder

Method Details

Hide inherited methods

build() public method

public string build ( \Yiisoft\Db\Schema\Column\ColumnInterface $column )
$column \Yiisoft\Db\Schema\Column\ColumnInterface

                public function build(ColumnInterface $column): string
{
    if ($column->isUnsigned()) {
        throw new NotSupportedException('The "unsigned" attribute is not supported by MSSQL.');
    }
    return $this->buildType($column)
        . $this->buildAutoIncrement($column)
        . $this->buildPrimaryKey($column)
        . $this->buildUnique($column)
        . $this->buildNotNull($column)
        . $this->buildDefault($column)
        . $this->buildCheck($column)
        . $this->buildCollate($column)
        . $this->buildReferences($column)
        . $this->buildExtra($column);
}

            
buildAlter() public method

public string buildAlter ( \Yiisoft\Db\Schema\Column\ColumnInterface $column )
$column \Yiisoft\Db\Schema\Column\ColumnInterface

                public function buildAlter(ColumnInterface $column): string
{
    return $this->buildType($column)
        . $this->buildNotNull($column)
        . $this->buildExtra($column);
}

            
buildCheck() protected method

protected string buildCheck ( \Yiisoft\Db\Schema\Column\ColumnInterface $column )
$column \Yiisoft\Db\Schema\Column\ColumnInterface

                protected function buildCheck(ColumnInterface $column): string
{
    $check = $column->getCheck();
    if (empty($check)) {
        $name = $column->getName();
        if (!empty($name)
            && in_array($column->getType(), [ColumnType::ARRAY, ColumnType::STRUCTURED, ColumnType::JSON], true)
        ) {
            return ' CHECK (isjson(' . $this->queryBuilder->getQuoter()->quoteSimpleColumnName($name) . ') > 0)';
        }
    }
    return parent::buildCheck($column);
}

            
buildOnDelete() protected method

protected string buildOnDelete ( string $onDelete )
$onDelete string

                protected function buildOnDelete(string $onDelete): string
{
    if (strtoupper($onDelete) === ReferentialAction::RESTRICT) {
        return '';
    }
    return " ON DELETE $onDelete";
}

            
buildOnUpdate() protected method

protected string buildOnUpdate ( string $onUpdate )
$onUpdate string

                protected function buildOnUpdate(string $onUpdate): string
{
    if (strtoupper($onUpdate) === ReferentialAction::RESTRICT) {
        return '';
    }
    return " ON UPDATE $onUpdate";
}

            
getDbType() protected method

protected string getDbType ( \Yiisoft\Db\Schema\Column\ColumnInterface $column )
$column \Yiisoft\Db\Schema\Column\ColumnInterface

                protected function getDbType(ColumnInterface $column): string
{
    $size = $column->getSize();
    /** @psalm-suppress DocblockTypeContradiction */
    $dbType = $column->getDbType() ?? match ($column->getType()) {
        ColumnType::BOOLEAN => 'bit',
        ColumnType::BIT => match (true) {
            $size === null => 'bigint',
            $size === 1 => 'bit',
            $size <= 8 => 'tinyint',
            $size <= 16 => 'smallint',
            $size <= 32 => 'int',
            $size <= 64 => 'bigint',
            default => 'varbinary(' . ceil($size / 8) . ')',
        },
        ColumnType::TINYINT => 'tinyint',
        ColumnType::SMALLINT => 'smallint',
        ColumnType::INTEGER => 'int',
        ColumnType::BIGINT => 'bigint',
        ColumnType::FLOAT => 'real',
        ColumnType::DOUBLE => 'float(53)',
        ColumnType::DECIMAL => 'decimal',
        ColumnType::MONEY => 'money',
        ColumnType::CHAR => 'nchar',
        ColumnType::STRING => 'nvarchar(' . (($size ?? '255') ?: 'max') . ')',
        ColumnType::TEXT => 'nvarchar(max)',
        ColumnType::BINARY => 'varbinary(max)',
        ColumnType::UUID => 'uniqueidentifier',
        ColumnType::TIMESTAMP => 'datetime2',
        ColumnType::DATETIME => 'datetime2',
        ColumnType::DATETIMETZ => 'datetimeoffset',
        ColumnType::TIME => 'time',
        ColumnType::TIMETZ => 'time',
        ColumnType::DATE => 'date',
        ColumnType::ARRAY => 'nvarchar(max)',
        ColumnType::STRUCTURED => 'nvarchar(max)',
        ColumnType::JSON => 'nvarchar(max)',
        ColumnType::ENUM => 'nvarchar',
        default => 'nvarchar',
    };
    return match ($dbType) {
        'timestamp' => 'datetime2',
        'varchar' => 'varchar(' . ($size ?: 'max') . ')',
        'nvarchar' => 'nvarchar(' . ($size ?: 'max') . ')',
        'varbinary' => 'varbinary(' . ($size ?: 'max') . ')',
        default => $dbType,
    };
}

            
getDefaultUuidExpression() protected method

protected string getDefaultUuidExpression ( )

                protected function getDefaultUuidExpression(): string
{
    return 'newid()';
}