Search code examples
androiddatabasesqliteselect-query

SQLite query not work on Android rawQuery


Edit: Problem solved, query is correct. My problem is; I work with local database. And i'm not reach database directly from assets folder. My code copy database from assets folder to SD card when database not exits on SD card. Therefore my database changes only effect database in asset folder. And i was tried right query on old database. Sorry for the question.

I tried my SQLite query on DB Browser for SQLite and it's worked.

But on Android same query not worked.

 String[] a = new String[1];
 a[0] =   yazilanKelime + '%';
 Cursor friendCursor = db.rawQuery( "SELECT * FROM kelimeler WHERE kelime LIKE ? ORDER BY sayi DESC LIMIT 10", a);

If i remove "ORDER BY sayi DESC" part, it's work. Where am I doing wrong?

UPDATE: Return this Exception: android.database.sqlite.SQLiteException: no such column: sayi (code 1): , while compiling: SELECT * FROM kelimeler WHERE kelime LIKE ? ORDER BY sayi DESC LIMIT 10

DB Schema: enter image description here


Solution

  • As the exception says, no such column: sayi means that the column sayi does not exists in your table kelimeler. Check this first.