1
0
mirror of synced 2025-03-22 16:03:49 +03:00

Merge pull request #540 from FabioBatSilva/DDC-2208

[DDC-2208] Fix DDC-2208
This commit is contained in:
Benjamin Eberlei 2012-12-22 03:53:14 -08:00
commit 6f5948746e
2 changed files with 29 additions and 1 deletions

View File

@ -1807,7 +1807,14 @@ class Parser
return new AST\Literal(AST\Literal::BOOLEAN, $this->lexer->token['value']);
case ($lookahead === Lexer::T_INPUT_PARAMETER):
return $this->InputParameter();
switch (true) {
case $this->isMathOperator($peek):
// :param + u.value
return $this->SimpleArithmeticExpression();
default:
return $this->InputParameter();
}
case ($lookahead === Lexer::T_CASE):
case ($lookahead === Lexer::T_COALESCE):

View File

@ -1773,6 +1773,27 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase
'SELECT q0_."group-id" AS groupid0, q0_."group-name" AS groupname1, q1_."group-id" AS groupid2, q1_."group-name" AS groupname3 FROM "quote-group" q0_ INNER JOIN "quote-group" q1_ ON q0_."parent-id" = q1_."group-id"'
);
}
/**
* @group DDC-2208
*/
public function testCaseThenParameterArithmeticExpression()
{
$this->assertSqlGeneration(
'SELECT SUM(CASE WHEN e.salary <= :value THEN e.salary - :value WHEN e.salary >= :value THEN :value - e.salary ELSE 0 END) FROM Doctrine\Tests\Models\Company\CompanyEmployee e',
'SELECT SUM(CASE WHEN c0_.salary <= ? THEN c0_.salary - ? WHEN c0_.salary >= ? THEN ? - c0_.salary ELSE 0 END) AS sclr0 FROM company_employees c0_ INNER JOIN company_persons c1_ ON c0_.id = c1_.id'
);
$this->assertSqlGeneration(
'SELECT SUM(CASE WHEN e.salary <= :value THEN e.salary - :value WHEN e.salary >= :value THEN :value - e.salary ELSE e.salary + 0 END) FROM Doctrine\Tests\Models\Company\CompanyEmployee e',
'SELECT SUM(CASE WHEN c0_.salary <= ? THEN c0_.salary - ? WHEN c0_.salary >= ? THEN ? - c0_.salary ELSE c0_.salary + 0 END) AS sclr0 FROM company_employees c0_ INNER JOIN company_persons c1_ ON c0_.id = c1_.id'
);
$this->assertSqlGeneration(
'SELECT SUM(CASE WHEN e.salary <= :value THEN (e.salary - :value) WHEN e.salary >= :value THEN (:value - e.salary) ELSE (e.salary + :value) END) FROM Doctrine\Tests\Models\Company\CompanyEmployee e',
'SELECT SUM(CASE WHEN c0_.salary <= ? THEN c0_.salary - ? WHEN c0_.salary >= ? THEN ? - c0_.salary ELSE c0_.salary + ? END) AS sclr0 FROM company_employees c0_ INNER JOIN company_persons c1_ ON c0_.id = c1_.id'
);
}
}
class MyAbsFunction extends \Doctrine\ORM\Query\AST\Functions\FunctionNode