0
votes

I use Symfony 2.7 with Doctrine and I'm trying to use an existing database where I have columns name with non-ascii characters e.g. libellé (in French).

All goes well except when trying to build a DQL query using that name explicitely. I then get the error :

[Syntax Error] line 0, col 15: Error: Expected Doctrine\ORM\Query\Lexer::T_FROM, got '�'

with the query :

SELECT R.libellé, V.libellé 
FROM IutFranceBundle:Regions R 
INNER JOIN R.cheflieu V 
ORDER BY R.libellé ASC

The only answer I found for this problem is to avoid using non-ascii chars in column names... I use the same database with PDO/MySQL queries, using non-ascii chars without any problem.

I dug a little in Doctrine code and found that the problem seemed to be in Lexer.php class, which uses inapropriate regex.

Thanks in advance if you can share a solution to this.

2
Never ever use NON-ASCII chars when programming... They are only allowed in user content not in the code or in DB column name. Using them can only lead you to the kind of problem you are currently facing. - Rybus

2 Answers

0
votes

Try to add utf8 to your doctrine config database params:

'params' => array(
    'host'     => 'localhost',
    'port'     => 'yourport',
    'user'     => 'username',
    'password' => 'password',
    'dbname'   => 'yourdatabase',
    'charset'  => 'utf8',
)

Check my answer here for more details.

0
votes

Thanks for your answers. The point is not between Doctrine and MySQL, I configured Symfony to use UTF-8, it works fine.

The issue concerns Doctrine itself, when parsing a DQL query. I've found a solution which need to patch 2 doctrine files :

vendor/doctrine/lexer/lib/Doctrine/Common/Lexer/AbstractLexer.php
vendor/doctrine/orm/lib/Doctrine/ORM/Query/Lexer.php

In the first I simply add the 'u' modifier in method getModifiers, and then in the last I change the method getCatchablePatterns, replacing a-z_ by \w (wich stands for any letter or _).

It works now fine. I think the last patch can also be applied safely to the method getCatchablePatterns of :

vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/DocLexer.php

Thanks again.