我需要一些幫助,這方法:核心數據:表達式樹太大
// deletes all points in database except points with given identifiers
- (void)deleteAllPointsExcept:(NSArray *)safeIdentifiers save:(BOOL)save {
// create request to fetch all 'doomed' points
NSManagedObjectContext *context = [[TSAppDelegate delegate] managedObjectContext];
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] initWithEntityName:@"MapPoint"];
NSMutableArray *subpredicates = [NSMutableArray array];
for (NSNumber *identifier in safeIdentifiers) {
NSPredicate *pred = [NSPredicate predicateWithFormat:@"pid!=%@", identifier];
[subpredicates addObject:pred];
}
fetchRequest.predicate = [NSCompoundPredicate andPredicateWithSubpredicates:subpredicates];
// fetch 'em & destroy 'em
NSError *error;
NSArray *points = [context executeFetchRequest:fetchRequest error:&error];
for (TSMapPoint *point in points) {
[context deleteObject:point];
}
// save if requested
if (save) {
[[[TSAppDelegate delegate] managedObjectContext] save:NULL];
}
}
它應該從我的核心數據NSManagedObjectContext
清除不需要的MapPoints。它工作正常,但有一天,我收到了這樣的信息:
CoreData: error: (1) I/O error for database at ... SQLite error code:1, 'Expression tree is too large (maximum depth 1000)'
我GOOGLE了,當謂語過長就像WHERE id=1 OR id=2 OR id=3 ...
但我不知道如何解決這個發生這種情況。有人有想法嗎?
在此先感謝, 皮特。
哇,這看起來很優雅。 :)你是否肯定它可以在iOS上的Core Data下使用SQLite? – 2014-09-29 17:30:58
是的 - 有一個可怕的很多強大的謂詞,比這更復雜的工作與SQLite完美 – 2014-09-29 17:32:10
嗯,我已經試過你的方法,並得到:'NSInvalidArgumentException - 未實現SQL生成謂詞︰(pid IN {931,1023 ,2971,3060})。不幸的是,這似乎不適用於iOS。你怎麼看呢? – 2014-09-29 17:40:41