How can i check to see if my sqlite table has data in it?

后端 未结 13 1518
情话喂你
情话喂你 2020-12-01 13:14

EDIT, Changed the code slightly based on answers below, but still haven\'t got it working. I also added a log message to tell me if getCount was returning > 0, and i

相关标签:
13条回答
  • 2020-12-01 13:50

    As paxdiablo said, the cursor will not be null. What you can do is try like this:

    if (cur != null && cur.getCount() > 0){
         // do nothing, everything's as it should be
    }
    

    EDIT

    Actually i had used the db.query() and it worked for me. I did this.

    cursor = db.query(TABLE_NAME, new String[] { KEY_TYPE }, null, null, null, null, null);
    if (cursor != null && cursor.getCount() > 0)
    {
       retVal = true;
    }
    

    TABLE_NAME is my table and KEY_TYPE was my columnname

    0 讨论(0)
提交回复
热议问题