ios - How to write NSArrays and NSDictionaries for getting and to Join two table's data into another table SQLite, iPhone? -
when joining 2 tables data tableview
using sqlite getting null value how write nsarray
, nsdictionary
.and how set objects , keys. below database class
+(nsmutablearray *)getdata { sqlite3 *dbobj; nsstring *dbpath =[dbclass connectdb]; nsmutablearray *readarray=[[nsmutablearray alloc]init]; if(sqlite3_open([dbpath utf8string], &dbobj)==sqlite_ok) { sqlite3_stmt *statement=nil; //**** nsstring *string=@"select name emptable"; nsstring *string=@"select emp_id, age, dept company inner join department on company.id = department.emp_id"; ; const char *query=[string utf8string]; if(sqlite3_prepare_v2(dbobj, query, -1, &statement, null)==sqlite_ok) { while (sqlite3_step(statement)==sqlite_row) { nsmutabledictionary *readdic=[[nsmutabledictionary alloc] init]; [readdic setobject:[nsstring stringwithutf8string:(char *)sqlite3_column_text(statement, 2)] forkey:@"dept"]; //[readdic setobject:[nsstring stringwithutf8string:(char *)sqlite3_column_text(statement, 1)] forkey:@"age"]; [readarray addobject:readdic]; // nslog(@"%@",readdic); } } sqlite3_finalize(statement); } nslog(@"%@",readarray); sqlite3_close(dbobj); return readarray; }
the below 1 jointviewcontroller.m
- (void)viewdidload { [super viewdidload]; array=[[nsmutablearray alloc]init]; data=[[nsmutablearray alloc]init]; array=[dbclass getdata]; for( nsdictionary *obj in array) { nslog(@"%@",obj); [data addobject:[obj objectforkey:@"dept"]]; //[data addobject:[obj objectforkey:@"age"]]; } nslog(@"\n%d",[data count]); [table reloaddata]; }
you need specify tablename before columnname. i.e. table particular column belongs.
see example of inner join
, try relate code.
select customers.customername, orders.orderid customers inner join orders on customers.customerid=orders.customerid order customers.customername;
Comments
Post a Comment