Jithin U. Ahmed
Jithin U. Ahmed

Reputation: 1811

How to view the sqlite db in the application installed in iOS for testing

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));
    }
}

Upvotes: 2

Views: 5155

Answers (5)

Ucdemir
Ucdemir

Reputation: 3098

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

Upvotes: 0

Truong Le
Truong Le

Reputation: 111

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/

Upvotes: 1

Laxman Sahni
Laxman Sahni

Reputation: 612

  • 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

Upvotes: 3

Karthik CP
Karthik CP

Reputation: 1200

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.

Upvotes: 1

Rafał Piekara
Rafał Piekara

Reputation: 74

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

Upvotes: 1

Related Questions