Permalink
Browse files

ORDER BY removed from all count queries regardless of the platform

  • Loading branch information...
1 parent 6a7a625 commit 3d8e1149c65c22643a81ed967019a655cf2ffde5 Norbert Orzechowicz committed Feb 26, 2013
@@ -15,7 +15,6 @@
use Doctrine\ORM\Query\SqlWalker;
use Doctrine\ORM\Query\AST\SelectStatement;
-use Doctrine\DBAL\Platforms\SQLServerPlatform;
/**
* Wraps the query in order to accurately count the root objects.
@@ -80,13 +79,7 @@ public function __construct($query, $parserResult, array $queryComponents)
*/
public function walkSelectStatement(SelectStatement $AST)
{
- // The ORDER BY clause is invalid in views, inline functions, derived
- // tables, subqueries, and common table expressions, unless TOP or
- // FOR XML is also specified
- if ($this->platform instanceof SQLServerPlatform) {
- $AST->orderByClause = null;
- }
-
+ $AST->orderByClause = null;
$sql = parent::walkSelectStatement($AST);
// Find out the SQL alias of the identifier column of the root entity
@@ -44,20 +44,15 @@ public function testCountQuery_Having()
public function testCountQueryOrderBySqlServer()
{
- $odp = $this->entityManager->getConnection()->getDatabasePlatform();
- $this->entityManager->getConnection()->setDatabasePlatform(new \Doctrine\DBAL\Platforms\SQLServerPlatform());
-
$query = $this->entityManager->createQuery(
'SELECT p FROM Doctrine\Tests\ORM\Tools\Pagination\BlogPost p ORDER BY p.id');
$query->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, 'Doctrine\ORM\Tools\Pagination\CountOutputWalker');
$query->setFirstResult(null)->setMaxResults(null);
$this->assertEquals(
- "SELECT COUNT(*) AS dctrn_count FROM (SELECT DISTINCT id0 FROM (SELECT b0_.id AS id0, b0_.author_id AS author_id1, b0_.category_id AS category_id2 FROM BlogPost b0_ WITH (NOLOCK)) dctrn_result) dctrn_table",
+ "SELECT COUNT(*) AS dctrn_count FROM (SELECT DISTINCT id0 FROM (SELECT b0_.id AS id0, b0_.author_id AS author_id1, b0_.category_id AS category_id2 FROM BlogPost b0_) dctrn_result) dctrn_table",
$query->getSql()
);
-
- $this->entityManager->getConnection()->setDatabasePlatform($odp);
}
}

0 comments on commit 3d8e114

Please sign in to comment.