Android SQLite ORDER BY COLLATE "NOCASE" 和 "LOCALIZED" 在一起

Android SQLite ORDER BY COLLATE "NOCASE" and "LOCALIZED" together

有没有什么方法可以不区分大小写按语言环境字母顺序对数据集进行排序?我找到了 "COLLATE LOCALIZED"、"COLLATE NOCASE",但是 "COLLATE LOCALIZED NOCASE" 显示错误(也是以相反的顺序)。

感谢您的回复!

我没有找到任何简单的方法。我创建了额外的排序 table 列,其中包含标准化数据(注释 here)。为规范化 table 列名称前缀创建常量:

public static final String ASCII_PREFIX = "ascii_";

已创建 table(对于文本列,再创建一个带前缀的列):

String sql = "CREATE TABLE IF NOT EXISTS " + tableName + " (";
for( columnModel column: table.columns ) {
  if( column.position > 0 ){  sql += ", ";  }
  sql += column.dbName + " " + column.dbType;
}
for( columnModel column: table.columns ) {
  if( column.dbType.equals("TEXT") ) {
    sql += ", " + ASCII_PREFIX + column.dbName + " " + column.dbType;
  }
}
sql += ")";
db.execSQL(sql);

更改了table数据填充(为特殊列添加规范化数据):

//...cycle for data filling...
ContentValues values = new ContentValues();
for( columnModel column: table.columns ) {
     values.put(column.dbName, valueStr);
     if( column.dbType.equals("TEXT") ){
      values.put(ASCII_PREFIX + column.dbName, normalize(valueStr));
     }
}
db.insert(tableName, null, values);

然后我对文本列进行交替排序:

//... in method for sorting...
String orderBy;
....                  
if( column.dbType.equals("TEXT") ) {
    orderBy = ASCII_PREFIX + column.dbName;
}else {
    orderBy = column.dbName;
}

这对我有用:

field COLLATE LOCALIZED, field COLLATE NOCASE