Sqliteopenhelper class
Use the SQLiteOpenHelper and methods in the class getWritableDatabase() getReadableDatabase() to get a reference to the database.
To enable the management of database versions, the SQLiteOpenHelper class provides two important methods, namely onCreate() onUpgrade() , the first to generate a database table when using the software, and the database table structure to be updated when the software is upgraded.
When calling Sqliteopenhelper's Getwritabledatabase () or Getreadabledatabase () method to get the Sqlitedatabase instance used to manipulate the database, if the database does not exist, The Android system automatically generates a database and then calls the OnCreate () method.
The onCreate () method is called only when the database is first generated, and in the OnCreate () method, the database table structure can be generated and the initialization data used by some applications to be added.
The Onupgrade () method is called when the version of the database changes, and the version number is usually changed when the software is upgraded, and the version of the database is controlled by the programmer.
Assuming that the database version is 1, due to business changes, modify the database table structure, it is necessary to upgrade the software, upgrade the software to update the database table structure of the user's phone, in order to achieve this goal, the original database version can be set to 2, and in Onupgrade () method to implement the table structure update.
When the version of the software upgrade more than the number, then in the Onupgrade () method can be based on the original number and the target version number to judge, and then make the corresponding table structure and data update.
Sqlitedatabase class
Android provides a SQLiteDatabase class named ( SQLiteOpenHelper and methods in the class that getWritableDatabase() getReadableDatabase() return objects of this class).
SQLiteDatabaseThe class encapsulates some APIs that manipulate the database, which you can use to complete the Add (Create), query (Retrieve), update, and delete operations of the data (these operations are referred to as CRUD).
Sqlitedatabase's study should focus on mastering the Execsql () and Rawquery () methods.
The Execsql () method can perform SQL statements with change behavior such as INSERT, delete, update, and create table;
The rawquery () method is used to execute a SELECT statement.
How to store your Android sqlite data