Skip to content

Commit

Permalink
Added detection of autoincrement column to Sqlite schema
Browse files Browse the repository at this point in the history
  • Loading branch information
hason committed Nov 19, 2012
1 parent 38bd069 commit 33555d3
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
25 changes: 25 additions & 0 deletions lib/Doctrine/DBAL/Schema/SqliteSchemaManager.php
Expand Up @@ -197,6 +197,31 @@ protected function _getPortableTableIndexDefinition($tableIndex)
); );
} }


protected function _getPortableTableColumnList($table, $database, $tableColumns)
{
$list = parent::_getPortableTableColumnList($table, $database, $tableColumns);
$autoincrementColumn = null;
$autoincrementCount = 0;
foreach ($tableColumns as $tableColumn) {
if ('1' == $tableColumn['pk']) {
$autoincrementCount++;
if (null === $autoincrementColumn && 'integer' == strtolower($tableColumn['type'])) {
$autoincrementColumn = $tableColumn['name'];
}
}
}

if (1 == $autoincrementCount && null !== $autoincrementColumn) {
foreach ($list as $column) {
if ($autoincrementColumn == $column->getName()) {
$column->setAutoincrement(true);
}
}
}

return $list;
}

protected function _getPortableTableColumnDefinition($tableColumn) protected function _getPortableTableColumnDefinition($tableColumn)
{ {
$e = explode('(', $tableColumn['type']); $e = explode('(', $tableColumn['type']);
Expand Down
Expand Up @@ -38,11 +38,11 @@ public function testRenameTable()
$this->assertNotContains('oldname', $tables); $this->assertNotContains('oldname', $tables);
} }


public function testAutoincrementDetection() public function createListTableColumns()
{ {
$this->markTestSkipped( $table = parent::createListTableColumns();
'There is currently no reliable way to determine whether an SQLite column is marked as ' $table->getColumn('id')->setAutoincrement(true);
. 'auto-increment. So, while it does support a single identity column, we cannot with '
. 'certainty determine which it is.'); return $table;
} }
} }

0 comments on commit 33555d3

Please sign in to comment.