- - (void)insertStudentsUseTransaction:(NSArray*)students {
- [self.db open];
- [self.db beginTransaction];
- BOOL isRollBack = NO;
- @try {
- for(StudentEntity *studentEntityin students) {
- BOOL isSuccess = [self.db executeUpdate:@"insert into StuList(sid, user_id, realname, avatar_url, isyjmember) values(?,?,?,?,?)", studentEntity.sid, studentEntity.user_id, studentEntity.realname, studentEntity.avatar_url, studentEntity.isyjmember];
- NSLog(@"%@", isSuccess@"插入学生数据成功":@"插入学生数据失败");
- }
- } @catch(NSException *exception) {
- isRollBack = YES;
- [self.db rollback];
- } @finally {
- if(!isRollBack) {
- [self.db commit];
- }
- }
- [self.db close];
- }
来源: http://www.bubuko.com/infodetail-1964157.html