Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Restore SqlitePlatform#supportsForeignKeyConstraints (no lies!) #242

Merged
merged 3 commits into from

5 participants

@Ocramius
Owner

This PR applies a hotfix for broken behavior introduced in DBAL-370 (doctrine/dbal#220).

Basically, the SQLite platform lies about its ability to support foreign key constraint generation. This leads to various failures in the ORM schema tools.

In fact, the platform itself doesn't even generate the foreign key generation SQL, and instead throws a Doctrine\DBAL\DBALException (similar to "not implemented" in this particular case).
The PR introduces a failing test that exposes the (currently) missing feature in the platform and restores the return value of Doctrine\DBAL\Platforms\SqlitePlatform#supportsForeignKeyConstraints().

While SQLite 3.6.19 introduces support for Foreign keys, the DBAL platform still doesn't have it.

Ping @lsmith77 @hason

@doctrinebot
Collaborator

Hello,

thank you for positing this Pull Request. I have automatically opened an issue on our Jira Bug Tracker for you with the details of this Pull-Request. See the Link:

http://doctrine-project.org/jira/browse/DDC-1232

@hason

:+1: The #220 was WIP. I will continue on it.

@Ocramius
Owner

@hason I was just panicking because my CI environment was going bananas ;)

@beberlei beberlei merged commit e65517e into from
@zorang

New doctrine 2.3.3 version is available, and I waited a lot for that because i hoped that when create SQLite schema that FK-s will be created also! But not! FK-s are still not generated! Can anyone tell me why?! I know that it was implemented last year (2012) in some branch... What happened?! Its removed or what?! Its not supported in new 2.3.3 doctrine?!?!

Zoran

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
8 lib/Doctrine/DBAL/Platforms/SqlitePlatform.php
@@ -605,6 +605,14 @@ public function canEmulateSchemas()
/**
* {@inheritDoc}
*/
+ public function supportsForeignKeyConstraints()
+ {
+ return false;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
public function getCreatePrimaryKeySQL(Index $index, $table)
{
throw new DBALException('Sqlite platform does not support alter primary key.');
View
14 tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php
@@ -433,12 +433,14 @@ public function testAlterTableScenario()
// dont check for index size here, some platforms automatically add indexes for foreign keys.
$this->assertFalse($table->hasIndex('foo_idx'));
- $this->assertEquals(1, count($table->getForeignKeys()));
- $fks = $table->getForeignKeys();
- $foreignKey = current($fks);
- $this->assertEquals('alter_table_foreign', strtolower($foreignKey->getForeignTableName()));
- $this->assertEquals(array('foreign_key_test'), array_map('strtolower', $foreignKey->getColumns()));
- $this->assertEquals(array('id'), array_map('strtolower', $foreignKey->getForeignColumns()));
+ if ($this->_sm->getDatabasePlatform()->supportsForeignKeyConstraints()) {
+ $fks = $table->getForeignKeys();
+ $this->assertCount(1, $fks);
+ $foreignKey = current($fks);
+ $this->assertEquals('alter_table_foreign', strtolower($foreignKey->getForeignTableName()));
+ $this->assertEquals(array('foreign_key_test'), array_map('strtolower', $foreignKey->getColumns()));
+ $this->assertEquals(array('id'), array_map('strtolower', $foreignKey->getForeignColumns()));
+ }
}
public function testCreateAndListViews()
View
17 tests/Doctrine/Tests/DBAL/Platforms/AbstractPlatformTestCase.php
@@ -10,7 +10,7 @@
abstract class AbstractPlatformTestCase extends \Doctrine\Tests\DbalTestCase
{
/**
- * @var Doctrine\DBAL\Platforms\AbstractPlatform
+ * @var \Doctrine\DBAL\Platforms\AbstractPlatform
*/
protected $_platform;
@@ -156,6 +156,21 @@ public function testGeneratesConstraintCreationSql()
$this->assertEquals($this->getGenerateConstraintForeignKeySql(), $sql);
}
+ public function testGeneratesForeignKeySqlOnlyWhenSupportingForeignKeys()
+ {
+ $fk = new \Doctrine\DBAL\Schema\ForeignKeyConstraint(array('fk_name'), 'foreign', array('id'), 'constraint_fk');
+
+ if ($this->_platform->supportsForeignKeyConstraints()) {
+ $this->assertInternalType(
+ 'string',
+ $this->_platform->getCreateForeignKeySQL($fk, 'test')
+ );
+ } else {
+ $this->setExpectedException('Doctrine\DBAL\DBALException');
+ $this->_platform->getCreateForeignKeySQL($fk, 'test');
+ }
+ }
+
protected function getBitAndComparisonExpressionSql($value1, $value2)
{
return '(' . $value1 . ' & ' . $value2 . ')';
Something went wrong with that request. Please try again.