0 follower

Final Class Yiisoft\Db\Mysql\DDLQueryBuilder

InheritanceYiisoft\Db\Mysql\DDLQueryBuilder » Yiisoft\Db\QueryBuilder\AbstractDDLQueryBuilder

Implements a (Data Definition Language) SQL statements for MySQL, MariaDB.

Method Details

Hide inherited methods

addCheck() public method

public addCheck( string $table, string $name, string $expression ): string
$table string
$name string
$expression string
throws \Yiisoft\Db\Exception\NotSupportedException

                public function addCheck(string $table, string $name, string $expression): string
{
    throw new NotSupportedException(__METHOD__ . ' is not supported by MySQL.');
}

            
addCommentOnColumn() public method

public addCommentOnColumn( string $table, string $column, string $comment ): string
$table string
$column string
$comment string
throws Throwable

                public function addCommentOnColumn(string $table, string $column, string $comment): string
{
    /** @var string $definition Strip existing comment which may include escaped quotes */
    $definition = preg_replace("/COMMENT '(?:''|[^'])*'/i", '', $this->getColumnDefinition($table, $column));
    $definition = trim($definition);
    $checkRegex = '/CHECK *(\(([^()]|(?-2))*\))/';
    $check = preg_match($checkRegex, $definition, $checkMatches);
    if ($check === 1) {
        $definition = preg_replace($checkRegex, '', $definition);
    }
    $alterSql = 'ALTER TABLE '
        . $this->quoter->quoteTableName($table)
        . ' CHANGE '
        . $this->quoter->quoteColumnName($column)
        . ' '
        . $this->quoter->quoteColumnName($column)
        . (empty($definition) ? '' : ' ' . $definition)
        . ' COMMENT '
        . $this->quoter->quoteValue($comment);
    if ($check === 1) {
        $alterSql .= ' ' . $checkMatches[0];
    }
    return $alterSql;
}

            
addCommentOnTable() public method

public addCommentOnTable( string $table, string $comment ): string
$table string
$comment string

                public function addCommentOnTable(string $table, string $comment): string
{
    return 'ALTER TABLE '
        . $this->quoter->quoteTableName($table)
        . ' COMMENT '
        . $this->quoter->quoteValue($comment);
}

            
addDefaultValue() public method

public addDefaultValue( string $table, string $name, string $column, mixed $value ): string
$table string
$name string
$column string
$value mixed

                public function addDefaultValue(string $table, string $name, string $column, mixed $value): string
{
    throw new NotSupportedException(__METHOD__ . ' is not supported by MySQL.');
}

            
checkIntegrity() public method

public checkIntegrity( string $schema '', string $table '', boolean $check true ): string
$schema string
$table string
$check boolean

                public function checkIntegrity(string $schema = '', string $table = '', bool $check = true): string
{
    return 'SET FOREIGN_KEY_CHECKS = ' . ($check ? 1 : 0);
}

            
createIndex() public method

public createIndex( string $table, string $name, array|string $columns, string|null $indexType null, string|null $indexMethod null ): string
$table string
$name string
$columns array|string
$indexType string|null
$indexMethod string|null

                public function createIndex(
    string $table,
    string $name,
    array|string $columns,
    ?string $indexType = null,
    ?string $indexMethod = null,
): string {
    return 'CREATE ' . (!empty($indexType) ? $indexType . ' ' : '') . 'INDEX '
        . $this->quoter->quoteTableName($name)
        . (!empty($indexMethod) ? " USING $indexMethod" : '')
        . ' ON ' . $this->quoter->quoteTableName($table)
        . ' (' . $this->queryBuilder->buildColumns($columns) . ')';
}

            
dropCheck() public method

public dropCheck( string $table, string $name ): string
$table string
$name string
throws \Yiisoft\Db\Exception\NotSupportedException

                public function dropCheck(string $table, string $name): string
{
    throw new NotSupportedException(__METHOD__ . ' is not supported by MySQL.');
}

            
dropCommentFromColumn() public method

public dropCommentFromColumn( string $table, string $column ): string
$table string
$column string
throws \Yiisoft\Db\Exception\Exception
throws Throwable

                public function dropCommentFromColumn(string $table, string $column): string
{
    return $this->addCommentOnColumn($table, $column, '');
}

            
dropCommentFromTable() public method

public dropCommentFromTable( string $table ): string
$table string
throws Exception

                public function dropCommentFromTable(string $table): string
{
    return $this->addCommentOnTable($table, '');
}

            
dropDefaultValue() public method

public dropDefaultValue( string $table, string $name ): string
$table string
$name string

                public function dropDefaultValue(string $table, string $name): string
{
    throw new NotSupportedException(__METHOD__ . ' is not supported by MySQL.');
}

            
dropForeignKey() public method

public dropForeignKey( string $table, string $name ): string
$table string
$name string

                public function dropForeignKey(string $table, string $name): string
{
    return 'ALTER TABLE '
        . $this->quoter->quoteTableName($table)
        . ' DROP FOREIGN KEY '
        . $this->quoter->quoteColumnName($name);
}

            
dropPrimaryKey() public method

public dropPrimaryKey( string $table, string $name ): string
$table string
$name string

                public function dropPrimaryKey(string $table, string $name): string
{
    return 'ALTER TABLE ' . $this->quoter->quoteTableName($table) . ' DROP PRIMARY KEY';
}

            
dropTable() public method

public dropTable( string $table, boolean $ifExists false, boolean $cascade false ): string
$table string
$ifExists boolean
$cascade boolean
throws \Yiisoft\Db\Exception\NotSupportedException

MySQL doesn't support cascade drop table.

                public function dropTable(string $table, bool $ifExists = false, bool $cascade = false): string
{
    if ($cascade) {
        throw new NotSupportedException('MySQL doesn\'t support cascade drop table.');
    }
    return parent::dropTable($table, $ifExists, false);
}

            
dropUnique() public method

public dropUnique( string $table, string $name ): string
$table string
$name string

                public function dropUnique(string $table, string $name): string
{
    return $this->dropIndex($table, $name);
}

            
renameColumn() public method

public renameColumn( string $table, string $oldName, string $newName ): string
$table string
$oldName string
$newName string
throws \Yiisoft\Db\Exception\Exception
throws Throwable

                public function renameColumn(string $table, string $oldName, string $newName): string
{
    $quotedTable = $this->quoter->quoteTableName($table);
    $columnDefinition = $this->getColumnDefinition($table, $oldName);
    /* try to give back an SQL anyway */
    return "ALTER TABLE $quotedTable CHANGE "
        . $this->quoter->quoteColumnName($oldName) . ' '
        . $this->quoter->quoteColumnName($newName)
        . (!empty($columnDefinition) ? ' ' . $columnDefinition : '');
}