填充使用默认的数据SQLite数据库时,什么是最好的做法? [英] What's the best practice when populating a sqlite database with default data?

查看:205
本文介绍了填充使用默认的数据SQLite数据库时,什么是最好的做法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在做一个应用程序,将使用从SQLite数据库几百数据库的职位。该应用程序的生命周期内我不会再增加新的数据(除非我更新了整个应用程序)。

I'm making an app that will be using few hundred database posts from a sqlite database. I will not be adding new data during the lifetime of the app (unless I update the whole app).

我可能最终使用静态XML的数据,但我需要标志的职位,所以我想一个SQLite数据库将完成这项工作最好的。我知道如何实现它,我才......

I might end up using a static xml for the data, but I need to flag posts, so I guess a sqlite db would do the job best. I know how to implement it and I've released apps using sqlite before...

但我的问题是。如何以最好的填充sqlite的分贝的第一次应用程序运行?我应该在我作为一个资源使用,然后复制到应用程序空间的文件只是带来了什么?什么是最好/最简单的做法是什么?

But my question is. How to I best populate the sqlite db the first time the app runs? Should I just bring in a file that I use as a resource and then copy to the apps space? What's the best/easiest practice?

推荐答案

最简单的解决办法是的使用 SQLiteAssetHelper 。你基本上放弃你的SQLite数据库到项目的资产/ 目录,并使用 SQLiteAssetHelper 代替 SQLiteOpenHelper 。除了样品code杰夫Gilfelt的GitHub库弥补了图书馆,我的 证明它还有一个示例应用程序。

The simplest solution is to use SQLiteAssetHelper. You basically drop your SQLite database into your project's assets/ directory, and use SQLiteAssetHelper in lieu of SQLiteOpenHelper. In addition to the sample code up on Jeff Gilfelt's GitHub repo for the library, I have a sample app demonstrating it as well.

这篇关于填充使用默认的数据SQLite数据库时,什么是最好的做法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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