What is the the difference between SQLiteOpenHelper
and SQLiteAssetHelper
?And how do I use them?
I know that when you use SQLiteOpenHelper
you have to override the onCreate()
and onUpgrade()
methods. 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.
So basically:
What is the fundamental difference between these two?
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.)
How would I go about setting up the right one?
1) What is the fundamental difference between these two?
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.
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.
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)
Both will work just fine with dynamically inserted data and the code after obtaining a SQLiteDatabase
object e.g. with getWritableDatabase()
is the same.
3) And how would I go about setting up the right one?
Android docs for SQLiteOpenHelper
README for SQLiteAssetHelper
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With