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 string addCheck ( string $table, string $name, string $expression )
$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 string addCommentOnColumn ( string $table, string $column, string $comment )
$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 string addCommentOnTable ( string $table, string $comment )
$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 string addDefaultValue ( string $table, string $name, string $column, mixed $value )
$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 string checkIntegrity ( string $schema '', string $table '', boolean $check true )
$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 string createIndex ( string $table, string $name, array|string $columns, ?string $indexType null, ?string $indexMethod null )
$table string
$name string
$columns array|string
$indexType ?string
$indexMethod ?string

                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 string dropCheck ( string $table, string $name )
$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 string dropCommentFromColumn ( string $table, string $column )
$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 string dropCommentFromTable ( string $table )
$table string
throws Exception

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

            
dropDefaultValue() public method

public string dropDefaultValue ( string $table, string $name )
$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 string dropForeignKey ( string $table, string $name )
$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 string dropPrimaryKey ( string $table, string $name )
$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 string dropTable ( string $table, boolean $ifExists false, boolean $cascade false )
$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 string dropUnique ( string $table, string $name )
$table string
$name string

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

            
renameColumn() public method

public string renameColumn ( string $table, string $oldName, string $newName )
$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 : '');
}