以preloaded SQLite的应用程序更新 [英] Update app with preloaded SQLite
问题描述
我的应用程序使用了preloaded和复制从/资产数据/数据(<一个href=\"http://stackoverflow.com/questions/513084/how-to-ship-an-android-application-with-a-database\">How船舶与数据库的Android应用程序?)分贝这简直是产品数据的一个表,并只读,因为用户不保存到数据库。如果我添加更多的产品到数据库表,我需要得到这个现有用户。如果更新我的新的数据库应用程序将在更新过程中删除从资产目录数据复制旧的数据库/数据,从而使DBexists检查失败第一次运行的更新版本从而引发新的数据库复制从/资产数据/数据?
My app uses a preloaded and copied from /assets to data/data ( How to ship an Android application with a database?) db which is simply a single table of product data and is 'read only' as users do not save to the DB. If I add more products to the DB table I need to get this to existing users. If I update my app with the new DB will the update process delete the old DB that was copied from the assets dir to data/data thereby allowing the 'DBexists' check to fail on first running the updated version thus triggering copying of the new DB from /assets to data/data?
推荐答案
简短的回答,是的,如果你把下面的代码片段吧 onUpgrade()
方法:
Short answer, yes, if you put the following snippet it the onUpgrade()
method:
try {
copyDataBase("database.db");
} catch (IOException e) {
Log.w(TAG, e);
}
这可能是值得删除的数据库文件 copyDataBase()
写在它之前,只是为了让不太可能损坏。
It may be worth deleting the db file in copyDataBase()
before writing over it, just to make it less likely to corrupt.
注:这里使用在您链接的问题接受的答案使用的实施
NB: this uses the implementation as used in the accepted answer of the question you linked.
这篇关于以preloaded SQLite的应用程序更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!