简体   繁体   English

FMDB / Sqlite查询问题

[英]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. 我有一个名为shuffledQuestions的表,其中有2列category_id和question_id都是主键。 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. 我当前的问题是我无法抓住question_id,相反,它只是给了我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. categoryFromCategoryMenu是一个全局字符串,其含义是将其更改为其他内容,但是当我在场景之间传递对象时,它将立即执行。 I've tried changing the categoryFromCategoryMenu variable to just @"Action" incase it was just playing up but I still just get the row id. 我试图将categoryFromCategoryMenu变量更改为@“ Action”,以防它只是在播放,但我仍然只获取行ID。

The only way I can get the question_id column contents is if I remove the category_id from the sqlite query. 我可以获取question_id列内容的唯一方法是从sqlite查询中删除category_id。 but that poses a problem when I have multiple categories there I don't want to select all the question_id's. 但是当我有多个类别时,这会带来一个问题,我不想选择所有的question_id。 just the question_id's from a particular category. 只是特定类别中的question_id。

this is the database http://dl.dropbox.com/u/35218644/Slot1.sqlite 这是数据库http://dl.dropbox.com/u/35218644/Slot1.sqlite

I have it solved. 我解决了。 Someone suggested to make the category_id and question_id not primary keys. 有人建议使category_id和question_id不是主键。

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

because my question_id was a primary key it autoincremented (i think?). 因为我的question_id是主键,所以它会自动递增(我认为?)。 So in actual fact the ascending list of numbers i kept getting wasn't the rowid r 所以实际上,我不断得到的数字升序不是rowid r

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM