不区分大小写的 utf8 选择
在 SQLite 中我想要不区分大小写 "SELECT LIKE name"
对于正常的拉丁名称工作正常,但是当名称为 UTF-8 且包含非拉丁字符时,选择将区分大小写,如何使其像拉丁字符一样不区分大小写?
ps 我的 sqlite 是 v3 并且我使用 PHP PDO 连接
In SQLite I want to case-insensitive "SELECT LIKE name"
works fine for normal latin names, but when the name is in UTF-8 with non-latin characters then the select becomes case-sensitive, how to make it also case-insensitive like latin characters?
p.s. my sqlite is v3 and I connect with PHP PDO
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
对于 SQLite,您有 2 个选项:
For SQLite you have 2 options:
使用无大小写排序规则,例如:
LIKE name COLLATE NOCASE< /code>
如果您需要将不属于 ASCII 的特定字符与大小写折叠进行比较,则
NOCASE
将不起作用,因为 SQLite 不支持此类折叠 - 您必须提供自己的使用您选择的 Unicode 库和 sqlite3_create_collation() 的排序函数。编辑:另外,这可能很有趣:
如何使用指定的语言环境对 sqlite3 中的文本进行排序?
Use a no-case collation, such as :
LIKE name COLLATE NOCASE
If you need specific characters that are not part of ASCII to be compared with case folding, the
NOCASE
will not work, as such folding is not supported by SQLite - you will have to provide your own collation function using your Unicode library of choice andsqlite3_create_collation()
.EDIT: also, this might be interesting:
How to sort text in sqlite3 with specified locale?
通过 UDF 进行
LIKE
重载的改进版本:尊重
case_sensitive_like
PRAGMA 并正确处理x LIKE y ESCAPE z
语法。我还编写了另一个版本基本 和扩展罗马化
x
和y
值,以便重音字符与其对应的非重音字符相匹配,例如:SELECT 'Á' LIKE 'à%';
。您可以为要点加注星标以关注偶尔的更新。
An improved version of
LIKE
overloading via a UDF:Respects the
case_sensitive_like
PRAGMA and correctly handlesx LIKE y ESCAPE z
syntax.I also wrote another version that does basic and extended romanization of
x
andy
values, so that an accented character will match it's unaccented counterpart, for instance:SELECT 'Á' LIKE 'à%';
.You can star the gist to keep an eye on occasional updates.