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:
commit
c398f8c2c2
@ -13,6 +13,7 @@
|
|||||||
|
|
||||||
namespace Doctrine\ORM\Tools\Pagination;
|
namespace Doctrine\ORM\Tools\Pagination;
|
||||||
|
|
||||||
|
use Doctrine\ORM\Query\AST\PathExpression;
|
||||||
use Doctrine\ORM\Query\SqlWalker;
|
use Doctrine\ORM\Query\SqlWalker;
|
||||||
use Doctrine\ORM\Query\AST\SelectStatement;
|
use Doctrine\ORM\Query\AST\SelectStatement;
|
||||||
use Doctrine\DBAL\Platforms\PostgreSqlPlatform;
|
use Doctrine\DBAL\Platforms\PostgreSqlPlatform;
|
||||||
@ -196,12 +197,14 @@ class LimitSubqueryOutputWalker extends SqlWalker
|
|||||||
$orderBy = array();
|
$orderBy = array();
|
||||||
if (isset($AST->orderByClause)) {
|
if (isset($AST->orderByClause)) {
|
||||||
foreach ($AST->orderByClause->orderByItems as $item) {
|
foreach ($AST->orderByClause->orderByItems as $item) {
|
||||||
$possibleAliases = (is_object($item->expression))
|
$expression = $item->expression;
|
||||||
? array_keys($this->rsm->fieldMappings, $item->expression->field)
|
|
||||||
: array_keys($this->rsm->scalarMappings, $item->expression);
|
$possibleAliases = $expression instanceof PathExpression
|
||||||
|
? array_keys($this->rsm->fieldMappings, $expression->field)
|
||||||
|
: array_keys($this->rsm->scalarMappings, $expression);
|
||||||
|
|
||||||
foreach ($possibleAliases as $alias) {
|
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;
|
$sqlOrderColumns[] = $alias;
|
||||||
$orderBy[] = $alias . ' ' . $item->type;
|
$orderBy[] = $alias . ' ' . $item->type;
|
||||||
break;
|
break;
|
||||||
|
@ -2,6 +2,9 @@
|
|||||||
|
|
||||||
namespace Doctrine\Tests\ORM\Tools\Pagination;
|
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;
|
use Doctrine\ORM\Query;
|
||||||
|
|
||||||
class LimitSubqueryOutputWalkerTest extends PaginationTestCase
|
class LimitSubqueryOutputWalkerTest extends PaginationTestCase
|
||||||
@ -22,7 +25,7 @@ class LimitSubqueryOutputWalkerTest extends PaginationTestCase
|
|||||||
public function testLimitSubqueryWithSortPg()
|
public function testLimitSubqueryWithSortPg()
|
||||||
{
|
{
|
||||||
$odp = $this->entityManager->getConnection()->getDatabasePlatform();
|
$odp = $this->entityManager->getConnection()->getDatabasePlatform();
|
||||||
$this->entityManager->getConnection()->setDatabasePlatform(new \Doctrine\DBAL\Platforms\PostgreSqlPlatform);
|
$this->entityManager->getConnection()->setDatabasePlatform(new PostgreSqlPlatform);
|
||||||
|
|
||||||
$query = $this->entityManager->createQuery(
|
$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');
|
'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()
|
public function testLimitSubqueryWithScalarSortPg()
|
||||||
{
|
{
|
||||||
$odp = $this->entityManager->getConnection()->getDatabasePlatform();
|
$odp = $this->entityManager->getConnection()->getDatabasePlatform();
|
||||||
$this->entityManager->getConnection()->setDatabasePlatform(new \Doctrine\DBAL\Platforms\PostgreSqlPlatform);
|
$this->entityManager->getConnection()->setDatabasePlatform(new PostgreSqlPlatform);
|
||||||
|
|
||||||
$query = $this->entityManager->createQuery(
|
$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'
|
'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()
|
public function testLimitSubqueryWithMixedSortPg()
|
||||||
{
|
{
|
||||||
$odp = $this->entityManager->getConnection()->getDatabasePlatform();
|
$odp = $this->entityManager->getConnection()->getDatabasePlatform();
|
||||||
$this->entityManager->getConnection()->setDatabasePlatform(new \Doctrine\DBAL\Platforms\PostgreSqlPlatform);
|
$this->entityManager->getConnection()->setDatabasePlatform(new PostgreSqlPlatform);
|
||||||
|
|
||||||
$query = $this->entityManager->createQuery(
|
$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'
|
'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()
|
public function testLimitSubqueryWithHiddenScalarSortPg()
|
||||||
{
|
{
|
||||||
$odp = $this->entityManager->getConnection()->getDatabasePlatform();
|
$odp = $this->entityManager->getConnection()->getDatabasePlatform();
|
||||||
$this->entityManager->getConnection()->setDatabasePlatform(new \Doctrine\DBAL\Platforms\PostgreSqlPlatform);
|
$this->entityManager->getConnection()->setDatabasePlatform(new PostgreSqlPlatform);
|
||||||
|
|
||||||
$query = $this->entityManager->createQuery(
|
$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'
|
'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()
|
public function testLimitSubqueryPg()
|
||||||
{
|
{
|
||||||
$odp = $this->entityManager->getConnection()->getDatabasePlatform();
|
$odp = $this->entityManager->getConnection()->getDatabasePlatform();
|
||||||
$this->entityManager->getConnection()->setDatabasePlatform(new \Doctrine\DBAL\Platforms\PostgreSqlPlatform);
|
$this->entityManager->getConnection()->setDatabasePlatform(new PostgreSqlPlatform);
|
||||||
|
|
||||||
$this->testLimitSubquery();
|
$this->testLimitSubquery();
|
||||||
|
|
||||||
@ -106,7 +109,7 @@ class LimitSubqueryOutputWalkerTest extends PaginationTestCase
|
|||||||
public function testLimitSubqueryWithSortOracle()
|
public function testLimitSubqueryWithSortOracle()
|
||||||
{
|
{
|
||||||
$odp = $this->entityManager->getConnection()->getDatabasePlatform();
|
$odp = $this->entityManager->getConnection()->getDatabasePlatform();
|
||||||
$this->entityManager->getConnection()->setDatabasePlatform(new \Doctrine\DBAL\Platforms\OraclePlatform);
|
$this->entityManager->getConnection()->setDatabasePlatform(new OraclePlatform);
|
||||||
|
|
||||||
$query = $this->entityManager->createQuery(
|
$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');
|
'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()
|
public function testLimitSubqueryWithScalarSortOracle()
|
||||||
{
|
{
|
||||||
$odp = $this->entityManager->getConnection()->getDatabasePlatform();
|
$odp = $this->entityManager->getConnection()->getDatabasePlatform();
|
||||||
$this->entityManager->getConnection()->setDatabasePlatform(new \Doctrine\DBAL\Platforms\OraclePlatform);
|
$this->entityManager->getConnection()->setDatabasePlatform(new OraclePlatform);
|
||||||
|
|
||||||
$query = $this->entityManager->createQuery(
|
$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'
|
'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()
|
public function testLimitSubqueryWithMixedSortOracle()
|
||||||
{
|
{
|
||||||
$odp = $this->entityManager->getConnection()->getDatabasePlatform();
|
$odp = $this->entityManager->getConnection()->getDatabasePlatform();
|
||||||
$this->entityManager->getConnection()->setDatabasePlatform(new \Doctrine\DBAL\Platforms\OraclePlatform);
|
$this->entityManager->getConnection()->setDatabasePlatform(new OraclePlatform);
|
||||||
|
|
||||||
$query = $this->entityManager->createQuery(
|
$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'
|
'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()
|
public function testLimitSubqueryOracle()
|
||||||
{
|
{
|
||||||
$odp = $this->entityManager->getConnection()->getDatabasePlatform();
|
$odp = $this->entityManager->getConnection()->getDatabasePlatform();
|
||||||
$this->entityManager->getConnection()->setDatabasePlatform(new \Doctrine\DBAL\Platforms\OraclePlatform);
|
$this->entityManager->getConnection()->setDatabasePlatform(new OraclePlatform);
|
||||||
|
|
||||||
$query = $this->entityManager->createQuery(
|
$query = $this->entityManager->createQuery(
|
||||||
'SELECT p, c, a FROM Doctrine\Tests\ORM\Tools\Pagination\MyBlogPost p JOIN p.category c JOIN p.author a');
|
'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);
|
$this->entityManager->getConnection()->setDatabasePlatform($odp);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCountQuery_MixedResultsWithName()
|
public function testCountQueryMixedResultsWithName()
|
||||||
{
|
{
|
||||||
$query = $this->entityManager->createQuery(
|
$query = $this->entityManager->createQuery(
|
||||||
'SELECT a, sum(a.name) as foo FROM Doctrine\Tests\ORM\Tools\Pagination\Author a');
|
'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()
|
"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()
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,6 +6,9 @@ use Doctrine\Tests\OrmTestCase;
|
|||||||
|
|
||||||
abstract class PaginationTestCase extends OrmTestCase
|
abstract class PaginationTestCase extends OrmTestCase
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @var \Doctrine\ORM\EntityManagerInterface
|
||||||
|
*/
|
||||||
public $entityManager;
|
public $entityManager;
|
||||||
|
|
||||||
public function setUp()
|
public function setUp()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user