开发者

How to rollback transaction in onCreate-Method

开发者 https://www.devze.com 2023-03-08 05:25 出处:网络
I am trying to execute an .sql-file in my onCreate()-method of my SQLiteOpenHelper to create all tables of the db and to populate them with data.

I am trying to execute an .sql-file in my onCreate()-method of my SQLiteOpenHelper to create all tables of the db and to populate them with data.

If this fails due to a syntax error I need to executed another file. But before doing that I need to rollback the previous changes.

As is shown in the linked post the transaction is handled outside of the onCreate-method.

So is it possible at all to rollback changes inside the onCreate()-Method?开发者_开发问答


If you look at the SQLiteDatabase documentation for beginTransaction() http://developer.android.com/reference/android/database/sqlite/SQLiteDatabase.html#beginTransaction%28%29 you'll see that with the standard try/finally block, that if any exception occurs before reaching the setTransactionSuccessful() method the transaction would be rolled back. You could add a catch block as well to do any other exception handling.

0

精彩评论

暂无评论...
验证码 换一张
取 消