0
votes

i wnant to fetch the data fromt the database but getting error when i try to get the empty column... i used the following code to do it.. NSString *aDescription = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 2)]; so if my second column is empty than i get exception

1
have got the solution to do this... NSString aDescription = [NSString stringWithUTF8String:(char *)sqlite3_column_text_check(compiledStatement, 2)]; const unsigned char *sqlite3_column_text_check(sqlite3_stmt stmt, int iCol){ const unsigned char *val = sqlite3_column_text(stmt,iCol); if(val==nil) return (unsigned char *)""; else return val; }Jaimin

1 Answers

0
votes

Please put the condition to check the value:

NSString *aDescription = nil;
if((char *)sqlite3_column_text(compiledStatement, 2) != NULL)
{
      aDescription = [NSString stringWithUTF8String:(char*)sqlite3_column_text(compiledStatement, 2)];
}

Now the it will not generate the exception.