android – 通过带有重音字符的列排序sqlite的问题(Á)

前端之家收集整理的这篇文章主要介绍了android – 通过带有重音字符的列排序sqlite的问题(Á)前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个sqlite数据库,我需要通过一个有一些以重音字符开头的单词的列来排序.这些物品订购错误,它们出现在结果的最后:

安东尼奥
BONZO
Zeto
安吉拉

sqlite数据库在该列中有重音时,如何正确订购?

谢谢

解决方法

... ORDER BY column COLLATE UNICODE

要么

... ORDER BY column COLLATE LOCALIZED

Reference:

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.

例:

db.execsql("CREATE TABLE foo(a TEXT);");
db.execsql("INSERT INTO foo VALUES('Antonio'),('Bonzo'),('Zeto'),('Ángela');");

Cursor c = db.rawQuery("SELECT * FROM foo ORDER BY a COLLATE UNICODE",null);
while (c.moveToNext()) {
   Log.d("foo",c.getString(0));
}

输出

Ángela
Antonio
Bonzo
Zeto
原文链接:https://www.f2er.com/android/311154.html

猜你在找的Android相关文章