Tuesday, 15 July 2014

iphone - Unable to remove data from database ios -



iphone - Unable to remove data from database ios -

i have database, when tried remove info database nil happens, should create sure works? because when pressed delete dta still in database

this code:

/file path database -(nsstring*)filepath { nsarray*paths = nssearchpathfordirectoriesindomains(nsdocumentdirectory, nsuserdomainmask, yes); homecoming [[paths objectatindex:0]stringbyappendingpathcomponent:@"bp.sql"]; } //open database -(void)opendb { if(sqlite3_open([[self filepath]utf8string], &db) !=sqlite_ok) { sqlite3_close(db); nsassert(0, @"databese failed open"); } else { nslog(@"database opemed"); } } - (ibaction)del:(id)sender { nsstring*sql = [nsstring stringwithformat:@"delete key, thedate, customer, code1, code2 summary key=\"%@\"",customername]; const char* query_stmt = [sql utf8string]; sqlite3_stmt*statement; sqlite3_prepare_v2(db, query_stmt, -1, & statement, null); if (sqlite3_step(statement) == sqlite_done) { nsassert(0, @"database object delete failed"); } else { nslog(@"no error"); } sqlite3_finalize(statement); sqlite3_close(db)

you can't delete specific column values using delete query. it's removing entire row.

the problem next query:

nsstring*sql = [nsstring stringwithformat:@"delete key, thedate, customer, code1, code2 summary key=\"%@\"",customername];

change to:

nsstring*sql = [nsstring stringwithformat:@"delete summary key=\"%@\"",customername];

if need remove particular column value of row utilize update query.

please check sqlite documentation details

iphone ios database sqlite ios6

No comments:

Post a Comment