Android does not update SQLite database?

Up vote 1 down vote favorite 1 share g+ share fb share tw.

I am experiencing some trouble with an SQLIte database in my Android application. The issue is that the database is never updated, not even on multiple restarts of the emulator, of Eclipse or after deletion from DDMS. This is my onCreate method, located in a class that extends SQLiteOpenHelper: public void onCreate(SQLiteDatabase database) { try { database.

ExecSQL(ESSENCE_TABLE_CREATE); database. ExecSQL(PACCO_TABLE_CREATE); database. ExecSQL(TAVOLE_TABLE_CREATE); database.

RawQuery("insert into essenza values(1, 'Rovere')", null); // added later } catch (SQLException e) { Log. E("DB", e.getMessage()); } } After instantiating the helper, I request a reference to the database: helper = new DBHelper(context, dbpath + "/" + DATABASE_NAME); database = helper. GetWritableDatabase(); It seems that the rawQuery statement (which was added at a later time) is not executed and that the database in use is instead cached from a previous version.

I also tried to change the version of the database, but it did not work. Am I missing something? Thanks in advance.

Android sqliteopenhelper link|improve this question edited Sep 1 '11 at 13:46 asked Aug 31 '11 at 17:26Tilvia83.

You have an open quote. – MrZander Aug 31 '11 at 17:32 1 this is because the the database already exists. This will be executed on fresh install if your logic is (if (!dbExists) {createDb} else {//do nothing} – mihail Aug 31 '11 at 18:06 @MrZander : I just edited the code, it was just a typo.

– Tilvia Sep 1 '11 at 13:47 @mihail : I am aware of the fact that the database exists. What is not clear to me is why it is never deleted and recreated. – Tilvia Sep 1 '11 at 13:49.

You have two options: Use DDMs to delete the database file from your device (look in /data/data/). This will force Android to run onCreate again. In your constructor, increment the database version you pass to SQLiteOpenHelper.

Add your raw query to onUpgrade. You probably want option 1. Option 2 is better if you have users of your app whose databases you want to update.

Even if I delete the database file from DDMS, the problem is still there, as if onCreate is not run again. I should mention that the database is being saved in a (virtual) external memory. – Tilvia Sep 1 '11 at 13:50 When you delete the database, does it get recreated?

If so, you should try stepping through onCreate with the debugger to see what is happening. – elevine Sep 1 '11 at 14:08 Solved it (at least apparently) by recreating the whole emulator and moving the raw query after getWritableDatabase rather than in onCreate. No clue what happened, though.

– Tilvia Sep 1 '11 at 14:23.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions