0

I've again problem with Android database. This time it is showing me again error: Error inserting to database. Database has no column named coverurl, whereas it is there. What is wrong?

    public static final String TABLE_NAME = "gifs";
      public static final String NAME = "name";
      public static final String RATING = "rating";
      public static final String DATE = "date";
      public static final String URL = "url";
      public static final String COVERURL = "coverurl";

      private static final String DATABASE_NAME = "gifs.db";
      private static final int DATABASE_VERSION = 1;

      private static final String DATABASE_CREATE = "create table " + TABLE_NAME + "(" + NAME + " text" + "," + RATING 
              + " int" + "," + URL + " text" + "," + DATE + " text" + "," + COVERURL + " text" + ");";

    public SqliteHelper(Context context) {
        super(context, DATABASE_NAME, null, DATABASE_VERSION);
        //Log.i("DATA BASE", getDatabaseName());
      }

    @Override
    public void onCreate(SQLiteDatabase database) {

         database.execSQL(DATABASE_CREATE);
    }

    @Override
    public void onUpgrade(SQLiteDatabase database, int oldVersion, int newVersion) {

        database.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
        onCreate(database);

    }
}

HERE IS A LOGCAT:

04-12 16:28:27.770: E/Database(20963): Error inserting coverurl=http://i1.kwejk.pl/site_media/obrazki/2013/08/d18316c4c5a92ea4a3bbf5cd8bc34d5a_original.gif?1376656456 rating=444 date=1397316244427 url=http://i1.kwejk.pl/site_media/obrazki/2013/08/d18316c4c5a92ea4a3bbf5cd8bc34d5a_cropped.gif?1376656456 name=fff
04-12 16:28:27.770: E/Database(20963): android.database.sqlite.SQLiteException: table gifs has no column named coverurl: , while compiling: INSERT INTO gifs(coverurl, rating, date, url, name) VALUES(?, ?, ?, ?, ?);
04-12 16:28:27.770: E/Database(20963):  at android.database.sqlite.SQLiteCompiledSql.native_compile(Native Method)
04-12 16:28:27.770: E/Database(20963):  at android.database.sqlite.SQLiteCompiledSql.compile(SQLiteCompiledSql.java:92)
04-12 16:28:27.770: E/Database(20963):  at android.database.sqlite.SQLiteCompiledSql.<init>(SQLiteCompiledSql.java:65)
04-12 16:28:27.770: E/Database(20963):  at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:83)
04-12 16:28:27.770: E/Database(20963):  at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:41)
04-12 16:28:27.770: E/Database(20963):  at android.database.sqlite.SQLiteDatabase.compileStatement(SQLiteDatabase.java:1149)
04-12 16:28:27.770: E/Database(20963):  at android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1569)
04-12 16:28:27.770: E/Database(20963):  at android.database.sqlite.SQLiteDatabase.insert(SQLiteDatabase.java:1426)
04-12 16:28:27.770: E/Database(20963):  at pl.app.storage.DataBaseManager.insertGifToDataBase(DataBaseManager.java:45)
04-12 16:28:27.770: E/Database(20963):  at pl.engine.main.MainActivity.onActivityResult(MainActivity.java:193)
04-12 16:28:27.770: E/Database(20963):  at android.app.Activity.dispatchActivityResult(Activity.java:3908)
04-12 16:28:27.770: E/Database(20963):  at android.app.ActivityThread.deliverResults(ActivityThread.java:2549)
04-12 16:28:27.770: E/Database(20963):  at android.app.ActivityThread.handleSendResult(ActivityThread.java:2595)
04-12 16:28:27.770: E/Database(20963):  at android.app.ActivityThread.access$2000(ActivityThread.java:121)
04-12 16:28:27.770: E/Database(20963):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:973)
04-12 16:28:27.770: E/Database(20963):  at android.os.Handler.dispatchMessage(Handler.java:99)
04-12 16:28:27.770: E/Database(20963):  at android.os.Looper.loop(Looper.java:123)
04-12 16:28:27.770: E/Database(20963):  at android.app.ActivityThread.main(ActivityThread.java:3701)
04-12 16:28:27.770: E/Database(20963):  at java.lang.reflect.Method.invokeNative(Native Method)
04-12 16:28:27.770: E/Database(20963):  at java.lang.reflect.Method.invoke(Method.java:507)
04-12 16:28:27.770: E/Database(20963):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:862)
04-12 16:28:27.770: E/Database(20963):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:620)
04-12 16:28:27.770: E/Database(20963):  at dalvik.system.NativeStart.main(Native Method)
Cœur
  • 37,241
  • 25
  • 195
  • 267
Darek
  • 193
  • 3
  • 14
  • 2
    If you recently added the column, just uninstall your app so the old database is removed and recreated. – laalto Apr 12 '14 at 14:32
  • Thank for this annotation. It's helped – Darek Apr 12 '14 at 14:35
  • 1
    As @Iaalto said the problem is the fact you are using an old database version or you do as him said (ok for tests) or you change private static final int DATABASE_VERSION = 1; this "1" with 2 and so on every time you update the DB in a drastic way. – Marco Acierno Apr 12 '14 at 14:35
  • It can be deleted if you must do this. Btw @laalto answer's helped – Darek Apr 12 '14 at 14:38
  • Just change your database version. – Naddy Apr 12 '14 at 14:39

0 Answers0