これで、SQLiteクエリでうまくいくようになっていますが、明らかにまだマスターではありません。iOS 5のすべてのエントリに対して0を返すSQLite3クエリ
これが返す配列をループしようとしていますが、すべてのエントリに対して0が得られます。今ここに呼び出し、それをループするときに私がやっているものです
-(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;
}
:
ここ問い合わせ電話をかけると、結果を返しているものですが(この特定のクエリは、現在、データの6行を返す必要があります):
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
私の文字列(athlete_name、athlete_idなど)はすべて正しく定義されています(Athletes.mおよび.hファイル内)。
私は何かが簡単ではないと確信していますが、どんな助けも高く評価されます。
ありがとうございます!
マソチストはObjective-Cで直接SQLite C APIを使用します。 [FMDBの使用](http://github.com/ccgus/fmdb)(SQLiteラッパー)または[CoreData](http://developer.apple.com/library/mac/#documentation/cocoa/conceptual/CoreData/ cdProgrammingGuide.html)(オブジェクトグラフマネージャ)を使用します。 –
うわー... FMDBはずっと簡単です。ありがとう! – TheTC