DDC-2934 Added support for function declarations in order by.
This commit is contained in:
parent
54898eca60
commit
ceada41b83
@ -1512,7 +1512,7 @@ Items
|
||||
.. code-block:: php
|
||||
|
||||
UpdateItem ::= SingleValuedPathExpression "=" NewValue
|
||||
OrderByItem ::= (SimpleArithmeticExpression | SingleValuedPathExpression | ScalarExpression | ResultVariable) ["ASC" | "DESC"]
|
||||
OrderByItem ::= (SimpleArithmeticExpression | SingleValuedPathExpression | ScalarExpression | ResultVariable | FunctionDeclaration) ["ASC" | "DESC"]
|
||||
GroupByItem ::= IdentificationVariable | ResultVariable | SingleValuedPathExpression
|
||||
NewValue ::= SimpleArithmeticExpression | "NULL"
|
||||
|
||||
|
@ -1456,37 +1456,41 @@ class Parser
|
||||
/**
|
||||
* OrderByItem ::= (
|
||||
* SimpleArithmeticExpression | SingleValuedPathExpression |
|
||||
* ScalarExpression | ResultVariable
|
||||
* ScalarExpression | ResultVariable | FunctionDeclaration
|
||||
* ) ["ASC" | "DESC"]
|
||||
*
|
||||
* @return \Doctrine\ORM\Query\AST\OrderByItem
|
||||
*/
|
||||
public function OrderByItem()
|
||||
{
|
||||
|
||||
$this->lexer->peek(); // lookahead => '.'
|
||||
$this->lexer->peek(); // lookahead => token after '.'
|
||||
|
||||
$peek = $this->lexer->peek(); // lookahead => token after the token after the '.'
|
||||
|
||||
$this->lexer->resetPeek();
|
||||
|
||||
$glimpse = $this->lexer->glimpse();
|
||||
|
||||
switch (true) {
|
||||
case ($this->isFunction($peek)):
|
||||
$expr = $this->FunctionDeclaration();
|
||||
break;
|
||||
|
||||
case ($this->isMathOperator($peek)):
|
||||
$expr = $this->SimpleArithmeticExpression();
|
||||
|
||||
break;
|
||||
|
||||
case ($glimpse['type'] === Lexer::T_DOT):
|
||||
$expr = $this->SingleValuedPathExpression();
|
||||
|
||||
break;
|
||||
|
||||
case ($this->lexer->peek() && $this->isMathOperator($this->peekBeyondClosingParenthesis())):
|
||||
$expr = $this->ScalarExpression();
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
$expr = $this->ResultVariable();
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -1836,6 +1836,14 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase
|
||||
);
|
||||
}
|
||||
|
||||
public function testOrderByClauseSupportsFunction()
|
||||
{
|
||||
$this->assertSqlGeneration(
|
||||
'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u ORDER BY CONCAT(u.username, u.name) ',
|
||||
'SELECT c0_.id AS id_0, c0_.status AS status_1, c0_.username AS username_2, c0_.name AS name_3 FROM cms_users c0_ ORDER BY c0_.username || c0_.name ASC'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DDC-1719
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user