tags:

views:

6

answers:

0

hi i am cuurently working in simple application inwhich i need to reterive data from salite database . iam successfully reterive all data when i write sql query "select * from User" but i want tget value base on input parameter then sqlite3_step(statement) give me 101 and sqliterow =100 then data can not be reteive form database. mydatabse strutcure is user(userName varchar,address varchar) like .

-(void)contactAllData:(NSString *)userName { @try {
sqlite3 *db =[dbclass dbcon]; sqlite3_stmt *statement =nil;

    if (db != nil)
    {       
        const char *sql = "SELECT * FROM user  WHERE userName=?";
        if(sqlite3_prepare_v2(db, sql, -1, &statement, NULL) != SQLITE_OK)
        {
            NSAssert1(0, @"Error while creating detail view statement. '%s'", sqlite3_errmsg(db));
        }       
        else
        {
            sqlite3_bind_text(statement, 1, [userName UTF8String], -1, SQLITE_TRANSIENT);
                while(sqlite3_step(statement) == SQLITE_ROW)
                {   
                    [array1 addObject:[NSString stringWithFormat:@"%s",(char*)sqlite3_column_text(statement,1)]];
                    [array2 addObject:[NSString stringWithFormat:@"%s",(char*)sqlite3_column_text(statement,2)]];


                }
            }
            sqlite3_finalize(statement);
        }
    }
@catch (NSException * e)
{
    UIAlertView *alert = [[UIAlertView alloc] 
                          initWithTitle:nil 
                          message:[e reason] 
                          delegate:nil
                          cancelButtonTitle:@"OK" 
                          otherButtonTitles:nil]; 
    [alert show]; 
    [alert release];

}

} plz give me help or code snnipet thanks in advance