iphone - how to inserting data after completion of inserting and updating the data -
iphone - how to inserting data after completion of inserting and updating the data -
i developing 1 application. in iam facing problem @ inserting info database. first insert , update performed well. after updating if want perform insert operation app crashed. code inserting , updating below
+(bool)update:(calendarinfo*)clinfo { nsstring *query = [nsstring stringwithformat:@"update abc set = '%@' b =%d , c=%d",clinfo.a,clinfo.b,clinfo.c]; sqlite3_stmt *ststatement; if(sqlite3_prepare_v2(database, [query utf8string], -1, &ststatement, nil)==sqlite_ok) { if(sqlite_done == sqlite3_step(ststatement)) nsassert1(0, @"error while inserting data. '%s'", sqlite3_errmsg(database)); else nslog(@"updation successful"); } homecoming 0; } +(bool)insert:(calendarinfo*)clinfo{ sqlite3_stmt *addstmt = nil; sqlite3 *contactdb; nsarray *docpatharr = nssearchpathfordirectoriesindomains(nsdocumentdirectory, nsuserdomainmask, yes); nsstring *destpath = [nsstring stringwithformat:@"%@/example.sqlite",[docpatharr objectatindex:0]]; if (sqlite3_open([destpath utf8string], &contactdb)==sqlite_ok) { nsstring *query2 = [nsstring stringwithformat:@"insert abc(c,b,a) values(%d,%d,'%@')",clinfo.c,clinfo.b, clinfo.a]; if(sqlite3_prepare_v2(database, [query2 utf8string], -1, &addstmt, null) != sqlite_ok) nsassert1(0, @"error while creating add together statement. '%s'", sqlite3_errmsg(database)); } if(sqlite_done != sqlite3_step(addstmt)) nsassert1(0, @"error while inserting data. '%s'", sqlite3_errmsg(database)); else nslog(@"insertion successful"); sqlite3_reset(addstmt); homecoming 0; }
so please tell me how solve problem.
from limited code you've posted, think reply has have two different sqlite3
instances here. intentional?
you phone call sqlite3_open([destpath utf8string], &contactdb);
and effort error result off sqlite
instance:
sqlite3_errmsg(database)
either utilize database
or contactdb
, should set.
iphone sqlite
Comments
Post a Comment