iOS FMDB 查询 批量更新

作者:杭州车成汽车事务代理服务部 来源:www.guohuicar.com 发布时间:2017-09-06 10:16:54
iOS FMDB 查询 批量更新



+ (NSMutableArray *)querygoodsByIdFromLocal:(NSString *)dayFlightId{
FMDatabase *fmdb = [SADBManager sharedDB];
if (!fmdb) {
//失败处理
return nil;
}
//编写SQL查询语句
NSString *query = [NSString stringWithFormat:@select * from FlightGoods where dayFlightId= '%@', dayFlightId];
FMResultSet *rs = [fmdb executeQuery:query];
NSMutableArray *invArray = [[NSMutableArray alloc]init];
FlightGoods *flightgoods;
while ([rs next]) {
flightgoods = [[FlightGoods alloc]init];
flightgoods.dayFlightId = [rs stringForColumn:@dayFlightId];
flightgoods.goodsCode = [rs stringForColumn:@goodsCode];
flightgoods.goodsName = [rs stringForColumn:@goodsName];
flightgoods.goodsUnit = [rs stringForColumn:@goodsUnit];
flightgoods.remarks = [rs stringForColumn:@remarks];
flightgoods.cabinStockNum = [[NSNumber alloc]initWithInt:[rs intForColumn:@cabinStockNum]];
flightgoods.loseNum = [[NSNumber alloc]initWithInt:[rs intForColumn:@loseNum]];
flightgoods.actualNum = [[NSNumber alloc]initWithInt:[rs intForColumn:@actualNum]];
flightgoods.tempActualNum = flightgoods.actualNum;// 这里为tempActualNum赋值,之后根据这个值判断能否加1操作
flightgoods.tempLoseNum = flightgoods.loseNum;
flightgoods.tempRemarks = flightgoods.remarks;
[invArray addObject:flightgoods];
}
return invArray;
}

// 更新对象值到数据库
+ (BOOL)updateGoodsByFlightGoods:(NSMutableArray *)flightGoodsArr{
FMDatabase *fmdb = [SADBManager sharedDB];
if (!fmdb) {
//失败处理
return nil;
}
[fmdb beginTransaction];
BOOL isRollBack = NO;
@try {
for (int i = 0; i<[flightGoodsArr count]; i++) {
FlightGoods * flightGoods = [flightGoodsArr objectAtIndex:i];
NSString * update = [NSString stringWithFormat:@update FlightGoods set actualNum = '%@', loseNum = '%@',remarks = '%@' where goodsCode = '%@',flightGoods.actualNum,flightGoods.loseNum,flightGoods.remarks,flightGoods.goodsCode];
BOOL isSuccess = [fmdb executeUpdate:update];
if (!isSuccess) {
NSLog(@update Failure);
}
}
}
@catch (NSException *exception) {
isRollBack = YES;
[fmdb rollback];
}
@finally {
if (!isRollBack) {
[fmdb commit];
}
}
return !isRollBack;

}

企业建站2800元起,携手武汉肥猫科技,做一个有见地的颜值派!更多优惠请戳:宜昌SEO http://yichang.4567w.com

  • 上一篇:iOS应用生命周期相关内容
  • 下一篇:最后一页
  • 
    COPYRIGHT © 2015 杭州车成汽车事务代理服务部 ALL RIGHTS RESERVED.
    本站所有原创信息,未经许可请勿任意转载或复制使用 网站地图 技术支持:肥猫科技
    精彩专题:网站建设
    购买本站友情链接、项目合作请联系客服QQ:2500-38-100