Skip to content
This repository was archived by the owner on Nov 24, 2021. It is now read-only.

Calling drop crashes app (persistentstorecoordinator sqlite error code:522 'not an error') #19

Closed
denrase opened this issue Sep 30, 2015 · 3 comments

Comments

@denrase
Copy link

denrase commented Sep 30, 2015

Hey,

we got an error when calling drop and then trying to use the stack again. This is due to the fact that the wal and shm file are not deleted (http://stackoverflow.com/questions/18277092/persistentstorecoordinator-sqlite-error-code522-not-an-error). We have implemented a workaround in a subclass for now which fixes the issue.

br
denis

- (void)drop {
    NSPersistentStore *store = [self.mainContext.persistentStoreCoordinator.persistentStores lastObject];

    NSString *sqliteFile = store.URL.path;
    sqliteFile = [sqliteFile stringByDeletingPathExtension];

    NSString *shm = [NSString stringWithFormat:@"%@.sqlite-shm", sqliteFile];
    NSString *wal = [NSString stringWithFormat:@"%@.sqlite-wal", sqliteFile];

    NSFileManager *fileManager = [NSFileManager defaultManager];

    NSError *error = nil;
    if ([fileManager fileExistsAtPath:shm]) {
        [fileManager removeItemAtURL:[NSURL fileURLWithPath:shm] error:&error];
    }
    if ([fileManager fileExistsAtPath:wal]) {
        [fileManager removeItemAtURL:[NSURL fileURLWithPath:wal] error:&error];
    }

    if (error) {
        NSLog(@"ERROR Could not delete persitent store sql or wal file: %@", error.localizedDescription);
    }

    [super drop];
}
@3lvis
Copy link
Owner

3lvis commented Sep 30, 2015

Thanks ❤️

@3lvis
Copy link
Owner

3lvis commented Sep 30, 2015

@3lvis 3lvis closed this as completed Sep 30, 2015
@denrase
Copy link
Author

denrase commented Oct 1, 2015

hey, awesome! thanks! 👍

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants