Today is the second day of work, I heard that my recent task is to change the bug, alas, when the right to learn, some of the problems encountered are recorded.
SQLite database is a very common in Android database, today to help others fix bugs, encountered some problems recorded.
1. Modify the structure of the database table to be implemented through a database upgrade, the database will automatically execute SQLiteOpenHelper
methods in the inheriting class, public void onCreate(SQLiteDatabase db) {}
if the database is to be upgraded, you need to call the public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion){}
method to implement the database upgrade function, if you modify the database version number (version becomes larger), the system will execute onUpgrade
method.
All database modification operations are done 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, which TEXT
represents the new data type of the added field.
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
SQLite Database Modification and upgrade