iOS SQLite.swift,关于app的升级? [英] iOS SQLite.swift, regarding upgrade of app?
问题描述
关于华丽而神奇的SQLite.swift,我想知道
Regarding the magnificent and amazing SQLite.swift, I'm wondering
你在应用程序商店中有一个应用程序,v7。有一个升级到v8。用户X使用应用程序商店将v7升级到v8。
You have an app in the app store, v7. There's an upgrade to v8. User X does upgrade v7 to v8 using the app store.
在v8中说,我们稍微改变了一个sql表,可能是添加一个列或重命名一列。
Say in v8, we have slightly changed one of the sql tables, perhaps add a column or rename a column.
在这种情况下,在SQLite.swift中是否应该执行任何特殊操作?
Should anything or must anything special be done in SQLite.swift in this case?
SQLite.swift处理它的方法是什么?
What's the SQLite.swift way to handle that?
(例如,Android有一个方便的< a href =https://developer.android.com/reference/android/database/sqlite/SQLiteOpenHelper.html#onUpgrade(android.database.sqlite.SQLiteDatabase,%20int,%20int)\"rel =noreferrer> onUpgrade 助手类中的概念......它附带了它自己的一系列复杂问题。)
(In for example, Android there's a handy onUpgrade concept in their helper class ... which comes with it's own set of complex issues.)
推荐答案
SQLiteOpenHelper 非常简单:
db = SQLiteDatabase.openDatabase(...);
onConfigure(db);
int version = db.getVersion();
if (version != mNewVersion) {
db.beginTransaction();
try {
if (version == 0) {
onCreate(db);
} else {
if (version > mNewVersion) {
onDowngrade(db, version, mNewVersion);
} else {
onUpgrade(db, version, mNewVersion);
}
}
db.setVersion(mNewVersion);
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
}
在Swift中也一样。
Just do the same in Swift.
关于如何实施 onUpgrade()
,请参阅 SQLiteOpenHelper onUpgrade()混淆Android 。
For how to implement onUpgrade()
, see SQLiteOpenHelper onUpgrade() Confusion Android.
这篇关于iOS SQLite.swift,关于app的升级?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!