Android SQLite 通过 utf8 整理/排序

标签 android sqlite

我在 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/

相关文章:

android - 使用 lua 作为 SDK 的跨平台语言的优点/缺点

android - 如何在 Android 中使用 Union

android - Google 从当前位置到已知位置的定向路线

android - 使用 android.content.Intent.ACTION_SENDTO 启动 whatsapp

android - Android 中的 OpenGL ES 2.0 上下文

c++ - 从 blob SQLite 读取二进制图像并使用 OpenCV imdecode 对其进行解码的最佳方法是什么?

mysql - Linux SED AWK Sqlite 转储到 MySQL 将以 create table 开头的行上的字符串更改为 varchar

macos - AppleScript中的SQLite?

python - Qt:从一个 QSqlTableModel 在两个 QListView 之间移动条目

java - ActionBar 设置区域的自定义背景颜色