+ (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;
}
iOS FMDB 查询 批量更新
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 当谈到“事务”时,我想到了sqlite本身是支持事务操作的,FMDB作为sqlite的上层封装也对事务进行了支持,...
- 简书博客已经暂停更新,想看更多技术博客请到: 掘金 :J_Knight_ 个人博客: J_Knight_ 个人公众...
- 插入: dao : int addAllSkuPassList(@Param("skuPassList") Lis...