Skip to content

Instantly share code, notes, and snippets.

@maltzsama
Created April 16, 2013 13:52
Show Gist options
  • Select an option

  • Save maltzsama/5396063 to your computer and use it in GitHub Desktop.

Select an option

Save maltzsama/5396063 to your computer and use it in GitHub Desktop.
FMDB with transaction
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