FMDB/Sqlite查询问题

发布于 2024-11-28 13:04:00 字数 1005 浏览 1 评论 0原文

我有一个数据库,其中有一个名为 shuffledQuestions 的表,其中有 2 列 Category_id 和 Question_id 都是主键。这是我保存已整理问题的存储列表的地方。我当前的问题是我无法获取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 是一个全局字符串,旨在将其更改为其他内容,但现在当我在场景之间传递对象时它会这样做。我尝试将categoryFromCategoryMenu 变量更改为@“Action”,以防它刚刚播放,但我仍然只获取行ID。

我可以获得 Question_id 列内容的唯一方法是从 sqlite 查询中删除category_id。但是当我有多个类别时,这会带来问题,我不想选择所有的 Question_id。只是question_id 来自特定类别。

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

始终不够爱げ你 2024-12-05 13:04:00

我已经解决了有人建议将category_id和question_id设置为不是主键。

另请阅读:
http://www.sqlite.org/datatypes.html

因为我的 Question_id 是主键自动增量(我认为?)。所以实际上我不断得到的数字升序列表不是 rowid r

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文