What is the difference between SQLiteOpenHelper and SQLiteAssetHelper?
What is the difference between SQLiteOpenHelper
and SQLiteAssetHelper
? How do I use them?
I know that when you use SQLiteOpenHelper
, you have to override the onCreate() and onUpgrade()
methods. In addition, you can add, delete, and look up database values.
However, I
read that SQLiteAssetHelper
is better suited to my situation – since I will have a pre-populated database, I will do more queries than add or remove or anything else.
So basically:
What is the fundamental difference between the two?
Which is better to query data in a database that is unknown at compile time rather than at runtime? (I’ll use
query
() orSQLiteQueryBuilder()
for this.) )How will I set it up correctly?
Solution
1) What is the fundamental difference between these two?
Both are assistants for managing and versioning database files. The only differences are in how the schema and initial content are set up and how the version migration is done.
SQLiteOpenHelper
sets up a new database file by calling your onCreate() callback, and migrates the old database file by calling your onUpgrade()
callback
SQLiteAssetHelper
sets up new database files by copying files from Assets, and migrates old database files by running upgrade scripts from Assets.
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)
After getting the SQLiteDatabase
object, both can handle dynamically inserted data and code well, for example with getWritableDatabase().
3) And how would I go about setting up the right one?
Android docs for
SQLiteOpenHelper
README for
SQLiteAssetHelper