I have around 2600 entries in mySQLite database. I need to delete all those entries and put in updated entries. I know that the database can be updated by changing the database version in theDatabaseHandler class, but that can only be done if the whole app is updated. I need to programatically update the database. Can this be done? I searched but couldn't find a satisfactory answer. Thanks.
- If the schema is the same, the version should be the same, no? Just delete and add the records as appropriate. Consider using a simple in-database "last version of data" token (which works well for "get all latest" synchronization with external sources).user2246674– user22466742013-06-23 19:05:47 +00:00CommentedJun 23, 2013 at 19:05
- You can replace databases on the fly. What have you tried?Andrei– Andrei2013-06-23 19:09:07 +00:00CommentedJun 23, 2013 at 19:09
- @user2246674 Is there a more elegant way to update the whole database, instead of updating values one by one?vergil corleone– vergil corleone2013-06-23 19:10:44 +00:00CommentedJun 23, 2013 at 19:10
- What is wrong with "one by one"? Obviously a loop would be used - andinside a single transaction, multiple inserts are very fast. (An insert can be fed multiple records at a time, but it won't make a noticeable difference for SQLitewhen transactions are used and it makes the looping/building code more complex.) Also, if an entire external database is downloaded, it can be attached and the records can be pulled over in one statement. It really depends on where the data comes from, etc.user2246674– user22466742013-06-23 19:11:49 +00:00CommentedJun 23, 2013 at 19:11
- 1Looks like a good start. Make sure to commit the transaction.user2246674– user22466742013-06-23 19:23:26 +00:00CommentedJun 23, 2013 at 19:23
1 Answer1
I guess you can call a method some what like this
public void emptyDatabase() { db = this.getWritableDatabase(); db.execSQL("DELETE FROM " + TABLE_Your_Tbl);}Even this will be able to delete those values quickly. Without updating the version number.
Plus as you mentioned that you have to delete the records and add new values.It will be much faster that updating those values.
2 Comments
Explore related questions
See similar questions with these tags.

