sqlite 3“SQL错误'内存不足'(7)"对象 [英] sqlite 3 "SQL error 'out of memory' (7)" objc

查看:15
本文介绍了sqlite 3“SQL错误'内存不足'(7)"对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人能指出我做错了什么吗?错误是这样的:

Hi can anyone point out what I'm doing wrong please? The error is this:

SQL error 'out of memory' (7)



  - (NSArray *)RecipeInfo
{    
    NSMutableArray *retval = [[NSMutableArray alloc] init];
    NSString *query = [NSString stringWithFormat:@"SELECT key, name FROM recipes WHERE type = \'%@\'", self.RecipeType];

NSLog(query);

sqlite3_stmt *statement;

if (sqlite3_prepare_v2(_database, [query UTF8String], -1, &statement, NULL) != SQLITE_OK)
{
    NSLog(@"[SQLITE] Error when preparing query!");
    NSLog(@"%s SQL error '%s' (%1d)", __FUNCTION__, sqlite3_errmsg(_database), sqlite3_errcode(_database));

    }
    else
    {
        while (sqlite3_step(statement) == SQLITE_ROW)
        {
            int uniqueId = sqlite3_column_int(statement, 0);
            char *nameChars = (char *) sqlite3_column_text(statement, 1);
            NSString *name = [[NSString alloc] initWithUTF8String:nameChars];
            RecipeInfo *info = [[RecipeInfo alloc] initWithUniqueId:uniqueId name:name];
            [retval addObject:info];
        }

        sqlite3_finalize(statement);
    }
return retval;
}

sql 在我使用的数据库管理环境中执行得很好,这与我使用 sql api 的方式有关,有人能发现什么问题吗?

The sql executes fine in the database management environment I use, it has to be something to do with the way I'm using the sql api, can anyone spot whats wrong?

推荐答案

如果您忽略打开数据库并且指针为 NULL(或者,正如 rmaddy 所说,如果它是 NULL 出于任何原因).在打开数据库的地方放一条日志语句,确保它成功并且你有一个有效的 sqlite3 指针.

You can get that error, confusingly, if you neglected to open the database and the pointer is NULL (or, as rmaddy says, if it's NULL for any reason). Put a log statement where you open the database and make sure that it was successful and that you have a valid sqlite3 pointer.

这篇关于sqlite 3“SQL错误'内存不足'(7)"对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆