Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6bbf2d9

Browse files
Added support for ResultVariable referencing in ArithmeticPrimary. Fixes DDC-1346.
1 parent ddfdb37 commit 6bbf2d9

3 files changed

Lines changed: 21 additions & 3 deletions

File tree

lib/Doctrine/ORM/Query/Parser.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2381,7 +2381,7 @@ public function ArithmeticFactor()
23812381
/**
23822382
* ArithmeticPrimary ::= SingleValuedPathExpression | Literal | "(" SimpleArithmeticExpression ")"
23832383
* | FunctionsReturningNumerics | AggregateExpression | FunctionsReturningStrings
2384-
* | FunctionsReturningDatetime | IdentificationVariable | CaseExpression
2384+
* | FunctionsReturningDatetime | IdentificationVariable | ResultVariable | CaseExpression
23852385
*/
23862386
public function ArithmeticPrimary()
23872387
{
@@ -2410,7 +2410,11 @@ public function ArithmeticPrimary()
24102410
if ($peek['value'] == '.') {
24112411
return $this->SingleValuedPathExpression();
24122412
}
2413-
2413+
2414+
if (isset($this->_queryComponents[$this->_lexer->lookahead['value']]['resultVariable'])) {
2415+
return $this->ResultVariable();
2416+
}
2417+
24142418
return $this->StateFieldPathExpression();
24152419

24162420
case Lexer::T_INPUT_PARAMETER:

lib/Doctrine/ORM/Query/SqlWalker.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1971,6 +1971,12 @@ public function walkSimpleArithmeticExpression($simpleArithmeticExpr)
19711971
public function walkArithmeticTerm($term)
19721972
{
19731973
if (is_string($term)) {
1974+
if (isset($this->_queryComponents[$term])) {
1975+
$columnName = $this->_queryComponents[$term]['token']['value'];
1976+
1977+
return $this->_scalarResultAliasMap[$columnName];
1978+
}
1979+
19741980
return $term;
19751981
}
19761982

tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public function assertSqlGeneration($dqlToBeTested, $sqlToBeConfirmed, array $qu
3838
foreach ($queryHints AS $name => $value) {
3939
$query->setHint($name, $value);
4040
}
41-
41+
4242
parent::assertEquals($sqlToBeConfirmed, $query->getSQL());
4343
$query->free();
4444
} catch (\Exception $e) {
@@ -991,6 +991,14 @@ public function testSubSelectAliasesFromOuterQueryWithSubquery()
991991
);
992992
}
993993

994+
public function testSubSelectAliasesFromOuterQueryReuseInWhereClause()
995+
{
996+
$this->assertSqlGeneration(
997+
"SELECT uo, (SELECT ui.name FROM Doctrine\Tests\Models\CMS\CmsUser ui WHERE ui.id = uo.id) AS bar FROM Doctrine\Tests\Models\CMS\CmsUser uo WHERE bar = ?0",
998+
"SELECT c0_.id AS id0, c0_.status AS status1, c0_.username AS username2, c0_.name AS name3, (SELECT c1_.name FROM cms_users c1_ WHERE c1_.id = c0_.id) AS sclr4 FROM cms_users c0_ WHERE sclr4 = ?"
999+
);
1000+
}
1001+
9941002
/**
9951003
* @group DDC-1298
9961004
*/

0 commit comments

Comments
 (0)