下面是我的代碼存儲在SQLite數據庫圖像。當我用它來存儲它的價值,現在我試圖在sqlite數據庫中存儲圖像。我不知道我做錯了什麼。我已經搜查過了,我無法得到我需要的答案。任何人都可以用他的代碼幫助我將圖像存儲到SQLite數據庫
sqlite3 *database;
[email protected]"dataTable.sqlite";
NSArray *documentpath=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentdir=[documentpath objectAtIndex:0];
dbPath=[documentdir stringByAppendingPathComponent:dbName];
sqlite3_stmt *compiledStmt;
if(sqlite3_open([dbPath UTF8String], &database)==SQLITE_OK){
NSLog(@"Name:%@,Company:%@,URL:%@",model.personName,model.companyName,model.imgurl);
const char *insertSQL="insert into Persons(PersonName,CompanyName,ImgUrl,PersonImage)values(?,?,?,?)";
if(sqlite3_prepare_v2(database,insertSQL, -1, &compiledStmt, NULL)==SQLITE_OK){
sqlite3_bind_text(compiledStmt,1,[model.personName UTF8String],-1,SQLITE_TRANSIENT);
sqlite3_bind_text(compiledStmt,2,[model.companyName UTF8String],-1,SQLITE_TRANSIENT);
sqlite3_bind_text(compiledStmt,3,[model.imgurl UTF8String],-1,SQLITE_TRANSIENT);
NSData *imageData=UIImagePNGRepresentation(imageView.image);
sqlite3_bind_blob(compiledStmt, 4, [imageData bytes], [imageData length], NULL);
NSLog(@"Prepare");
sqlite3_step(compiledStmt);
}sqlite3_finalize(compiledStmt);
}
UPDATE: 感謝大家。我清除這個問題通過問另一個問題從這裏.. store and retrieve image into sqlite database for iphone這可以幫助別人。
IM有代碼來讀取我的appdelegate數據庫,查看應用程序的同時在我的項目啓動的文件.... – 2012-01-04 11:29:04
請一次只問一個* *問題。 – Sathya 2012-01-04 11:33:00
@Sathya OKK ......你能幫助我與我的第一question..i將編輯.. – 2012-01-04 11:34:48