3

我想从数据库中检索笔记(非空),我写了以下代码:

public Cursor getmynotesss(int id){
    Cursor mCursor = database.query(true, NOTES_TABLE, new String[] {
            NOTE_TEXT, PAGE_NO,BOOK_ID},BOOK_ID + "=? AND "+NOTE_TEXT+" IS NOT NULL OR "+NOTE_TEXT+" != ''" ,
            new String[] { String.valueOf(id) }, null, null, null, null);

    if (mCursor != null) {
        mCursor.moveToFirst();
    }
    return mCursor;
}

但它仍然给了我空笔记。我的代码有什么问题?

4

4 回答 4

8

看起来OR条件应该是AND

"=? AND "+NOTE_TEXT+" IS NOT NULL AND "+NOTE_TEXT+" != ''"
于 2012-09-08T13:06:17.503 回答
2

我已经像这样解决了我的问题

SELECT pk_video_master_id AS _id,
video_title,
video_added_date,
video_thumbnail FROM tbl_video_master
WHERE NOT video_detail_last_view ='' // this is return not null values and work for me 
ORDER BY video_detail_last_view ASC";

所以你可以这样尝试

Cursor mCursor = database.query(true, NOTES_TABLE,new String[] {NOTE_TEXT,AGE_NO,BOOK_ID},BOOK_ID + "=? AND NOT "+NOTE_TEXT+" = ''" ,new String[] {String.valueOf(id) }, null, null, null, null);
于 2014-03-19T10:04:14.230 回答
0

尝试

      Cursor mCursor = database.query(true, NOTES_TABLE, new String[] {
        NOTE_TEXT, PAGE_NO,BOOK_ID}, NOTE_TEXT+" IS NOT NULL AND "+BOOK_ID + "=?" ,
        new String[] { String.valueOf(id) }, null, null, null, null);

SQLITE 中的不等于是“<>”而不是“!=”

于 2012-09-08T13:10:47.540 回答
-1

尝试更换

IS NOT NULL 

<>``
于 2013-10-24T18:50:09.093 回答