8000 [Syntax Error] line 0, col 28: Error: Expected Doctrine\ORM\Query\Lexer::T_CLOSE_PARENTHESIS, got '(' · Issue #7280 · doctrine/orm · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
[Syntax Error] line 0, col 28: Error: Expected Doctrine\ORM\Query\Lexer::T_CLOSE_PARENTHESIS, got '(' #7280
Closed
@dancostinel

Description

@dancostinel

Bug Report

Q A
BC Break no
Version ~1.2

Summary

Having this dql code:

# UserRepository.php
public function testCoalesce()
{
    return $this
        ->createQueryBuilder('u')
        ->select("GROUP_CONCAT(COALESCE(u.id), 0) SEPARATOR ', '")
        ->groupBy('u.id')
        ->getQuery()
        ->getArrayResult()
    ;
}

Current behavior

When executing the query, it throws this error:
https://imgur.com/a/Odx0HJE

Seems like writing COALESCE function inside GROUP_CONCAT function is not working, even though I have the CoalesceExpression() method inside vendor/doctrine/orm/lib/Doctrine/ORM/Query/Parser.php class.

/**
 * CoalesceExpression ::= "COALESCE" "(" ScalarExpression {"," ScalarExpression}* ")"
 *
 * @return \Doctrine\ORM\Query\AST\CoalesceExpression
 */
public function CoalesceExpression()
{
    $this->match(Lexer::T_COALESCE);
    $this->match(Lexer::T_OPEN_PARENTHESIS);

    // Process ScalarExpressions (1..N)
    $scalarExpressions = array();
    $scalarExpressions[] = $this->ScalarExpression();

    while ($this->lexer->isNextToken(Lexer::T_COMMA)) {
        $this->match(Lexer::T_COMMA);

        $scalarExpressions[] = $this->ScalarExpression();
    }

    $this->match(Lexer::T_CLOSE_PARENTHESIS);

    return new AST\CoalesceExpression($scalarExpressions);
}

How to reproduce

added DQL code above

If I write the equivalent SQL code inside the repo's method, then it works as expected.

#UserRepository.php
$db = $this->getEntityManager()->getConnection();
$sql = "SELECT GROUP_CONCAT(COALESCE(u.id, 0) SEPARATOR ', ') AS tst FROM User u GROUP BY u.id";
$stmt = $db->prepare($sql);
$stmt->execute();

return $stmt->fetchAll();

Please, help.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0