ios – 使用SQLite和CoreData进行批量插入

我有一个使用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

相关文章

当我们远离最新的 iOS 16 更新版本时,我们听到了困扰 Apple...
欧版/美版 特别说一下,美版选错了 可能会永久丧失4G,不过只...
一般在接外包的时候, 通常第三方需要安装你的app进行测...
前言为了让更多的人永远记住12月13日,各大厂都在这一天将应...