Commit ad6b0cca authored by Benjamin Eberlei's avatar Benjamin Eberlei

DBAL-126 - Special case for dropping MySQL Primary keys

parent 5cba1ea7
......@@ -20,7 +20,9 @@
namespace Doctrine\DBAL\Platforms;
use Doctrine\DBAL\DBALException,
Doctrine\DBAL\Schema\TableDiff;
Doctrine\DBAL\Schema\TableDiff,
Doctrine\DBAL\Schema\Index,
Doctrine\DBAL\Schema\Table;
/**
* The MySqlPlatform provides the behavior, features and SQL dialect of the
......@@ -523,20 +525,37 @@ class MySqlPlatform extends AbstractPlatform
* @override
*/
public function getDropIndexSQL($index, $table=null)
{
if($index instanceof \Doctrine\DBAL\Schema\Index) {
$index = $index->getQuotedName($this);
} else if(!is_string($index)) {
{
if($index instanceof Index) {
$indexName = $index->getQuotedName($this);
} else if(is_string($index)) {
$indexName = $index;
} else {
throw new \InvalidArgumentException('MysqlPlatform::getDropIndexSQL() expects $index parameter to be string or \Doctrine\DBAL\Schema\Index.');
}
if($table instanceof \Doctrine\DBAL\Schema\Table) {
if($table instanceof Table) {
$table = $table->getQuotedName($this);
} else if(!is_string($table)) {
throw new \InvalidArgumentException('MysqlPlatform::getDropIndexSQL() expects $table parameter to be string or \Doctrine\DBAL\Schema\Table.');
}
if ($index instanceof Index && $index->isPrimary()) {
// mysql primary keys are always named "PRIMARY",
// so we cannot use them in statements because of them being keyword.
return $this->getDropPrimaryKeySQL($table);
}
return 'DROP INDEX ' . $index . ' ON ' . $table;
return 'DROP INDEX ' . $indexName . ' ON ' . $table;
}
/**
* @param Index $index
* @param Table $table
*/
protected function getDropPrimaryKeySQL($table)
{
return 'ALTER TABLE ' . $table . ' DROP PRIMARY KEY';
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment