Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

markredson

macrumors newbie
Original poster
Feb 27, 2009
3
0
I am building an app that DID work fine. But now when is installed on simulator OR iPhone, a database file is automatically added in the documents folder, therefor it does not copy the database I have provided (with the proper tables) The auto generated database file has nothing in it, so when I try to preform a query, the app fails.

Code: (which is copied right from sqlitebooks except for the DB name)
Code:
    // First, test for existence.
    BOOL success;
    NSFileManager *fileManager = [NSFileManager defaultManager];
    NSError *error;
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString *writableDBPath = [documentsDirectory stringByAppendingPathComponent:@"db.sqlite"];
    success = [fileManager fileExistsAtPath:writableDBPath];
    if (success) return;
    // The writable database does not exist, so copy the default to the appropriate location.
    NSString *defaultDBPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"db.sqllite"];
    success = [fileManager copyItemAtPath:defaultDBPath toPath:writableDBPath error:&error];
    if (!success) {
        NSAssert1(0, @"Failed to create writable database file with message '%@'.", [error localizedDescription]);
    }

Interestingly enough, I think the command that checks for the file is creating the file... no matter what I name it that file shows up somehow.

Help!?
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.