如何保存数据库信息到android中的文件? [英] How to save database information to a file in android?

查看:134
本文介绍了如何保存数据库信息到android中的文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序使用预定义的数据库来列出事件。该应用程序允许人们将这些事件保存到他们的收藏夹通过设置一个'1'到列isFavorite。然后,用户只能查看搜索具有isFavorite = 1的所有行的已收藏事件列表。

I have an application that uses a pre-polulated database to list events. The app allows people to save these events to their favorites by setting a '1' to the column isFavorite. Then the user can view only a list of 'favorited' events which searches for all rows that have isFavorite = 1.

如果事件发生任何更改,或者我需要添加更多的列表,我必须进行这些更改,然后推动更新到完全写在表,清除自己的收藏夹的应用程序。

If any changes happen to the events or I need to add more to the list, I have to make those changes and then push the update to the app which completely writes over the table, clearing out their favorites.

有任何方式,我可以,在升级时,保存所有事件的id的列表,他们已经设置为他们的收藏夹,然后在新的数据库加载后,将所有的列表中的ID设置为1,所以用户不会丢失他们最喜欢的数据?

Is there any way that I can, on upgrade, save a list of id's of all the events that they have set to their favorites, then after the new database has been loaded, to set all id's in that list to 1 so the user doesn't lose their favorited data?

如果有任何其他更好的解决方案,这个问题,我会真的很感激,这是迄今为止我最大的障碍。

If there are any other better solutions to this problem I would really appreciate it, this has been the biggest hurdle for me so far.

推荐答案

我想你有一个 SQLiteOpenHelper -class?这个类必须被扩展,然后提供两个函数: onCreate (当查询数据库并且它不存在时被调用(通常首先创建你的数据库) )和 onUpdate (在更新数据库结构时查询)。

I guess, you have a SQLiteOpenHelper-class? This class must be extended and then provides two functions: onCreate (which is called when the Database is queried and it doesn't exist (Normally creates your Database in the first place)) and onUpdate (which is queried when the Database structure should be updated).

onUpdate -method有一个 SQLiteDatabase -Object参数,这是您的数据库。然后,您可以查询所需的信息,保存它们,然后创建新的数据库表。之后,您可以将保存的数据插入数据库。

The onUpdate-method has an SQLiteDatabase-Object parameter, which is your Database. You can then Query the information you need, save them and then create the new Database-tables. After that, you can insert your saved data back into the Database.

这篇关于如何保存数据库信息到android中的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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