自己的呼叫onUpgrade方法 [英] self call onUpgrade method

查看:127
本文介绍了自己的呼叫onUpgrade方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎么能调用数据库的 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.

这篇关于自己的呼叫onUpgrade方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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