Re: [web2py] Re: db query not working
On 11 Jul 2012, at 8:03 AM, hasan alnator wrote: > Where ?? In the DAL chapter, toward the end of the "Logical operators" section. http://web2py.com/books/default/chapter/29/6#Logical-operators > > On Wed, Jul 11, 2012 at 6:00 PM, Jonathan Lundell wrote: > On 11 Jul 2012, at 7:25 AM, Jonathan Lundell wrote: > > > > On 11 Jul 2012, at 7:19 AM, hasan alnator wrote: > >> ohh thank you Jonathan its working now , but can you tell me why ? i dont > >> understand > > > > web2py overloads & to perform a logical-and role here, but it can't alter > > Python's operator precedence. The & operator has higher precedence than ==, > > unlike the 'and' operator (or the '&&' operator in C). So this: > > > > video = db(db.Videos.Video_Type == "XXX" & db.Videos.Teacher == > > "xx").select(db.Videos.ALL) > > > > evaluates the same as this: > > > > video = db(db.Videos.Video_Type == ("XXX" & db.Videos.Teacher) == > > "xx").select(db.Videos.ALL) > > I added a line to the book pointing this out. >
Re: [web2py] Re: db query not working
Where ?? On Wed, Jul 11, 2012 at 6:00 PM, Jonathan Lundell wrote: > On 11 Jul 2012, at 7:25 AM, Jonathan Lundell wrote: > > > > On 11 Jul 2012, at 7:19 AM, hasan alnator wrote: > >> ohh thank you Jonathan its working now , but can you tell me why ? i > dont understand > > > > web2py overloads & to perform a logical-and role here, but it can't > alter Python's operator precedence. The & operator has higher precedence > than ==, unlike the 'and' operator (or the '&&' operator in C). So this: > > > > video = db(db.Videos.Video_Type == "XXX" & db.Videos.Teacher == > "xx").select(db.Videos.ALL) > > > > evaluates the same as this: > > > > video = db(db.Videos.Video_Type == ("XXX" & db.Videos.Teacher) == > "xx").select(db.Videos.ALL) > > I added a line to the book pointing this out. > > > > > > >> > >> On Wed, Jul 11, 2012 at 5:14 PM, Jonathan Lundell > wrote: > >> On 11 Jul 2012, at 7:09 AM, hasan alnator wrote: > >>> Dear David, > >>> > >>> the '&' is not supported when i use it i get this : > >>> > >>> unsupported operand type(s) for &: 'str' and 'Field' > >>> > >> > >> video = db((db.Videos.Video_Type == "XXX") & (db.Videos.Teacher == > "xx")).select(db.Videos.ALL) > >> > >> > >>> On Wed, Jul 11, 2012 at 1:41 PM, David Marko > wrote: > >>> Should not this ... > >>> video = db(db.Videos.Video_Type == "XXX" and db.Videos.Teacher == > "xx").select(db.Videos.ALL) > >>> > >>> be rather like this? (see and vs. &) > >>> video = db(db.Videos.Video_Type == "XXX" & db.Videos.Teacher == > "xx").select(db.Videos.ALL) > > > > >
Re: [web2py] Re: db query not working
On 11 Jul 2012, at 7:25 AM, Jonathan Lundell wrote: > > On 11 Jul 2012, at 7:19 AM, hasan alnator wrote: >> ohh thank you Jonathan its working now , but can you tell me why ? i dont >> understand > > web2py overloads & to perform a logical-and role here, but it can't alter > Python's operator precedence. The & operator has higher precedence than ==, > unlike the 'and' operator (or the '&&' operator in C). So this: > > video = db(db.Videos.Video_Type == "XXX" & db.Videos.Teacher == > "xx").select(db.Videos.ALL) > > evaluates the same as this: > > video = db(db.Videos.Video_Type == ("XXX" & db.Videos.Teacher) == > "xx").select(db.Videos.ALL) I added a line to the book pointing this out. > > >> >> On Wed, Jul 11, 2012 at 5:14 PM, Jonathan Lundell wrote: >> On 11 Jul 2012, at 7:09 AM, hasan alnator wrote: >>> Dear David, >>> >>> the '&' is not supported when i use it i get this : >>> >>> unsupported operand type(s) for &: 'str' and 'Field' >>> >> >> video = db((db.Videos.Video_Type == "XXX") & (db.Videos.Teacher == >> "xx")).select(db.Videos.ALL) >> >> >>> On Wed, Jul 11, 2012 at 1:41 PM, David Marko wrote: >>> Should not this ... >>> video = db(db.Videos.Video_Type == "XXX" and db.Videos.Teacher == >>> "xx").select(db.Videos.ALL) >>> >>> be rather like this? (see and vs. &) >>> video = db(db.Videos.Video_Type == "XXX" & db.Videos.Teacher == >>> "xx").select(db.Videos.ALL) >
Re: [web2py] Re: db query not working
On 11 Jul 2012, at 7:19 AM, hasan alnator wrote: > ohh thank you Jonathan its working now , but can you tell me why ? i dont > understand web2py overloads & to perform a logical-and role here, but it can't alter Python's operator precedence. The & operator has higher precedence than ==, unlike the 'and' operator (or the '&&' operator in C). So this: video = db(db.Videos.Video_Type == "XXX" & db.Videos.Teacher == "xx").select(db.Videos.ALL) evaluates the same as this: video = db(db.Videos.Video_Type == ("XXX" & db.Videos.Teacher) == "xx").select(db.Videos.ALL) > > On Wed, Jul 11, 2012 at 5:14 PM, Jonathan Lundell wrote: > On 11 Jul 2012, at 7:09 AM, hasan alnator wrote: >> Dear David, >> >> the '&' is not supported when i use it i get this : >> >> unsupported operand type(s) for &: 'str' and 'Field' >> > > video = db((db.Videos.Video_Type == "XXX") & (db.Videos.Teacher == > "xx")).select(db.Videos.ALL) > > >> On Wed, Jul 11, 2012 at 1:41 PM, David Marko wrote: >> Should not this ... >> video = db(db.Videos.Video_Type == "XXX" and db.Videos.Teacher == >> "xx").select(db.Videos.ALL) >> >> be rather like this? (see and vs. &) >> video = db(db.Videos.Video_Type == "XXX" & db.Videos.Teacher == >> "xx").select(db.Videos.ALL) >
Re: [web2py] Re: db query not working
ohh thank you Jonathan its working now , but can you tell me why ? i dont understand On Wed, Jul 11, 2012 at 5:14 PM, Jonathan Lundell wrote: > On 11 Jul 2012, at 7:09 AM, hasan alnator wrote: > > Dear David, > > the '&' is not supported when i use it i get this : > > unsupported operand type(s) for &: 'str' and 'Field' > > > video = db((db.Videos.Video_Type == "XXX") & (db.Videos.Teacher == > "xx")).select(db.Videos.ALL) > > > On Wed, Jul 11, 2012 at 1:41 PM, David Marko wrote: > >> Should not this ... >> video = db(db.Videos.Video_Type == "XXX" and db.Videos.Teacher == >> "xx").select(db.Videos.ALL) >> >> be rather like this? (see and vs. &) >> video = db(db.Videos.Video_Type == "XXX" & db.Videos.Teacher == >> "xx").select(db.Videos.ALL) >> > > > >
Re: [web2py] Re: db query not working
On 11 Jul 2012, at 7:09 AM, hasan alnator wrote: > Dear David, > > the '&' is not supported when i use it i get this : > > unsupported operand type(s) for &: 'str' and 'Field' > video = db((db.Videos.Video_Type == "XXX") & (db.Videos.Teacher == "xx")).select(db.Videos.ALL) > On Wed, Jul 11, 2012 at 1:41 PM, David Marko wrote: > Should not this ... > video = db(db.Videos.Video_Type == "XXX" and db.Videos.Teacher == > "xx").select(db.Videos.ALL) > > be rather like this? (see and vs. &) > video = db(db.Videos.Video_Type == "XXX" & db.Videos.Teacher == > "xx").select(db.Videos.ALL) >
Re: [web2py] Re: db query not working
Dear David, the '&' is not supported when i use it i get this : unsupported operand type(s) for &: 'str' and 'Field' On Wed, Jul 11, 2012 at 1:41 PM, David Marko wrote: > Should not this ... > video = db(db.Videos.Video_Type == "XXX" and db.Videos.Teacher == > "xx").select(db.Videos.ALL) > > be rather like this? (see and vs. &) > video = db(db.Videos.Video_Type == "XXX" & db.Videos.Teacher == > "xx").select(db.Videos.ALL) >