Skip to content

Commit

Permalink
Merge upstream
Browse files Browse the repository at this point in the history
  • Loading branch information
beberlei committed Dec 22, 2013
2 parents c40a24f + d284525 commit ba4ab89
Show file tree
Hide file tree
Showing 6 changed files with 114 additions and 2 deletions.
31 changes: 31 additions & 0 deletions lib/Doctrine/DBAL/Platforms/AbstractPlatform.php
Expand Up @@ -2618,6 +2618,37 @@ public function supportsIdentityColumns()
return false;
}

/**
* Whether the platform emulates identity columns through sequences.
*
* Some platforms that do not support identity columns natively
* but support sequences can emulate identity columns by using
* sequences.
*
* @return boolean
*/
public function usesSequenceEmulatedIdentityColumns()
{
return false;
}

/**
* Returns the name of the sequence for a particular identity column in a particular table.
*
* @param string $tableName The name of the table to return the sequence name for.
* @param string $columnName The name of the identity column in the table to return the sequence name for.
*
* @return string
*
* @throws \Doctrine\DBAL\DBALException If not supported on this platform.
*
* @see usesSequenceEmulatedIdentityColumns
*/
public function getIdentitySequenceName($tableName, $columnName)
{
throw DBALException::notSupported(__METHOD__);
}

/**
* Whether the platform supports indexes.
*
Expand Down
18 changes: 17 additions & 1 deletion lib/Doctrine/DBAL/Platforms/OraclePlatform.php
Expand Up @@ -448,7 +448,7 @@ public function getCreateAutoincrementSql($name, $table, $start = 1)
END IF;
END;';

$sequenceName = $table . '_' . $name . '_SEQ';
$sequenceName = $this->getIdentitySequenceName($table, $name);
$sequence = new Sequence($sequenceName, $start);
$sql[] = $this->getCreateSequenceSQL($sequence);

Expand Down Expand Up @@ -695,6 +695,22 @@ public function prefersSequences()
return true;
}

/**
* {@inheritdoc}
*/
public function usesSequenceEmulatedIdentityColumns()
{
return true;
}

/**
* {@inheritdoc}
*/
public function getIdentitySequenceName($tableName, $columnName)
{
return $tableName . '_' . $columnName . '_SEQ';
}

/**
* {@inheritDoc}
*/
Expand Down
18 changes: 17 additions & 1 deletion lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php
Expand Up @@ -180,6 +180,22 @@ public function supportsIdentityColumns()
return true;
}

/**
* {@inheritdoc}
*/
public function usesSequenceEmulatedIdentityColumns()
{
return true;
}

/**
* {@inheritdoc}
*/
public function getIdentitySequenceName($tableName, $columnName)
{
return $tableName . '_' . $columnName . '_seq';
}

/**
* {@inheritDoc}
*/
Expand Down Expand Up @@ -466,7 +482,7 @@ public function getAlterTableSQL(TableDiff $diff)
if ($columnDiff->hasChanged('autoincrement')) {
if ($column->getAutoincrement()) {
// add autoincrement
$seqName = $diff->name . '_' . $oldColumnName . '_seq';
$seqName = $this->getIdentitySequenceName($diff->name, $oldColumnName);

$sql[] = "CREATE SEQUENCE " . $seqName;
$sql[] = "SELECT setval('" . $seqName . "', (SELECT MAX(" . $oldColumnName . ") FROM " . $diff->getName()->getQuotedName($this) . "))";
Expand Down
17 changes: 17 additions & 0 deletions tests/Doctrine/Tests/DBAL/Platforms/AbstractPlatformTestCase.php
Expand Up @@ -530,4 +530,21 @@ public function testAlterTableChangeQuotedColumn()
implode(';', $this->_platform->getAlterTableSQL($tableDiff))
);
}

/**
* @group DBAL-563
*/
public function testUsesSequenceEmulatedIdentityColumns()
{
$this->assertFalse($this->_platform->usesSequenceEmulatedIdentityColumns());
}

/**
* @group DBAL-563
* @expectedException \Doctrine\DBAL\DBALException
*/
public function testReturnsIdentitySequenceName()
{
$this->_platform->getIdentitySequenceName('mytable', 'mycolumn');
}
}
16 changes: 16 additions & 0 deletions tests/Doctrine/Tests/DBAL/Platforms/OraclePlatformTest.php
Expand Up @@ -330,4 +330,20 @@ public function testAlterTableNotNULL()
);
$this->assertEquals($expectedSql, $this->_platform->getAlterTableSQL($tableDiff));
}

/**
* @group DBAL-563
*/
public function testUsesSequenceEmulatedIdentityColumns()
{
$this->assertTrue($this->_platform->usesSequenceEmulatedIdentityColumns());
}

/**
* @group DBAL-563
*/
public function testReturnsIdentitySequenceName()
{
$this->assertSame('mytable_mycolumn_SEQ', $this->_platform->getIdentitySequenceName('mytable', 'mycolumn'));
}
}
16 changes: 16 additions & 0 deletions tests/Doctrine/Tests/DBAL/Platforms/PostgreSqlPlatformTest.php
Expand Up @@ -410,4 +410,20 @@ public function testDroppingConstraintsBeforeColumns()

$this->assertEquals($expectedSql, $sql);
}

/**
* @group DBAL-563
*/
public function testUsesSequenceEmulatedIdentityColumns()
{
$this->assertTrue($this->_platform->usesSequenceEmulatedIdentityColumns());
}

/**
* @group DBAL-563
*/
public function testReturnsIdentitySequenceName()
{
$this->assertSame('mytable_mycolumn_seq', $this->_platform->getIdentitySequenceName('mytable', 'mycolumn'));
}
}

0 comments on commit ba4ab89

Please sign in to comment.