Search code examples
iphonesqlitefmdb

FMDB/Sqlite query problem


I have a database with a table called shuffledQuestions with 2 columns category_id and question_id both are primary keys. It's where I keep a stored list of shuffled questions. My current problem is that I can't grab the question_id, instead it just gives me the rowid.

    FMResultSet * slotQuestionQuery = [SlotDb executeQuery:@"SELECT question_id FROM shuffledQuestions WHERE category_id = ?", categoryFromCategoryMenu];
    while ([slotQuestionQuery next]) {
        //place questions into an array
        int Q = [slotQuestionQuery intForColumn:@"question_id"];
        NSLog(@"Q %d", Q);
        [ShuffledQuestionList addObject:[NSNumber numberWithInt:[slotQuestionQuery intForColumn:@"question_id"]]];
    }

categoryFromCategoryMenu is a global string been meaning to change that to something else but it'll do for now when i'm passing objects between scenes. I've tried changing the categoryFromCategoryMenu variable to just @"Action" incase it was just playing up but I still just get the row id.

The only way I can get the question_id column contents is if I remove the category_id from the sqlite query. but that poses a problem when I have multiple categories there I don't want to select all the question_id's. just the question_id's from a particular category.

this is the database http://dl.dropbox.com/u/35218644/Slot1.sqlite


Solution

  • I have it solved. Someone suggested to make the category_id and question_id not primary keys.

    read this also: http://www.sqlite.org/datatypes.html

    because my question_id was a primary key it autoincremented (i think?). So in actual fact the ascending list of numbers i kept getting wasn't the rowid r