objective c - How to recieve data of a group by sqlite query in iOS ? -


i want data of group query , load them textfields. here table integer id name text duration real time real there few names in in name column tried calling method each name , caused insert failure.

i want receive query , load result on specific label: dont know how can response

select  name,sum (time)  cost group name; 

there current code

 nsstring *docsdir; nsarray *dirpaths;   double totaltime = 1.0;  // documents directory dirpaths = nssearchpathfordirectoriesindomains(nsdocumentdirectory, nsuserdomainmask, yes); docsdir = dirpaths[0];  // build path database file databasepath = [[nsstring alloc]                 initwithstring: [docsdir stringbyappendingpathcomponent:                                  @"database.db"]];   nsstring *querystring=@"select sum(duration) total records"; sqlite3_stmt    *statement;  if(sqlite3_open([databasepath utf8string], &mydatabase) == sqlite_ok) {      if(sqlite3_prepare_v2(mydatabase, [querystring utf8string], -1, &statement, nil) == sqlite_ok){         while (sqlite3_step(statement) == sqlite_row) {              totaltime =  sqlite3_column_double(statement, 0);             nslog(@"the sum  %f ", totaltime);         }     } } integer_t intotal=totaltime; nsstring* total=[nsstring stringwithformat:@"%d min",intotal]; totaltimefield.text=total; 

this covered pretty nicely in documentation, but, in short, once update sql have 2 columns:

const unsigned char* name = sqlite3_column_text(statement, 0); double totaltime =  sqlite3_column_double(statement, 1); nslog(@"the sum %s  %f ", name, totaltime); 

the second parameter int sqlite3_column_x functions column number.


Comments

Popular posts from this blog

curl - PHP fsockopen help required -

HTTP/1.0 407 Proxy Authentication Required PHP -

c# - Resource not found error -