where“not null”子句在sqlite android中

4ktjp1zp  于 2023-10-14  发布在  Android
关注(0)|答案(4)|浏览(109)

我想从数据库中检索笔记,笔记是(不为空),我写了下面的代码:

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;
}

但它还是给了我空音我的代码有什么问题?

c0vxltue

c0vxltue1#

看起来OR条件应该是AND

"=? AND "+NOTE_TEXT+" IS NOT NULL AND "+NOTE_TEXT+" != ''"
rdrgkggo

rdrgkggo2#

我已经这样解决了我问题

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);
ne5o7dgx

ne5o7dgx3#

尝试

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中,not equals是“<>”not“!=”

xnifntxz

xnifntxz4#

尝试更换

IS NOT NULL

<>``

相关问题