Phonegap Sqlite排序不正确utf8问题

时间:2012-11-22 15:40:04

标签: ios sqlite cordova

我正在尝试在Phonegap上使用Sqlite对数据进行SQL订购,但结果不正确! 它将是:abcçdeéě

我的代码:

db.transaction(function(tx){

        tx.executeSql('SELECT id,keyword FROM Glossary ORDER BY lower(keyword) COLLATE NOCASE',[] , function(tx, results){
            var lastAlpha = "*";
            for(i=0;i<results.rows.length;i++){
                var firstChr = results.rows.item(i).keyword.substring(0,1).toUpperCase();
                if(firstChr!=lastAlpha){
                    console.log(firstChr);
                    lastAlpha = firstChr;
                }
            }
        },errorCB2);
    });

结果:

2012-11-22 17:14:14.641[15032:c07] [LOG] A
2012-11-22 17:14:14.641[15032:c07] [LOG] B
2012-11-22 17:14:14.642[15032:c07] [LOG] C
2012-11-22 17:14:14.644[15032:c07] [LOG] D
2012-11-22 17:14:14.645[15032:c07] [LOG] E
2012-11-22 17:14:14.646[15032:c07] [LOG] F
2012-11-22 17:14:14.647[15032:c07] [LOG] G
2012-11-22 17:14:14.648[15032:c07] [LOG] H
2012-11-22 17:14:14.649[15032:c07] [LOG] I
2012-11-22 17:14:14.650[15032:c07] [LOG] J
2012-11-22 17:14:14.651[15032:c07] [LOG] K
2012-11-22 17:14:14.652[15032:c07] [LOG] L
2012-11-22 17:14:14.654[15032:c07] [LOG] M
2012-11-22 17:14:14.655[15032:c07] [LOG] N
2012-11-22 17:14:14.656[15032:c07] [LOG] O
2012-11-22 17:14:14.657[15032:c07] [LOG] P
2012-11-22 17:14:14.658[15032:c07] [LOG] Q
2012-11-22 17:14:14.659[15032:c07] [LOG] R
2012-11-22 17:14:14.660[15032:c07] [LOG] S
2012-11-22 17:14:14.661[15032:c07] [LOG] T
2012-11-22 17:14:14.662[15032:c07] [LOG] U
2012-11-22 17:14:14.664[15032:c07] [LOG] V
2012-11-22 17:14:14.665[15032:c07] [LOG] W
2012-11-22 17:14:14.666[15032:c07] [LOG] X
2012-11-22 17:14:14.668[15032:c07] [LOG] Y
2012-11-22 17:14:14.669[15032:c07] [LOG] Z
2012-11-22 17:14:14.671[15032:c07] [LOG] Ç
2012-11-22 17:14:14.672[15032:c07] [LOG] É
2012-11-22 17:14:14.673[15032:c07] [LOG] Ö
2012-11-22 17:14:14.674[15032:c07] [LOG] Ü
2012-11-22 17:14:14.674[15032:c07] [LOG] İ
2012-11-22 17:14:14.676[15032:c07] [LOG] Ş

我在The Last看过像“拉丁字符”。 ! 你有什么想法吗?

1 个答案:

答案 0 :(得分:1)

http://www.sqlite.org/datatype3.html#collation

  

NOCASE - 与二进制相同,除了在执行比较之前将ASCII的26个大写字符折叠为它们的小写等价物。请注意,只有ASCII字符是大小写折叠的。由于所需表的大小,SQLite不会尝试执行完整的UTF大小写折叠。

我相信它说SQLite不会提供那种排序,因为它需要太多的处理时间才能实现。 SQLite确实提供了一个界面来整理你自己的整理顺序(http://www.sqlite.org/c3ref/create_collat​​ion.html),但我认为这不会在PhoneGap中轻易使用。

如果你非常坚定地进行这种排序,你可以稍微破解它并进行多个查询,这些查询将基于'starts with'类型运算符进行查询,然后按所需顺序将它们链接在一起。但我真的想要这样做,我感到畏缩。