SQLiteOpenHelper 是如何管理版本的

来源:互联网 发布:你呀上瘾了网络剧资源 编辑:程序博客网 时间:2024/06/06 02:29

public class DBHelper extends SQLiteOpenHelper {private final static String DB_NAME = "note_info.db";private final static int VERSION = 345;// 版本号private static DBHelper instance = null;@Overridepublic void onCreate(SQLiteDatabase database) {// 建表语句直接使用db.execSQL(String sql)方法执行SQL建表语句String createTable = "create table note(id integer primary key,title text,content text,time text);";database.execSQL(createTable);Log.e("zzzzzzzzzz", "1111111111111111111");}@Overridepublic void onUpgrade(SQLiteDatabase arg0, int arg1, int arg2) {Log.e("zzzzzzzzzz", "22222222222222222222222");}private DBHelper(Context context) {super(context, DB_NAME, null, VERSION);}...}


用SQLiteExpert打开sqlite的db



可以看到里面有个user_version的值,和代码里的VERSION是一样的,SQLiteOpenHelper就是通过比较这个值来判断是否要调用onUpgrade这个方法。


0 0
原创粉丝点击