How do I retrieve data from multiple columns in the database?


I am new to this database programming.i retrieved single column data from the database.but i am unable to retrieve multiple columns data from the database.

here is my code

-(void) readItemsFromDatabaseforTable:(NSString *)tableName {

    arrayItems = [[NSMutableArray alloc] init];

    if(sqlite3_open([databasePath UTF8String], &database) == SQLITE_OK)

           NSString *sql_str = [NSString stringWithFormat:@"select * from %@", tableName];

        const char *sqlStatement = (char *)[sql_str UTF8String];

            NSLog(@"query %s",sqlStatement);

        sqlite3_stmt *compiledStatement;

if(sqlite3_prepare_v2(database, sqlStatement, -1, &compiledStatement, NULL) == SQLITE_OK)

            while(sqlite3_step(compiledStatement) == SQLITE_ROW) {

                NSString *idsstr = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 3)];               

                [arrayItems addObject:idsstr];
                NSLog(@"*************** %@",arrayItems);
            while(sqlite3_step(compiledStatement) == SQLITE_ROW)

          NSString *caloriesstr = [NSString stringWithUTF8String:  

(char*)sqlite3_column_text(compiledStatement, 4)];               

                [caloriesarry addObject:caloriesstr];


                 NSLog(@"*************** %@",caloriesarry);



my main aim is to retrieve columns data from the database and store into multiple arrays.

please guys anyone help me,

Use this sample Query and make your query according to your requirements..

NSString *str = [NSString stringWithFormat:@"Select * from Yourtablename where image1 = '%@' AND person1 = '%@' AND category = '%@' AND PurchaseAmt = '%@'",Str,person1,category,Amountdata];

Use this tutorial