Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Please wrap migrate() in a transaction and throws a SQLException #13

Open
yukoba opened this issue Dec 11, 2016 · 5 comments
Open

Please wrap migrate() in a transaction and throws a SQLException #13

yukoba opened this issue Dec 11, 2016 · 5 comments

Comments

@yukoba
Copy link

yukoba commented Dec 11, 2016

Could you please wrap migrate() in a transaction and throws a SQLException?
The current code destroys the database when a SQLException is thrown.

@Bertkiing
Copy link

I meet the same problem...

@yukoba
Copy link
Author

yukoba commented Jan 11, 2017

What I want is this.
yukoba@431d00e

@Bertkiing
Copy link

I think it can help you. Good luck!!!

http://stackoverflow.com/questions/16154113/greendao-schema-upgrade

@xuzc
Copy link

xuzc commented Mar 17, 2017

thanks ☺ @yukoba

@zzzhouzhong
Copy link

@yukoba i find that OpenHelper.onUpgrade() will be execute in transaction by default.

@Override
public void onUpgrade(Database db, int oldVersion, int newVersion) {
    boolean isInTransaction = db.inTransaction();//Here isInTransaction=true
}

My Conclusion is:
1.There is no need to begin a transaction
2.Throw all exception and catch it in onUpgrade()(Don't catch SQLException in MigrationHelper).

//MigrationHelper.java
....
public static void migrate(Database database, Class>... daoClasses) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
....
}
....

//MyOpenHelper.java
......
@OverRide
public void onUpgrade(Database db, int oldVersion, int newVersion) {
Log.i(TAG, "Upgrading schema from version " + oldVersion + " to " + newVersion);
try {
MigrationHelper.migrate(db,XXDAO.class);
Log.i(TAG, "Upgrading success!!!");
} catch (Exception e) {
e.printStackTrace();
Log.e(TAG, "Upgrading failed, drop all tables!!!");
DaoMaster.dropAllTables(db, true);
onCreate(db);
}
}
....

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants