1
votes

EDIT: Original title" Text environment: "Function "year" does not supported for platform "sqlite""

Incorporating beberlei\DoctrineExtensions in the test environment results in

Uncaught PHP Exception Doctrine\ORM\Query\QueryException: "[Syntax Error] Function "year" does not supported for platform "sqlite""...

composer show -i includes

beberlei/DoctrineExtensions          v1.0.5

The extensions are installed: they exist at "...vendor\beberlei\DoctrineExtensions".

The month() function does NOT throw an error.

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

function call

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;
}

Edit:

The error does not occur if the dql in config.yml (as shown above) are commented out!

Edit #2:

Error persists in functional test with app_dev.php created. Functional test uses Liip\FunctionalTestBundle\Test\WebTestCase

2
Namespace updated per @nifr below. Error persists. - geoB

2 Answers

1
votes

The correct namespace for the Sqlite Plugin is:

DoctrineExtensions\Query\Sqlite\Year

Update your config.yml to include:

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

I wish I had a rational explanation for why the error(s) have disappeared. I experimented with the order and labeling DQL to no effect. I deleted and re-entered the entries and now no errors. Best guess is there was at least one non-display character in an entry. For now all tests pass in SQLite!