Hi,
I am displaying the contacts on the table. Section I pass in the method is name of section i.e. A-Z.. and the index is the index of the row in that particular section. So to get the id based on the row I tapped in particular section,I wrote the following method. I am trying to get the id from the database whose values match with the query I pass. So if I check for the firstnames starting with letter 'A' there are around 4 values under section A. So I took a variable i and trying to increment until it finds the correct index such that it returns the id for that particular index. The condition validates but I always get the nil string and hence the values displayed on the table for each field are empty.
Please help me..Its very urgent and I am clueless on what to do..Thanks for the help!!!
Here is the method:
-(NSString *)getSugarId

NSString *)tableName bySection

NSString *)section andIndex

int)index
{
int i=0;
NSString *sid;
NSString *qsql = [[NSString stringWithFormat: @"SELECT sugar_id FROM CONTACTS WHERE first_name LIKE '%@",section] stringByAppendingString:@"%'"];
sqlite3_stmt *statement;
if (sqlite3_prepare_v2( db, [qsql UTF8String], -1, &statement, nil) == SQLITE_OK) {
while (sqlite3_step(statement) == SQLITE_ROW) {
char * utf8string = (char *)sqlite3_column_text(statement, 1);
if(i==index){
sid = utf8string ? [[NSString alloc ]initWithUTF8String:utf8string] : nil;
// sid = [[NSString alloc]initWithUTF8String

char *)sqlite3_column_text(statement, 1)];
break;
}
i++;
}
}
return sid;
}