Advertise here




Advertise here

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Google Sign In with OpenID
Please do not post the same thing multiple times. The board software automatically flags certain posts as needing moderator attention. This happens the most often for new users. I'm pretty sure this is made clear at the time you attempt to post. Posting the same thing over and over again just makes that many more posts the moderators have to weed through later. This makes us sad. Don't make us sad. If your post/thread doesn't appear, just wait a while. Don't post it again. If it hasn't shown up by the next day, then you can try again. I normally go through posts in the mornings, and try to check a few times throughout the day, but I'm not here 24/7. There will typically be a significant delay before posts are approved. Just be patient.

Core Data (SQLITE3) does not refresh when updating the application with a new DB?

AjaxxAjaxx Posts: 68Registered Users
Hi,
I generate a Core Data / Sqlite3 DB in the simulator and then distribute it to my test device. Every thing works beautifully in the simulator but not on the device.

When i do an update in the database and do a simulator build the DB is updated when i run the app. However, on the device the data base is not updated so it keep the old version.

This is driving me crazy and i wonder of someone nice could help me to fix this as it is the last piece to fix before the app (my first) is ready for prime time?
:confused:
Post edited by Ajaxx on

Replies

  • dany_devdany_dev Posts: 4,700Tutorial Authors, Registered Users
    ehm........post the code?

    However maybe you are trying to write outside your documents directory, or is something related to case sensitive file name....
  • AjaxxAjaxx Posts: 68Registered Users
    Well, the code below is from the delegate.

    My question is really about why i am not able to distribute a new version of the Sqlite3 database on the device. Works only in the simulator.


    Returns the managed object model for the application.
    If the model doesn't already exist, it is created from the application's model.
    */
    - (NSManagedObjectModel *)managedObjectModel {

    if (managedObjectModel != nil) {
    return managedObjectModel;
    }
    NSString *modelPath = [[NSBundle mainBundle] pathForResource:@\"FamQuiz_R0_1\" ofType:@\"momd\"];
    NSURL *modelURL = [NSURL fileURLWithPath:modelPath];
    managedObjectModel = [[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL];
    return managedObjectModel;
    }




    - (NSPersistentStoreCoordinator *)persistentStoreCoordinator {
    if (persistentStoreCoordinator != nil) {
    return persistentStoreCoordinator;
    }


    // NSString *storePath = [[self applicationDocumentsDirectory] stringByAppendingPathComponent: @\"FamQuiz_R0_1.sqlite\"];

    NSString *storePath = [[self applicationDocumentsDirectory] stringByAppendingPathComponent: @\"FamQuiz_R0_1.sqlite\"];
    /*
    Set up the store.
    For the sake of illustration, provide a pre-populated default store.
    */
    NSFileManager *fileManager = [NSFileManager defaultManager];
    // If the expected store doesn't exist, copy the default store.
    if (![fileManager fileExistsAtPath:storePath]) {
    NSString *defaultStorePath = [[NSBundle mainBundle] pathForResource:@\"FamQuiz_R0_1\" ofType:@\"sqlite\"];
    if (defaultStorePath) {
    [fileManager copyItemAtPath:defaultStorePath toPath:storePath error:NULL];
    }
    }

    NSURL *storeUrl = [NSURL fileURLWithPath:storePath];

    NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption, [NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption, nil];
    persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel: [self managedObjectModel]];

    NSError *error;
    if (![persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeUrl options:options error:&error]) {
    // Update to handle the error appropriately.
    NSLog(@\"Unresolved error %@, %@\", error, [error userInfo]);
    exit(-1); // Fail
    }

    return persistentStoreCoordinator;
    }



    #pragma mark -
    #pragma mark Application's Documents directory

    /**
    Returns the path to the application's Documents directory.
    */
    - (NSString *)applicationDocumentsDirectory {
    return [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
    }


    #pragma mark -
    #pragma mark Memory management

    - (void)applicationDidReceiveMemoryWarning:(UIApplication *)application {
    /*
    Free up as much memory as possible by purging cached data objects that can be recreated (or reloaded from disk) later.
    */
    }


    I read somewhere that data in the documents directory is not refreshed when distributing a new version, dunno if that is correct. If it is, why is it working in the simulator?

    Again, this is the sequence i use:

    1. Run the app in the simulator

    2. Use the magic password, which results:

    a. Delete all records in the Sqlite DB
    b. Populate the (empty) DB with new records

    3. Run the app in the simulator and can see the new updated data

    4. Attach the test device and build

    5. Run the app on the test device. The old version of the database is still there, no update


    :confused:
  • dljefferydljeffery Posts: 1,311iPhone Dev SDK Supporter, Registered Users
    Have you stepped through the execution in the debugger?
    Recall It! Tag your notes. Tag your photos. Tag your thoughts. Tag your life.

    Recall It! for iPad
  • roberthuttingerroberthuttinger Posts: 96Registered Users
    Ajaxx;343581 said:
    someone? :confused:
    delete the app and all its data in the device and or simulator, then reinstall the data will be there.

    bo
Sign In or Register to comment.