Skip to content

Commit

Permalink
Merge pull request beberlei#54 from matjaz/master
Browse files Browse the repository at this point in the history
limited support for GROUP_CONCAT
  • Loading branch information
beberlei committed Oct 15, 2011
2 parents 0f0ff09 + 2bf5bb4 commit b642de6
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions lib/DoctrineExtensions/Query/Mysql/GroupConcat.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

/**
* DoctrineExtensions Mysql Function Pack
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to [email protected] so I can send you a copy immediately.
*/

namespace DoctrineExtensions\Query\Mysql;

use Doctrine\ORM\Query\AST\Functions\FunctionNode,
Doctrine\ORM\Query\Lexer;

// limited support for GROUP_CONCAT
class GroupConcat extends FunctionNode
{
public $isDistinct = false;
public $expression = null;

public function getSql(\Doctrine\ORM\Query\SqlWalker $sqlWalker)
{
return 'GROUP_CONCAT(' .
($this->isDistinct ? 'DISTINCT ' : '') .
$this->expression->dispatch($sqlWalker) .
')';
}

public function parse(\Doctrine\ORM\Query\Parser $parser)
{

$parser->match(Lexer::T_IDENTIFIER);
$parser->match(Lexer::T_OPEN_PARENTHESIS);

$lexer = $parser->getLexer();
if ($lexer->isNextToken(Lexer::T_DISTINCT)) {
$parser->match(Lexer::T_DISTINCT);

$this->isDistinct = true;
}

$this->expression = $parser->SingleValuedPathExpression();

$parser->match(Lexer::T_CLOSE_PARENTHESIS);
}

}

0 comments on commit b642de6

Please sign in to comment.