私は sqlite テーブルからデータを取得しています。変数を渡したいので、sub_Catgeory がその変数と等しい場合、レコードをフェッチする必要があります。
const char *sql = "select * from category where sub_Category=appDelegate.sub_Category";
appDelegate.Sub_Category 変数を使用しない場合と同じように、正常に動作します
const char *sql = "select * from category where sub_Category='Glucagon'";
私の完全なコード
+ (void) getInitialData:(NSString *)dbPath {
MultipleDetailViewsWithNavigatorAppDelegate *appDelegate = (MultipleDetailViewsWithNavigatorAppDelegate *)[[UIApplication sharedApplication] delegate];
if (sqlite3_open([dbPath UTF8String], &database) == SQLITE_OK) {
//const char *sql = "select * from category where sub_Category='Glucagon'";
NSLog(@"Sub Category is %@",appDelegate.subCategory);
const char *sql = "select * from category where sub_Category='appDelegate. subcategory'";
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);
Coffee *coffeeObj = [[Coffee alloc] initWithPrimaryKey:primaryKey];
coffeeObj.category=sqlite3_column_int(selectstmt,1);
coffeeObj.sub_Category = [NSString stringWithUTF8String:(char *)sqlite3_column_text(selectstmt, 2)];
coffeeObj.content_Type = [NSString stringWithUTF8String:(char *)sqlite3_column_text(selectstmt, 3)];
coffeeObj.content_Title = [NSString stringWithUTF8String:(char *)sqlite3_column_text(selectstmt,4)];
coffeeObj.publisher = [NSString stringWithUTF8String:(char *)sqlite3_column_text(selectstmt, 5)];
coffeeObj.content_Description = [NSString stringWithUTF8String:(char *)sqlite3_column_text(selectstmt, 6)];
coffeeObj.content_Id = [NSString stringWithUTF8String:(char *)sqlite3_column_text(selectstmt, 7)];
coffeeObj.content_Source = [NSString stringWithUTF8String:(char *)sqlite3_column_text(selectstmt, 8)];
int count=[appDelegate.arrayOneC count];
NSLog(@"count is beofore getting values %d",count);
[appDelegate.arrayOneC addObject:coffeeObj];
int countone=[appDelegate.arrayOneC count];
NSLog(@"count is after getting values %d",countone);
[coffeeObj release];
}
}
}
else
sqlite3_close(database); //Even though the open call failed, close the database connection to release all the memory.
}