The cursor returns -1, but are there elements?

I use a SQLite database to store and restore my application data and verify double entries. I try to get all entries where the names match:

Cursor c = mDb.query(DatabaseHelper.GOALS_TABLE_NAME, new String[] { Goals.GOAL_ID, Goals.TITLE }, Goals.TITLE + "='" + title + "'", null, null, null, null, null); 

where the title is the one that is being compared.

This query is executed, but the cursor gives a counter of -1. A call without a where clause also returns -1, but I know that the data is present, since I can bind a list view to it.

Is there something that I am missing, do I need to fill out the cursor somehow?

Thanks in advance,

Venatu

+4
source share
1 answer

When you execute query() , Cursor returns immediately. The request itself is not yet running. Only when you do something that requires data loading will the request be completed. Before calling getCount() try another method (for example, moveToFirst() ) and see if this has changed.

+12
source

All Articles