如何在 Drupal 中对带有变音符号的文本进行 MySQL 查询?
我需要区分以“O”开头的节点和以“Ö”(o 元音变音)开头的节点。
问题是,由于节点表和标题列具有 utf8_general_ci 排序规则,MYSQL 不会以不同方式对待 o 和 ö 元音变音,并且此查询返回以 O 开头的节点 AND 以 Ö 开头的节点
SELECT node.nid AS nid
FROM节点AS节点
WHERE 节点.status <> 0
AND SUBSTR( node.title, 1, 1 ) = 'O'
由于所有 Drupal 模块都使用 utf8_general_ci 排序规则,我想更改表和整个数据库的排序规则可能不是一个好主意。
对此有什么好的解决方法吗?
I need to differentiate between nodes starting with 'O' and nodes starting with 'Ö' (o umlaut).
The problem is that since the node table and the title column have utf8_general_ci collation, MYSQL does not treat o and ö umlaut differently and this query returns nodes starting with O AND nodes starting with Ö
SELECT node.nid AS nid
FROM node AS node
WHERE node.status <> 0
AND SUBSTR( node.title, 1, 1 ) = 'O'
Since all Drupal modules use utf8_general_ci collation, I guess changing the collation of the table and entire database is probably not a good idea.
What is a good workaround for this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用与列所使用的排序规则不同的排序规则进行比较:(
o
和ö
是瑞典语排序规则中的不同字母。您也可以使用utf8_bin
(如果您不想匹配任何不同的字符,甚至是同一字母的不同大小写)。)但是,对排序规则与排序规则不同的列进行比较每列都意味着不能使用索引。因此,只需将表
ALTER
更改为您想要的更具体的排序规则可能会更有效。You can do a comparison using a different collation to the one the columns are using:
(
o
andö
being different letters in the Swedish collation. You could also useutf8_bin
if you don't want any different characters to match, even different cases of the same letter.)However doing a compare of columns where the collation is not the same as the collation of each column means indexes can't be used. So it may be more efficient simply to
ALTER
the tables to the more-specific collation you want.不幸的是,正如您所注意到的,Drupal 6 强制执行
utf8_general_ci
排序规则。然而,这是一个已知问题,人们一直致力于允许在
settings.php
中指定排序规则:不遵守数据库默认排序规则有 当前该问题中的补丁 (#90)审查中的 Drupal 6 添加了此功能。修补后,您所需要做的就是将: 添加
到您的
settings.php
文件中。Unfortunately, as you've noticed, Drupal 6 enforces
utf8_general_ci
collation.However, this is a known issue, and people have been working on allowing the collation to be specified in
settings.php
: Database default collation is not respectedThere's currently a patch in that issue (#90) for Drupal 6 in review that adds this ability. Once patched, all you need to do is add:
to your
settings.php
file.