FMDB/Sqlite查询问题
我有一个数据库,其中有一个名为 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 来自特定类别。
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我已经解决了有人建议将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