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,
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With