关于 iphone 版 sqlite3 的另一个问题..抱歉*
假设我正在尝试将从照片库中选择的图像保存到数据库中。以下代码正确吗?
然后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];
}
获取我使用的“对象”..
snap2playObj.snapImage = imageView.image;
我正在使用 UIImageView 顺便说一下..我的错误消息..
-[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'
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'
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的 SQL 语句与您绑定的参数不匹配。您的插入语句中有三个参数:
但绑定了四个参数:
您需要使这些语句匹配。
Your SQL statement does not match the parameters your are binding. You have three parameters in your insert statement:
but you bind four parameters:
You need to make these statements match.