Skip to content

Commit

Permalink
Merge pull request #759 from deeky666/fix-sql-anywhere-index-introspe…
Browse files Browse the repository at this point in the history
…ction

[DBAL-1095] Fix index introspection on SQL Anywhere
  • Loading branch information
Ocramius committed Dec 28, 2014
2 parents dde863a + 7d1b5a6 commit aea8383
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/Doctrine/DBAL/Platforms/SQLAnywherePlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -891,6 +891,7 @@ public function getListTableIndexesSQL($table, $currentDatabase = null)
ON idx.table_id = tbl.table_id
WHERE tbl.table_name = '$table'
AND tbl.creator = USER_ID($user)
AND idx.index_category != 2 -- exclude indexes implicitly created by foreign key constraints
ORDER BY idx.index_id ASC, idxcol.sequence ASC";
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -995,4 +995,34 @@ public function getAlterColumnComment()
array('0', '0', 'foo', 'foo'),
);
}

/**
* @group DBAL-1095
*/
public function testDoesNotListIndexesImplicitlyCreatedByForeignKeys()
{
if (! $this->_sm->getDatabasePlatform()->supportsForeignKeyConstraints()) {
$this->markTestSkipped('This test is only supported on platforms that have foreign keys.');
}

$primaryTable = new Table('test_list_index_implicit_primary');
$primaryTable->addColumn('id', 'integer');
$primaryTable->setPrimaryKey(array('id'));

$foreignTable = new Table('test_list_index_implicit_foreign');
$foreignTable->addColumn('fk1', 'integer');
$foreignTable->addColumn('fk2', 'integer');
$foreignTable->addIndex(array('fk1'), 'explicit_fk1_idx');
$foreignTable->addForeignKeyConstraint('test_list_index_implicit_primary', array('fk1'), array('id'));
$foreignTable->addForeignKeyConstraint('test_list_index_implicit_primary', array('fk2'), array('id'));

$this->_sm->dropAndCreateTable($primaryTable);
$this->_sm->dropAndCreateTable($foreignTable);

$indexes = $this->_sm->listTableIndexes('test_list_index_implicit_foreign');

$this->assertCount(2, $indexes);
$this->assertArrayHasKey('explicit_fk1_idx', $indexes);
$this->assertArrayHasKey('idx_6d88c7b4fdc58d6c', $indexes);
}
}

0 comments on commit aea8383

Please sign in to comment.