不频繁更新 Android 数据库的最佳实践?
我有一个 Android 应用程序,它在首次打开时将数据库(所有表中约 2000 行)安装到设备上。用户可以对其进行较小的更改(仅限一列),并且仅在新版本发布时更新。
由于数据库/应用程序的性质,尚无法将数据放到网上(尚)。
我假设我将安装带有大量插入的数据库(onCreate),然后时不时地更新它,然后在每个新版本中插入更多行(onUpdate?)。此过程的最佳实践是什么?
- 我是否应该有一个 XML(或其他结构)文件来模拟数据并在每次更新时插入每个新行?
- 每次更新时,我应该删除所有旧数据,或者将取决于当前数据库版本与新数据库版本的过程保留在 onUpdate() 内(例如:版本<X,然后更新这些行并添加这些...)?
- 用户可以更改每行的列(特定于该用户)。将其存储在首选项文件中是否更有意义?
使用已部署的数据库对我来说是新的,所以任何帮助将不胜感激!
谢谢!
I have an Android application that installs a database (~2000 rows across all tables) to the device when it is first opened. The user can make minor changes to it (one column only) and it is only updated on a new version release.
Due to the nature of the database/application, it is not possible to put the data online (yet).
I am assuming I will install the database (onCreate) with a LOT of inserts, then update it every now and then, and then insert more rows (onUpdate?) with each new release. What would be the best practices for this procedure?
- Should I have an XML (or other structure) file that mimics the data and inserts every new row on every update from there?
- On each update should I erase all old data, or keep procedures inside of onUpdate() that depend on the current vs new database version (ex: version < X then update these rows and add these...)?
- The user can change a column (specific to that user) for each row. Would storing this in a preferences file make more sense?
Working with deployed databases is new to me, so any help would be appreciated!
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,我可以建议迁移方式。将数据版本保存在数据库中。使每个应用程序发行版都具有 1.0-to-1.3.upd、1.3-to-1.4.upd 等文件来保存所有更新数据,以转换到新版本的数据。
每个 OnUpdate() 都应该检查数据库中的数据版本,并检查它必须的 *.upd 文件列表,以确定是否需要数据更新。然后一一应用必要的更新,每次增加数据库中的数据版本。
这就像 VBulletin 和 XenForo 论坛的更新工作一样。
Well, I can suggest the migration way. Keep data version in the database. Make each application distribution have files like 1.0-to-1.3.upd, 1.3-to-1.4.upd holding all the update data to make a transition to a new version of the data.
Each OnUpdate() should check data version in the database and check a list of *.upd files it have to determine if data update is required. And then just applies necessary updates one by one, increasing data version in db each time.
This is like VBulletin and XenForo forums updates work.