テーブルからデータを選択したいのですが、質問テーブルと回答テーブルで同じ質問IDを持つデータです。これで、回答からすべてのデータが選択されます。コードは以下に示されています
+ (void) getAnswers:(NSString*)dbPath{
CereniaAppDelegate *appDelegate = (CereniaAppDelegate *)[[UIApplication sharedApplication] delegate];
if (sqlite3_open([dbPath UTF8String], &database) == SQLITE_OK) {
const char *sql = "select *from answers";
sqlite3_stmt *selectstmt;
if(sqlite3_prepare_v2(database, sql, -1, &selectstmt, NULL) == SQLITE_OK) {
while(sqlite3_step(selectstmt) == SQLITE_ROW) {
NSInteger primaryKey = sqlite3_column_int(selectstmt, 0);
Answers *coffeeObj = [[Answers alloc] initWithPrimaryKey:primaryKey];
coffeeObj.answer_text = [NSString stringWithUTF8String:(char *)sqlite3_column_text(selectstmt, 3)];
NSString*testString=coffeeObj.answer_text;
NSLog(testString);
[appDelegate.answerArray addObject:coffeeObj];
int mycount=[appDelegate.answerArray count];
NSLog(@"This is int of latest %d",mycount);
[coffeeObj release];
}
}
}
else
sqlite3_close(database); //Even though the open call failed, close the database connection to release all the memory.
}