自己的呼叫onUpgrade方法自己的、方法、onUpgrade

由网友(痴人说梦 2π/d)分享简介:我怎么能调用数据库的 onUpgrade 方法?How can I call the onUpgrade Method of the database?我的问题背景:我做的完整数据库的SD卡备份。而且用户可以恢复这个数据库。Background of my question:I do a backup on...

我怎么能调用数据库的 onUpgrade 方法?

How can I call the onUpgrade Method of the database?

我的问题背景: 我做的完整数据库的SD卡备份。 而且用户可以恢复这个数据库。

Background of my question: I do a backup on the sdcard of the full database. And the user can restore this database.

但是,如果在此期间(之间的备份和恢复),一个应用程序更新对数据库的修改,我会得到恢复的问题。新列不存在恢复后。

But, if in the meantime (between backup and restore) an app update changes to the database, I will get a problem on restoring. The new columns are not there after restoring.

所以,我想叫 onUpgrade 方法添加的所有新/改列。

So I want to call the onUpgrade method to add all new/changed columns.

或者有什么更好的办法呢?

Or is there any better way for this?

推荐答案

在进行恢复,关闭所有打开的句柄到数据库,然后用你的 SQLiteOpenHelper 来获得一个可写的数据库。这应该引起 onUpgrade()来调用,AFAIK。

After a restore, close all open handles to the database, then use your SQLiteOpenHelper to get a writable database. That should trigger onUpgrade() to be called, AFAIK.

阅读全文

相关推荐

最新文章