objective c - Sqlite insert statement doesn't add records in iOS app -


i trying execute simple hard-coded insert statement sqlite database. code works , success message own nslog, however, no records added database. can help? thx! viv

-(void)addfavorites{     const char *sqlinsert = "insert rivers (stat_id, stat_name, state) values ('03186500','williams river','wa')";     sqlite3_stmt *statement;      sqlite3_prepare_v2(_database, sqlinsert, -1, &statement, null);     if(sqlite3_step(statement) == sqlite_done){         nslog(@"record added!");     } else {         nslog(@"record not added!");     }     sqlite3_finalize(statement); } 

do have code in app delegate copy database out of bundle nsdocuments directory? sure copy database there, point there when you're running sqlite3_open, not bundle. nsdocument directory saved when device synced itunes or icloud, it's place want database maintaining data.

nsstring *databasename = @"mydatabase.sqlite";   nsarray *systempaths = nssearchpathfordirectoriesindomains(nsdocumentdirectory, nsuserdomainmask, yes); nsstring *librarydirectory = [systempaths objectatindex:0]; nsstring *databasefullpath = [librarydirectory stringbyappendingformat:@"%@%@",@"/",databasename];  //copy database file system if hasn't been done yet. nsfilemanager *filemanager = [nsfilemanager defaultmanager]; bool exists = [filemanager fileexistsatpath:databasefullpath]; if(exists == no) {     nsstring *dbpathinbundle = [[[nsbundle mainbundle] resourcepath] stringbyappendingpathcomponent:databasename];     [filemanager copyitematpath:dbpathinbundle topath:databasefullpath error:nil]; } 

Comments

Popular posts from this blog

ios - iPhone/iPad different view orientations in different views , and apple approval process -

java Extracting Zip file -

C# WinForm - loading screen -