objective c - Sqlite not inserting data once the application is stopped and execute again iPhone -


im developing simple application in creating sqlite database , insert data it. working fine , data insert table.

but when stop application(in xcode) , run again data not inserting database.

this code used:

+(dbmanager*)getsharedinstance{     if (!sharedinstance) {         sharedinstance = [[super allocwithzone:null]init];         [sharedinstance createdb];     }     return sharedinstance; }   -(bool)createdb{     nsstring *docsdir;     nsarray *dirpaths;     // documents directory     dirpaths = nssearchpathfordirectoriesindomains     (nsdocumentdirectory, nsuserdomainmask, yes);     docsdir = dirpaths[0];     // build path database file     databasepath = [[nsstring alloc] initwithstring:                     [docsdir stringbyappendingpathcomponent: @"schedulerdatabase.db"]];     bool issuccess = yes;     nsfilemanager *filemgr = [nsfilemanager defaultmanager];     if ([filemgr fileexistsatpath: databasepath ] == no)     {         const char *dbpath = [databasepath utf8string];         if (sqlite3_open(dbpath, &database) == sqlite_ok)         {             char *errmsg;             const char *sql_stmt ="create table if not exists scheduler (date integer primary key,event text)";             if (sqlite3_exec(database, sql_stmt, null, null, &errmsg)                 != sqlite_ok)             {                 issuccess = no;                 nslog(@"failed create table");             }             sqlite3_close(database);             return  issuccess;         }         else {             issuccess = no;             nslog(@"failed open/create database");         }     }     return issuccess; }  -(bool)savedata:(int)date withevent:(nsstring *)event {     const char *dbpath = [databasepath utf8string];     if (sqlite3_open(dbpath, &database) == sqlite_ok)     {         nsstring *insertsql = [nsstring stringwithformat:@"insert scheduler (date, event) values(\"%d\", \"%@\")",date,event];         const char *insert_stmt = [insertsql utf8string];         sqlite3_prepare_v2(database, insert_stmt,-1, &statement, null);         if (sqlite3_step(statement) == sqlite_done)         {             return yes;         }         else {             return no;         }         sqlite3_reset(statement);     }     return no; } 

when stopped project , tried save database entering in else condition of loop.

if (sqlite3_step(statement) == sqlite_done)             {                 return yes;             }             else {                 return no;             } 

can please me this. in advance.

in save data method, looks you're never finalizing statement or closing database

sqlite3_finalize(statement); sqlite3_close (_database); 

perhaps database still locked previous save attempt.


Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -