iOS中FMDB按条件查询数据

iOS中FMDB按条件查询数据,第1张

1、假如创建一张PersonVO表,并存储自定义PersonVO类的数据

NSString *createSql = @"CREATE TABLE IF NOT EXISTS PersonVO (ID TEXT NOT NULL,goodsName TEXT NOT NULL,shopNo TEXT NOT NULL)"

2、根据条件查询PersonVO表中的数据

使用FMResultSet在' <FMDatabase>'上执行查询的结果

/**

/**

*  @author fangbmian, 16-03-18 10:03:50

*

*  获取本地品牌数据

*/

NSString *dbFilePath = [[NSBundle mainBundle] pathForResource:@"name" ofType:@"db"]

if (!dbFilePath) return

carBrandList = [NSMutableArray new]

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{

queue = [FMDatabaseQueue databaseQueueWithPath:dbFilePath]

[queue inDatabase:^(FMDatabase *db)

{

FMResultSet *rs = [db executeQuery:@"select distinct CAR_BRAND,CAR_BRAND_LOGO from CAR_VEHICLE"]

while([rs next])

{

CarBrandInfoBean * info = [CarBrandInfoBean new]

info.carBrand = [rs stringForColumn:@"CAR_BRAND"]

info.carBrandLogo = [rs stringForColumn:@"CAR_BRAND_LOGO"]

[carBrandList addObject:info]

}

}]

})

/**

*  @author fangbmian, 16-03-17 13:03:01

*

*  item被点击

*

*  @param brandName 品牌名称

*/

-(void)didClickItem:(NSString*)brandName

{

if (!queue) return

NSMutableArray *carList = [NSMutableArray new]

[queue inDatabase:^(FMDatabase *db)

{

NSString *sql = [NSString stringWithFormat:@"select CAR_BRAND,CAR_SERIES,CAR_YEAR,CAR_TYPE,CAR_GAS,CAR_ID from CAR_VEHICLE where CAR_BRAND = \'%@\'", brandName]

FMResultSet *rs = [db executeQuery:sql]

while([rs next])

{

CarInfoBean *info = [CarInfoBean new]

info.carBrand = [rs stringForColumn:@"CAR_BRAND"]

info.carSeries = [rs stringForColumn:@"CAR_SERIES"]

info.carYear = [rs stringForColumn:@"CAR_YEAR"]

info.carType = [rs stringForColumn:@"CAR_TYPE"]

info.carGas = [rs stringForColumn:@"CAR_GAS"]

info.carTypeId = [rs stringForColumn:@"CAR_ID"]

[carList addObject:info]

}

}]

}


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/sjk/6703188.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-03-27
下一篇 2023-03-27

发表评论

登录后才能评论

评论列表(0条)

保存