1
0
mirror of synced 2025-01-31 04:21:44 +03:00

DDC-2934 Added support for function declarations in order by.

This commit is contained in:
Guilherme Blanco 2014-04-17 04:15:35 +00:00
parent 54898eca60
commit ceada41b83
3 changed files with 19 additions and 7 deletions

View File

@ -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"

View File

@ -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;
}

View File

@ -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
*/