我有一个使用sqlite作为持久性存储的CoreData模型.在对每条记录进行一些处理之后,我需要插入大量的行.有没有办法将这些命令发送到sqlite
PRAGMA synchronous=OFF PRAGMA count_changes=OFF PRAGMA journal_mode=MEMORY PRAGMA temp_store=MEMORY
我需要加快处理时间,因为它需要几个小时才能完成.
任何提示将不胜感激.
谢谢
解决方法
将商店添加到商店协调员时,可以指定编译指示:
NSMutableDictionary *pragmaOptions = [NSMutableDictionary dictionary]; [pragmaOptions setobject:@"OFF" forKey:@"synchronous"]; [pragmaOptions setobject:@"OFF" forKey:@"count_changes"]; [pragmaOptions setobject:@"MEMORY" forKey:@"journal_mode"]; [pragmaOptions setobject:@"MEMORY" forKey:@"temp_store"]; NSDictionary *storeOptions = [NSDictionary dictionaryWithObject:pragmaOptions forKey:NSsqlitePragmasOption]; NSPersistentStore *store; NSError *error = nil; store = [psc addPersistentStoreWithType:NSsqliteStoreType configuration: nil URL:url options:storeOptions error:&error];
(改编自Persistent Store Features)
我强烈建议您阅读“有效导入数据”.
相关文档:
NSSQLitePragmasOption
Efficiently Importing Data