diff --git a/lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php b/lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php index 8e9dbecbdd1..a554baa0090 100644 --- a/lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php +++ b/lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php @@ -893,7 +893,7 @@ public function getListTableIndexesSQL($table, $currentDatabase = null) JOIN sys.index_columns AS idxcol ON idx.object_id = idxcol.object_id AND idx.index_id = idxcol.index_id JOIN sys.columns AS col ON idxcol.object_id = col.object_id AND idxcol.column_id = col.column_id WHERE " . $this->getTableWhereClause($table, 'scm.name', 'tbl.name') . " - ORDER BY idx.index_id ASC, idxcol.index_column_id ASC"; + ORDER BY idx.index_id ASC, idxcol.key_ordinal ASC"; } /** diff --git a/tests/Doctrine/Tests/DBAL/ConnectionTest.php b/tests/Doctrine/Tests/DBAL/ConnectionTest.php index ae5a439646a..aa9f8e8b780 100644 --- a/tests/Doctrine/Tests/DBAL/ConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/ConnectionTest.php @@ -131,9 +131,7 @@ public function testEventManagerPassedToPlatform() */ public function testDriverExceptionIsWrapped($method) { - $this->setExpectedException('Doctrine\DBAL\DBALException', "An exception occurred while executing 'MUUHAAAAHAAAA': - -SQLSTATE[HY000]: General error: 1 near \"MUUHAAAAHAAAA\""); + $this->setExpectedException('Doctrine\DBAL\DBALException', "An exception occurred while executing 'MUUHAAAAHAAAA':\n\nSQLSTATE[HY000]: General error: 1 near \"MUUHAAAAHAAAA\""); $con = \Doctrine\DBAL\DriverManager::getConnection(array( 'driver' => 'pdo_sqlite', diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/SQLServerSchemaManagerTest.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/SQLServerSchemaManagerTest.php index 948d0c0c642..da51840c73a 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Schema/SQLServerSchemaManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Schema/SQLServerSchemaManagerTest.php @@ -329,4 +329,30 @@ public function testColumnComments() $this->assertNull($columns['added_commented_type']->getComment()); $this->assertEquals('666', $columns['added_commented_type_with_comment']->getComment()); } + + 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(array('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]); + } } diff --git a/tests/Doctrine/Tests/DBAL/SQLParserUtilsTest.php b/tests/Doctrine/Tests/DBAL/SQLParserUtilsTest.php index d3b9fe73b47..05e71454928 100644 --- a/tests/Doctrine/Tests/DBAL/SQLParserUtilsTest.php +++ b/tests/Doctrine/Tests/DBAL/SQLParserUtilsTest.php @@ -38,13 +38,7 @@ public function dataGetPlaceholderPositions() array('SELECT "Doctrine\DBAL?" FROM foo WHERE bar = ?', true, array(45)), // Ticket DBAL-558 array('SELECT `Doctrine\DBAL?` FROM foo WHERE bar = ?', true, array(45)), // Ticket DBAL-558 array('SELECT [Doctrine\DBAL?] FROM foo WHERE bar = ?', true, array(45)), // Ticket DBAL-558 - array( -<<<'SQLDATA' -SELECT * FROM foo WHERE bar = 'it\'s a trap? \\' OR bar = ? -AND baz = "\"quote\" me on it? \\" OR baz = ? -SQLDATA - , true, array(58, 104) - ), + array("SELECT * FROM FOO WHERE bar = 'it\\'s a trap? \\\\' OR bar = ?\nAND baz = \"\\\"quote\\\" me on it? \\\\\" OR baz = ?", true, array(58, 104)), array('SELECT * FROM foo WHERE foo = ? AND bar = ?', true, array(1 => 42, 0 => 30)), // explicit keys // named