I have a CoreData model that uses SQLite as persistence store. I need to insert large numbers of rows after doing some processing to each record. Is there any way to send those commands to SQLite
PRAGMA synchronous=OFF
PRAGMA count_changes=OFF
PRAGMA journal_mode=MEMORY
PRAGMA temp_store=MEMORY
I need to speed up the processing time, as it takes couple of hours to complete.
Any hints will be appreciated.
Thanks
You can specify the pragmas when adding your store to the store coordinator:
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];
(Adapted from Persistent Store Features)
I strongly suggest to also read "Efficiently Importing Data".
Related documentation: NSSQLitePragmasOption Efficiently Importing Data
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With