Doctrine用utf8列名查询 [英] Doctrine Query with utf8 column name
问题描述
除了尝试使用该名称明确构建DQL查询之外,一切顺利。我然后得到错误:
[语法错误]行0,列15:错误:预期
Doctrine\ORM\\ \\ Query \Lexer :: T_FROM,得到' '
查询:
SELECTR.libellé,V.libellé
FROM IutFranceBundle:Regions R
INNER JOIN R.cheflieu V
ORDER BYR.libellé ASC
我发现这个问题的唯一答案是避免在列名中使用非ascii字符。 ..
我使用与PDO / MySQL查询相同的数据库,使用非ascii字符没有任何问题。
我在Doctrine代码中挖了一点,发现这个问题似乎在Lexer.php类中,它使用不正确的正则表达式。
提前感谢您可以共享一个解决方案。
感谢您的答案。关键在于Doctrine和MySQL之间,我配置Symfony使用UTF-8,它的工作正常。
解析DQL查询时,问题涉及到Doctrine本身。我找到了一个解决方案,需要修补2个学说文件:
vendor / doctrine / lexer / lib / Doctrine / Common / Lexer / AbstractLexer.php
vendor / doctrine / orm / lib / Doctrine / ORM / Query / Lexer.php
在第一个我只是在方法 getModifiers
中添加'u'修饰符,然后在最后我更改方法 getCatchablePatterns
,将 a-z _
替换为 \w
(代表任何字母或_) 。
现在可以正常工作了。我认为最后一个补丁也可以安全地应用于 getCatchablePatterns
的方法:
vendor / doctrine / annotations / lib / Doctrine / Common / Annotations / DocLexer.php
谢谢再次。
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.
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.
这篇关于Doctrine用utf8列名查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!