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.
精彩评论