0 follower

Final Class Yiisoft\Db\Oracle\Column\ColumnDefinitionBuilder

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

Constants

Hide inherited constants

Constant Value Description Defined By
AUTO_INCREMENT_KEYWORD 'GENERATED BY DEFAULT AS IDENTITY' Yiisoft\Db\Oracle\Column\ColumnDefinitionBuilder
TYPES_WITH_SCALE [ 'number', ] Yiisoft\Db\Oracle\Column\ColumnDefinitionBuilder
TYPES_WITH_SIZE [ 'char', 'nchar', 'character', 'varchar', 'varchar2', 'nvarchar2', 'number', 'float', 'timestamp', 'interval day(0) to second', 'raw', 'urowid', ] Yiisoft\Db\Oracle\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 Oracle.');
    }
    return $this->buildType($column)
        . $this->buildAutoIncrement($column)
        . $this->buildDefault($column)
        . $this->buildPrimaryKey($column)
        . $this->buildUnique($column)
        . $this->buildNotNull($column)
        . $this->buildCheck($column)
        . $this->buildCollate($column)
        . $this->buildReferences($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)) {
            $type = $column->getType();
            if (in_array($type, [ColumnType::ARRAY, ColumnType::STRUCTURED, ColumnType::JSON], true)) {
                return version_compare($this->queryBuilder->getServerInfo()->getVersion(), '21', '<')
                    ? ' CHECK (' . $this->queryBuilder->getQuoter()->quoteSimpleColumnName($name) . ' IS JSON)'
                    : '';
            }
            if ($type === ColumnType::BOOLEAN) {
                return ' CHECK (' . $this->queryBuilder->getQuoter()->quoteSimpleColumnName($name) . ' IN (0,1))';
            }
        }
    }
    return parent::buildCheck($column);
}

            
buildOnDelete() protected method

protected string buildOnDelete ( string $onDelete )
$onDelete string

                protected function buildOnDelete(string $onDelete): string
{
    return match ($onDelete = strtoupper($onDelete)) {
        ReferentialAction::CASCADE,
        ReferentialAction::SET_NULL => " ON DELETE $onDelete",
        default => '',
    };
}

            
buildOnUpdate() protected method

protected string buildOnUpdate ( string $onUpdate )
$onUpdate string

                protected function buildOnUpdate(string $onUpdate): string
{
    return '';
}

            
getDbType() protected method

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

                protected function getDbType(ColumnInterface $column): string
{
    $dbType = $column->getDbType();
    $size = $column->getSize();
    $scale = $column->getScale();
    /** @psalm-suppress DocblockTypeContradiction */
    return match ($dbType) {
        default => $dbType,
        null => match ($column->getType()) {
            ColumnType::BOOLEAN => 'char(1)',
            ColumnType::BIT => match (true) {
                $size === null => 'number(38)',
                $size <= 126 => 'number(' . ceil(log10(2 ** $size)) . ')',
                default => 'raw(' . ceil($size / 8) . ')',
            },
            ColumnType::TINYINT => 'number(' . ($size ?? 3) . ')',
            ColumnType::SMALLINT => 'number(' . ($size ?? 5) . ')',
            ColumnType::INTEGER => 'number(' . ($size ?? 10) . ')',
            ColumnType::BIGINT => 'number(' . ($size ?? 20) . ')',
            ColumnType::FLOAT => 'binary_float',
            ColumnType::DOUBLE => 'binary_double',
            ColumnType::DECIMAL => 'number(' . ($size ?? 10) . ',' . ($scale ?? 0) . ')',
            ColumnType::MONEY => 'number(' . ($size ?? 19) . ',' . ($scale ?? 4) . ')',
            ColumnType::CHAR => 'char',
            ColumnType::STRING => 'varchar2(' . ($size ?? 255) . ')',
            ColumnType::TEXT => 'clob',
            ColumnType::BINARY => 'blob',
            ColumnType::UUID => 'raw(16)',
            ColumnType::TIMESTAMP => 'timestamp',
            ColumnType::DATETIME => 'timestamp',
            ColumnType::DATETIMETZ => 'timestamp' . ($size !== null ? "($size)" : '') . ' with time zone',
            ColumnType::TIME => 'interval day(0) to second',
            ColumnType::TIMETZ => 'interval day(0) to second',
            ColumnType::DATE => 'date',
            ColumnType::ARRAY, ColumnType::STRUCTURED, ColumnType::JSON
                => version_compare($this->queryBuilder->getServerInfo()->getVersion(), '21', '>=')
                ? 'json'
                : 'clob',
            ColumnType::ENUM => 'varchar2(' . $this->calcEnumSize($column) . ' BYTE)',
            default => 'varchar2',
        },
        'timestamp with time zone' => 'timestamp' . ($size !== null ? "($size)" : '') . ' with time zone',
        'timestamp with local time zone' => 'timestamp' . ($size !== null ? "($size)" : '') . ' with local time zone',
        'interval day to second' => 'interval day' . ($scale !== null ? "($scale)" : '') . ' to second' . ($size !== null ? "($size)" : ''),
        'interval year to month' => 'interval year' . ($scale !== null ? "($scale)" : '') . ' to month',
    };
}

            
getDefaultUuidExpression() protected method

protected string getDefaultUuidExpression ( )

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