When this app is started it checks to see if the database has been copied to the App's folders, this is all working great, I can see that the Database is bein copied accross, my trouble is when I try to access the database in other files I get an [EGODatabase] Error opening DB: 14 error. This I assume means that it can't find the database file in the App's documents. But I have outputted the file path and gone to that directory in the simulator and I can see the file:
App Delegate (This Works Fine):
- (BOOL)createEditableCopyOfDatabaseIfNeeded {
NSLog(@"TEST");
// First, test for existence.
BOOL success;
BOOL newInstallation;
NSFileManager *fileManager = [[NSFileManager alloc] init];
NSError *error;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory,NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *writableDBPath = [documentsDirectory stringByAppendingPathComponent:@"purchase_items.db"];
success = [fileManager fileExistsAtPath:writableDBPath];
newInstallation = !success;
if (success) {
[fileManager release];
return newInstallation;
}
// The writable database does not exist, so copy the default to the appropriate location.
NSLog(@"database does not exist");
NSString *defaultDBPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"purchase_items.db"];
success = [fileManager copyItemAtPath:defaultDBPath toPath:writableDBPath error:&error];
NSLog(@"File Copy = %d", success);
[fileManager release];
if (!success) {
NSAssert1(0, @"Failed to create writable database file with message '%@'.", [error localizedDescription]);
}
return newInstallation;
}
ProductView.m
-(void) viewWillAppear:(BOOL)animated {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *writableDBPath = [documentsDirectory stringByAppendingPathComponent:@"purchase_items.db"];
NSLog(@"%@", writableDBPath);
EGODatabase *database = [EGODatabase databaseWithPath:[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent: writableDBPath]];
EGODatabaseResult *result = [database executeQuery:[NSString stringWithFormat:@"SELECT * FROM items WHERE id = %d LIMIT 1", tale_id]];
}

New Topic/Question
Reply


MultiQuote


|