本文介绍了如何禁用WAL日志模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在停用日志模式时遇到问题。
I am having trouble in disabling journal mode.
我的代码是:
static NSManagedObjectContext *managedObjectContext(){
static NSManagedObjectContext *context = nil;
if (context != nil) {
return context;
}
NSString * const NSSQLitePragmasOption;
NSSQLitePragmasOption : @{ @"journal_mode" : @"DELETE" };
@autoreleasepool {
context = [[NSManagedObjectContext alloc] init];
NSPersistentStoreCoordinator *coordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:managedObjectModel()];
[context setPersistentStoreCoordinator:coordinator];
NSString *STORE_TYPE = NSSQLiteStoreType;
NSString *path = @"ExerciseDB";
NSURL *url = [NSURL fileURLWithPath:[path stringByAppendingPathExtension:@"sqlite"]];
NSError *error;
NSPersistentStore *newStore = [coordinator addPersistentStoreWithType:STORE_TYPE configuration:nil URL:url options:NSSQLitePragmasOption error:&error];
if (newStore == nil) {
NSLog(@"Store Configuration Failure %@", ([error localizedDescription] != nil) ? [error localizedDescription] : @"Unknown Error");
}
}
return context;
}
如何禁用日志模式WAL。
How would I go about disabling journal mode WAL.
感谢
推荐答案
要禁用WAL模式,请将journal_mode设置为DELETE
To disable WAL mode, set the journal_mode to DELETE
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];
[_persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:options error:&error]
这篇关于如何禁用WAL日志模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!