To access the Android relational database SQLite, you must use a class like Sqliteopenhelper.
If you don't use this class, it's more cumbersome. Since there is such a class, it is good to use it directly.
Sqliteopenhelper is the helper class that operates on database creation and versioning. By inheriting the class, we write some methods to implement the operation of the database.
Getreadabledatabase () Creates or opens a database. The database that is created or opened is readable.
The query data is a read operation. Additions, deletions, and modifications are write operations.
Sqlitedatabase is a number of ways to provide management of SQLite databases. such as INSERT, IsOpen, query, update.
To operate on a database, you must obtain an object of the class such as sqlitedatabase to manipulate the database. How to get this object, first get a Sqliteopenhelper object, and then use the Sqliteopenhelper object Getreadabledatabase, Getwriteabledatabase to get a readable or writable database to get a Sqlitedatabase object, then use this object to manipulate the database.
OnCreate (Sqlitedatabase db), OnOpen (Sqlitedatabase db), Onupgrade (sqlitedatabase db,int oldversion,int newversion) These three functions are callback functions that are called when an operation is performed. These three callback functions are called when you create a database, open a database, and update a database.
The operation to create the table structure is written in the OnCreate (Swlitedatabase db) method
Upgrading the database, adding tables, modifying table names can be written in the Onupgrade (sqlitedatabase db,int oldversion,int newversion) method
Summarize:
When you need to manipulate the SQLite database, you must have a class object such as Sqliteopenhelper, but since the class is abstract, you must write a class to inherit it. After inheritance, there are 2 functions: Getreadabledatabase, Getwriteabledatabase. These 2 objects are objects of the Sqlitedatabase class. When querying the database, it is necessary to use a class such as Getreadabledatabase, when the database is added, deleted, modified operation, it is necessary to use getwriteabledatabase such a class to get sqlitedatabase such an object.
In addition, OnCreate, OnOpen, Onupgrade can also be replicated.