1. Basic use of SQLite database
1. Features
(1) Embedded database, small in size
(2) The database is dynamically generated by the code of the underlying sqlite
.
2. Inherit the abstract class SQLiteOpenHelper to create your own tool class management database
(1) Inherit the onCreate and onUpgrade methods, which are used when upgrading;
(2) A constructor is required, and the version number and database name of the database need to be passed in;
(3) To provide external functions, you can call the instance of SQliteOpenHelper, instance, singleton mode creation, and define the information of the database.
The source code indicates that the version number of the incoming database needs to start from 1 to facilitate database upgrades .
3. Use database
(1) Call the instance to create a database
(2) Create a table, create a table by writing a sql statement in the onCreate() method, the table will only be created once when the database is initialized, and will not be created the second time.
_id, unique primary key, autoincrement, type (Text);
4. Add, delete, modify and check
(1) Inquiry
The query returned by the sql statement is the cursor, and then iterate the cursor to fetch data. Remember to close the cursor after fetching, otherwise it will consume performance and the database will also need to be closed;
(2) Insert
Insert is inserted through sql statement. Note that it is best to monitor whether the database is open before operating .
(3) Modification
(4) delete
2. Room framework
. . .
Room saves data to local database
3. GreenDao
。。。