Is it better to have a single big SQLiteOpenHelper
subclass that defines onCreate
and onUpgrade
methods for every table in the database, or is better to have many SQLiteOpenHelper
subclasses, one for each table?
Is there a best practice? Or are both acceptable, but with different good and bad side effects?
Create a helper object to create, open, and/or manage a database. This method always returns very quickly. The database is not actually created or opened until one of getWritableDatabase() or getReadableDatabase() is called.
there is no difference between SQLiteOpenHeloper::close() and SQLiteDatabase::close() . SQLiteOpenHeloper::close() is just a wrapper around SQLiteDatabase::close() . but as a rule of thumb, either let SQLiteOpenHelper manages your connections, or don't use it and manage it yourself. see this blog post.
When you write the table/column names directly into the SQL statements, you increase the risk that you misspell it somewhere, and that the app will blow up later. If you use constants instead, the compiler will complain about any typos. So in general, you should always use the constants.
The recommended approach to using SQLite in an Android app is to create a Database Helper class whose only function is to provide for the creation, modification, and deletion of tables in the database.
You should have a single SQLiteOpenHelper class for all the tables. Check this link.
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