问题
I have created a SQLite database with an id AUTOINCREMENT and image BLOB.
Now, I want to INSERT a image in the image column. I am a big objective-c nube and have been trying all sorts of stuff but they don't seem to be working. I know lots about MYSQl, but not SQLite and I can't seem to figure it out.
I have uploadImage
(UIImage). I am using Matteo Bertozzi's SQLite wrapper here. Here's some of my code I have after someone picks an image off their phone:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo {
[picker.parentViewController dismissModalViewControllerAnimated:YES];
uploadImage = image;
NSData *dataForImage = UIImagePNGRepresentation(uploadImage);
[database executeNonQuery:@"INSERT INTO process (image) VALUES (dataForImage)"];
}
Thanks again!
Coulton
回答1:
- the language is Objective-C, not C++. :)
In general, shoving lots of images into a SQLite database is going to be inefficient, both in terms of potential memory use and I/O. It'll be slower and use more resources. Better to put the images into the filesystem and then refer to the filesystem from the SQLite database.
This is related to Blob Data Type?
回答2:
Your executeNonQuery never actually passes your dataForImage parameter (you're just passing a string), so...
Change this:
[database executeNonQuery:@"INSERT INTO process (image) VALUES (dataForImage)"];
To this:
[database executeNonQuery:@"INSERT INTO process (image) VALUES (?);", dataForImage];
来源:https://stackoverflow.com/questions/4981154/blob-in-sqlite