iOS 使用FMDB对本地的.db数据进行查询

/**

*  @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];

}

}];

}

你可能感兴趣的:(iOS 使用FMDB对本地的.db数据进行查询)