function toDialectString(IDialect $dialect) { $table = $dialect->quoteIdentifier($this->constraint->getTable()->getName()); $ct = $dialect->quoteIdentifier($this->constraint->getName()); if ($dialect->getDBDriver()->is(DBDriver::MYSQL)) { if ($this->constraint instanceof DBUniqueConstraint) { return 'ALTER TABLE ' . $table . ' DROP INDEX ' . $ct; } else { if ($this->constraint instanceof DBPrimaryKeyConstraint) { return 'ALTER TABLE ' . $table . ' DROP PRIMARY KEY'; } else { if ($this->constraint instanceof DBOneToOneConstraint || $this->constraint instanceof DBForeignKeyConstraint) { return 'ALTER TABLE ' . $table . ' DROP FOREIGN KEY ' . $ct; } } } Assert::isUnreachable('Do not know how to remove constraint %s from MySQL', get_class($this->constraint)); } return 'ALTER TABLE ' . $table . ' DROP CONSTRAINT ' . $ct . ' CASCADE;'; }
/** * Adds a table constraint * * @param DBConstraint $constraint constraint to add * @throws DuplicationException thrown when another constaint with the same name already added * @return DBTable itself */ function addConstraint(DBConstraint $constraint) { $name = $constraint->getName(); if ($name) { if (isset($this->constraints[$name])) { throw new DuplicationException('constraint', $name); } } else { $name = 'constraint_' . $this->name . '_' . (sizeof($this->constraints) + 1); $constraint->setName($name); } $this->constraints[$name] = $constraint; return $this; }
/** * Adds a table constraint * * @param DBConstraint $constraint constraint to add * @throws DuplicationException thrown when another constaint with the same name already added * @return DBTable itself */ function addConstraint(DBConstraint $constraint) { $name = $constraint->getName(); if ($name) { if (isset($this->constraints[$name])) { throw new DuplicationException('constraint', $name); } } else { $name = 'constraint_' . join('_', $constraint->getFields()) . (sizeof($this->constraints) + 1); $constraint->setName($name); } $this->constraints[$name] = $constraint; if ($constraint instanceof DBPrimaryKeyConstraint) { if ($this->pk) { throw new DuplicationException('constraint', $name); } $this->pk = $constraint; } return $this; }