1
我試圖在xcode 4.2和ios5 sdk中使用sqlite數據庫。下面的代碼中的if條件返回false,數據庫關閉。無法在xcode中打開sqlite數據庫
在控制檯中顯示以下消息。
[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
請幫忙。
//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);
}