JOIN query not working in iphone device but working in iOS Simulator -
i have 2 tables resources,resourceviewhistory resources has these fields:resourceid,typeid,name,url,isfavorite,languagecode,categoryid. resourceviewhistory has these fields:viewid,resourceid,dateviewed,longitude,latitude
i want result set resourceid in resources table: name,url,isfavorite,resourceid , dateviewed,longitude,latitude same resourceid in resourceviewhistory table , categoryid=1,typeid=1
my query is:
select r.resourceid,url,name,isfavorite,max(v.dateviewed) lastvisited,longitude,latitude resources r left join resourceviewhistory v on (r.resourceid=v.resourceid) categoryid=1 , typeid=1 group r.resourceid
the above query working in simulator not working in iphone device.my objectivec code below.the arrurldetails array showing 0 objects
+(nsmutablearray*)geturldetails{ nsstring *strhome = nshomedirectory(); nsstring *strdestpath = [nsstring stringwithformat:@"%@/documents/test.sqlite",strhome]; nsmutablearray *arrurldetails=[[nsmutablearray alloc]init]; sqlite3 *db; int n = sqlite3_open([strdestpath utf8string], &db); if (n==sqlite_ok) { nsstring *strquery=@"select r.resourceid,url,name,isfavorite,max(v.dateviewed) lastvisited,longitude,latitude resources r left join resourceviewhistory v on (r.resourceid=v.resourceid) categoryid=1 , typeid=1 group r.resourceid"; sqlite3_stmt *stmt; const char *err_msg; int res=sqlite3_prepare_v2(db, [strquery utf8string], -1, &stmt, &err_msg); if (res == sqlite_ok) { while (sqlite3_step(stmt)==sqlite_row) { resources *resources=[[resources alloc]init]; resources.resourceid=sqlite3_column_int(stmt,0); resources.name=[nsstring stringwithutf8string:(char *) sqlite3_column_text(stmt, 2)]; resources.url=[nsstring stringwithutf8string:(char *) sqlite3_column_text(stmt, 1)]; resources.isfavorite=[nsstring stringwithutf8string:(char *) sqlite3_column_text(stmt, 3)]; resources.dateviewed=[nsstring stringwithutf8string:(char *) sqlite3_column_text(stmt, 4)]; resources.latitude=sqlite3_column_double(stmt, 6); [arrurldetails addobject:resources]; } } } return arrurldetails;
}
Comments
Post a Comment