0

Right now i am using coredata to save my data. Its all working fine but now i changed the logic to save values to the database. So i need to compare that the after logic change same values are getting saved in tables. So I need to compare tables.

I went through many links like link 1 link 2

all the links shows that the database file that coredata create is of .sqlite extension. But the files create at that location are "persistentStore, persistentStore-shm, persistentStore-wal" as show in screenshot.

Image of database file

How should i suppose to open these files to see the saved data in tables. Thanks in advance

 - (void)setupDatabase:(void (^)(BOOL))completionHandler
{

    NSURL *url = [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject];
    url = [url URLByAppendingPathComponent:@"MainDataModel"];

    self.db = [[CWUIManagedDocument alloc] initWithFileURL:url];

    NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:
                                                  [NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption,
                                                  [NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption, nil];

    self.db.persistentStoreOptions = options;

    if(![[NSFileManager defaultManager] fileExistsAtPath:[self.db.fileURL path]])
    {
        [self.db saveToURL:self.db.fileURL forSaveOperation:UIDocumentSaveForCreating completionHandler:^(BOOL success) {
            self.dataManager.db = self.db;
            completionHandler(success);
        }];
    } else if (self.db.documentState == UIDocumentStateClosed) {
        [self.db openWithCompletionHandler:^(BOOL success) {
            self.dataManager.db = self.db;
            completionHandler(success);
        }];
    }
}
duan
  • 8,515
  • 3
  • 48
  • 70
Parv Bhasker
  • 1,773
  • 1
  • 20
  • 39

3 Answers3

1

Your sql file is the one without extension. The other 2 files are for journaling mode.

This has already been explained in this question. Apple changed the default journaling mode to WAL on iOS 7.

pesch
  • 1,976
  • 2
  • 17
  • 29
1

In setupDatabase() method replace the following line

 url = [url URLByAppendingPathComponent:@"MainDataModel"]

with

 url = [url URLByAppendingPathComponent:@"MainDataModel.sqlite"]

You have to create the persistent store type as Sqlite

Subramanian P
  • 4,365
  • 2
  • 21
  • 25
1

Run these commands on terminal and open yourpersistentStore in sqlite manager. These commands will merge the WAL file into the main sqlite file

$ sqlite3 persistentStore
sqlite> PRAGMA wal_checkpoint;

Press control + d

These steps are already covered in the answer of the above link : https://stackoverflow.com/a/43406516/468724

Inder Kumar Rathore
  • 39,458
  • 17
  • 135
  • 184