How to clean/delete greenDao database

前端 未结 6 1953
误落风尘
误落风尘 2021-01-11 11:41

Currently I\'m doing it like this:

DaoMaster.dropAllTables(getDb(), true);
DaoMaster.createAllTables(getDb(), true);

but then, when I\'m tr

6条回答
  •  一向
    一向 (楼主)
    2021-01-11 12:35

    Until now, I don't worry if tables are locked or not; in my case, i do the following and it works:

    First, when App.onCreate executes, I make the standard initializations.

        T.devOpenHelper= new DaoMaster.DevOpenHelper(context, "mydatabase", null);
        T.sqLiteDatabase= T.devOpenHelper.getWritableDatabase();
        T.daoMaster= new DaoMaster(T.sqLiteDatabase);
        T.daoSession= T.daoMaster.newSession();
        T.dao_myEntity= T.daoSession.getMyEntityDao();
    

    In some moment in the future I drop and recreate all tables, just like you:

        T.daoMaster.dropAllTables(T.sqLiteDatabase, true);
        T.daoMaster.createAllTables(T.sqLiteDatabase, true);
    

    But in my case, then I can immediately insert a new entity:

        MyEntity e= new MyEntity();
        e.setId_ticket(1L);
        e.setDescription("wololo");
        long id= T.dao_myEntity.insert(e);
        Log.d(G.tag, "T.erase_all: id: " + id); // prints "T.erase_all: id: 1"
    

    I hope it helps.

提交回复
热议问题