Back to project page ProjectStudio.
The source code is released under:
Apache License
If you think the Android project ProjectStudio listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package DB_Provider; //from w w w. j a v a2 s . com import android.content.Context; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; import android.util.Log; /** * Created by desmond on 1/23/14. */ public class DBManager extends SQLiteOpenHelper { private static String DATABASE_NAME = "UtilDB.db"; private static int DATABASE_VERSION = 1; public DBManager(Context context) { super(context, DATABASE_NAME, null, DATABASE_VERSION); } public DBManager(Context context, String name, SQLiteDatabase.CursorFactory factory, int version) { super(context, DATABASE_NAME, factory, DATABASE_VERSION); } //CALLED ONLY WHEN NO DATABASE EXISTS IN DISK AND THE //HELPER CLASS NEEDS TO CREATE A NEW ONE @Override public void onCreate(SQLiteDatabase db) { db.execSQL(DB_ABSTRACTS.DBProfessor.CREATE_TABLE); db.execSQL(DB_ABSTRACTS.DBCourse.CREATE_TABLE); db.execSQL(DB_ABSTRACTS.DBTasks.CREATE_TABLE); } //CALLED WHEN THERE IS A DATABAS VERSION MISMATCH MEANING THAT //THE VERSION OF THE DATABASE ON DISK NEEDS TO BE UPGRADED TO THE //CURRENT VERSION @Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { //Log the version upgrade Log.w("DBUPGRADE", "UPGRADING FROM VERSION " + oldVersion + " TO " + newVersion + ", which will destroy all old date"); //UPGRADE THE EXISTING DATABASE TO CONFORM TO THE NEW VERSION. //MULTIPLE PREVIOUS VERSIONS CAN BE HANDLED BY COMPARING OLD VERSIONS //AND NEW VERSIONS VALUES //THE SIMPLEST CASE IS TO DROP THE OLD TABLE AND CREATE A NEW ONE db.execSQL(DB_ABSTRACTS.DBProfessor.DELETE_TABLE); db.execSQL(DB_ABSTRACTS.DBCourse.DELETE_TABLE); db.execSQL(DB_ABSTRACTS.DBTasks.DELETE_TABLE); onCreate(db); } }