我的图片没有插入我的数据库,但我插入的所有字段除了图像我如何在我的数据库中插入图像我想从图像选择器和相机中选择图像然后保存到数据库。
const char*dbspath=[_database UTF8String];
if (sqlite3_open(dbspath,&_db)==SQLITE_OK) {
sqlite3_busy_timeout(_db, 500);
NSString*insert_sql=[NSString stringWithFormat:@"INSERT INTO addmedicien (medicienname,typesofmedicien,fromdate,date,noofdose,image)values('%s','%s','%s','%s','%s','%@')",[self.medicienname.text UTF8String],[self.typesofmedicien.text UTF8String],[self.fromdate.text UTF8String],[self.date.text UTF8String],[self.noofdose.text UTF8String],images];
const char*insert_statement=[insert_sql UTF8String];
sqlite3_stmt*statement;
if (sqlite3_prepare_v2(_db, insert_statement, -1, &statement, NULL)==SQLITE_OK) {
sqlite3_bind_blob(statement,6, [UIImagePNGRepresentation(self.imagess.image)bytes], [UIImagePNGRepresentation(self.imagess.image) length], SQLITE_TRANSIENT);
NSData*data=[NSData dataWithBytes:sqlite3_column_blob(statement, 6) length:sqlite3_column_bytes(statement, 6)];
if (data) {
self.imagess.image=[UIImage imageWithData:data];
}
sqlite3_step(statement);
NSLog(@"medicien and images added to db");
}
else
{
[self showUIAlertviewwithmessage:@"images not added" andtitle:@"message"];
}sqlite3_finalize(statement);
}
sqlite3_close(_db);
}