hi everyone I have some problems using sqlite in iOS. I have a selection of data from a database, and then I want to save this data in a variable. But when I use the while(sqlite3_step(statement) == SQLITE_ROW) , the code never executes.
here is my code:
-(void)retrieveProjectNameFromDb:(NSString *)segmenId{ NSString *query; NSString *nameProjectStr; NSString *dbPath = [[NSBundle mainBundle] pathForResource:@"database" ofType:@"sqlite"]; if (sqlite3_open([dbPath UTF8String], &db) != SQLITE_OK) { sqlite3_close(db); NSAssert(0, @"Database failed to open."); }else { query = [NSString stringWithFormat:@"SELECT remote_projectname, remote_base_uri FROM REMOTE_SETTING WHERE remote_settingid = '%@' ORDER BY remote_projectname", segmenId]; NSLog(@"query : %@", query); } sqlite3_stmt *statement; if(sqlite3_prepare_v2(db, [query UTF8String], -1, &statement, nil)==SQLITE_OK){ NSLog(@"sqlite row : %d", SQLITE_ROW); NSLog(@"sqlite 3 : %d", sqlite3_step(statement)); while (sqlite3_step(statement) == SQLITE_ROW) { char *nameProject = (char *)sqlite3_column_text(statement, 0); if (nameProject == nil) { NSLog(@"UNNAMED"); }else { NSLog(@"else"); nameProjectStr = [NSString stringWithUTF8String:nameProject]; } projectName.text = nameProjectStr; nameProject = nil; } NSLog(@"project name : %@", projectName.text); sqlite3_close(db); }
}
when i nslog the value, sqlite3_step (statement) always shows 101, and sqlite_row always shows 100. Why can this happen ?? can someone help me please?
Thank you
Hello
-risma -
source share