how to upgrade database version with new rows with SQLiteAssetHelper

此生再无相见时 提交于 2019-11-29 12:01:20
CL.

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.)

varsha valanju

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!