iPhone 和 sqlite 查询的问题
当我尝试运行我的程序时,出现以下错误。有什么理由让我得到它吗?我已经尝试了几个小时,但我放弃了。谢谢!
错误:
2011-03-08 19:18:29.967 iphoneApp[2561:207] * 由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“* +[NSString stringWithUTF8String:]: NULL cString”
- (AnswerDTO *)findAnswerById:(NSInteger)primary_key {
AnswerDTO *dto = [[[AnswerDTO alloc] init] autorelease];
sqlite3_stmt *statement = nil;
const char *sql = "SELECT * FROM klb_answers WHERE id = 7;";
if (sqlite3_prepare_v2(database, sql, -1, &statement, NULL) == SQLITE_OK) {
sqlite3_bind_int(statement, 1, primary_key);
NSInteger answerId = sqlite3_column_int(statement, ANSWER_ID);
NSInteger answerQuestionId = sqlite3_column_int(statement, ANSWER_QUESTION_ID);
NSString *answerDescription = [NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, ANSWER_DESCRIPTION)];
NSString *answerSerialNumber = [NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, ANSWER_SERIAL_NUMBER)];
NSInteger answerIsCorrect = sqlite3_column_int(statement, ANSWER_IS_CORRECT);
dto.answerID = answerId;
dto.questionID = answerQuestionId;
dto.description = answerDescription;
dto.serialNumber = answerSerialNumber;
if (answerIsCorrect == 0) {
dto.isCorrect = NO;
} else {
dto.isCorrect = YES;
}
} else {
NSLog(@"Noe feil med statementet");
}
sqlite3_finalize(statement);
return dto;
}
I get the following error when I try to run my program. Any reasons why I get it? I have tried for several hours now but I give up. THANKS!
Error:
2011-03-08 19:18:29.967 iphoneApp[2561:207] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '* +[NSString stringWithUTF8String:]: NULL cString'
- (AnswerDTO *)findAnswerById:(NSInteger)primary_key {
AnswerDTO *dto = [[[AnswerDTO alloc] init] autorelease];
sqlite3_stmt *statement = nil;
const char *sql = "SELECT * FROM klb_answers WHERE id = 7;";
if (sqlite3_prepare_v2(database, sql, -1, &statement, NULL) == SQLITE_OK) {
sqlite3_bind_int(statement, 1, primary_key);
NSInteger answerId = sqlite3_column_int(statement, ANSWER_ID);
NSInteger answerQuestionId = sqlite3_column_int(statement, ANSWER_QUESTION_ID);
NSString *answerDescription = [NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, ANSWER_DESCRIPTION)];
NSString *answerSerialNumber = [NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, ANSWER_SERIAL_NUMBER)];
NSInteger answerIsCorrect = sqlite3_column_int(statement, ANSWER_IS_CORRECT);
dto.answerID = answerId;
dto.questionID = answerQuestionId;
dto.description = answerDescription;
dto.serialNumber = answerSerialNumber;
if (answerIsCorrect == 0) {
dto.isCorrect = NO;
} else {
dto.isCorrect = YES;
}
} else {
NSLog(@"Noe feil med statementet");
}
sqlite3_finalize(statement);
return dto;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看起来您没有“运行”查询。您准备好了它并绑定了参数,但您从未运行 sqlite3_step() 来执行查询并获取响应。即使它是单个记录或标量。
结果,您的列函数返回空值。
It doesn't look like you are "running" your query. You prepared it and bound your params but you never ran sqlite3_step() to execute the query and get the response. Even if it is a single record or a scalar.
As a result, your column functions returning null values.