标签:
public class DBHelper extends SQLiteOpenHelper { private static int CURRENTVERSION = 3; public DBHelper(Context context) { super(context, "qianfeng.db", null, CURRENTVERSION); } @Override public void onCreate(SQLiteDatabase db) { Log.d("google_lenve_fb", "onCreate: -----"); db.execSQL("CREATE TABLE IF NOT EXISTS USER (_id INTEGER PRIMARY KEY AUTOINCREMENT,NAME)"); //解决用户不是从第一个版本开始安装的问题 onUpgrade(db, 1, CURRENTVERSION); } @Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { Log.d("google_lenve_fb", "onUpgrade: "); //解决用户跳跃安装问题 switch (oldVersion) { //App升级到2.0时数据库更新代码 case 1: db.execSQL("CREATE TABLE IF NOT EXISTS PERSON (_id INTEGER PRIMARY KEY AUTOINCREMENT,NAME)"); //添加Person表 //App升级到3.0时数据库更新代码 case 2: //添加一个Food表 db.execSQL("CREATE TABLE IF NOT EXISTS FOOD (_id INTEGER PRIMARY KEY AUTOINCREMENT,NAME)"); case 3: case 4: break; } } }
标签:
原文地址:http://www.cnblogs.com/anni-qianqian/p/5481105.html