填充使用默认的数据SQLite数据库时,什么是最好的做法?做法、数据库、数据、是最好的

2023-09-13 23:59:15 作者:妖孽♡

我在做一个应用程序,将使用从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.