简体   繁体   中英

upgrade exist table greendao android studio

According to this stack overflow greenDao Schema Upgrade

The guy "DiscDev" answer his own question but I got a question,on the onUpgrade method of these following code :

if(oldVersion == 3 && newVersion == 4){
   boolean ifNotExists = false;

   //Leave old tables alone and only create ones that didn't exist
   //in the previous schema
     NewTable1Dao.createTable(db, ifNotExists);
     NewTable2Dao.createTable(db, ifNotExists);
     NewTable3Dao.createTable(db, ifNotExists);
     NewTable4Dao.createTable(db, ifNotExists);
} else {
     dropAllTables(db, true);
     onCreate(db);
}

the number of old version and new version how did he know the old version is 3 and new version is 4? And also why it needs to be hard code instead of declaration of constant number?

The oldVersion and newVersion are provided by the OpenHelper onUpgrade method. It provides oldVersion as the current version of the db the user has, and newVersion as the version that they are currently upgrading to.

You can set the current version, which is what newVersion will be, in the green dao generator.

public static void main(String[] args) throws Exception {
    int currentVersion  = 4;
    Schema schema = new Schema(currentVersion, "com.example.app.model.generated");

    new DaoGenerator().generateAll(schema, "app/src/main/java/");
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM