I am trying to fetch data from SQLite database(NSArray of strings) and populate the contents in table view cells. I tried to execute the query in command prompt and it works fine. But in code, it returns an empty array.
NSString *temp = [[NSString alloc]initWithFormat:@"select img.image from images img,illness i,illness_images ii where img.img_id=ii.img_id and i.i_id=ii.i_id and i.i_id = '%d'",illid];
const char *sqlStatement = [temp UTF8String];
sqlite3_stmt *compiledStatement;
if(sqlite3_prepare_v2(database, sqlStatement, -1, &compiledStatement, NULL) == SQLITE_OK)
{
// Loop through the results and add them to the array
while(sqlite3_step(compiledStatement) == SQLITE_ROW)
{
// Read the data from the result row
NSString *imgname = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 0)];
[imglist addObject:imgname];
sqlite3_finalize(compiledStatement);
}
}
else{
NSAssert1(0,@"Error retrieving image names '%s'",sqlite3_errmsg(database));
}
I tried to debug and when it reaches while(sqlite3_step(compiledStatement) == SQLITE_ROW) , it does not enter the loop.
Not sure whats the mistake I am doing.
Thanks!
Try
NSLogafter assigning the string query totempvariable.and check if the variable
illidis giving you the correct value and run that query on the database directly.and you better
releasetheallocated object or use class methods setting value, for memory management.HTH.