Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should there be one SQLiteOpenHelper for each table in the database?

Tags:

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?

like image 681
Matteo Bononi 'peorthyr' Avatar asked Dec 14 '12 11:12

Matteo Bononi 'peorthyr'


People also ask

What is the purpose of SQLiteOpenHelper?

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.

What is difference SQLiteOpenHelper and SQLiteDatabase?

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.

Why should you use constants for column names in your SQLite DB?

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.

What is the main purpose of creating Databasehelper class in SQLite database?

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.


1 Answers

You should have a single SQLiteOpenHelper class for all the tables. Check this link.

like image 166
MysticMagicϡ Avatar answered Sep 25 '22 08:09

MysticMagicϡ