Android database (SQLite) returns a non-empty cursor from an empty table

I checked with SQLite Database Browser that the table does not contain rows. I went through the query builder code to get the generated query and run the query in SQLite Database Broswer. The query returned null rows. However, the cursor returned by the SQLiteQueryBuilder.query Android method returns true in the cursor.moveToFirst () call and returns null values.

Has anyone seen something like this before?

+4
source share
3 answers

OK: I realized that this is because I use the MAX aggregation function in the request. Could it be a mistake, maybe? Now I use sort with limit clause instead of MAX and work around.

+4
source

I think you should do something like:

if (c.getCount()>0) { c.moveToFirst(); 
0
source

moveToFirst actually implemented as moveToPosition(0) . moveToPosition is the final method defined in AbstractCursor. By looking at the code, you can see that the result is partially depentandt on getCount . and it seems that in your case getCount returns a nonzero value.

See what the value of the "_id" column is, and try deleting it. Alternatively, try calling this code after re-creating the database (calling "drop table" and then "create table").

0
source

Source: https://habr.com/ru/post/1336661/


All Articles