数据库保存byte(只是自己做个笔记 )

2019-05-14  本文已影响0人  wodeph

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

    NSString*documentDirectory = [pathsobjectAtIndex:0];

    NSString *dbPath = [documentDirectory stringByAppendingPathComponent:@"handy.db"];

    NSLog(@"dbPath = %@",dbPath);

    FMDatabase*dataBase = [FMDatabasedatabaseWithPath:dbPath];

   [dataBaseopen];

   BOOL issusscss = [dataBase executeUpdate:@"CREATE TABLE IF  NOT EXISTS t_homes ( homeId text,meshName text,name text,phone text,pic text,testByte blob)"];

    HDDEBUGLOG(@"model=======%d",issusscss);

[dataBaseclose];

转nsdata保存数据

for(inti =0;i< resultDict.count; i++) {

            HDFamilyInfoModel*model = [HDFamilyInfoModelwhc_ModelWithJson:resultDict[i]];

            inti =8;

             NSData*adddata =[NSDatadataWithBytes: &ilength:sizeof(i)];

          BOOL issusscss = [dataBase executeUpdate:@"INSERT INTO t_homes (homeId,meshName,name,phone,pic,testByte) VALUES (?, ?, ?, ?, ?,?);",model.homeId,model.meshName, model.name,model.phone,model.pic,adddata];

             HDDEBUGLOG(@"model2222222=====%@===%d",model.homeId,issusscss);

        }

上一篇 下一篇

猜你喜欢

热点阅读