Commit 356b5291 authored by Steve Müller's avatar Steve Müller

apply reserved keyword as index name test case for all platforms

parent 083c80fb
...@@ -26,20 +26,6 @@ abstract class AbstractMySQLPlatformTestCase extends AbstractPlatformTestCase ...@@ -26,20 +26,6 @@ abstract class AbstractMySQLPlatformTestCase extends AbstractPlatformTestCase
$this->assertEquals('CREATE TABLE Foo (Bar INT NOT NULL) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB', array_shift($sql)); $this->assertEquals('CREATE TABLE Foo (Bar INT NOT NULL) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB', array_shift($sql));
} }
public function testReservedKeywordInIndexGeneratedTableSql()
{
$table = new Table("Foo");
$table->addColumn("user_name", "string");
$table->addColumn("last_login", "date");
$table->addIndex(array('user_name', 'last_login'), 'key');
$sql = $this->_platform->getCreateTableSQL($table);
$this->assertEquals(
'CREATE TABLE Foo (user_name VARCHAR(255) NOT NULL, last_login DATE NOT NULL, INDEX `key` (user_name, last_login)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB',
array_shift($sql)
);
}
public function getGenerateTableSql() public function getGenerateTableSql()
{ {
return 'CREATE TABLE test (id INT AUTO_INCREMENT NOT NULL, test VARCHAR(255) DEFAULT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB'; return 'CREATE TABLE test (id INT AUTO_INCREMENT NOT NULL, test VARCHAR(255) DEFAULT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB';
...@@ -655,4 +641,20 @@ abstract class AbstractMySQLPlatformTestCase extends AbstractPlatformTestCase ...@@ -655,4 +641,20 @@ abstract class AbstractMySQLPlatformTestCase extends AbstractPlatformTestCase
"COMMENT ON COLUMN `select`.`from` IS 'comment'", "COMMENT ON COLUMN `select`.`from` IS 'comment'",
); );
} }
/**
* {@inheritdoc}
*/
protected function getQuotesReservedKeywordInUniqueConstraintDeclarationSQL()
{
return 'CONSTRAINT `select` UNIQUE (foo)';
}
/**
* {@inheritdoc}
*/
protected function getQuotesReservedKeywordInIndexDeclarationSQL()
{
return 'INDEX `select` (foo)';
}
} }
...@@ -167,12 +167,17 @@ abstract class AbstractPlatformTestCase extends \Doctrine\Tests\DbalTestCase ...@@ -167,12 +167,17 @@ abstract class AbstractPlatformTestCase extends \Doctrine\Tests\DbalTestCase
{ {
$where = 'test IS NULL AND test2 IS NOT NULL'; $where = 'test IS NULL AND test2 IS NOT NULL';
$indexDef = new \Doctrine\DBAL\Schema\Index('name', array('test', 'test2'), false, false, array(), array('where' => $where)); $indexDef = new \Doctrine\DBAL\Schema\Index('name', array('test', 'test2'), false, false, array(), array('where' => $where));
$uniqueIndex = new \Doctrine\DBAL\Schema\Index('name', array('test', 'test2'), true, false, array(), array('where' => $where));
$expected = ' WHERE ' . $where; $expected = ' WHERE ' . $where;
$actuals = array(); $actuals = array();
$actuals []= $this->_platform->getIndexDeclarationSQL('name', $indexDef);
$actuals []= $this->_platform->getUniqueConstraintDeclarationSQL('name', $indexDef); if ($this->supportsInlineIndexDeclaration()) {
$actuals []= $this->_platform->getIndexDeclarationSQL('name', $indexDef);
}
$actuals []= $this->_platform->getUniqueConstraintDeclarationSQL('name', $uniqueIndex);
$actuals []= $this->_platform->getCreateIndexSQL($indexDef, 'table'); $actuals []= $this->_platform->getCreateIndexSQL($indexDef, 'table');
foreach ($actuals as $actual) { foreach ($actuals as $actual) {
...@@ -587,6 +592,54 @@ abstract class AbstractPlatformTestCase extends \Doctrine\Tests\DbalTestCase ...@@ -587,6 +592,54 @@ abstract class AbstractPlatformTestCase extends \Doctrine\Tests\DbalTestCase
$this->assertEquals($this->getQuotedColumnInForeignKeySQL(), $sql); $this->assertEquals($this->getQuotedColumnInForeignKeySQL(), $sql);
} }
/**
* @group DBAL-1051
*/
public function testQuotesReservedKeywordInUniqueConstraintDeclarationSQL()
{
$index = new Index('select', array('foo'), true);
$this->assertSame(
$this->getQuotesReservedKeywordInUniqueConstraintDeclarationSQL(),
$this->_platform->getUniqueConstraintDeclarationSQL('select', $index)
);
}
/**
* @return string
*/
abstract protected function getQuotesReservedKeywordInUniqueConstraintDeclarationSQL();
/**
* @group DBAL-1051
*/
public function testQuotesReservedKeywordInIndexDeclarationSQL()
{
$index = new Index('select', array('foo'));
if (! $this->supportsInlineIndexDeclaration()) {
$this->setExpectedException('Doctrine\DBAL\DBALException');
}
$this->assertSame(
$this->getQuotesReservedKeywordInIndexDeclarationSQL(),
$this->_platform->getIndexDeclarationSQL('select', $index)
);
}
/**
* @return string
*/
abstract protected function getQuotesReservedKeywordInIndexDeclarationSQL();
/**
* @return boolean
*/
protected function supportsInlineIndexDeclaration()
{
return true;
}
/** /**
* @expectedException \Doctrine\DBAL\DBALException * @expectedException \Doctrine\DBAL\DBALException
*/ */
......
...@@ -739,4 +739,20 @@ abstract class AbstractPostgreSqlPlatformTestCase extends AbstractPlatformTestCa ...@@ -739,4 +739,20 @@ abstract class AbstractPostgreSqlPlatformTestCase extends AbstractPlatformTestCa
$this->_platform->getAlterTableSQL($tableDiff) $this->_platform->getAlterTableSQL($tableDiff)
); );
} }
/**
* {@inheritdoc}
*/
protected function getQuotesReservedKeywordInUniqueConstraintDeclarationSQL()
{
return 'CONSTRAINT "select" UNIQUE (foo)';
}
/**
* {@inheritdoc}
*/
protected function getQuotesReservedKeywordInIndexDeclarationSQL()
{
return 'INDEX "select" (foo)';
}
} }
...@@ -1186,4 +1186,20 @@ abstract class AbstractSQLServerPlatformTestCase extends AbstractPlatformTestCas ...@@ -1186,4 +1186,20 @@ abstract class AbstractSQLServerPlatformTestCase extends AbstractPlatformTestCas
array('CaScAdE', 'CASCADE'), array('CaScAdE', 'CASCADE'),
); );
} }
/**
* {@inheritdoc}
*/
protected function getQuotesReservedKeywordInUniqueConstraintDeclarationSQL()
{
return 'CONSTRAINT [select] UNIQUE (foo) WHERE foo IS NOT NULL';
}
/**
* {@inheritdoc}
*/
protected function getQuotesReservedKeywordInIndexDeclarationSQL()
{
return 'INDEX [select] (foo)';
}
} }
...@@ -615,4 +615,28 @@ class DB2PlatformTest extends AbstractPlatformTestCase ...@@ -615,4 +615,28 @@ class DB2PlatformTest extends AbstractPlatformTestCase
), ),
); );
} }
/**
* {@inheritdoc}
*/
protected function getQuotesReservedKeywordInUniqueConstraintDeclarationSQL()
{
return 'CONSTRAINT "select" UNIQUE (foo)';
}
/**
* {@inheritdoc}
*/
protected function getQuotesReservedKeywordInIndexDeclarationSQL()
{
return ''; // not supported by this platform
}
/**
* {@inheritdoc}
*/
protected function supportsInlineIndexDeclaration()
{
return false;
}
} }
...@@ -642,4 +642,20 @@ EOD; ...@@ -642,4 +642,20 @@ EOD;
$this->assertEquals($createTriggerStatement, $sql[3]); $this->assertEquals($createTriggerStatement, $sql[3]);
} }
/**
* {@inheritdoc}
*/
protected function getQuotesReservedKeywordInUniqueConstraintDeclarationSQL()
{
return 'CONSTRAINT "select" UNIQUE (foo)';
}
/**
* {@inheritdoc}
*/
protected function getQuotesReservedKeywordInIndexDeclarationSQL()
{
return 'INDEX "select" (foo)';
}
} }
...@@ -817,11 +817,6 @@ class SQLAnywherePlatformTest extends AbstractPlatformTestCase ...@@ -817,11 +817,6 @@ class SQLAnywherePlatformTest extends AbstractPlatformTestCase
); );
} }
public function testGeneratesPartialIndexesSqlOnlyWhenSupportingPartialIndexes()
{
$this->markTestSkipped('Index declaration in statements like CREATE TABLE is not supported.');
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
...@@ -932,4 +927,28 @@ class SQLAnywherePlatformTest extends AbstractPlatformTestCase ...@@ -932,4 +927,28 @@ class SQLAnywherePlatformTest extends AbstractPlatformTestCase
array('CaScAdE', 'CASCADE'), array('CaScAdE', 'CASCADE'),
); );
} }
/**
* {@inheritdoc}
*/
protected function getQuotesReservedKeywordInUniqueConstraintDeclarationSQL()
{
return 'CONSTRAINT "select" UNIQUE (foo)';
}
/**
* {@inheritdoc}
*/
protected function getQuotesReservedKeywordInIndexDeclarationSQL()
{
return ''; // not supported by this platform
}
/**
* {@inheritdoc}
*/
protected function supportsInlineIndexDeclaration()
{
return false;
}
} }
...@@ -608,4 +608,20 @@ class SqlitePlatformTest extends AbstractPlatformTestCase ...@@ -608,4 +608,20 @@ class SqlitePlatformTest extends AbstractPlatformTestCase
'COMMENT ON COLUMN "select"."from" IS \'comment\'', 'COMMENT ON COLUMN "select"."from" IS \'comment\'',
); );
} }
/**
* {@inheritdoc}
*/
protected function getQuotesReservedKeywordInUniqueConstraintDeclarationSQL()
{
return 'CONSTRAINT "select" UNIQUE (foo)';
}
/**
* {@inheritdoc}
*/
protected function getQuotesReservedKeywordInIndexDeclarationSQL()
{
return 'INDEX "select" (foo)';
}
} }
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