GreenDao處理數據庫降級的時候報 getDatabase called recursively 異常

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);

}

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容