ios - How to view the content of .db file? -
i using xcode 6.4, developing apps ios 8 need use database. inserted information database ("something.db" file). want see content of "something.db" see inserted. how can view content?
this code creating database "company.db" , table "staff"(id pk, name text, age integer):
-(void) createoropendb { nsarray *path = nssearchpathfordirectoriesindomains(nsdocumentdirectory, nsuserdomainmask, yes); nsstring *docpath = [path objectatindex:0]; dbpathstring = [docpath stringbyappendingpathcomponent:@"company.db"]; char *error; nsfilemanager *filemanager = [nsfilemanager defaultmanager]; if(![filemanager fileexistsatpath:dbpathstring]) { const char *dbpath =[dbpathstring utf8string]; if(sqlite3_open(dbpath, &persondb)==sqlite_ok) { const char *sql_stmt = "create table if not exists staff (id integer primary key autoincrement, name text, age integer)"; sqlite3_exec(persondb, sql_stmt, null, null, &error); sqlite3_close(persondb); } } } this code inserting information table "staff":
- (ibaction)addpersonbutton:(id)sender { char *error; if(sqlite3_open([dbpathstring utf8string], &persondb) == sqlite_ok) { nsstring *insertstmt = [nsstring stringwithformat:@"insert staff (name, age) values ('%s', '%d')", [self.namefield.text utf8string], [self.agefield.text intvalue]]; const char *insert_stmt = [insertstmt utf8string]; if(sqlite3_exec(persondb, insert_stmt, null, null, &error) == sqlite_ok) { nslog(@"person added"); person *person = [[person alloc] init]; [person setname:self.namefield.text]; [person setage:[self.agefield.text intvalue]]; [arrayofperson addobject:person]; } sqlite3_close(persondb); } } the code works because able display information of "staff" table in tableview. how view information in .db file?
p/s: changed "something.xls" excel not display human readable information. downloaded fileviewpro did not know how use. helps me please!
thank much!
you can use app designed view contents of sqlite file. example: http://sqlitebrowser.org
if running on simulator can use ~/library/developer/coresimulator/devices/1a8df360-b0a6-4815-95f3-68a6ab0bcc78/data/container/data/application/ simulator replace long udid device.
Comments
Post a Comment