-1

I have project with MAgicalRecords and OSX it is convertor SQLITe -> coreData . Before Yosemite - it worked well but after update - have some troubles

My Steps

[MagicalRecord saveWithBlockAndWait:^(NSManagedObjectContext *localContext) {
                      //do some workd with save entity  }];

than i try to copy database which i get after converting

 if ([fileManager fileExistsAtPath:from]) {

    NSFileHandle *fileHandle = [NSFileHandle fileHandleForUpdatingAtPath:from];
    [fileHandle seekToEndOfFile];
    [fileHandle closeFile];

    [fileManager copyItemAtPath:from toPath:to error:NULL];
}

BUT file here HAS a tables and colums before copy and his size is 165kb - and after coping NO - he is empty. Does it new feature of MAC ? As you can see - i put [fileHandle closeFile]; but it still not working.

I noticed that if i close project before copyng file "from" has 1.8mb and has all data.

and there are 3 files

Main.sqlite
Main.sqlite-shm
Main.sqlite-wal

It looks like OS white data in "some memory" but not in file directly. I try to find solutions but didn find any. Please help

Kampai
  • 22,848
  • 21
  • 95
  • 95

2 Answers2

0

Copying these three files will not fully copy your database. I suggest the answer from this question:

Using MagicalRecord to prepopulate a database (swift). -wal journal created, however, data not copied to database

Community
  • 1
  • 1
casademora
  • 67,775
  • 17
  • 69
  • 78
0

Thanks it was problem with SQL journal mode

+ (NSDictionary *) getOptionsForCreate {
NSDictionary *pragmaOptions = [NSDictionary dictionaryWithObject:@"MEMORY" forKey:@"journal_mode"];

NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:
                         [NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption,
                         [NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption,
                         pragmaOptions, NSSQLitePragmasOption, nil];
return options;

}

  NSPersistentStore *store = [self addPersistentStoreWithType:NSSQLiteStoreType
                                              configuration:nil
                                                        URL:url
                                                    options:[sel getOptionsForCreate]
                                                      error:&error];