数据库版本更新和数据备份

来源:互联网 发布:c语言如何加密文件 编辑:程序博客网 时间:2024/06/08 19:51
<span style="font-size:18px;">public class DBservice extends SQLiteOpenHelper {    private String CREATE_BOOK = "create table book(bookId integer primarykey,bookName text);";    private String CREATE_TEMP_BOOK = "alter table book rename to _temp_book";    private String INSERT_DATA = "insert into book select *,'' from _temp_book";    private String DROP_BOOK = "drop table _temp_book";    public DBservice(Context context, String name, CursorFactory factory,int version) {        super(context, name, factory, version);    }    @Override    public void onCreate(SQLiteDatabase db) {        db.execSQL(CREATE_BOOK);    }    @Override    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {        switch (newVersion) {            case 2:                db.execSQL(CREATE_TEMP_BOOK);                db.execSQL(CREATE_BOOK);                db.execSQL(INSERT_DATA);                db.execSQL(DROP_BOOK);                break;        }    }}</span>

0 0
原创粉丝点击