简体   繁体   English

SQLiteOpenHelper和SQLiteAssetHelper之间的区别?

[英]Difference between SQLiteOpenHelper and SQLiteAssetHelper?

What is the the difference between SQLiteOpenHelper and SQLiteAssetHelper ?And how do I use them? SQLiteOpenHelperSQLiteAssetHelper什么SQLiteAssetHelper ?我该如何使用它们?

I know that when you use SQLiteOpenHelper you have to override the onCreate() and onUpgrade() methods. 我知道当你使用SQLiteOpenHelper你必须覆盖onCreate()onUpgrade()方法。 Furthermore one can add, remove, and look-up database values. 此外,可以添加,删除和查找数据库值。

However, I read that SQLiteAssetHelper is better for something in my situation- being that I will have a pre-populated database and I will do more queries than adding or removing or anything else. 但是,我读到SQLiteAssetHelper对于我的情况更好 - 因为我将有一个预先填充的数据库,我会做更多的查询,而不是添加或删除或其他任何东西。

So basically: 所以基本上:

  1. What is the fundamental difference between these two? 这两者之间的根本区别是什么?

  2. Which one would be better for doing a query for data in the database that is not known at compile time but instead at runtime? 对数据库中的数据进行查询哪个更好,这在编译时是未知的,而是在运行时? (I will use query() or SQLiteQueryBuilder() for this.) (我将使用query()SQLiteQueryBuilder() 。)

  3. How would I go about setting up the right one? 我该如何设置正确的?

1) What is the fundamental difference between these two? 1)这两者之间的根本区别是什么?

Both are helpers for managing and versioning database files. 两者都是管理和版本化数据库文件的助手。 The difference is only in how the schema and initial contents are set up and how version migrations are done. 区别仅在于如何设置架构和初始内容以及如何完成版本迁移。

SQLiteOpenHelper sets up a new database file by calling your onCreate() callback and migrates old database files by calling your onUpgrade() callback. SQLiteOpenHelper通过调用onCreate()回调SQLiteOpenHelper设置新的数据库文件,并通过调用onUpgrade()回调来迁移旧的数据库文件。

SQLiteAssetHelper sets up a new database file by copying a file from your assets and migrates old database files by running upgrade scripts from assets. SQLiteAssetHelper通过从资产复制文件并通过从资产运行升级脚本来迁移旧数据库文件来设置新数据库文件。

2) Which one would be better for doing a query for data in the database that is not known at compile time but instead at runtime (will use query() or SQLiteQueryBuilder() right here) 2)对于数据库中的数据进行查询哪个更好,这个数据在编译时是未知的,而是在运行时(在这里将使用query()或SQLiteQueryBuilder())

Both will work just fine with dynamically inserted data and the code after obtaining a SQLiteDatabase object eg with getWritableDatabase() is the same. 两者都可以很好地使用动态插入的数据,并且获得SQLiteDatabase对象后的代码,例如getWritableDatabase()是相同的。

3) And how would I go about setting up the right one? 3)我将如何设置正确的?

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM