Aviel Gross
Aviel Gross

Reputation: 9975

Read through my app's Core Data files (.sqlite, .sqlite-wal)

I am trying to browse through the data written by Core Data in an iOS app I am developing.

After the app ran for a while, and I assume collected some data, I now wish to look through the data and see what was written.

I have tried getting and browsing the .sqlite file through getting the app container from the device (Xcode > Devices > myApp > Download Container...).

I got the db files, myAppDB.sqlite, myAppDB.sqlite-shm and myAppDB.sqlite-wal.

When trying to look through them, it seems like the .sqlite is an empty table (except maybe some generic CoreData/sqlite stuff), and the -wal file has all the info.

The thing is I was only able to know that the wal has useful data when opening it with TextEdit, which din't show it in a very readable way, and when I tried to use an SQLite Manager app I an alert saying the wal is encrypted and I am asked to put a password...

For what it matters, I am writing a framework which handles the db (the model file and the code for writing data is inside the framework), then I have this framework running in an app I am developing. This is the code I use to create the store from within the framework (using MagicalRecord):

NSBundle *frameworkBundle = [NSBundle bundleForClass:[self class]];
[MagicalRecord setDefaultModelNamed:@"myAppStore.momd" inBundle:frameworkBundle];

NSURL *storeURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"myAppStoreDB.sqlite"];
[MagicalRecord setupCoreDataStackWithStoreAtURL:storeURL];

UPDATE: I managed to open the sqlite file with both Core-Data-Editor and CoreDataUtility but they both override and delete the contents of the .wal file, and show an empty table... It does have the model (entity names/properties etc.) but no data.

My wal file is 873KB but when I open the sqlite with one of these 2 tools it becomes 0Bytes...

tl;dr

How can I browse through the info written by Core Data of the app I am developing?

Upvotes: 2

Views: 2417

Answers (1)

Aviel Gross
Aviel Gross

Reputation: 9975

Well, for some reason I had to force not using WAL in my store (using @"journal_mode":@"DELETE" as explained here).

I then got only .sqlite file without the smh and wal files, and was able to open it and view the data using the 2 mentioned tools (Core-Data-Editor and CoreDataUtility).

My guess is that this is something to do with either the fact that I am dealing with CoreData from a framework (creating a moc, creating entities, saving etc.) and not from the application. Another guess is that it has something to do with the fact that I am using MagicalRecord.

Any insights regarding the cause would be appreciated...

Upvotes: 2

Related Questions