Permalink
Browse files

Added detection of autoincrement column to Sqlite schema

  • Loading branch information...
1 parent 38bd069 commit 33555d36e7e7d07a5880e01e03fb23a2314e450b @hason hason committed Oct 20, 2012
View
25 lib/Doctrine/DBAL/Schema/SqliteSchemaManager.php
@@ -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)
{
$e = explode('(', $tableColumn['type']);
View
10 tests/Doctrine/Tests/DBAL/Functional/Schema/SqliteSchemaManagerTest.php
@@ -38,11 +38,11 @@ public function testRenameTable()
$this->assertNotContains('oldname', $tables);
}
- public function testAutoincrementDetection()
+ public function createListTableColumns()
{
- $this->markTestSkipped(
- 'There is currently no reliable way to determine whether an SQLite column is marked as '
- . 'auto-increment. So, while it does support a single identity column, we cannot with '
- . 'certainty determine which it is.');
+ $table = parent::createListTableColumns();
+ $table->getColumn('id')->setAutoincrement(true);
+
+ return $table;
}
}

0 comments on commit 33555d3

Please sign in to comment.