Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sqlite 3 "SQL error 'out of memory' (7)" objc

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;
}

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?

like image 225
dev6546 Avatar asked Feb 16 '23 12:02

dev6546


1 Answers

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.

like image 131
Rob Avatar answered Feb 23 '23 09:02

Rob