1

Im trying to use an sqlite database in xcode 4.2 and ios5 sdk. The if condition in the code below returns false and the database closes.

In the console the following message is displayed.

[71280:5303] Failed at Prepare Statement in NumberOfOrders. Reason out of memory
2011-12-07 03:14:31.893 Database Closed
2011-12-07 03:14:31.897  ### *** -[__NSArrayM objectAtIndex:]: index 0 beyond bounds for empty  
array
2011-12-07 03:14:31.898 ### *** -[__NSArrayM objectAtIndex:]: index 0 beyond bounds for empty 
array

Kindly help.

//Open Database connection & assign to pointer dbInstance variable
-(void) OpenDatabase { @try {
NSArray *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSLog(@"path is %@", path); 
NSString *documentDir = [path objectAtIndex:0];
NSLog(@"doc directory is %@", documentDir);
NSString *dbPath = [documentDir stringByAppendingPathComponent: @"MAKitTutorials.sqlite"];
NSLog(@"dbPath is %@", dbPath);

if (sqlite3_open_v2([dbPath UTF8String], &dbInstance, SQLITE_OPEN_NOMUTEX, NULL) == SQLITE_OK) {
    NSLog(@"Database Open Succeeds");
} else {
    sqlite3_close(dbInstance);
}
} @catch (NSException * e) {
NSLog(@"Failed to open the database. Reason %@",[e reason] );
}
}
//Close Database connection
-(void) CloseDatabase { sqlite3_close(dbInstance);
}

1 Answer 1

2

I hit the same problem when tried to use another flag: SQLITE_OPEN_SHAREDCACHE. Solved by explicitly adding two flags used by sqlite3_open() call:
SQLITE_OPEN_CREATE | SQLITE_OPEN_READWRITE.

So in your case it's going to be:

SQLITE_OPEN_CREATE | SQLITE_OPEN_READWRITE | SQLITE_OPEN_NOMUTEX.
Sign up to request clarification or add additional context in comments.

Comments

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.