Skip to content Skip to sidebar Skip to footer

How To Upgrade Database Version With New Rows With Sqliteassethelper

i have developed a tutorial app in which i have saved more than 500 questions and answers. their is one more table called favourites. which is for user input. now, i want to update

Solution 1:

The documentation tells you to

create a text file containing all required SQL commands to upgrade the database from its previous version to it's current version.

You can use any SQL commands, not only ALTER TABLE, but also INSERT.

The database file in the assets folder is used only if there is no old data (if the app is installed for the first time). If there is old data, SQLiteAssetHelper executes the SQL upgrade script instead.

The SQLiteAssetHelper project contains an example that shows how such a script would look like.

To keep the data in the favourites table, you do not need to do anything. To add the new question/answers, use a bunch of INSERT statements. (For how to get those INSERT statements, see How to compare two SQLite databases.)

Solution 2:

finally i got answer for my questions. as i said i am using SQLiteAssetHelper library. and now i want to add new records and want to release the update version. so i was finding the feature by which i can store new updated db in assets folder. and this library will update the old db in user's phone. with keeping particular table in old db.

but currently this library doesnt offers such feature. the upgrade script can be use only to make changes is old db. we can add new updated db and copy the data from new one.

if we want to add new data and also dont want to erase local data table. then we need to write insert queries in upgrade script as described in documentation of that library.

but if we have to add 100 queries then their is no shortcut for it. we have to write 100 insert statements in upgrade script.

and in case if we gate a error saying cannot upgrade read only database from version x to y then here is the solution for it:

SQLITE cant upgrade read-only database from version 1 to 2

Post a Comment for "How To Upgrade Database Version With New Rows With Sqliteassethelper"