本文整理汇总了PHP中Doctrine\DBAL\Platforms\AbstractPlatform::getPreAlterTableIndexForeignKeySQL方法的典型用法代码示例。如果您正苦于以下问题:PHP AbstractPlatform::getPreAlterTableIndexForeignKeySQL方法的具体用法?PHP AbstractPlatform::getPreAlterTableIndexForeignKeySQL怎么用?PHP AbstractPlatform::getPreAlterTableIndexForeignKeySQL使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\DBAL\Platforms\AbstractPlatform
的用法示例。
在下文中一共展示了AbstractPlatform::getPreAlterTableIndexForeignKeySQL方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getPreAlterTableIndexForeignKeySQL
/**
* {@inheritDoc}
*/
protected function getPreAlterTableIndexForeignKeySQL(TableDiff $diff)
{
$sql = array();
$table = $diff->name;
foreach ($diff->removedIndexes as $remKey => $remIndex) {
foreach ($diff->addedIndexes as $addKey => $addIndex) {
if ($remIndex->getColumns() == $addIndex->getColumns()) {
$type = '';
if ($addIndex->isUnique()) {
$type = 'UNIQUE ';
}
$query = 'ALTER TABLE ' . $table . ' DROP INDEX ' . $remIndex->getName() . ', ';
$query .= 'ADD ' . $type . 'INDEX ' . $addIndex->getName();
$query .= ' (' . $this->getIndexFieldDeclarationListSQL($addIndex->getQuotedColumns($this)) . ')';
$sql[] = $query;
unset($diff->removedIndexes[$remKey]);
unset($diff->addedIndexes[$addKey]);
break;
}
}
}
$sql = array_merge($sql, parent::getPreAlterTableIndexForeignKeySQL($diff));
return $sql;
}
示例2: getPreAlterTableIndexForeignKeySQL
/**
* {@inheritDoc}
*/
protected function getPreAlterTableIndexForeignKeySQL(TableDiff $diff)
{
$sql = array();
$table = $diff->getName()->getQuotedName($this);
foreach ($diff->removedIndexes as $remKey => $remIndex) {
// Dropping primary keys requires to unset autoincrement attribute on the particular column first.
if ($remIndex->isPrimary() && $diff->fromTable instanceof Table) {
foreach ($remIndex->getColumns() as $columnName) {
$column = $diff->fromTable->getColumn($columnName);
if ($column->getAutoincrement() === true) {
$column->setAutoincrement(false);
$sql[] = 'ALTER TABLE ' . $table . ' MODIFY ' . $this->getColumnDeclarationSQL($column->getQuotedName($this), $column->toArray());
}
}
}
foreach ($diff->addedIndexes as $addKey => $addIndex) {
if ($remIndex->getColumns() == $addIndex->getColumns()) {
$indexClause = 'INDEX ' . $addIndex->getName();
if ($addIndex->isPrimary()) {
$indexClause = 'PRIMARY KEY';
} elseif ($addIndex->isUnique()) {
$indexClause = 'UNIQUE INDEX ' . $addIndex->getName();
}
$query = 'ALTER TABLE ' . $table . ' DROP INDEX ' . $remIndex->getName() . ', ';
$query .= 'ADD ' . $indexClause;
$query .= ' (' . $this->getIndexFieldDeclarationListSQL($addIndex->getQuotedColumns($this)) . ')';
$sql[] = $query;
unset($diff->removedIndexes[$remKey]);
unset($diff->addedIndexes[$addKey]);
break;
}
}
}
$engine = 'INNODB';
if ($diff->fromTable instanceof Table && $diff->fromTable->hasOption('engine')) {
$engine = strtoupper(trim($diff->fromTable->getOption('engine')));
}
// Suppress foreign key constraint propagation on non-supporting engines.
if ('INNODB' !== $engine) {
$diff->addedForeignKeys = array();
$diff->changedForeignKeys = array();
$diff->removedForeignKeys = array();
}
$sql = array_merge($sql, parent::getPreAlterTableIndexForeignKeySQL($diff));
return $sql;
}
示例3: getPreAlterTableIndexForeignKeySQL
/**
* {@inheritDoc}
*/
protected function getPreAlterTableIndexForeignKeySQL(TableDiff $diff)
{
$sql = array();
$table = $diff->getName($this)->getQuotedName($this);
foreach ($diff->removedIndexes as $remKey => $remIndex) {
foreach ($diff->addedIndexes as $addKey => $addIndex) {
if ($remIndex->getColumns() == $addIndex->getColumns()) {
if ($remIndex->isPrimary()) {
$sql[] = 'ALTER TABLE ' . $table . ' DROP PRIMARY KEY';
} elseif ($remIndex->isUnique()) {
$sql[] = 'ALTER TABLE ' . $table . ' DROP UNIQUE ' . $remIndex->getQuotedName($this);
} else {
$sql[] = $this->getDropIndexSQL($remIndex, $table);
}
$sql[] = $this->getCreateIndexSQL($addIndex, $table);
unset($diff->removedIndexes[$remKey]);
unset($diff->addedIndexes[$addKey]);
break;
}
}
}
$sql = array_merge($sql, parent::getPreAlterTableIndexForeignKeySQL($diff));
return $sql;
}
示例4: getPreAlterTableIndexForeignKeySQL
/**
* {@inheritDoc}
*/
protected function getPreAlterTableIndexForeignKeySQL(TableDiff $diff)
{
$sql = array();
$table = $diff->getName($this)->getQuotedName($this);
foreach ($diff->changedIndexes as $changedIndex) {
$sql = array_merge($sql, $this->getPreAlterTableAlterPrimaryKeySQL($diff, $changedIndex));
}
foreach ($diff->removedIndexes as $remKey => $remIndex) {
$sql = array_merge($sql, $this->getPreAlterTableAlterPrimaryKeySQL($diff, $remIndex));
foreach ($diff->addedIndexes as $addKey => $addIndex) {
if ($remIndex->getColumns() == $addIndex->getColumns()) {
$indexClause = 'INDEX ' . $addIndex->getName();
if ($addIndex->isPrimary()) {
$indexClause = 'PRIMARY KEY';
} elseif ($addIndex->isUnique()) {
$indexClause = 'UNIQUE INDEX ' . $addIndex->getName();
}
$query = 'ALTER TABLE ' . $table . ' DROP INDEX ' . $remIndex->getName() . ', ';
$query .= 'ADD ' . $indexClause;
$query .= ' (' . $this->getIndexFieldDeclarationListSQL($addIndex->getQuotedColumns($this)) . ')';
$sql[] = $query;
unset($diff->removedIndexes[$remKey]);
unset($diff->addedIndexes[$addKey]);
break;
}
}
}
$engine = 'INNODB';
if ($diff->fromTable instanceof Table && $diff->fromTable->hasOption('engine')) {
$engine = strtoupper(trim($diff->fromTable->getOption('engine')));
}
// Suppress foreign key constraint propagation on non-supporting engines.
if ('INNODB' !== $engine) {
$diff->addedForeignKeys = array();
$diff->changedForeignKeys = array();
$diff->removedForeignKeys = array();
}
$sql = array_merge($sql, $this->getPreAlterTableAlterIndexForeignKeySQL($diff), parent::getPreAlterTableIndexForeignKeySQL($diff), $this->getPreAlterTableRenameIndexForeignKeySQL($diff));
return $sql;
}
示例5: getPreAlterTableIndexForeignKeySQL
/**
* {@inheritDoc}
*/
protected function getPreAlterTableIndexForeignKeySQL(TableDiff $diff)
{
$sql = array();
$table = $diff->name;
foreach ($diff->changedIndexes as $changedKey => $changedIndex) {
$sql[] = $this->getDropConstraintSQL('IF EXISTS ' . $changedIndex->getName(), $table);
$sql[] = $this->getDropIndexSQL('IF EXISTS ' . $changedIndex->getName(), $table);
$diff->addedIndexes[$changedKey] = $diff->changedIndexes[$changedKey];
unset($diff->changedIndexes[$changedKey]);
}
$sql = array_merge($sql, parent::getPreAlterTableIndexForeignKeySQL($diff));
return $sql;
}
示例6: getPreAlterTableIndexForeignKeySQL
/**
* {@inheritDoc}
*/
protected function getPreAlterTableIndexForeignKeySQL(TableDiff $diff)
{
$sql = array();
$table = $diff->name;
foreach ($diff->removedIndexes as $remKey => $remIndex) {
// Dropping primary keys requires to unset autoincrement attribute on the particular column first.
if ($remIndex->isPrimary() && $diff->fromTable instanceof Table) {
foreach ($remIndex->getColumns() as $columnName) {
$column = $diff->fromTable->getColumn($columnName);
if ($column->getAutoincrement() === true) {
$column->setAutoincrement(false);
$sql[] = 'ALTER TABLE ' . $table . ' MODIFY ' . $this->getColumnDeclarationSQL($column->getQuotedName($this), $column->toArray());
// original autoincrement information might be needed later on by other parts of the table alteration
$column->setAutoincrement(true);
}
}
}
foreach ($diff->addedIndexes as $addKey => $addIndex) {
if ($remIndex->getColumns() == $addIndex->getColumns()) {
$indexClause = 'INDEX ' . $addIndex->getName();
if ($addIndex->isPrimary()) {
$indexClause = 'PRIMARY KEY';
} elseif ($addIndex->isUnique()) {
$indexClause = 'UNIQUE INDEX ' . $addIndex->getName();
}
$query = 'ALTER TABLE ' . $table . ' DROP INDEX ' . $remIndex->getName() . ', ';
$query .= 'ADD ' . $indexClause;
$query .= ' (' . $this->getIndexFieldDeclarationListSQL($addIndex->getQuotedColumns($this)) . ')';
$sql[] = $query;
unset($diff->removedIndexes[$remKey]);
unset($diff->addedIndexes[$addKey]);
break;
}
}
}
$sql = array_merge($sql, $this->getPreAlterTableAlterIndexForeignKeySQL($diff), parent::getPreAlterTableIndexForeignKeySQL($diff));
return $sql;
}
示例7: getPreAlterTableIndexForeignKeySQL
/**
* {@inheritDoc}
*/
protected function getPreAlterTableIndexForeignKeySQL(TableDiff $diff)
{
$sql = array();
$table = $diff->name;
foreach ($diff->removedIndexes as $remKey => $remIndex) {
foreach ($diff->addedIndexes as $addKey => $addIndex) {
if ($remIndex->getColumns() == $addIndex->getColumns()) {
$columns = $addIndex->getColumns();
$type = '';
if ($addIndex->isUnique()) {
$type = 'UNIQUE ';
}
$query = 'ALTER TABLE ' . $table . ' DROP INDEX ' . $remIndex->getName() . ', ';
$query .= 'ADD ' . $type . 'INDEX ' . $addIndex->getName();
$query .= ' (' . $this->getIndexFieldDeclarationListSQL($columns) . ')';
$sql[] = $query;
unset($diff->removedIndexes[$remKey]);
unset($diff->addedIndexes[$addKey]);
break;
}
}
}
foreach ($diff->changedIndexes as $changedKey => $changedIndex) {
if ($changedIndex->isPrimary() && $changedKey != 'PRIMARY') {
$index = $diff->changedIndexes[$changedKey];
$index = new index($changedKey, $index->getColumns(), $index->isUnique(), false);
$diff->removedIndexes[$changedKey] = $index;
$diff->addedIndexes['PRIMARY'] = $diff->changedIndexes[$changedKey];
unset($diff->changedIndexes[$changedKey]);
}
}
$sql = array_merge($sql, parent::getPreAlterTableIndexForeignKeySQL($diff));
return $sql;
}