ABCid、ABCname、ABCImagePath、ABCSequenceのフィールドを持つABCというテーブルが1つあるとします。現在、このテーブルには同じ内に40を超える行が含まれています。
これで、1、4、5、7、8などの数値の配列ができました。これらの数値をABCidと比較し、これらのIDに従ってテーブルABCからすべてのデータをフェッチします。
+ (void) getSelectedData : (int)ABCId
{
NSString *dbPath = [self getDBPath];
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
if (sqlite3_open([dbPath UTF8String], &database) == SQLITE_OK)
{
NSString *query =[NSString stringWithFormat:@"select * from [ABC] where ABCId=%d",ABCId];
const char *sql = [query cStringUsingEncoding:NSUTF8StringEncoding];
sqlite3_stmt *selectstmt;
if(sqlite3_prepare_v2(database, sql, -1, &selectstmt, NULL) == SQLITE_OK)
{
[self getInitialDataToDisplay:dbPath];
ABC *DataObj = [[ABC alloc] initWithPrimaryKey:ABCId];
DataObj.ABCName = [NSString stringWithUTF8String:(char *)sqlite3_column_text(selectstmt, 1)];
ABCImagePath = [NSString stringWithUTF8String:(char *)sqlite3_column_text(selectstmt, 2)];
DataObj.ABCSequence = sqlite3_column_int(selectstmt,8);
[appDelegate.arrGetData addObject:DataObj]; }
else
{
NSAssert1(0,@"Error: failed to prepare statement with message '%s'.", sqlite3_errmsg(database));
}
NSLog(@"%d",[appDelegate.DataArrayTrans count]);
}
else
sqlite3_close(database); //Even though the open call failed, close the database connection to release all the memory.
}
しかし、アプリはif条件でクラッシュします。また、pageControllerから以下の行を使用して、ABCオブジェクトファイルから上記の関数を呼び出すことにも注意してください。
for(int i=0;i<[arrRId count];i++)
{
[ABC getSelectedData:[[arrRId objectAtIndex:i]integerValue]];
[arr576576 addObject:[appDelegate.arrGetData valueForKey:@"ABCId"]];
}
どこを間違えているのか教えてください。ありがとうございました。