如何使用目标 c 查询 sqlite 数据库



我正在尝试按类型向用户显示食物。 不同类型的食物是表中的不同元素(水果、蔬菜、肉类等)。 我使用sqlite将所有食物放在一个数据库中。 如何使用目标 c 查询此数据库,以便我只能显示用户在下一个视图的表中选择的正确食物类型?

我们在两个应用程序中使用 FMDB。它工作正常。

-(NSArray *)GetAllFoods
{
NSMutableArray *filesArray = [[NSMutableArray alloc] init];
// Open the database from the users filessytem
NSString *DBPath = [ClsCommonFunctions GetDatabasePath];
if ([self OpenDBWithPath:DBPath])
{
    // Setup the SQL Statement and compile it for faster access
    const char *sqlStatement = "your query";
    sqlite3_stmt *compiledStatement;
    if(sqlite3_prepare_v2(filesDB, sqlStatement, -1, &compiledStatement, NULL) == SQLITE_OK) {
        while(sqlite3_step(compiledStatement) == SQLITE_ROW) 
        {
            // Need to get data from database...
NSSstring *foodObj = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 0)]
            [filesArray addObject:foodObj];
            FileObj = nil;
        }
    }
    // Release the compiled statement from memory
    sqlite3_finalize(compiledStatement);
    sqlite3_close(filesDB);
}
return filesArray;

最新更新