0

I'm getting an error while I run this Query:

public List<byte[]> getImageBlobs() {
        List<byte[]> list = new ArrayList<>();
        Cursor cursor = database.rawQuery("SELECT imageBlob FROM boardgames", null);
        cursor.moveToFirst();
        while (!cursor.isAfterLast()) {
            list.add(cursor.getBlob(0));
            cursor.moveToNext();
        }
        cursor.close();
        return list;
}

Database structure from DB Browser for SQLite

enter image description here

From logcat:

03-06 10:43:51.342 10469-10469/? E/SQLiteLog: (1) no such column: imageBlob
03-06 10:43:51.343 10469-10469/? E/AndroidRuntime: FATAL EXCEPTION: main
                                                   Process: com.boardgamehelper.boardgamehelper, PID: 10469
                                                   android.database.sqlite.SQLiteException: no such column: imageBlob (code 1): , while compiling: SELECT imageBlob FROM boardgames
                                                       at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
Shank
  • 1,387
  • 11
  • 32
  • Reinstall application and try again. – Ahmad Aghazadeh Mar 06 '16 at 16:03
  • Adb pull down the db and look at the structure of the table- I suspect your create query was wrong or you had an old version of the table without that column and didn't update it correctly. – Gabe Sechan Mar 06 '16 at 16:04
  • @ahmadaghazadeh what application? the app or Sqlite browser – Shank Mar 06 '16 at 16:05
  • Do you have changed the structure of your database? – Ahmad Aghazadeh Mar 06 '16 at 16:07
  • yes, i fixed it. i had to clear data on the app – Shank Mar 06 '16 at 16:08
  • make sure you have `imageBlob` column in your table: the easiest way to do that is, just for testing, query for "select * from boardgames" and call `DatabaseUtils.dumpCursor()` – pskink Mar 06 '16 at 16:11
  • This error occurred when column name not exists into your database, make sure your database is upgraded or not after the change in the table. You have to reset whenever your table has changed. – Android Leo Mar 06 '16 at 16:19

2 Answers2

0

When the database structure changes need to be removed and re-created database. Reinstall application and try again.

Then remove and reinstall the program to do it.

Ahmad Aghazadeh
  • 16,571
  • 12
  • 101
  • 98
0

Clear data is not a good idea. If your application is already in production. You should be using ALTER statement and adding the column in the onUpgrade() of the class extending SQLiteOpenHelper Do not forget to update the database version whenever you alter the tables schema.

Umang
  • 966
  • 2
  • 7
  • 17