0

I am getting an error in my iOS app. Frustratingly, it is an intermittent error - The task I am performing works 5 or 6 times in a row then crashes unexpectedly. The error log suggests an error opening a sqlite database - presumably the core data model in my app. However Xcode shows that the line in which the error occurs is accessing the Apple contacts database. So I am not clear what has happened. The error log is below. Can anyone interpret the output below and shed any light on this?

    warning: Could not compile statement PRAGMA journal_mode = wal;: unable to open database file
error 14 creating properties table: unable to open database file
warning: Could not compile statement SELECT value FROM _SqliteDatabaseProperties WHERE key = ?;: unable to open database file
warning: Could not compile statement SELECT value FROM _SqliteDatabaseProperties WHERE key = ?;: unable to open database file
warning: Could not compile statement SELECT value FROM _SqliteDatabaseProperties WHERE key = ?;: unable to open database file
warning: Could not compile statement SELECT ROWID, First, Last, Middle, NULL, NULL, NULL, Organization, NULL, NULL, Kind, NULL, NULL, Nickname, Prefix, Suffix, FirstSort, LastSort, CreationDate, ModificationDate, CompositeNameFallback, NULL, StoreID, NULL, FirstSortSection, LastSortSection, FirstSortLanguageIndex, LastSortLanguageIndex, NULL, NULL, NULL, PersonLink, NULL, IsPreferredName FROM ABPerson;: unable to open database file
warning: Could not compile statement SELECT ROWID, First, Last, Middle, NULL, NULL, NULL, Organization, NULL, NULL, Kind, NULL, NULL, Nickname, Prefix, Suffix, FirstSort, LastSort, CreationDate, ModificationDate, CompositeNameFallback, NULL, StoreID, NULL, FirstSortSection, LastSortSection, FirstSortLanguageIndex, LastSortLanguageIndex, NULL, NULL, NULL, PersonLink, NULL, IsPreferredName FROM ABPerson;: unable to open database file
warning: Could not compile statement INSERT OR REPLACE INTO _SqliteDatabaseProperties VALUES (?, ?);: unable to open database file
warning: Could not compile statement SELECT value FROM _SqliteDatabaseProperties WHERE key = ?;: unable to open database file
warning: Could not compile statement INSERT OR REPLACE INTO _SqliteDatabaseProperties VALUES (?, ?);: unable to open database file
2012-03-29 11:43:13.813 iPT[10500:11303] Error loading /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.1.sdk/System/Library/DataClassMigrators/AccountMigrator.migrator/AccountMigrator:  dlopen(/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.1.sdk/System/Library/DataClassMigrators/AccountMigrator.migrator/AccountMigrator, 265): no suitable image found.  Did find:
    /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.1.sdk/System/Library/DataClassMigrators/AccountMigrator.migrator/AccountMigrator: open() failed with errno=24
2012-03-29 11:43:13.814 iPT[10500:11303] [+[AccountsManager _migrateAccountsIfNeeded]] Accounts migration failed
warning: Could not compile statement SELECT value FROM _SqliteDatabaseProperties WHERE key = ?;: unable to open database file
warning: Could not compile statement SELECT value FROM _SqliteDatabaseProperties WHERE key = ?;: unable to open database file
warning: Could not compile statement SELECT ROWID, First, Last, Middle, NULL, NULL, NULL, Organization, NULL, NULL, Kind, NULL, NULL, Nickname, Prefix, Suffix, FirstSort, LastSort, CreationDate, ModificationDate, CompositeNameFallback, NULL, StoreID, NULL, FirstSortSection, LastSortSection, FirstSortLanguageIndex, LastSortLanguageIndex, NULL, NULL, NULL, PersonLink, NULL, IsPreferredName FROM ABPerson WHERE ROWID = ?;: unable to open database file

The code I am executing when the crash occurs is...

Client *client = [mutableFetchResults objectAtIndex:loop];
            ABRecordID recordID = [client.addressBookID intValue];
            ABRecordRef person = ABAddressBookGetPersonWithRecordID (addressBook,recordID);
            NSString *clientFirstName = (NSString *)ABRecordCopyValue(person, kABPersonFirstNameProperty);
            NSString *clientLastName = (NSString *)ABRecordCopyValue(person, kABPersonLastNameProperty);
            NSString *clientCompositeName = [NSString stringWithFormat:@"%@ %@", clientFirstName, clientLastName];
Ben Thompson
  • 4,743
  • 7
  • 35
  • 52

1 Answers1

0

I assume you are declaring addressBook in the following manner?

    ABAddressBookRef addressBook = ABAddressBookCreate();
JimP
  • 87
  • 5
  • Yes - just above where I declare *client. – Ben Thompson Mar 29 '12 at 14:17
  • If you NSLog the client object, does the error occur at that point? If so, then the problem is likely your migration options being set on your persistent store. NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys: [NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption, [NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption, nil]; if (![persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeUrl options:options error:&error]) { – JimP Mar 29 '12 at 14:22
  • Apologies, I don't fully understand the answer. Where would you suggest I create an NSLog? Also, should I be looking for that code somewhere to change a setting, or do I need to insert it somewhere? Apologies if these are dumb questions! – Ben Thompson Mar 29 '12 at 14:31
  • No problem Ben... in your code, right after the assignment of client, add this statement: NSLog( @"%@ %d", client, [client.addressBookID intValue] ); – JimP Mar 29 '12 at 14:38
  • It gets through that stage ok. It fails at the NSString *clientFirstName = (NSString *)ABRecordCopyValue(person, kABPersonFirstNameProperty); line – Ben Thompson Mar 29 '12 at 16:23