views:

153

answers:

1

Hi I am new to iphone, i tried to select the values from database i gave the conditions through sqlite3_bind_int() everything worksfine (ie. Database is opened) but when i compile the line sqlite3_step(statement) it is not fetching the values but according to my query it should fetch values. I dont know weather the values are binded.

After the values are binded with sqlite3_bind_int() how to check the complete query through NSLog().

Below is the code i have used, plz help me

- (void) getDataToDisplay:(NSString *)dbPath
{

    if (sqlite3_open([dbPath UTF8String], &MYDB) == SQLITE_OK)
    {
        const char *sql;

            sql="select name,address,phonenumber from doctorlist where sno between %d and %d";

            if(sqlite3_prepare_v2(MYDB, sql, -1, &mystmt, NULL) != SQLITE_OK)
            {
               NSLOG(@"Insert Values");
            }

              sqlite3_bind_int(mystmt,1,10);

              sqlite3_bind_int(mystmt, 2,15);

               while(sqlite3_step(mystmt) == SQLITE_ROW)
               {
                   [DoctorName addObject:[NSString stringWithString:[NSString stringWithUTF8String:(char *)sqlite3_column_text(mystmt, 0)]]];
                   [DoctorAddress addObject:[NSString stringWithString:[NSString stringWithUTF8String:(char *)sqlite3_column_text(mystmt, 1)]]];
                   [PhoneNumber addObject:[NSString stringWithString:[NSString stringWithUTF8String:(char *)sqlite3_column_text(mystmt, 2)]]];
               }      
    }
    sqlite3_reset(mystmt);
    if(MYDB)sqlite3_close(MYDB);

}

Thanks in advance

+1  A: 

You sql should read:

sql="select name,address,phonenumber from doctorlist where sno between ?1 and ?2"; 
Claus Broch
Thank You dude.
Prakash.S