Question

I need to check my database column is not equal to null. I used one condition for 0 value like isEqual:@"0". How to use instead of isEqual use !=

SqlStatement:

    sqlStatement =[[NSString stringWithFormat:@"SELECT a.*,b.AM_Answer,b.AM_Comments 
FROM question_master a 
left join Assessment_master b 
on (b.AM_QM_ID = a.QM_ID AND b.AM_HNM_ID = %d AND b.AM_HM_ID = %d and b.AM_ASM_Local_Id = %@) where a.QM_Parent_Id = 0 and a.QM_Status ='A' and a.QM_QCM_ID =%@ and a.QM_QRM_Id = %@ union SELECT c.*,d.AM_Answer,d.AM_Comments FROM question_master c left join Assessment_master d on (d.AM_QM_ID = c.QM_ID AND d.AM_HNM_ID = %d AND d.AM_HM_ID = %d and d.AM_ASM_Local_Id = %@) where c.QM_Parent_Id in (SELECT QM_ID FROM question_master where QM_Parent_Id = 0 and QM_Status ='A' and QM_QCM_ID =%@ and QM_QRM_Id = %@) and c.QM_Status ='A' and c.QM_QCM_ID =%@ and c.QM_QRM_Id = %@"

     return [self getOuestionDetails_Answer:sqlStatement];

Insert:

-(NSMutableArray*)getOuestionDetails_Answer:(const char*)sqlStatement{
    sqlite3_stmt *compiledStatement;

    NSMutableArray* parentArray = [NSMutableArray new];

    int result = sqlite3_prepare_v2(database, sqlStatement, -1, &compiledStatement, NULL) ;
    if( result == SQLITE_OK)
    {
        NSMutableDictionary* parentDict = [NSMutableDictionary new];

        NSMutableArray* childArray = [NSMutableArray new];
        while(sqlite3_step(compiledStatement) == SQLITE_ROW) {
         char *question = (char *)sqlite3_column_text(compiledStatement, 4);
            char *answer = (char *)sqlite3_column_text(compiledStatement, 13);
            char *comments = (char *)sqlite3_column_text(compiledStatement, 14);

                    if (answer && comments && question && strcmp(question, "0") == 0) {

    [parentDict setObject:[NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 0)] forKey:@"QM_ID"];
                    [parentDict setObject:[NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 1)] forKey:@"QM_QRM_ID"];
                    [parentDict setObject:[NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 2)] forKey:@"QM_LCM_ID"];
                    [parentDict setObject:[NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 3)] forKey:@"QM_QCM_Id"];
                    [parentDict setObject:[NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 4)] forKey:@"QM_Question"];
                    [parentDict setObject:[NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 5)] forKey:@"QM_Question_Parent"];
                    [parentDict setObject:[NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 6)] forKey:@"QM_Type"];
                    [parentDict setObject:[NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 7)] forKey:@"QM_Parent_Id"];

                    [parentDict setObject:[NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 8)] forKey:@"QM_Status"];
                    [parentDict setObject:[NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 9)] forKey:@"QM_Created_Date"];
                    [parentDict setObject:[NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 10)] forKey:@"QM_Created_By"];
                    [parentDict setObject:[NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 11)] forKey:@"QM_Modified_Date"];
                    [parentDict setObject:[NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 12)] forKey:@"QM_Modified_By"];
                    [parentDict setObject:[NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 13)== NULL?"":(char *)sqlite3_column_text(compiledStatement, 13)] forKey:@"AM_Answer"];
                    [parentDict setObject:[NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 14)== NULL?"":(char *)sqlite3_column_text(compiledStatement, 14)] forKey:@"AM_Comments"];
        }

No correct solution

OTHER TIPS

Break up your code (and get rid of the extra square brackets):

char *dbStr = (char *)sqlite3_column_text(compiledStatement, 4);
if (dbStr) {
    NSString *str = [NSString stringWithUTF8String:dbStr];
    // do stuff with str
} else {
    // database value was NULL
}

Update:

char *question = (char *)sqlite3_column_text(compiledStatement, 4);
char *answer = (char *)sqlite3_column_text(compiledStatement, 13);
char *comments = (char *)sqlite3_column_text(compiledStatement, 14);
if (answer && comments && question && strcmp(question, "0") == 0) {
    // do your stuff here
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top