BLOB in SQLite?

故事扮演 提交于 2020-01-06 18:32:33

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!