1
0
mirror of synced 2025-02-02 13:31:45 +03:00

Merge branch 'hotfix/backport-DDC-3336-undefined-property-in-paginator-walkers-with-scalar-expressions-in-order-by-clause' into 2.4

Close #1210
This commit is contained in:
Marco Pivetta 2014-12-05 16:46:52 +01:00
commit c398f8c2c2
3 changed files with 41 additions and 14 deletions

View File

@ -13,6 +13,7 @@
namespace Doctrine\ORM\Tools\Pagination;
use Doctrine\ORM\Query\AST\PathExpression;
use Doctrine\ORM\Query\SqlWalker;
use Doctrine\ORM\Query\AST\SelectStatement;
use Doctrine\DBAL\Platforms\PostgreSqlPlatform;
@ -196,12 +197,14 @@ class LimitSubqueryOutputWalker extends SqlWalker
$orderBy = array();
if (isset($AST->orderByClause)) {
foreach ($AST->orderByClause->orderByItems as $item) {
$possibleAliases = (is_object($item->expression))
? array_keys($this->rsm->fieldMappings, $item->expression->field)
: array_keys($this->rsm->scalarMappings, $item->expression);
$expression = $item->expression;
$possibleAliases = $expression instanceof PathExpression
? array_keys($this->rsm->fieldMappings, $expression->field)
: array_keys($this->rsm->scalarMappings, $expression);
foreach ($possibleAliases as $alias) {
if (!is_object($item->expression) || $this->rsm->columnOwnerMap[$alias] == $item->expression->identificationVariable) {
if (!is_object($expression) || $this->rsm->columnOwnerMap[$alias] == $expression->identificationVariable) {
$sqlOrderColumns[] = $alias;
$orderBy[] = $alias . ' ' . $item->type;
break;

View File

@ -2,6 +2,9 @@
namespace Doctrine\Tests\ORM\Tools\Pagination;
use Doctrine\DBAL\Platforms\MySqlPlatform;
use Doctrine\DBAL\Platforms\OraclePlatform;
use Doctrine\DBAL\Platforms\PostgreSqlPlatform;
use Doctrine\ORM\Query;
class LimitSubqueryOutputWalkerTest extends PaginationTestCase
@ -22,7 +25,7 @@ class LimitSubqueryOutputWalkerTest extends PaginationTestCase
public function testLimitSubqueryWithSortPg()
{
$odp = $this->entityManager->getConnection()->getDatabasePlatform();
$this->entityManager->getConnection()->setDatabasePlatform(new \Doctrine\DBAL\Platforms\PostgreSqlPlatform);
$this->entityManager->getConnection()->setDatabasePlatform(new PostgreSqlPlatform);
$query = $this->entityManager->createQuery(
'SELECT p, c, a FROM Doctrine\Tests\ORM\Tools\Pagination\MyBlogPost p JOIN p.category c JOIN p.author a ORDER BY p.title');
@ -39,7 +42,7 @@ class LimitSubqueryOutputWalkerTest extends PaginationTestCase
public function testLimitSubqueryWithScalarSortPg()
{
$odp = $this->entityManager->getConnection()->getDatabasePlatform();
$this->entityManager->getConnection()->setDatabasePlatform(new \Doctrine\DBAL\Platforms\PostgreSqlPlatform);
$this->entityManager->getConnection()->setDatabasePlatform(new PostgreSqlPlatform);
$query = $this->entityManager->createQuery(
'SELECT u, g, COUNT(g.id) AS g_quantity FROM Doctrine\Tests\ORM\Tools\Pagination\User u JOIN u.groups g ORDER BY g_quantity'
@ -58,7 +61,7 @@ class LimitSubqueryOutputWalkerTest extends PaginationTestCase
public function testLimitSubqueryWithMixedSortPg()
{
$odp = $this->entityManager->getConnection()->getDatabasePlatform();
$this->entityManager->getConnection()->setDatabasePlatform(new \Doctrine\DBAL\Platforms\PostgreSqlPlatform);
$this->entityManager->getConnection()->setDatabasePlatform(new PostgreSqlPlatform);
$query = $this->entityManager->createQuery(
'SELECT u, g, COUNT(g.id) AS g_quantity FROM Doctrine\Tests\ORM\Tools\Pagination\User u JOIN u.groups g ORDER BY g_quantity, u.id DESC'
@ -77,7 +80,7 @@ class LimitSubqueryOutputWalkerTest extends PaginationTestCase
public function testLimitSubqueryWithHiddenScalarSortPg()
{
$odp = $this->entityManager->getConnection()->getDatabasePlatform();
$this->entityManager->getConnection()->setDatabasePlatform(new \Doctrine\DBAL\Platforms\PostgreSqlPlatform);
$this->entityManager->getConnection()->setDatabasePlatform(new PostgreSqlPlatform);
$query = $this->entityManager->createQuery(
'SELECT u, g, COUNT(g.id) AS hidden g_quantity FROM Doctrine\Tests\ORM\Tools\Pagination\User u JOIN u.groups g ORDER BY g_quantity, u.id DESC'
@ -96,7 +99,7 @@ class LimitSubqueryOutputWalkerTest extends PaginationTestCase
public function testLimitSubqueryPg()
{
$odp = $this->entityManager->getConnection()->getDatabasePlatform();
$this->entityManager->getConnection()->setDatabasePlatform(new \Doctrine\DBAL\Platforms\PostgreSqlPlatform);
$this->entityManager->getConnection()->setDatabasePlatform(new PostgreSqlPlatform);
$this->testLimitSubquery();
@ -106,7 +109,7 @@ class LimitSubqueryOutputWalkerTest extends PaginationTestCase
public function testLimitSubqueryWithSortOracle()
{
$odp = $this->entityManager->getConnection()->getDatabasePlatform();
$this->entityManager->getConnection()->setDatabasePlatform(new \Doctrine\DBAL\Platforms\OraclePlatform);
$this->entityManager->getConnection()->setDatabasePlatform(new OraclePlatform);
$query = $this->entityManager->createQuery(
'SELECT p, c, a FROM Doctrine\Tests\ORM\Tools\Pagination\MyBlogPost p JOIN p.category c JOIN p.author a ORDER BY p.title');
@ -124,7 +127,7 @@ class LimitSubqueryOutputWalkerTest extends PaginationTestCase
public function testLimitSubqueryWithScalarSortOracle()
{
$odp = $this->entityManager->getConnection()->getDatabasePlatform();
$this->entityManager->getConnection()->setDatabasePlatform(new \Doctrine\DBAL\Platforms\OraclePlatform);
$this->entityManager->getConnection()->setDatabasePlatform(new OraclePlatform);
$query = $this->entityManager->createQuery(
'SELECT u, g, COUNT(g.id) AS g_quantity FROM Doctrine\Tests\ORM\Tools\Pagination\User u JOIN u.groups g ORDER BY g_quantity'
@ -144,7 +147,7 @@ class LimitSubqueryOutputWalkerTest extends PaginationTestCase
public function testLimitSubqueryWithMixedSortOracle()
{
$odp = $this->entityManager->getConnection()->getDatabasePlatform();
$this->entityManager->getConnection()->setDatabasePlatform(new \Doctrine\DBAL\Platforms\OraclePlatform);
$this->entityManager->getConnection()->setDatabasePlatform(new OraclePlatform);
$query = $this->entityManager->createQuery(
'SELECT u, g, COUNT(g.id) AS g_quantity FROM Doctrine\Tests\ORM\Tools\Pagination\User u JOIN u.groups g ORDER BY g_quantity, u.id DESC'
@ -164,7 +167,7 @@ class LimitSubqueryOutputWalkerTest extends PaginationTestCase
public function testLimitSubqueryOracle()
{
$odp = $this->entityManager->getConnection()->getDatabasePlatform();
$this->entityManager->getConnection()->setDatabasePlatform(new \Doctrine\DBAL\Platforms\OraclePlatform);
$this->entityManager->getConnection()->setDatabasePlatform(new OraclePlatform);
$query = $this->entityManager->createQuery(
'SELECT p, c, a FROM Doctrine\Tests\ORM\Tools\Pagination\MyBlogPost p JOIN p.category c JOIN p.author a');
@ -179,7 +182,7 @@ class LimitSubqueryOutputWalkerTest extends PaginationTestCase
$this->entityManager->getConnection()->setDatabasePlatform($odp);
}
public function testCountQuery_MixedResultsWithName()
public function testCountQueryMixedResultsWithName()
{
$query = $this->entityManager->createQuery(
'SELECT a, sum(a.name) as foo FROM Doctrine\Tests\ORM\Tools\Pagination\Author a');
@ -190,5 +193,23 @@ class LimitSubqueryOutputWalkerTest extends PaginationTestCase
"SELECT DISTINCT id0 FROM (SELECT a0_.id AS id0, a0_.name AS name1, sum(a0_.name) AS sclr2 FROM Author a0_) dctrn_result", $limitQuery->getSql()
);
}
/**
* @group DDC-3336
*/
public function testCountQueryWithArithmeticOrderByCondition()
{
$query = $this->entityManager->createQuery(
'SELECT a FROM Doctrine\\Tests\\ORM\\Tools\\Pagination\\Author a ORDER BY (1 - 1000) * 1 DESC'
);
$this->entityManager->getConnection()->setDatabasePlatform(new MySqlPlatform());
$query->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, 'Doctrine\ORM\Tools\Pagination\LimitSubqueryOutputWalker');
$this->assertSame(
'SELECT DISTINCT id_0 FROM (SELECT a0_.id AS id_0, a0_.name AS name_1 FROM Author a0_ ORDER BY (1 - 1000) * 1 DESC) dctrn_result',
$query->getSQL()
);
}
}

View File

@ -6,6 +6,9 @@ use Doctrine\Tests\OrmTestCase;
abstract class PaginationTestCase extends OrmTestCase
{
/**
* @var \Doctrine\ORM\EntityManagerInterface
*/
public $entityManager;
public function setUp()