Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 06-07-2011, 02:33 PM   #1 (permalink)
Registered Member
 
Join Date: Jul 2010
Posts: 67
Ajaxx is on a distinguished road
Default Core Data (SQLITE3) does not refresh when updating the application with a new DB?

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?
Ajaxx is offline   Reply With Quote
Old 06-07-2011, 03:01 PM   #2 (permalink)
Nuisance Developer
 
Join Date: Jul 2009
Location: Italy
Posts: 4,691
dany_dev is on a distinguished road
Default

ehm........post the code?

However maybe you are trying to write outside your documents directory, or is something related to case sensitive file name....
__________________
dany_dev is offline   Reply With Quote
Old 06-08-2011, 11:13 AM   #3 (permalink)
Registered Member
 
Join Date: Jul 2010
Posts: 67
Ajaxx is on a distinguished road
Default

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.

Code:
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


Ajaxx is offline   Reply With Quote
Old 06-10-2011, 12:13 AM   #4 (permalink)
Registered Member
 
Join Date: Jul 2010
Posts: 67
Ajaxx is on a distinguished road
Default

someone?
Ajaxx is offline   Reply With Quote
Old 06-10-2011, 01:42 AM   #5 (permalink)
Senior Member
iPhone Dev SDK Supporter
 
Join Date: Jan 2010
Location: Issaquah, WA
Age: 42
Posts: 1,244
dljeffery is on a distinguished road
Default

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

http://www.dljeffery.com
dljeffery is offline   Reply With Quote
Old 06-18-2011, 02:41 PM   #6 (permalink)
Registered Member
 
roberthuttinger's Avatar
 
Join Date: Sep 2008
Posts: 96
roberthuttinger is on a distinguished road
Default the database does not get overwritten

Quote:
Originally Posted by Ajaxx View Post
someone?
delete the app and all its data in the device and or simulator, then reinstall the data will be there.

bo
roberthuttinger is offline   Reply With Quote
Reply

Bookmarks

Tags
core data, sqlite

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 328
7 members and 321 guests
chemistry, Dnnake, iOS.Lover, jenniead38, lendo, pbart, Wikiboo
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,663
Threads: 94,120
Posts: 402,898
Top Poster: BrianSlick (7,990)
Welcome to our newest member, LezB44
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 02:19 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0