0

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.

askedJun 23, 2013 at 19:04
vergil corleone's user avatar
6
  • 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).CommentedJun 23, 2013 at 19:05
  • You can replace databases on the fly. What have you tried?CommentedJun 23, 2013 at 19:09
  • @user2246674 Is there a more elegant way to update the whole database, instead of updating values one by one?CommentedJun 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.CommentedJun 23, 2013 at 19:11
  • 1
    Looks like a good start. Make sure to commit the transaction.CommentedJun 23, 2013 at 19:23

1 Answer1

1

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.

answeredJun 23, 2013 at 20:16
MDMalik's user avatar
Sign up to request clarification or add additional context in comments.

2 Comments

If I add those values to rows which already contain data, will the rows get overwritten or appended?
It depends on what structure you used. If you have used Primary Key Auto increment then you can insert but after that you will find duplicate data. So better to Delete first then Add newer one.

Your Answer

Sign up orlog in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

By clicking “Post Your Answer”, you agree to ourterms of service and acknowledge you have read ourprivacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.