one more question on sqlite3 for iphone..sorry*
Posted
by summer
on Stack Overflow
See other posts from Stack Overflow
or by summer
Published on 2010-03-18T08:27:26Z
Indexed on
2010/03/18
8:31 UTC
Read the original article
Hit count: 1007
let's say i am trying to save an image selected from photo library to database..is the following code correct?
Snap.m
- (void) addSnap {
if(addStmt == nil) { const char *sql = "insert into Snap(snapTitle, snapDesc, snapImage) Values(?, ?, ?)"; if(sqlite3_prepare_v2(database, sql, -1, &addStmt, NULL) != SQLITE_OK) NSAssert1(0, @"Error while creating add statement. '%s'", sqlite3_errmsg(database)); } sqlite3_bind_text(addStmt, 1, [snapTitle UTF8String], -1, SQLITE_TRANSIENT);//bind titleSnap to insert statement sqlite3_bind_text(addStmt, 2, [snapDescription UTF8String], -2, SQLITE_TRANSIENT); sqlite3_bind_int(addStmt, 3, snapID);
NSData *imgData = UIImagePNGRepresentation(self.snapImage); int returnValue = -1; if(self.snapImage != nil) returnValue = sqlite3_bind_blob(addStmt, 3, [imgData bytes], [imgData length], SQLITE_TRANSIENT); else returnValue = sqlite3_bind_blob(addStmt, 3, nil, -1, NULL);
sqlite3_bind_int(addStmt, 4, snapID);
if(returnValue != SQLITE_OK) NSLog(@"Not OK!!!");
if(SQLITE_DONE != sqlite3_step(addStmt))//execute step statement if it return SQLITE_DONE NSAssert1(0, @"Error while inserting data. '%s'", sqlite3_errmsg(database)); else //sqlite3_last_insert_rowid snapID = sqlite3_last_insert_rowid(database);//get primary key for the row which was inserted
//reset add statement sqlite3_reset(addStmt); }
- (void)setSnapImage:(UIImageView *)theSnapImage {
self.isDirty = YES; [snapImage release]; snapImage = [theSnapImage copy]; }
then to get the "object" i use..
snap2playObj.snapImage = imageView.image;
i am using UIImageView by the way..my error message..
-[UIImage copyWithZone:]: unrecognized selector sent to instance 0xd74750 2010-03-18 16:22:27.808 Snap2Play[68317:20b] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '* -[UIImage copyWithZone:]: unrecognized selector sent to instance 0xd74750'
© Stack Overflow or respective owner