ios - Objective-c read image from sqlite -
nsdata *imagedata = uiimagejpegrepresentation(photoimage, 100); nsstring* querystring = ; [sqliteaccess insertwithsql: [nsstring stringwithformat:@"insert images (photo) values ('%@')", imagedata] // photo - blob column ]; // utilize class sqliteaccess
insert when read image sqlite
nsarray *photoselectarray = [sqliteaccess selectmanyrowswithsql: [nsstring stringwithformat:@"select photo places id=%i", idplace]]; nsdictionary *imagedatadic = [photoselectarray objectatindex:0]; nsdata *dataforcachedimage = [[nsdata alloc] initwithdata: [imagedatadic objectforkey:@"photo"]]; uiimage *cachedimage = [uiimage imagewithdata:dataforcachedimage];
i have error - sigabrt (terminating app due uncaught exception 'nsinvalidargumentexception', reason: '-[__nscfstring bytes]: unrecognized selector sent instance 0x1e5c46d0')
p.s. class easy access sqlite - sqliteaccess.h - http://pastebin.com/bfxfry7t - sqliteaccess.m - http://pastebin.com/m67ynvlm
yeah, think problem here:
[nsstring stringwithformat:@"insert images (photo) values ('%@')", imagedata]]; // utilize class sqliteaccess
when using sqlite directly, should set binary info sqlite3_bind_blob()
, you're setting binary info string.
so when data, it's not binary data, it's string
object, of course, string object don't response -[nsdata bytes]
meanwhile think should check field type in sqlite db file. photo
set blob
.
ios objective-c sqlite sqlite3
No comments:
Post a Comment