0
如何在數據庫中插入圖像,我試過,但沒有插入。查詢中的問題在哪裏?這是我的模型類.m文件:sqlite3_prepare_v2
之後的文件中的代碼我的跟蹤未插入sqlite3_bind_blob
它直接在sqlite3_prepare_v2
之後。這裏有什麼問題,請幫助我。在這裏保存數據是錯誤的。在模型類我創建UIImage* Photo;
,使協議和sys如何在iphone中的sqlite數據庫中插入圖像
+(void)SaveImagesToSql:(NSData *)imgDat :(int)getid
{
NSString *filePath = [BaseModal getDBPath];
sqlite3 *database;
sqlite3_stmt *updStmt;
NSLog(@"%@",filePath);
if (sqlite3_open([filePath UTF8String], &database) == SQLITE_OK)
{
NSString* sqliteQuery = [NSString stringWithFormat:@"UPDATE INTO Peoples (Photo) VALUES (?) where PeopleId =%i",getid];
if(sqlite3_prepare_v2(database, [sqliteQuery UTF8String] , -1, &updStmt, NULL) == SQLITE_OK) {
sqlite3_bind_blob(updStmt, 1, [imgDat bytes], [imgDat length], NULL);
}
sqlite3_finalize(updStmt);
}
sqlite3_close(database);
}
這是我的view.m文件我是從這個頁面中選擇圖像,然後插入到源碼文件
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
imageView.image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
//UIImageWriteToSavedPhotosAlbum(imageView.image, self, nil, nil);
NSArray *sysPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask,YES);
NSString *docDirectory = [sysPaths objectAtIndex:0];
NSString *filePath = [NSString stringWithFormat:@"%@", docDirectory];
NSLog(@"thiss%@",filePath);
UIImage *image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
if(picker.sourceType == UIImagePickerControllerSourceTypePhotoLibrary) {
UIImageWriteToSavedPhotosAlbum(image, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);
[picker dismissModalViewControllerAnimated:YES];
return;
}
[picker release];
UIImage *image1 =imageView.image;
NSData *myData = UIImagePNGRepresentation(image1);
[PeopleModal SaveImagesToSql:myData :peopleid];
//[self.parentViewController dismissModalViewControllerAnimated:YES];
[picker dismissModalViewControllerAnimated:YES];
}
不要將數據存儲在文檔目錄中的database.ave圖像中,然後將該路徑保存到數據庫中... – Narayana 2012-02-28 09:40:12