SQLite多个查询选择或

时间:2014-11-10 19:49:43

标签: android sqlite

嘿,关于多个选择查询有很多答案,我已经阅读了所有我能找到的内容。我的查询似乎对我来说是正确的,但我只能使用一个选择。希望另一双眼睛能注意到我所缺少的东西。

Cursor getSearch(String itemName) {
    String searchSelect = "( "+MediaStore.Audio.Media.TITLE + " LIKE ? OR"+
            MediaStore.Audio.Media.ARTIST + " LIKE ? OR"+
            MediaStore.Audio.Media.ALBUM + " LIKE ? )";
    String[]  selectArgs = { "%" + itemName + "%"};
    Cursor searchCursor = getContentResolver().query(
            queryUri,
            projection,
            searchSelect,
            selectArgs,
            MediaStore.Audio.Media.TITLE + " ASC"
    );
    return searchCursor;
}

1 个答案:

答案 0 :(得分:0)

在OR之后缺少空格

Cursor getSearch(String itemName) {
    String searchSelect = "( "+MediaStore.Audio.Media.TITLE + " LIKE ? OR "+
            MediaStore.Audio.Media.ARTIST + " LIKE ? OR "+
            MediaStore.Audio.Media.ALBUM + " LIKE ? )";
    String[]  selectArgs = { "%" + itemName + "%","%" + itemName + "%","%" + itemName + "%"};
    Cursor searchCursor = getContentResolver().query(
            queryUri,
            projection,
            searchSelect,
            selectArgs,
            MediaStore.Audio.Media.TITLE + " ASC"
    );
    return searchCursor;
}