【发布时间】:2015-08-10 14:54:06
【问题描述】:
编辑:原始标题”文本环境:“平台“sqlite”不支持函数“年份””
在测试环境中加入 beberlei\DoctrineExtensions 会导致
未捕获的 PHP 异常 Doctrine\ORM\Query\QueryException: "[Syntax 错误] 平台 "sqlite"" 不支持函数 "year"...
composer show -i 包括
beberlei/DoctrineExtensions v1.0.5
已安装扩展:它们存在于“...vendor\beberlei\DoctrineExtensions”。
month() 函数不会引发错误。
config_test.yml
doctrine:
dbal:
default_connection: test
connections:
test:
driver: pdo_sqlite
path: %kernel.cache_dir%/test.sqlite
orm:
dql:
string_functions:
Soundex: Truckee\VolunteerBundle\DQL\Soundex
month: DoctrineExtensions\Query\Sqlite\Month
datetime_functions:
year: DoctrineExtensions\Query\Sqlite\Year
config.yml DQL
dql:
string_functions:
Soundex: Truckee\VolunteerBundle\DQL\Soundex
numeric_functions:
month: Oro\ORM\Query\AST\Functions\SimpleFunction
year: Oro\ORM\Query\AST\Functions\SimpleFunction
函数调用
public function expiringOppsNotSent()
{
$nextMonth = date_add(new \DateTime(), new \DateInterval('P1M'));
$expiryMonth = date_format($nextMonth, 'm');
$expiryYear = date_format($nextMonth, 'Y');
$qb = $this->getEntityManager()->createQueryBuilder();
$qb->select('o')
->from('TruckeeVolunteerBundle:Opportunity', 'o')
->leftJoin('TruckeeVolunteerBundle:AdminOutbox', 'a', 'WITH', $qb->expr()->eq('a.oppId', 'o'))
->andWhere($qb->expr()->eq('month(o.expireDate)', ':month'))
->andWhere($qb->expr()->eq('year(o.expireDate)', ':year'))
->andWhere('a.id is NULL')
->setParameter(':month', $expiryMonth)
->setParameter(':year', $expiryYear)
;
$notSent = $qb->getQuery()->getResult();
return $notSent;
}
编辑:
如果config.yml中的dql(如上图)被注释掉也不会出现该错误!
编辑#2:
在创建 app_dev.php 的功能测试中仍然存在错误。
功能测试使用Liip\FunctionalTestBundle\Test\WebTestCase
【问题讨论】:
-
根据下面的@nifr 更新命名空间。错误仍然存在。
标签: php sqlite symfony doctrine-orm