Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between SQLiteOpenHelper and SQLiteAssetHelper?

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:

  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.)

  3. How would I go about setting up the right one?

like image 640
KellysOnTop23 Avatar asked Mar 20 '23 03:03

KellysOnTop23


1 Answers

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

like image 124
laalto Avatar answered Apr 25 '23 07:04

laalto