Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix sqlite autoincrement detection #515

Merged
merged 2 commits into from
Feb 8, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/Doctrine/DBAL/Schema/SqliteSchemaManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ protected function _getPortableTableColumnList($table, $database, $tableColumns)
$autoincrementColumn = null;
$autoincrementCount = 0;
foreach ($tableColumns as $tableColumn) {
if ('1' == $tableColumn['pk']) {
if ('0' != $tableColumn['pk']) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does the magic 0 stand for here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Ocramius This number indicates the 1-based ordinal position in the PK index when retrieving the data with the PRAGMA statement. PK columns have a value > 0, all other columns have 0. http://www.sqlite.org/pragma.html#pragma_table_info

$autoincrementCount++;
if (null === $autoincrementColumn && 'integer' == strtolower($tableColumn['type'])) {
$autoincrementColumn = $tableColumn['name'];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,28 @@ public function testAutoincrementDetection()
$this->assertTrue($inferredTable->getColumn('id')->getAutoincrement());
}

/**
* @group DBAL-792
*/
public function testAutoincrementDetectionMulticolumns()
{
if (!$this->_sm->getDatabasePlatform()->supportsIdentityColumns()) {
$this->markTestSkipped('This test is only supported on platforms that have autoincrement');
}

$table = new \Doctrine\DBAL\Schema\Table('test_not_autoincrement');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Create a new test method instead (with @group DBAL-792)

$table->setSchemaConfig($this->_sm->createSchemaConfig());
$table->addColumn('id', 'integer');
$table->addColumn('other_id', 'integer');
$table->setPrimaryKey(array('id', 'other_id'));

$this->_sm->createTable($table);

$inferredTable = $this->_sm->listTableDetails('test_not_autoincrement');
$this->assertTrue($inferredTable->hasColumn('id'));
$this->assertFalse($inferredTable->getColumn('id')->getAutoincrement());
}

/**
* @group DDC-887
*/
Expand Down