I had a problem to retrieve the Distinct values from my database and the code I written for that is:
In viewWillAppear of my controller I written as.....
-(void)viewWillAppear:(BOOL)animated
{
CorkItAppDelegate* appDelegate = (CorkItAppDelegate*)[[UIApplication sharedApplication] delegate];
winesList = [appDelegate getWineDetails];
if(isWine == YES)
{
EventsListArray = [appDelegate getDistinctWineNames];
printf("\n count of EventsListArray..........%d",[EventsListArray count]);
}
}
And in the CorkItAppDelegate the function is as:
-(NSMutableArray*)getDistinctWineNames
{
[eventsListArray2 removeAllObjects];
sqlite3_stmt* statement;
const char *sql = "SELECT DISTINCT(wineType) from event ";
if (sqlite3_prepare_v2(database, sql, -1, &statement, NULL) != SQLITE_OK) {
NSAssert1(0, @"Error: failed to prepare statement with message '%s'.", sqlite3_errmsg(database));
}
while (sqlite3_step(statement) == SQLITE_ROW)
{
primaryKey = sqlite3_column_int(statement, 0);
EventsList *tempEvent2 = [[EventsList alloc] initWithPrimaryKey:primaryKey database:database];
[eventsListArray2 addObject:tempEvent2];
[tempEvent2 release];
}
sqlite3_finalize(statement);
printf("\n Inside AppDelegate .....wineRegionslist count:%d",[eventsListArray2 count]);
return eventsListArray2;
}
but here in this function if condition was failed and it goes into else condition and takes the nil value and not displaying anything in the tableview of my controller.
please help me guys.....