4

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?

2
  • At which step does it run out of memory? Commented Aug 20, 2013 at 1:25
  • (sqlite3_prepare_v2(_database, [query UTF8String], -1, &statement, NULL) It doesn't even get to the loop, the if statement hits and it prints the error message (the second NSLOG) Commented Aug 20, 2013 at 1:30

1 Answer 1

8

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Or if the database reference used happens to be NULL.
Your contribution with this comment saved me @rmaddy!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.