[FMDBManager inDatabase:^(FMDatabase *db) {
[db shouldCacheStatements];
//开始启动事务
[db beginTransaction];
BOOL isRollBack = NO;
@try {
for (NSDictionary *dic in resultDic[@"events"]) {
//replace into 首先尝试插入数据到表中, 1. 如果发现表中已经有此行数据(根据主键或者唯一索引判断)则先删除此行数据,然后插入新的数据。 2. 否则,直接插入新数据。
NSString *sql = [NSMutableString stringWithFormat:@"replace into events values(‘%@‘,‘%@‘,‘%@‘,‘%@‘,‘0‘,‘0‘)",dic[@"id"],dic[@"title"],dic[@"src"],dic[@"type"]];
BOOL a = [db executeUpdate:sql];
if (!a) {
NSLog(@"插入失败1");
}
}
}
@catch (NSException *exception) {
isRollBack = YES;
[db rollback];
}
@finally {
if (!isRollBack) {
[db commit];
}
}
}];
}
sqlite 批量插入, 重复插入(更新)
标签:
本文系统来源:http://www.cnblogs.com/levy/p/4978886.html
【说明】:本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!