1

I'm making an app where I need to store data for each day and it would be helpful if i could easily filter it, so i decided to learn about SQLite databases, found tutorial (several actually), followed it and in the end always got the same result - empty cursor.

enter public Day getDay(int year, int month, int day) {
    Day ret = null;

    SQLiteDatabase db = this.getReadableDatabase();
    Cursor c = db.rawQuery("SELECT '*' FROM '" + TABLE_DAYS + "'", null);
    Log.d("DATA", "entries found: " + c.getCount());
    c.close();
    db.close();
    return ret;
}

Method to insert new row seems to be functional as it returns expected number, but even though this is called just afterwards, it returns empty Cursor. I've read many tutorials and SO posts without finding a fix. I also tried metod .query(...) with same result.

2
  • '*'? do you mean *? Commented Jul 12, 2016 at 18:29
  • i'm faced same problem with android P, This solution saved me: stackoverflow.com/a/53258585/9967174 Commented Nov 2, 2019 at 21:41

5 Answers 5

1

It may be worth using the query() method in place of rawQuery() in order to avoid future syntax errors. The following will achieve the same outcome as your rawQuery() by returning the data for all rows.

Cursor c = db.query(TABLE_DAYS, null, null, null, null, null, null);
c.getCount();
Sign up to request clarification or add additional context in comments.

1 Comment

yes. Always use those methods instead of trying to write SQL yourself.
0

Use db.rawQuery("SELECT * FROM " + TABLE_DAYS + "", null);

Comments

0

try removing the quotes from SELECT * FROM

Comments

0

Replace

Cursor c = db.rawQuery("SELECT '*' FROM '" + TABLE_DAYS + "'", null);

With

Cursor c = db.rawQuery("SELECT * FROM "+ TABLE_DAYS ,null);

1 Comment

I have fixed your formatting, you don't have to destroy it again.
0

Turns out the mistake was somewhere else - passed wrong parameters to method creating the database. Thanks anyway for all responses.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.