我有以下代码,它依赖Doctrine的QueryBuilder API来生成DQL语句。
一个查看堆栈跟踪的例子,可以发现以下信息:
class PlayerRepository extends EntityRepository
{
public function findByPartialNameMatch($trainer, $fullName)
{
$qb = $this->createQueryBuilder('tp');
$qb->innerJoin('tp.player', 'p')
->where($qb->expr()->andX(
$qb->expr()->orX(
$qb->expr()->like(
$qb->expr()->concat('p.firstName', $qb->expr()->concat(' ', 'p.lastName')),
$qb->expr()->literal($fullName.'%')
),
$qb->expr()->like(
$qb->expr()->concat('p.lastName', $qb->expr()->concat(' ', 'p.firstName')),
$qb->expr()->literal($fullName.'%')
)
),
$qb->expr()->eq('tp.trainer', '?1')
)
)
->groupBy('p.id')
->orderBy('p.lastName', 'ASC')
->orderBy('p.firstName', 'ASC')
->setParameter(1, $trainer);
return $qb->getQuery()->getResult();
}
当我运行时,Symfony2会抛出以下错误信息:
[Syntax Error] line 0, col 123: Error: Expected StateFieldPathExpression | string | InputParameter | FunctionsReturningStrings | AggregateExpression, got ','
一个查看堆栈跟踪的例子,可以发现以下信息:
at QueryException ::syntaxError ('line 0, col 123: Error: Expected StateFieldPathExpression | string | InputParameter | FunctionsReturningStrings | AggregateExpression, got ','')
in D:\Work\vendor\doctrine\lib\Doctrine\ORM\Query\Parser.php at line 396 -+
at Parser ->syntaxError ('StateFieldPathExpression | string | InputParameter | FunctionsReturningStrings | AggregateExpression')
in D:\Work\vendor\doctrine\lib\Doctrine\ORM\Query\Parser.php at line 2391 -+
at Parser ->StringPrimary ()
in D:\Work\vendor\doctrine\lib\Doctrine\ORM\Query\AST\Functions\ConcatFunction.php at line 60 -+
at ConcatFunction ->parse (object(Parser))
in D:\Work\vendor\doctrine\lib\Doctrine\ORM\Query\Parser.php at line 2852 -
通过上面的内容,我了解到这个问题与 concat 帮助函数有关,该函数期望枚举输入,但是某种方式(?)收到了逗号(,)。
以上代码有什么问题?几小时的搜索都不能解决这个问题。
非常感谢您的帮助!
$orX ->add( $this->qb->expr()->like( $this->qb->expr()->concat( "{$alias}.{$name}", $this->qb->expr()->concat($this->qb->expr()->literal(' '), "{$alias}.{$lastname}" )), ":v0" ) )
- hvallenilla