SQLite: DB error, out of memory

I use FMDB to create and add records to d / b. D / b creation method:

//-----------------------    checkIfDatabaseExists    -----------------|
+ (void) openCreateDB  {

    NSArray *searchPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);  // Get the path to the database file
    NSString *documentPath = [searchPaths objectAtIndex:0];
    NSString *databasePath = [documentPath stringByAppendingPathComponent:@"ppcipher.s3db"];
    NSLog(@"d/b path: /%@", databasePath);

    char * errmsg = nil;   

    NSFileManager *fileManager = [NSFileManager defaultManager];
    [fileManager removeItemAtPath:databasePath error:NULL];  //  <------------  delete d/b  TESTING ONLY! 

    BOOL fileExists = [fileManager fileExistsAtPath:databasePath];
    if(!fileExists)  {
        FMDatabase* _db = [FMDatabase databaseWithPath: databasePath]; 

        if (![_db open]) {
            NSLog(@"Could not open/create database");
        }

        [_db executeUpdate:@"CREATE TABLE CardData (card_id TEXT PRIMARY KEY NOT NULL, card_name TEXT NOT NULL, "
         @"card_type TEXT, code_val TEXT, create_date TEXT DEFAULT CURRENT_DATE, user_notes TEXT, gps_loc TEXT)"];

        if(errmsg != nil)
            NSLog(@"error: %s", errmsg);  //  DEBUGGING ONLY!  (REMOVE when done!)
    }
    return;
}

What causes NO errors. However, when I then do one (1) "insert" after "open", I get a message from FMDB saying about DB: 7 "out of memory" error. And every SQL query after that, I get the same error (only creating d / b did not give any errors!). Here is the code to insert:

//---------------------    addRecordToDatabase    ----------------------|
+ (void)addRecordToDatabase: (ZBarSymbol *)symbol  {


    FMDatabase* _db = [FMDatabase sharedFMDatabase];

    [_db setLogsErrors:1];  //  log all of the SQLite d/b errors

    [_db executeUpdate: @"INSERT INTO CardData (card_id, card_name, code_val) VALUES (?, ?, ?)", symbol.data, @"Test Card", symbol.typeName, nil];

}

This is a very small d / b with minimal data. I ran the Inspector, and nothing was unusual. Any suggestions would be greatly appreciated.

+3
source share
1 answer

, [_db open] , . , " " FMDB , () , .

+18

All Articles