Reputation: 4641
I'm under a wall. I have a very simple method
public List<com.fixus.portals.model.Foothold> findAll() {
List<com.fixus.portals.model.Foothold> result = new ArrayList<com.fixus.portals.model.Foothold>();
Cursor cursor = this.db.query(MainHelper.TABLE_FOOTHOLD, FOOTHOLD_FIELDS, null, null, null, null, null);
cursor.moveToFirst();
while (!cursor.isAfterLast()) {
com.fixus.portals.model.Foothold foothold = this.mapToObject(cursor);
result.add(foothold);
cursor.moveToNext();
}
cursor.close();
return result;
}
It should return every record from table but it returns 0 (zero). I don't know why. I've debugged whole process the query looks ok. What is funny when I copy the query that is invoked and run it manualy on DB i receive the results. But when I do it from Android level I return nothing. What am I doing wrong ?
Upvotes: 0
Views: 59
Reputation: 1745
Use this code pattern for a cursor:
public List<com.fixus.portals.model.Foothold> findAll() {
List<com.fixus.portals.model.Foothold> result = new ArrayList<com.fixus.portals.model.Foothold>();
Cursor cursor = this.db.query(MainHelper.TABLE_FOOTHOLD, FOOTHOLD_FIELDS, null, null, null, null, null);
com.fixus.portals.model.Foothold foothold = this.mapToObject(cursor);
if(cursor.moveToFirst()){
do{
result.add(foothold);
}while(cursor.moveToNext());
}else{
//Your code for no data
}
cursor.close();
return result;
}
And make sure that your table is not empty.
Upvotes: 1