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

后端 未结 13 1673
情话喂你
情话喂你 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:36

    Here's what I did...

    Cursor cur = db.rawQuery("SELECT count(*) FROM " + SQLHelper.TABLE_CART, null);
    if (cur != null && cur.moveToFirst() && cur.getInt(0) > 0) {
        Log.i(getClass().getName(), "table not empty");
    } 
    else {
        Log.i(getClass().getName(), "table is empty");
    }
    

提交回复
热议问题