Хорошо, так что я поправляюсь с запросами SQLite ... но, очевидно, еще не мастер.
Я пытаюсь перебрать возвращаемый массив, и все, что я получаю, это 0 для каждой записи.
Вот что вызывает запрос и возвращает результат (этот конкретный запрос в настоящее время должен возвращать 6 строк данных):
-(NSMutableArray *)getMyAthleteList
{
NSMutableArray *athleteList = [[NSMutableArray alloc] init];
NSString *getAthleteListSQL = [[NSString alloc] initWithFormat:@"SELECT * FROM athletes"];
sqlite3_stmt *selectStmt;
if (sqlite3_prepare_v2(database, [getAthleteListSQL UTF8String], -1, &selectStmt, nil)==SQLITE_OK)
{
while (sqlite3_step(selectStmt)==SQLITE_ROW)
{
//NSLog(@"Adding athletes to the array");
Athletes *athlete_array = [Athletes alloc];
athlete_array.athlete_image = [[NSString alloc] initWithFormat:@"%d",sqlite3_column_int(selectStmt, 0)];
athlete_array.athlete_id = [[NSString alloc] initWithFormat:@"%d",sqlite3_column_int(selectStmt, 1)];
athlete_array.athlete_name = [[NSString alloc] initWithFormat:@"%d",sqlite3_column_int(selectStmt, 2)];
athlete_array.school_name = [[NSString alloc] initWithFormat:@"%d",sqlite3_column_int(selectStmt, 3)];
athlete_array.sport_name = [[NSString alloc] initWithFormat:@"%d",sqlite3_column_int(selectStmt, 4)];
athlete_array.athlete_flag = [[NSString alloc] initWithFormat:@"%d",sqlite3_column_int(selectStmt, 5)];
[athleteList addObject:athlete_array];
}
}
else
{
NSLog(@"Did not make a good query");
}
return athleteList;
}
Теперь вот что я делаю при вызове и циклическом просмотре:
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
NSArray *myAthleteList = [[NSArray alloc] initWithArray:[appDelegate getMyAthleteList]];
for (Athletes *athlete in myAthleteList) {
NSLog(@"Athlete Name: %@", athlete.athlete_name);
NSLog(@"Athlete ID: %@", athlete.athlete_id);
}
И вывод:
Имя спортсмена: 0
ID спортсмена: 0
Все мои строки (имя спортсмена, идентификатор спортсмена и т. Д.) Определены правильно (в моих файлах Athletes.m и .h).
Я уверен, что упускаю что-то простое, но любая помощь будет высоко оценена.
Спасибо!