我正在尝试关闭CoreData存储中的日志记录模式。这是我的代码,它只是创建一个新的CoreData存储,与旧的存储完全一样(使用日志模式),而不迁移数据。这是怎么回事?
NSManagedObjectModel *managedObjectModel = [NSManagedObjectModel mergedModelFromBundles:nil];
NSString *applicationDocumentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
NSString *urlString = [applicationDocumentsDirectory stringByAppendingPathComponent: @"saori.sqlite"];
NSURL *url = [NSURL fileURLWithPath:urlString];
NSPersistentStoreCoordinator *psc = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:managedObjectModel];
NSDictionary *dict = @{@"journal_mode":@"OFF"};
NSDictionary *opts = @{NSSQLitePragmasOption:dict};
NSError *theError;
if (![psc addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:url options:opts error: &theError ]) {
NSLog(@"\n\nDisable journaling failed with error: %@", theError);
}发布于 2014-07-16 05:22:58
根据sqlite.org上的文档:
删除日志记录模式是正常行为。在DELETE模式下,回滚日志将在每个事务结束时删除。实际上,删除操作是导致事务提交的操作。
因此,日志文件会被删除,但不会“关闭”日志,因此会立即重新创建它们。但是,您可以将日志设置为"OFF":
关闭日志记录模式将完全禁用回滚日志。不会创建回滚日志,因此永远不会有要删除的回滚日志。关闭日志记录模式禁用SQLite的原子提交和回滚功能。
https://stackoverflow.com/questions/24767177
复制相似问题