在SqLite中使用Collat​​e没有结果

时间:2019-02-24 10:52:36

标签: android android-sqlite collate

你好,我有sqlite数据库,当我从中搜索单词时,一切正常。现在我想如果用户输入(a,s,y,u,o,n,z),它也会搜索(ä,ş,ý,ü,ö,ň,ž)。我搜索了一下,发现Collat​​e将为我完成这项工作。我尝试使用phpmyadmin整理我的MySQl。然后我在Android的SQLiteDatabase中尝试了它,但是它不起作用。当我键入(a,s,y,u,o,n,z)时,它仅搜索该字母。这是我的代码:

public WordList getWordList(String word){
        if(!word.equals("")){
            word = word.replace("'", "");
            word = word.replace("\"", "");
            word = word.toUpperCase();
//          Cursor cursor = myDataBase.rawQuery("SELECT * FROM words WHERE word  LIKE \"" + word + "%\" COLLATE LOCALIZED LIMIT 50", null);
            Cursor cursor = myDataBase.rawQuery("SELECT * FROM words WHERE word COLLATE utf8_general_ci LIKE  \"" + word +"%\"  LIMIT 50", null);
            ArrayList<String> word_list = new ArrayList<String>();
            ArrayList<String> ids =  new ArrayList<String>();


            while(cursor.moveToNext()){
                word_list.add(cursor.getString(cursor.getColumnIndex("word")).toLowerCase());
                ids.add(cursor.getString(cursor.getColumnIndex("desc_ids")));

            }
            cursor.close();
            WordList wordList = new WordList();
            wordList.setWordList(word_list);
            wordList.setIdList(ids);
            return wordList;

        }               
        else{
            return null;
        }
    }

0 个答案:

没有答案