OnUpgrade 不使用删除表/创建表/插入
我真的很喜欢这种方法在为 Android 开发时处理 sqlite 数据库,但在应用程序升级期间升级数据库时我有一个问题。是否建议使用这种方法,或者在事务中使用删除表/创建表/插入来执行标准过程(看起来是这样)是否更安全,以便能够在失败时回滚?
I really like this approach for handling sqlite database when developing for Android but I have a question when it comes to upgrading the database during an upgrade of the application. Is this method recommended or is it so much safer to do the standard procedure (as it seem to be) with drop table/create table/insert into, within a transaction instead, in order to being able to roll back in case of failure?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
?您正在谈论一种特定的方法吗?
该链接似乎显示了
SQLiteOpenHelper
的简单使用 作为标准 API 的一部分,我认为是推荐的。您可以在
onUpgrade
方法中执行任何您喜欢的操作,无论是DROP
ping 表、ALTER
ing 表,还是其他任何操作。如果您想将它们包含在交易中,那由您决定。
Is there a particular method you're talking about?
That link seems to show simple use of an
SQLiteOpenHelper
which, as part of the standard API, I would say is recommended.You can do whatever you like in the
onUpgrade
method, whether it'sDROP
ping tables,ALTER
ing them, or whatever.If you want to wrap them in a transaction, that's up to you.