Created
April 16, 2013 13:52
-
-
Save maltzsama/5396063 to your computer and use it in GitHub Desktop.
FMDB with transaction
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
| FMDatabase* db = [FMDatabase databaseWithPath:@"/tmp/tmp.db"]; | |
| if (![db open]) { | |
| NSLog(@"Could not open db."); | |
| } | |
| // Depois crie uma tabela, "a" será texto e "d" será data | |
| [db executeUpdate:@"create table test (a text, d double)", nil]; | |
| // Iniciando a transação. | |
| [db beginTransaction]; | |
| if ([db executeUpdate:@"insert into test (a, d) values (?, ?)", @"oi'", [NSDate date], nil]){ | |
| //Finalizando a transação em caso de sucesso | |
| [db commit]; | |
| } | |
| else{ | |
| //Rollback em caso de falha na transação | |
| [db rollback]; | |
| } | |
| //Fechando o db após inserção. | |
| [db close]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment