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