iPhone 和 sqlite 查询的问题

发布于 2024-10-21 01:22:59 字数 1546 浏览 2 评论 0原文

当我尝试运行我的程序时,出现以下错误。有什么理由让我得到它吗?我已经尝试了几个小时,但我放弃了。谢谢!

错误:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

温馨耳语 2024-10-28 01:22:59

看起来您没有“运行”查询。您准备好了它并绑定了参数,但您从未运行 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文