更新新版本的应用程序商店不同的SQLite数据库结构 [英] Updating new version to app store with different sqlite db structure

查看:146
本文介绍了更新新版本的应用程序商店不同的SQLite数据库结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已上传的应用程序商店的应用程序(1.0版本)。我的应用程序是使用SQLite数据库来存储一些数据。现在,我已经在数据库中的一些变化(我在其中一个表在我的数据库添加2个或3个新列)。我想更新我的应用程序的previous的版本与新版本1.1(这是具有不同数据库结构)。现在,当它已经在使用1.0版的用户应用程序升级到1.1版,该数据库已经是美元的应用程序沙箱,因此,应用程序指向1.1版本p $ psent,但我的分贝仍是旧的。我想有旧数据的新的数据库,如果有的话。请帮助我。谢谢你。

I have uploaded an app on app store (version 1.0). My app is using a sqlite database for storing some data. Now, I have made some changes in the database (I have added 2 or 3 new columns in one of the tables in my db). I want to update the previous version of my app with the new version 1.1 (which is having different db structure). Now, when the users which are already using the version 1.0 upgrade the app to version 1.1, the db is already present in app sandbox and hence, the app is pointing to version 1.1, but my db is still the old one. I want to have the new db with the old data, if any. Please help me out. Thanks.

推荐答案

SQLite支持的东西称为user_version属性,您可以执行 PRAGMA user_version 来查询当前架构版本您的应用程序分贝。您的应用程序启动时,这个查询可以在开始发生写。

sqlite supports something called as user_version property, you can execute PRAGMA user_version to query for current schema version of your app db. This query can happen write at the beginning when your app starts.

更新此user_version执行下面的更新查询 PRAGMA user_version = VERSION_NUM ;

to update this user_version execute following update query PRAGMA user_version = version_num;

每当创建sqlite的分贝,这是把这个属性user_version,所以,当你在未来的升级可以查询当前值的最佳实践。检查什么它必须和执行剩余的改变或创建表升级架构版本。

Whenever you create sqlite db, it is best practice to put this property user_version, so that when you are upgrading in future you can query current value. Check what it's needs to be and execute remaining alter or create tables to upgrade your schema version.

例如:

在第一次发布我创建COL1表1,COL2

In first release I create table1 with col1, col2

我执行SQL创建表1,一旦成功完成,我执行编译user_version = 1,所以这将表明我目前的架构版本为1

I execute sql to create table1 and once it is successfully done, i execute pragma user_version = 1. so this will indicate my current schema version is 1

在未来的版本我添加新COL3,我需要我的架构的版本改为2

In future release i add new col3, i need to change my schema version to 2

我第一次查询user_version,检查它的价值,如果是1,那么你需要运行修改脚本来新列,并设置用户版本添加到2

I first query user_version, check it's value and if it is 1, then you need to run alter script to add new column and set user version to 2.

在你的情况,因为你以前没有设置user_version,这将是很难区分新安装VS升级方案。所以现在可能是你想如果db是present这是升级方案和执行修改脚本,如果没有present假定它是一个新的
安装方案并运行创建脚本。但是,看看你能不能用上面编译解决您的问题,在今后的ATLEAST。

In your case, since you haven't set the user_version before, it would be difficult to differentiate new install vs an upgrade scenario. So for now may be you assume if db is present it is upgrade scenario and execute alter scripts and if not present assume it is a new install scenario and run create scripts. But see if you can use above pragma to solve your problem in future atleast.

这篇关于更新新版本的应用程序商店不同的SQLite数据库结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆