iOS 使用FMDB对本地的.db数据进行查询
/**
创新互联公司主要从事网站制作、网站建设、网页设计、企业做网站、公司建网站等业务。立足成都服务红桥,10年网站建设经验,价格优惠、服务专业,欢迎来电咨询建站服务:13518219792
* @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时,如果数据模型中没有id,怎么创建数据库中的表
你得先创建一个对象啊 FMResultSet *resultAccurate = [FMResultSet new]; resultAccurate = [dbOperation executeQueryAccurately:mySqlAccurately];
iOS中FMDB按条件查询数据
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 '上执行查询的结果
/**
ios开发fmdb存放nsdata怎么写
NSData- NSStringNSString *aString = [[NSString alloc] initWithData:adata encoding:NSUTF8StringEncoding];NSString-NSDataNSString *aString = @"1234abcd";NSData *aData = [aString dataUsingEncoding: NSUTF8StringEncoding];2.NSData 与 ByteNSData- Byte数组NSString *testString = @"1234567890";NSData *testData = [testString dataUsingEncoding: NSUTF8StringEncoding];Byte *testByte = (Byte *)[testData bytes];for(int i=0;i[testData length];i++)printf("testByte = %d\n",testByte[i]);Byte数组- NSDataByte byte[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23};NSData *adata = [[NSData alloc] initWithBytes:byte length:24];Byte数组-16进制数Byte *bytes = (Byte *)[aData bytes];NSString *hexStr=@"";for(int i=0;i[encryData length];i++){NSString *newHexStr = [NSString stringWithFormat:@"%x",bytes[i]0xff]; ///16进制数if([newHexStr length]==1)hexStr = [NSString stringWithFormat:@"%@0%@",hexStr,newHexStr];elsehexStr = [NSString stringWithFormat:@"%@%@",hexStr,newHexStr];}NSLog(@"bytes 的16进制数为:%@",hexStr);16进制数-Byte数组///// 将16进制数据转化成Byte 数组NSString *hexString = @"3e435fab9c34891f"; //16进制字符串int j=0;Byte bytes[128]; ///3ds key的Byte 数组, 128位for(int i=0;i[hexString length];i++){int int_ch; /// 两位16进制数转化后的10进制数unichar hex_char1 = [hexString characterAtIndex:i]; ////两位16进制数中的第一位(高位*16)int int_ch1;if(hex_char1 = '0' hex_char1 ='9')int_ch1 = (hex_char1-48)*16; //// 0 的Ascll - 48else if(hex_char1 = 'A' hex_char1 ='F')int_ch1 = (hex_char1-55)*16; //// A 的Ascll - 65elseint_ch1 = (hex_char1-87)*16; //// a 的Ascll - 97i++;unichar hex_char2 = [hexString characterAtIndex:i]; ///两位16进制数中的第二位(低位)int int_ch2;if(hex_char2 = '0' hex_char2 ='9')int_ch2 = (hex_char2-48); //// 0 的Ascll - 48else if(hex_char1 = 'A' hex_char1 ='F')int_ch2 = hex_char2-55; //// A 的Ascll - 65elseint_ch2 = hex_char2-87; //// a 的Ascll - 97int_ch = int_ch1+int_ch2;NSLog(@"int_ch=%d",int_ch);bytes[j] = int_ch; ///将转化后的数放入Byte数组里j++;}NSData *newData = [[NSData alloc] initWithBytes:bytes length:128];NSLog(@"newData=%@",newData);3. NSData 与 UIImageNSData-UIImageUIImage *aimage = [UIImage imageWithData: imageData];//例:从本地文件沙盒中取图片并转换为NSDataNSString *path = [[NSBundle mainBundle] bundlePath];NSString *name = [NSString stringWithFormat:@"ceshi.png"];NSString *finalPath = [path stringByAppendingPathComponent:name];NSData *imageData = [NSData dataWithContentsOfFile: finalPath];UIImage *aimage = [UIImage imageWithData: imageData];UIImage- NSDataNSData *imageData = UIImagePNGRepresentation(aimae);
iOS开发数据库存储能用FMDB直接存储对象吗
如果要存储复杂对象类型的数据, 该对象必须遵循NSCoding协议, 并实现对应代理方法
对象类型实现代理后, 在存储之前还有一部操作, 是把对象进行归档, 归档完成才可以使用FMDB进行存储, 对应类型为BLOB类型,.
如果要直接存储复杂对象, 不想写归档什么的玩意, 可以使用一个第三方框架 JRDB , 这个可以直接存储复杂对象, jrdb是基于FMDB进行的二次封装框架, 可以试试噢
ios开发 fmdb怎么用pod导入
pod会用么?会用的话,新建一个podfile文件,然后在podfile文件中添加 pod ‘FMDB',保存后退出,然后输入pod install即可。
当前名称:ios开发fmdb,iOs开发自身优势
转载源于:http://scyingshan.cn/article/dsccedc.html