mercredi 30 septembre 2015

Error while calling sql statement

i am getting an weirded error, I have my code to get data from local db.my query is as follows

SELECT * FROM Survey_Details Where feedBack_status="YES"

When i fire above query the function gives proper output.But when i pass NO it gives me an error.Following is my function

-(NSMutableArray*)selectFromDBAndAddtoArrayForFeedbackStatus:(NSString *)feedBackStatus
{
   NSMutableArray *TableArray = [[NSMutableArray alloc]init];
   sqlite3_stmt    *statement;


const char *dbpath = [databasePath UTF8String];
if (sqlite3_open(dbpath, &passionDB) == SQLITE_OK)
{

    NSString *insertSQL = [NSString stringWithFormat: @"SELECT * FROM Survey_Details Where feedBack_status != \"%@\"",feedBackStatus];
    NSLog(@"insert stmnt %@", insertSQL);
    const char *insert_stmt = [insertSQL UTF8String];


if(sqlite3_prepare_v2(passionDB, insert_stmt, -1, &statement, nil)== SQLITE_OK)
    {
        NSLog(@"SQLITE_OK");
        if (SQLITE_ROW != sqlite3_step(passionDB))
        {

        }
        else{

        }
        while(sqlite3_step(statement) == SQLITE_ROW)
        {
            NSMutableArray *editTableArray = [[NSMutableArray alloc]init];

            NSString *title = [NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 2)];

            NSString *name = [NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 3)];

            NSString *surname = [NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 4)];

            NSString *time = [NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 14)];

            // NSString *user_ID = [NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 1)];

            NSNumber *user_ID = [NSNumber numberWithInt:(int)sqlite3_column_int(statement, 1)];


            [editTableArray addObject:title];
            [editTableArray addObject:name];
            [editTableArray addObject:surname];
            [editTableArray addObject:time];
            [editTableArray addObject:user_ID];

            NSString *imagePath;

            if ([feedBackStatus isEqualToString:@"YES"])
            {

                if(sqlite3_column_text(statement, 13) != nil)
                {
                    imagePath = [NSString stringWithUTF8String:(char    *)sqlite3_column_text(statement, 13)];
                }
                else
                {
                    imagePath = @"none";
                }
                [editTableArray addObject:imagePath];
            }


            [TableArray addObject:editTableArray];
            editTableArray=nil;

        }

        NSLog(@"TableArray1 is %@",TableArray);
    }

    if (sqlite3_step(statement) == SQLITE_DONE)

    {
        NSLog(@"sqlite is done");
        NSLog(@"Error %s while sqlite3_step ", sqlite3_errmsg(passionDB));
    } else {
        NSLog(@"sqlite is not  done");
        NSLog(@"Error %s while sqlite3_step ", sqlite3_errmsg(passionDB));
    }
    sqlite3_finalize(statement);
    sqlite3_close(passionDB);
}
NSLog(@"TableArray2 is %@",TableArray);
return TableArray;
}

Aucun commentaire:

Enregistrer un commentaire