【问题标题】:DQL in config.yml not overwritten in config_test.ymlconfig.yml 中的 DQL 未在 config_test.yml 中覆盖
【发布时间】: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


【解决方案1】:

Sqlite 插件的正确命名空间是:

DoctrineExtensions\Query\Sqlite\Year

更新您的 config.yml 以包括:

doctrine:
    orm:
        dql:
            datetime_functions:
                year: DoctrineExtensions\Query\Sqlite\Year

【讨论】:

  • 更改命名空间并没有消除错误。 (试用前删除了测试缓存。修改了月份和年份)请注意,条目是在 config_test.yml 中创建的。 config.yml 中的 dql 条目(例如,month: Oro\ORM\Query\AST\Functions\SimpleFunction)可能会被覆盖。
  • 该问题已被编辑以表明仅当出现 config.yml 中的 DQL 时才会出现错误。注释掉后,错误消失。 config.yml中的DQL不应该被config_test.yml中的覆盖吗?
  • 我赞成您的回答 - 这是解决方案的必要条件,但还不够。
【解决方案2】:

我希望对错误消失的原因有一个合理的解释。我尝试了订单并标记 DQL 无效。我删除并重新输入条目,现在没有错误。最好的猜测是条目中至少有一个非显示字符。目前所有测试都通过 SQLite!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-04
    • 2022-01-20
    • 2019-07-21
    • 1970-01-01
    • 2012-06-20
    相关资源
    最近更新 更多