Sorry for answering myself, but I think I've found the solution after a long search. My problem was use "and" instead of "&" in the query conditions. With the &, everything goes well now.
On Wednesday, January 2, 2013 9:57:51 PM UTC+1, Wonton wrote: > > Hello, > > I have a problem looking for rows in my database. I have a method like > this: > > def getBoughtItems(): > for item in self.allItems: > _itemId = item['itemId'] > rowsItems = self.db(self.db.tableItems.itemId==_itemId) > if rowsItems.count() > 0: > _id = rowsItems.select().first().id > print 'userId='+str(self.userId)+' itemId='+str(_id) > boughtItems = self.db(self.db.boughtItems.userId==self > .userId and self.db.boughtItems.itemId==_id) > if boughtItems.count() == 0: > print '1.NO' > item['bought'] = 'NO' > else: > print '2.YES' > item['bought'] = 'YES' > else: > print '3.NO' > item['bought'] = 'NO' > ... > > > And in my databases I have this: > > In db.auth >> > auth_user.id<https://192.168.1.128:8000/dianaappv1/appadmin/select/db?orderby=auth_user.id>1 > > auth_user.username<https://192.168.1.128:8000/dianaappv1/appadmin/select/db?orderby=auth_user.username>userA > ... > auth_user.id<https://192.168.1.128:8000/dianaappv1/appadmin/select/db?orderby=auth_user.id>2 > > auth_user.username<https://192.168.1.128:8000/dianaappv1/appadmin/select/db?orderby=auth_user.username>userB > ... > > In db.tableItems>> > tableItems.id 1 tableItems.name item1 ... > tableItems.id 2 tableItems.name item2 ... > tableItems.id 3 tableItems.name item3 ... > > In db.boughtItems>> > boughtItems.id 1 boughtItems.userId 1 boughtItems.itemId 1 > boughtItems.id 2 boughtItems.userId 2 boughtItems.itemId 2 > > Well, if I run this method I got this output: > userId=1 itemId=1 > 2.YES > userId=1 itemId=2 > 2.YES > userId=1 itemId=3 > 1.NO > > It seems to me that "self.db(self.db.boughtItems.userId==self.userId and > self.db.boughtItems.itemId==_id)" selects rows taking into accout only > the second condition (self.db.boughtItems.itemId==_id) and not the first > one. > > I'm sure I'm missing something, but I can't find out what it is. Could you > tell me what I am doing wrong? > > Thank you very much and kind regards! > > --