Commit 99a6b53d authored by Bill Schaller's avatar Bill Schaller Committed by Steve Müller

Add test for correct index column ordering on clustered indexes

parent 6f307161
......@@ -164,4 +164,30 @@ class SQLServerSchemaManagerTest extends SchemaManagerFunctionalTestCase
$this->assertNull($columns['df_current_timestamp']->getDefault());
$this->assertEquals(666, $columns['df_integer']->getDefault());
}
public function testPkOrdering()
{
// SQL Server stores index column information in a system table with two
// columns that almost always have the same value: index_column_id and key_ordinal.
// The only situation when the two values doesn't match up is when a clustered index
// is declared that references columns in a different order from which they are
// declared in the table. In that case, key_ordinal != index_column_id.
// key_ordinal holds the index ordering. index_column_id is just a unique identifier
// for index columns within the given index.
$table = new Table('sqlsrv_pk_ordering');
$table->addColumn('colA', 'integer', array('notnull' => true));
$table->addColumn('colB', 'integer', array('notnull' => true));
$table->setPrimaryKey(['colB', 'colA']);
$this->_sm->createTable($table);
$indexes = $this->_sm->listTableIndexes('sqlsrv_pk_ordering');
$this->assertCount(1, $indexes);
$firstIndex = current($indexes);
$columns = $firstIndex->getColumns();
$this->assertCount(2, $columns);
$this->assertEquals('colB', $columns[0]);
$this->assertEquals('colA', $columns[1]);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment