简体   繁体   English

用默认数据填充sqlite数据库时的最佳实践是什么?

[英]What's the best practice when populating a sqlite database with default data?

I'm making an app that will be using few hundred database posts from a sqlite database. 我正在制作一个将使用sqlite数据库中的数百个数据库帖子的应用程序。 I will not be adding new data during the lifetime of the app (unless I update the whole app). 在应用程序的生命周期内,我不会添加新数据(除非我更新整个应用程序)。

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. 我可能最终会使用静态xml来存储数据,但是我需要标记帖子,所以我猜sqlite db会做得最好。 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? 如何在应用程序首次运行时最好地填充sqlite数据库? 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? 最佳/最简便的做法是什么?

The simplest solution is to use SQLiteAssetHelper . 最简单的解决方案是使用SQLiteAssetHelper You basically drop your SQLite database into your project's assets/ directory, and use SQLiteAssetHelper in lieu of SQLiteOpenHelper . 基本上,您将SQLite数据库放入项目的assets/目录中,并使用SQLiteAssetHelper代替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. 除了在Jeff Gilfelt的GitHub存储库上提供示例代码外,我还有一个示例应用程序对其进行演示。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将大量数据导入数据库的最佳实践是什么? - What is the Best practice to import huge data into a database? 在Java Tomcat Web应用程序中存储加密密钥以对数据库中的敏感数据进行加密/解密的最佳实践是什么? - What's the best practice for storing encryption keys in a Java Tomcat web app for encrypting/decrypting sensitive data in a database? JPA-从数据库查找表加载静态数据的最佳实践是什么? - JPA - What's the best practice way to load static data from a Database lookup table? 在数据库中存储以Java列表表示的“大”数据的最佳实践是什么? - What is a best practice to store 'large' data, represented by List in Java, in database? 在JSP中呈现JSON数据的最佳实践是什么? - What's the best practice to render JSON data in JSPs? Spring Data JPA错误处理的最佳实践是什么 - What's best practice in Spring Data JPA Error handling 将初始(批量)数据导入RESTful系统的最佳实践是什么? - What's the best practice for initial (bulk) data import into RESTful system? 数据库数据过滤最佳实践 - Database Data Filtering Best Practice TextViews 没有在 RecyclerView 中填充来自 SQLite 数据库的数据 - TextViews not populating with data from SQLite database in RecyclerView 填充sqlite数据库时出错 - Error in populating sqlite database
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM