Cursor returns a count of -1, but items are present?
I am using an SQLite database to store and retreive my app data, and what to check for duplicate entries. I attempt to retrieve all entries where the titles match, as such:
Cursor c = mDb.query(DatabaseHelper.GOALS_TABLE_NAME,
new String[] { Goals.GOAL_ID, Goals.TITLE },
Goals.TITLE + "='" + title + "'", null, null, null,
开发者_如何学Go null, null);
where title is the one to compare against.
This query runs, but the cursor gives a count of -1. A call without the where clause also returns -1, but I know data is present, as I am able to bind a list view to it.
Is there something I am missing, do I have to populate the cursor somehow?
Thanks in advance,
Venatu
When you do a query()
, the Cursor
is returned immediately. The query itself is not yet run. Only when you do something that requires a data load will the query be executed. Try executing another method first (e.g., moveToFirst()
) before calling getCount()
and see if that changes things.
精彩评论