Skip to content

Commit

Permalink
Merge pull request #528 from doctrine/hotfix/sqlite-auto-increment
Browse files Browse the repository at this point in the history
Applying patch suggested by @guilhermeblanco for SQLite's auto-inc integer PKs
  • Loading branch information
guilhermeblanco committed Feb 14, 2014
2 parents 594e326 + 5523678 commit da43b76
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/Doctrine/DBAL/Platforms/SqlitePlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,11 @@ public function getTimeTypeDeclarationSQL(array $fieldDeclaration)
*/
protected function _getCommonIntegerTypeDeclarationSQL(array $columnDef)
{
// sqlite autoincrement is implicit for integer PKs, but not when the field is unsigned
if ( ! empty($columnDef['autoincrement'])) {
return '';
}

return ! empty($columnDef['unsigned']) ? ' UNSIGNED' : '';
}

Expand Down
8 changes: 8 additions & 0 deletions tests/Doctrine/Tests/DBAL/Platforms/SqlitePlatformTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,14 @@ public function testPrefersIdentityColumns()
$this->assertTrue($this->_platform->prefersIdentityColumns());
}

public function testIgnoresUnsignedIntegerDeclarationForAutoIncrementalIntegers()
{
$this->assertSame(
'INTEGER',
$this->_platform->getIntegerTypeDeclarationSQL(array('autoincrement' => true, 'unsigned' => true))
);
}

/**
* @group DBAL-752
*/
Expand Down

0 comments on commit da43b76

Please sign in to comment.