Ranjeet Sajwan
Ranjeet Sajwan

Reputation: 1921

How to check if database is returning NULL

I am using sqlite database with my app
following is my code which is getting data

        while(sqlite3_step(compiledStatement) == SQLITE_ROW)
        {


            NSString *str1 = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 0)];

            [dataArray addObject:str1];



        }   

this program crashed if there is null in database.

Actually i have multiple columns and i am saving data only to one column of a row so other remain null, this creating problem...

can anyone tell me how to check if current value is null
i have tried to check if str1 is null here?
but prog crashes ....

thank you please help

Upvotes: 0

Views: 1525

Answers (1)

KingofBliss
KingofBliss

Reputation: 15115

Code as follows,

if(sqlite3_column_text(statement, 0) != nil)
{
//Data exists
}

Upvotes: 12

Related Questions