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.

PecaWolf
  • 77
  • 1
  • 11

5 Answers5

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();
PPartisan
  • 8,173
  • 4
  • 29
  • 48
0

try removing the quotes from SELECT * FROM

Damian Kozlak
  • 7,065
  • 10
  • 45
  • 51
tibbi
  • 249
  • 4
  • 27
0

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

Damian Kozlak
  • 7,065
  • 10
  • 45
  • 51
Rishav Sengupta
  • 241
  • 2
  • 4
0

Replace

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

With

Cursor c = db.rawQuery("SELECT * FROM "+ TABLE_DAYS ,null);
Damian Kozlak
  • 7,065
  • 10
  • 45
  • 51
Priya Singhal
  • 1,261
  • 11
  • 16
0

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

PecaWolf
  • 77
  • 1
  • 11