我正在使用Phonegap为iOS开发一个词典应用程序。
当查询数据库以获取字母顺序列表时,我使用COLLATE NOCASE
:
ORDER BY term COLLATE NOCASE ASC
这解决了一个问题,即以小写字母开头的术语被附加到末尾(从那个问题中学到的)。
但是非标准字符如öäüéêè仍然最后排序~这里有两个例子:
Expected: Öffnungszeiten Oberved: Zuzahlung
Zuzahlung Öffnungszeiten
(or) clé cliquer sur
cliquer sur clé
我搜索了一下,发现有类似的问题在这里讨论,或者在这里 讨论,但是似乎通常建议安装某种类型的扩展。
这个扩展可能会帮助您...
...使用ICU作为扩展程序
SQLite支持与ICU集成...
但是我不确定这是否适用于我的情况,因为数据库不是由我自己托管而是运行在客户设备上。所以我猜我需要在我的应用程序包中捆绑这个扩展。
我对iOS不太熟悉,但我感觉这可能会很麻烦 - 至少。
另外,在官方论坛中,我找到了以下提示:
SQLite does not properly handle accented characters.
在文本中稍微往下,海报提到了SQLite的一个bug。
我找到的所有链接都已经不再活跃了1年或更长时间,而且其中没有任何一个似乎是处理我目前正在开发的移动环境的。
因此,我想知道是否有其他人在他们的iOS项目中找到了解决方案。
文档说明它们只有3个默认排序选项:
6.0 Collating Sequences
When SQLite compares two strings, it uses a collating sequence or collating function (two words for the same thing) to determine which string is greater or if the two strings are equal. SQLite has three built-in collating functions: BINARY, NOCASE, and RTRIM.
BINARY - Compares string data using memcmp(), regardless of text encoding. NOCASE - The same as binary, except the 26 upper case characters of ASCII are folded to their lower case equivalents before the
comparison is performed. Note that only ASCII characters are case folded. SQLite does not attempt to do full UTF case folding due to the size of the tables required. RTRIM - The same as binary, except that trailing space characters are ignored.
目前我的最佳猜测是使用JavaScript进行排序,但我怀疑这对整体性能不会有什么好处。