找到的一些SQLite3的int和二进制数据的插入、读取操作。
//插入
sqlite3_bind_int(insert_statement, 3, [e intValue]);
//提供png格式和jpg格式支持
int returnValue = -1;
NSData *imageData = nil;
UIImage *por = [UIImage imageNamed:@"kill.png"];
imageDate = UIImageJPEGRepresentation(<#UIImage *image#>, <#CGFloat compressionQuality#>)
imageData = UIImagePNGRepresentation(por);//png格式
if (nil == por) {
returnValue = sqlite3_bind_blob(insert_statement, 4, nil, -1, NULL);
}else {
returnValue = sqlite3_bind_blob(insert_statement, 4,[imageData bytes],[imageData length], NULL);
}
//更新
sqlite3_bind_int(update_statement, 3, [e intValue]);
//提供png格式和jpg格式支持
int returnValue = -1;
NSData *imageData = nil;
UIImage *por = [UIImage imageNamed:@"killer.png"];
if (nil == por) {
returnValue = sqlite3_bind_blob(update_statement, 4, nil, -1, NULL);
}else {
imageData = UIImageJPEGRepresentation(por,1.0f);//jpg格式
returnValue = sqlite3_bind_blob(update_statement, 4,[imageData bytes],[imageData length], NULL);
}
}
//读取
exp = sqlite3_column_int(statement,3);
if (NULL != sqlite3_column_blob(statement,4)) {
imgData = [[NSData alloc] initWithBytes:sqlite3_column_blob(statement,4) length:sqlite3_column_bytes(statement, 1)];
}
NSData* ImageData = UIImagePNGRepresentation( channel.image_);
NSInteger Imagelen = [ImageData length];
sqlite3_bind_int(statement, 4, Imagelen);
int imageLen = sqlite3_column_int(statement, 4);
UIImage* image = [UIImage imageWithData:[NSData dataWithBytes:imageData length:imageLen]];
channel.image_ = image;
}