Today is the second day of work. I heard that my recent task is to change the bug. Alas, right when learning, some of the problems encountered are recorded.
The SQLite database is a very frequently used database in Android. Today to help others change the bug, encountered some problems recorded.
1. Change the structure of the database table to be implemented through the database upgrade, the database will run its own SQLiteOpenHelper
method of inheriting classes, if public void onCreate(SQLiteDatabase db) {}
the database to upgrade, you need to call public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion){}
the method to implement the database upgrade function, if you change the database version number (version number becomes larger), The system will run the onUpgrade
method.
All the database changes are complete here.
2. Add a field to the database
db.execSQL("ALTER TABLE "+PATIENTFOCUSDATA_TABLE_NAME+" ADD COLUMN ‘account_id‘ TEXT ");
PATIENTFOCUSDATA_TABLE_NAME
Represents the database name, which account_id
represents the newly added database field, TEXT
representing the data type of the newly added field.
SQLite database Changes and upgrades