gpt4 book ai didi

Android SQLite 通过 utf8 整理/排序

转载 作者:太空狗 更新时间:2023-10-29 14:23:36 25 4
gpt4 key购买 nike

我在 Android 上的 SQLite 表中有以下项目(表选项卡有 1 列 - “名称”文本)

Beta
Work
Úpal
User

如果我在 SQL Server 中将这些项目与斯洛伐克语的排序规则相结合,并且 按名称从选项卡顺序中选择 *,它会正确输出项目排序为:

Beta
User
Úpal
Work

在斯洛伐克语中,带有重音符号的 U - Ú 应排在 U 之后。

在 Android 上的 SQLite 中,它按以下顺序输出它们:

Beta
User
Work
Úpal

我明白发生了什么,SQLite 可能正在使用字符代码比较字符,而 Ú 是在 W 之后。

我该怎么做才能让它按我的方式排序?有可能吗? SQLite docs on COLLATION声明基本上所有排序规则都是二进制比较的变体,并且使用 memcmp() 比较字符串数据,无论文本编码如何。

最佳答案

SQLite 的 C API 允许安装 new collation sequences .Android API 没有公开这些函数,但至少它安装了两个额外的排序规则:

In addition to SQLite's default BINARY collator, Android supplies two more, LOCALIZED, which changes with the system's current locale, and UNICODE, which is the Unicode Collation Algorithm and not tailored to the current locale.

关于Android SQLite 通过 utf8 整理/排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14467806/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com