2

I have installed my application in the simulator and need to view the DB. Please tell me the application to view this or can I view it from Xcode itself.

enter image description here

DATABASE

//database connection
con = [[DataBase alloc]init];
NSError *error = [[NSError alloc]init];
NSFileManager *filemanager = [NSFileManager defaultManager];

NSArray *arryPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *DocumentPath = [arryPath objectAtIndex:0];
NSString *strDocumentPath = [DocumentPath stringByAppendingPathComponent:@"School.sqlite"];

// check file is exist or not
int success = [filemanager fileExistsAtPath:strDocumentPath];

//if file not exist at path
if (!success) {
    NSLog(@"SchoolName is: %@",@"No Database exist");
    NSString *strDefaultPath = [[[NSBundle mainBundle]resourcePath]stringByAppendingPathComponent:@"School.sqlite"];
    success = [filemanager copyItemAtPath:strDefaultPath toPath:strDocumentPath error:&error];

    if (!success) {
        NSAssert1(0, @"Failed to create writable database file with message '%@'.", [error localizedDescription]);
    }
}
//file exist at path
if (success) {
    NSLog(@"SchoolName is: %@",@" Database exist");
    if (sqlite3_open([strDocumentPath UTF8String],&database) == SQLITE_OK) {

    } else {
        sqlite3_close(database);
        NSAssert1(0, @"Failed to open database with message '%s'.", sqlite3_errmsg(database));
    }
}
Arasuvel
  • 2,971
  • 1
  • 25
  • 40
Jithin U. Ahmed
  • 1,495
  • 1
  • 19
  • 29

5 Answers5

3
  • Install DB Browser for Sqlite in Mac.
  • Provide path of .sqlite in documents directory of app to DB browser
  • It'll open live db from simulator
  • All entities of Core Data will have ZTablename naming convention
  • Keep refreshing DB browser for updated data during testing
Laxman Sahni
  • 572
  • 1
  • 6
  • 8
1

Try to use the client e.g. from here http://sqlitebrowser.org/ and open sqlite file.

1

For live database Changes please try this:

1.Install DBBrowser for SQLite.

2.Log your strDocumentPath in console using NSLog And copy the path.

3.Open DBBrowser and open database and in finder press CMD+SHIFT+G and paste your link there and press ENTER. You will be redirected to that location.

4.Select your SQLite file and it will be opened in DBBrowser. And keep it there until you are done with your DB works.

Now whenever you refresh the database from DBBrowser you will get the recent changes in DB also any manual changes in DB will be effected in your Simulator.

Karthik CP
  • 1,150
  • 13
  • 24
  • can u help me with this issue ? i need to see my changes also but cant understand ur steps for it . – shira Jul 11 '20 at 14:12
1

If you installed firefox on your PC, use "SQLite Manager" add-on is quite good, it's easy, lightly, and free. I've used it before to manage my sqlite db with ~40k records with no problem. https://addons.mozilla.org/en-US/firefox/addon/sqlite-manager/

Truong Le
  • 111
  • 5
0

Here is a way I do that

 init() {
        
         do {
                  // Get database path
                  if let path = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true).first {
                      // Connect to database
                      db = try Connection("\(path)/db.sqlite3")
                      
                      // Initialize tables
                      try db?.run(rssNewspaper.create(ifNotExists: true) { table in
                        table.column(rssNewspaperId, primaryKey: .autoincrement)
                        table.column(rssNewspaperName)
                        table.column(rssIsActive)
                        
                      })
                  }
              } catch {
                  print(error.localizedDescription)
              }
    }

point debuger point in path and when deice is locked there print to path then open terminal and use this command "open (path/of/printed/path)" in between( ) past the printed value it will be open

Ucdemir
  • 2,852
  • 2
  • 26
  • 44