美文网首页
数据库保存byte(只是自己做个笔记 )

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

作者: wodeph | 来源:发表于2019-05-14 18:58 被阅读0次

    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);

        }

相关文章

网友评论

      本文标题:数据库保存byte(只是自己做个笔记 )

      本文链接:https://www.haomeiwen.com/subject/bdbeaqtx.html