美文网首页
GreenDao处理数据库降级的时候报 getDatabase

GreenDao处理数据库降级的时候报 getDatabase

作者: 逃跑的计划中 | 来源:发表于2017-11-03 10:02 被阅读0次

GreenDao处理数据库降级的时候报 getDatabase called recursively 异常

@Override
public void onDowngrade(SQLiteDatabase db, int oldVersion, int newVersion) {

//错误姿势,这里很容易想到调用this.getWritableDb(), this.getWritableDb() 这样会导致 数据库 onCreate, 然后又onDowngrade, 然后又onCreate ...造成上面的异常
DaoMaster.dropAllTables(this.getWritableDb(), true);

//正确的姿势是下面这种
DaoMaster.dropAllTables(this.wrap(db), true);
DaoMaster.createAllTables(this.wrap(db), true);

}

相关文章

网友评论

      本文标题:GreenDao处理数据库降级的时候报 getDatabase

      本文链接:https://www.haomeiwen.com/subject/bbnzpxtx.html