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 when I am trying to get the sid it throws objc_exception_throw. When I tried to add the debug point, I found that the exception is in this line and on debugger it says NSInvalidArgumentException: NULLcString..
Please help me..Its very urgent and I am clueless on what to do..Thanks for the help!!!
The error is on line where I get sid
Here is the method:
-(NSString *)getSugarIdNSString *)tableName bySectionNSString *)section andIndexint)inde
{
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 stringWithUTF8String:utf8string] : nil;
// sid = [[NSString alloc]initWithUTF8String:(char *)sqlite3_column_text(statement, 1)];
break;
}
i++;
}
}
return sid;
}