我有一个SQLite数据库,我需要由一些富人开始的话用重音字符列命令。这些项目正在有序的错误,他们出现在结果的结尾:
I have a sqlite database, and i need to order by a column that haves some words starting by a accented character. These items are being ordered wrong, they are appearing on the end of the results:
安东尼奥 BONZO Zeto 安吉拉
Antonio Bonzo Zeto Ángela
如何订购正确时,该列中的SQLite数据库富人的口音?
How can i order correctly when the sqlite database haves accents in that column?
感谢
为
... ORDER BY column COLLATE UNICODE
或
... ORDER BY column COLLATE LOCALIZED
Reference:
在除了SQLite的默认 BINARY
配页机,机器人提供了两个以上,中局部
,它与系统的电流的变化语言环境,以及 UNI code
,这是统一code归类算法,而不是针对当前语言环境。
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