Sqlite:用特殊字符排序丹麦æøå

时间:2012-08-09 17:25:38

标签: iphone sqlite sorting

我的Iphone应用程序中有一个sqlite数据库。我在tableView中使用sectionIndexTitlesForTableView时有一个名称需要排序的表。

sql语句是“SELECT * FROM buildings ORDER BY name ASC”。这给出了一个排序结果,但不知何故,排序失败了特殊字符 - 丹麦语æøå。 像:

  • ÅrhusUniversitet
  • ÅrhusÅ
  • ØerMaritimeFerieby

Å应该在Ø之后。

我曾尝试过阅读COLLATE,但对于在这里做什么感到非常无能为力。请注意,sqlite似乎工作正常 - 使用UTF8编码,在应用程序中的每一件事看起来都很好。字母排序除外。

任何线索?

1 个答案:

答案 0 :(得分:0)

由于我只需要对sectionForSectionIndexTitle中使用的数组进行正确的排序 - 表视图数据源我通过执行以下操作绕过了sqlite中的排序问题:


NSLocale *locale = [[NSLocale alloc] initWithLocaleIdentifier:@"da_DK"]; sections = [sections sortedArrayUsingComparator:^(NSDictionary *first, NSDictionary *second) { NSString *str1 = [first objectForKey:@"section"]; NSString *str2 = [second objectForKey:@"section"];

    return [str1 compare:str2
                  options:0
                    range:NSMakeRange(0, [str1 length])
                   locale:locale];

return [str1 compare:str2 options:0 range:NSMakeRange(0, [str1 length]) locale:locale];
我认为可以这样做,因为section数组中的条目数不会超过字母表中的字符数。