下面是我在 sqlite 数据库中存储图像的代码。当我用它来存储值时它可以工作,现在我尝试将图像存储在 sqlite 数据库中。我不知道我做错了什么。我已经搜索过,但无法得到我需要的答案。任何人都可以帮我解决他的代码。
sqlite3 *database;
dbName=@"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:
谢谢大家..我通过从这里问另一个问题解决了这个问题..将图像存储和检索到 iPhone 的 SQLite 数据库中这可能对其他人有帮助。