0 Replies - 17878 Views - Last Post: 11 December 2012 - 02:27 PM

#1 RabbitFactoryUK  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 11-December 12

Objective C & EgoDatabase Error Opening DB: 14 after coping file

Posted 11 December 2012 - 02:27 PM

I have added a Database to my app and I am using the EGODatabase class as I find it easy to use.

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 {
    // 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;


-(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]];

Is This A Good Question/Topic? 0
  • +

Page 1 of 1