Git Product home page Git Product logo

Comments (7)

renzos avatar renzos commented on September 2, 2024

It seems that the new Write-Ahead-Logging (WAL) of IOS 7 is causing problems because it splits up the sqlite database in 3 files:

  • persistentStore.sqlite
  • persistentStore.sqlite-wal
  • persistentStore.sqlite-shm

I tried to disable it with this option but it still creates 3 files:
NSDictionary *options = @{ NSSQLitePragmasOption : @{@"journal_mode" : @"DELETE"} };
Any suggestion?

from ticoredatasync.

pventura1976 avatar pventura1976 commented on September 2, 2024

How do you build the Core Data stack?

from ticoredatasync.

renzos avatar renzos commented on September 2, 2024

Here how I build the Core Data stack, even if I set up the option "NSDictionary *options = @{NSSQLitePragmasOption:@{@"journal_mode":@"DELETE"}};" it still creates 3 files. Reading the specification of the WriteAheadLogging (https://www.sqlite.org/wal.html) the original content is preserved in the database file and the changes are appended into the separate WAL file, so when I launch the app for the first time the Core Data Stack is build, the persistentStore.sqlite is created but it's empty and every time I add, delete or modify a record, changes are stored in the persistentStore.sqlite-wal file. So when I upload the Whole Store this is always empty:

#pragma mark - Core Data stack

// Returns the managed object context for the application.
// If the context doesn't already exist, it is created and bound to the persistent store coordinator for the application.
- (NSManagedObjectContext *)managedObjectContext
{
    if (_managedObjectContext != nil) {
        return _managedObjectContext;
    }

    NSPersistentStoreCoordinator *coordinator = [self persistentStoreCoordinator];
    if (coordinator != nil) {
        _managedObjectContext = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSMainQueueConcurrencyType];
        [_managedObjectContext setPersistentStoreCoordinator:coordinator];
    }
    return _managedObjectContext;
}

// 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;
    }
    NSURL *modelURL = [[NSBundle mainBundle] URLForResource:@"AppName" withExtension:@"momd"];
    _managedObjectModel = [[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL];
    return _managedObjectModel;
}

// Returns the persistent store coordinator for the application.
// If the coordinator doesn't already exist, it is created and the application's store added to it.
- (NSPersistentStoreCoordinator *)persistentStoreCoordinator
{
    if (_persistentStoreCoordinator != nil) {
        return _persistentStoreCoordinator;
    }

    NSURL *storeURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"persistentStore.sqlite"];

    /* Add the check for an existing store here... */
    if ([[NSFileManager defaultManager] fileExistsAtPath:storeURL.path] == NO) {
        self.downloadStoreAfterRegistering = NO;
    }

    NSError *error = nil;

    NSDictionary *options = @{NSSQLitePragmasOption:@{@"journal_mode":@"DELETE"}};

    _persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]];
    if (![_persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:options error:&error]) {
        /*
         Replace this implementation with code to handle the error appropriately.

         abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development. 

         Typical reasons for an error here include:
         * The persistent store is not accessible;
         * The schema for the persistent store is incompatible with current managed object model.
         Check the error message to determine what the actual problem was.


         If the persistent store is not accessible, there is typically something wrong with the file path. Often, a file URL is pointing into the application's resources directory instead of a writeable directory.

         If you encounter schema incompatibility errors during development, you can reduce their frequency by:
         * Simply deleting the existing store:
         [[NSFileManager defaultManager] removeItemAtURL:storeURL error:nil]

         * Performing automatic lightweight migration by passing the following dictionary as the options parameter:
         @{NSMigratePersistentStoresAutomaticallyOption:@YES, NSInferMappingModelAutomaticallyOption:@YES}

         Lightweight migration will only work for a limited set of schema changes; consult "Core Data Model Versioning and Data Migration Programming Guide" for details.

         */
        NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
        return nil;
    }
    return _persistentStoreCoordinator;
}

from ticoredatasync.

renzos avatar renzos commented on September 2, 2024

It seems that the error was here because I didn't previuosly set the pragmaOptions also here but just in the main Core Data Stack:

- (void)documentSyncManager:(TICDSDocumentSyncManager *)aSyncManager didReplaceStoreWithDownloadedStoreAtURL:(NSURL *)aStoreURL{
NSError *anyError = nil;
    NSMutableDictionary *pragmaOptions = [NSMutableDictionary dictionary];
    [pragmaOptions setObject:@"delete" forKey:@"journal_mode"];
    NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:
                             [NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption,
                             [NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption,
                             pragmaOptions, NSSQLitePragmasOption,
                             nil];

    id store = [self.persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:aStoreURL options:options error:&anyError];

    if (store == nil) {
        NSLog(@"Failed to add persistent store at %@: %@", aStoreURL, anyError);
    }
}

from ticoredatasync.

kevinhoctor avatar kevinhoctor commented on September 2, 2024

So did this remove the error for you?

Also, you can simplify your dictionary notation now in Objective-C:

NSDictionary *options = @{ NSMigratePersistentStoresAutomaticallyOption : @YES, NSInferMappingModelAutomaticallyOption : @YES, NSSQLitePragmasOption : @{ @"journal_mode" : @"DELETE" } };

I find the new notation much easier to read and understand as well.

from ticoredatasync.

renzos avatar renzos commented on September 2, 2024

It seems that WAL has been completely switched off but I'll make more tests tomorrow to confirm that, maybe it should be added to the documentation since WAL is ON by default in iOS7. I'll also simplified the dictionary notation as you suggested and it's ok, much easier to read, thanks.

from ticoredatasync.

renzos avatar renzos commented on September 2, 2024

I confirm I removed the problem as I told above, so summarizing it I had to set the pragmaOptions both in the Core Data stack and in the didReplaceStoreWithDownloadedStoreAtURL delegate method.

from ticoredatasync.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.