Last active
August 29, 2015 14:10
-
-
Save leandrovianna/05c8215559fb18901529 to your computer and use it in GitHub Desktop.
Transaction in Android (using SQLite)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| db.beginTransaction(); //inicia a transação | |
| try { | |
| //operações de bancos são feitas aqui | |
| //db.insert... | |
| //caso o fluxo chegue aqui a transacao nao teve erros | |
| //entao fazemos o commit da transacao | |
| db.setTransactionSuccessful(); | |
| } catch (Exception e) { | |
| //Um exceção foi disparada por alguma operação do banco | |
| Log.e("Transaction", "ERRO: Transacao mal sucedida"); | |
| } finally { | |
| //independente se a transação teve commit ou não, é necessário terminá-la. | |
| db.endTransaction(); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment